1 /* Copyright 2020 Google LLC. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 16 #include "ruy/context.h" 17 18 #include "ruy/ctx.h" 19 #include "ruy/ctx_impl.h" 20 #include "ruy/strategy_controls.h" 21 #include "ruy/path.h" 22 #include "ruy/performance_advisory.h" 23 #include "ruy/prepacked_cache.h" 24 #include "ruy/thread_pool.h" 25 #include "ruy/tune.h" 26 27 namespace ruy { 28 Context()29Context::Context() : impl_(new CtxImpl) {} ~Context()30Context::~Context() { delete impl_; } 31 ctx() const32const Ctx& Context::ctx() const { return static_cast<const Ctx&>(*impl_); } mutable_ctx()33Ctx* Context::mutable_ctx() { return static_cast<Ctx*>(impl_); } 34 last_used_path() const35Path Context::last_used_path() const { return ctx().last_used_path(); } explicit_tuning() const36Tuning Context::explicit_tuning() const { return ctx().explicit_tuning(); } set_explicit_tuning(Tuning value)37void Context::set_explicit_tuning(Tuning value) { 38 mutable_ctx()->set_explicit_tuning(value); 39 } thread_pool() const40const ThreadPool& Context::thread_pool() const { return ctx().thread_pool(); } mutable_thread_pool()41ThreadPool* Context::mutable_thread_pool() { 42 return mutable_ctx()->mutable_thread_pool(); 43 } max_num_threads() const44int Context::max_num_threads() const { return ctx().max_num_threads(); } set_max_num_threads(int value)45void Context::set_max_num_threads(int value) { 46 mutable_ctx()->set_max_num_threads(value); 47 } num_threads_strategy() const48NumThreadsStrategy Context::num_threads_strategy() const { 49 return ctx().num_threads_strategy(); 50 } set_num_threads_strategy(NumThreadsStrategy strategy)51void Context::set_num_threads_strategy(NumThreadsStrategy strategy) { 52 mutable_ctx()->set_num_threads_strategy(strategy); 53 } 54 ClearPrepackedCache()55void Context::ClearPrepackedCache() { mutable_ctx()->ClearPrepackedCache(); } 56 performance_advisory(PerformanceAdvisory advisory) const57bool Context::performance_advisory(PerformanceAdvisory advisory) const { 58 return ctx().performance_advisory(advisory); 59 } 60 set_runtime_enabled_paths(Path paths)61void Context::set_runtime_enabled_paths(Path paths) { 62 mutable_ctx()->SetRuntimeEnabledPaths(paths); 63 } 64 get_runtime_enabled_paths()65Path Context::get_runtime_enabled_paths() { 66 // The `& kAllPaths` hides internal test-only paths. 67 return mutable_ctx()->GetRuntimeEnabledPaths() & ruy::kAllPaths; 68 } 69 70 } // namespace ruy 71