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/path.h" 21 #include "ruy/performance_advisory.h" 22 #include "ruy/prepacked_cache.h" 23 #include "ruy/thread_pool.h" 24 #include "ruy/tune.h" 25 26 namespace ruy { 27 Context()28Context::Context() : impl_(new CtxImpl) {} ~Context()29Context::~Context() { delete impl_; } 30 ctx() const31const Ctx& Context::ctx() const { return static_cast<const Ctx&>(*impl_); } mutable_ctx()32Ctx* Context::mutable_ctx() { return static_cast<Ctx*>(impl_); } 33 last_used_path() const34Path Context::last_used_path() const { return ctx().last_used_path(); } explicit_tuning() const35Tuning Context::explicit_tuning() const { return ctx().explicit_tuning(); } set_explicit_tuning(Tuning value)36void Context::set_explicit_tuning(Tuning value) { 37 mutable_ctx()->set_explicit_tuning(value); 38 } thread_pool() const39const ThreadPool& Context::thread_pool() const { return ctx().thread_pool(); } mutable_thread_pool()40ThreadPool* Context::mutable_thread_pool() { 41 return mutable_ctx()->mutable_thread_pool(); 42 } max_num_threads() const43int Context::max_num_threads() const { return ctx().max_num_threads(); } set_max_num_threads(int value)44void Context::set_max_num_threads(int value) { 45 mutable_ctx()->set_max_num_threads(value); 46 } 47 ClearPrepackedCache()48void Context::ClearPrepackedCache() { mutable_ctx()->ClearPrepackedCache(); } 49 performance_advisory(PerformanceAdvisory advisory) const50bool Context::performance_advisory(PerformanceAdvisory advisory) const { 51 return ctx().performance_advisory(advisory); 52 } 53 set_runtime_enabled_paths(Path paths)54void Context::set_runtime_enabled_paths(Path paths) { 55 mutable_ctx()->SetRuntimeEnabledPaths(paths); 56 } 57 get_runtime_enabled_paths()58Path Context::get_runtime_enabled_paths() { 59 // The `& kAllPaths` hides internal test-only paths. 60 return mutable_ctx()->GetRuntimeEnabledPaths() & ruy::kAllPaths; 61 } 62 63 } // namespace ruy 64