1 | /******************************************************************************* |
2 | * Copyright 2019-2020 Intel Corporation |
3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. |
6 | * You may obtain a copy of the License at |
7 | * |
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | * |
10 | * Unless required by applicable law or agreed to in writing, software |
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. |
15 | *******************************************************************************/ |
16 | |
17 | #ifndef CPU_CPU_STREAM_HPP |
18 | #define CPU_CPU_STREAM_HPP |
19 | |
20 | #include "oneapi/dnnl/dnnl_config.h" |
21 | |
22 | #if DNNL_CPU_RUNTIME == DNNL_RUNTIME_THREADPOOL |
23 | #include "oneapi/dnnl/dnnl_threadpool_iface.hpp" |
24 | #endif |
25 | |
26 | #include "common/c_types_map.hpp" |
27 | #include "common/dnnl_thread.hpp" |
28 | #include "common/stream.hpp" |
29 | |
30 | namespace dnnl { |
31 | namespace impl { |
32 | namespace cpu { |
33 | |
34 | struct cpu_stream_t : public stream_t { |
35 | cpu_stream_t(engine_t *engine, unsigned flags) : stream_t(engine, flags) {} |
36 | virtual ~cpu_stream_t() = default; |
37 | |
38 | dnnl::impl::status_t wait() override { |
39 | // CPU execution is synchronous so return immediately |
40 | return dnnl::impl::status::success; |
41 | } |
42 | |
43 | #if DNNL_CPU_RUNTIME == DNNL_RUNTIME_THREADPOOL |
44 | cpu_stream_t(engine_t *engine, |
45 | dnnl::threadpool_interop::threadpool_iface *threadpool) |
46 | : stream_t(engine, threadpool) {} |
47 | |
48 | void before_exec_hook() override { |
49 | dnnl::threadpool_interop::threadpool_iface *tp; |
50 | auto rc = this->get_threadpool(&tp); |
51 | if (rc == status::success) threadpool_utils::activate_threadpool(tp); |
52 | } |
53 | |
54 | void after_exec_hook() override { |
55 | threadpool_utils::deactivate_threadpool(); |
56 | } |
57 | #endif |
58 | }; |
59 | |
60 | } // namespace cpu |
61 | } // namespace impl |
62 | } // namespace dnnl |
63 | |
64 | #endif |
65 | |