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 | |
28 | Context::Context() : impl_(new CtxImpl) {} |
29 | Context::~Context() { delete impl_; } |
30 | |
31 | const Ctx& Context::ctx() const { return static_cast<const Ctx&>(*impl_); } |
32 | Ctx* Context::mutable_ctx() { return static_cast<Ctx*>(impl_); } |
33 | |
34 | Path Context::last_used_path() const { return ctx().last_used_path(); } |
35 | Tuning Context::explicit_tuning() const { return ctx().explicit_tuning(); } |
36 | void Context::set_explicit_tuning(Tuning value) { |
37 | mutable_ctx()->set_explicit_tuning(value); |
38 | } |
39 | const ThreadPool& Context::thread_pool() const { return ctx().thread_pool(); } |
40 | ThreadPool* Context::mutable_thread_pool() { |
41 | return mutable_ctx()->mutable_thread_pool(); |
42 | } |
43 | int Context::max_num_threads() const { return ctx().max_num_threads(); } |
44 | void Context::set_max_num_threads(int value) { |
45 | mutable_ctx()->set_max_num_threads(value); |
46 | } |
47 | |
48 | void Context::ClearPrepackedCache() { mutable_ctx()->ClearPrepackedCache(); } |
49 | |
50 | bool Context::performance_advisory(PerformanceAdvisory advisory) const { |
51 | return ctx().performance_advisory(advisory); |
52 | } |
53 | |
54 | void Context::set_runtime_enabled_paths(Path paths) { |
55 | mutable_ctx()->SetRuntimeEnabledPaths(paths); |
56 | } |
57 | |
58 | Path 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 |