1/* Copyright 2020 Google LLC. All Rights Reserved.
2
3Licensed under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License.
5You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9Unless required by applicable law or agreed to in writing, software
10distributed under the License is distributed on an "AS IS" BASIS,
11WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12See the License for the specific language governing permissions and
13limitations 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
26namespace ruy {
27
28Context::Context() : impl_(new CtxImpl) {}
29Context::~Context() { delete impl_; }
30
31const Ctx& Context::ctx() const { return static_cast<const Ctx&>(*impl_); }
32Ctx* Context::mutable_ctx() { return static_cast<Ctx*>(impl_); }
33
34Path Context::last_used_path() const { return ctx().last_used_path(); }
35Tuning Context::explicit_tuning() const { return ctx().explicit_tuning(); }
36void Context::set_explicit_tuning(Tuning value) {
37 mutable_ctx()->set_explicit_tuning(value);
38}
39const ThreadPool& Context::thread_pool() const { return ctx().thread_pool(); }
40ThreadPool* Context::mutable_thread_pool() {
41 return mutable_ctx()->mutable_thread_pool();
42}
43int Context::max_num_threads() const { return ctx().max_num_threads(); }
44void Context::set_max_num_threads(int value) {
45 mutable_ctx()->set_max_num_threads(value);
46}
47
48void Context::ClearPrepackedCache() { mutable_ctx()->ClearPrepackedCache(); }
49
50bool Context::performance_advisory(PerformanceAdvisory advisory) const {
51 return ctx().performance_advisory(advisory);
52}
53
54void Context::set_runtime_enabled_paths(Path paths) {
55 mutable_ctx()->SetRuntimeEnabledPaths(paths);
56}
57
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