1 | /******************************************************************************* |
2 | * Copyright 2016-2022 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 | #include <string> |
18 | |
19 | #include <assert.h> |
20 | |
21 | #include "c_types_map.hpp" |
22 | #include "engine.hpp" |
23 | |
24 | #if defined(DNNL_ENABLE_ITT_TASKS) |
25 | #include "ittnotify.hpp" |
26 | #endif |
27 | |
28 | #include "primitive.hpp" |
29 | #include "primitive_desc.hpp" |
30 | #include "primitive_exec_types.hpp" |
31 | #include "reorder_pd.hpp" |
32 | #include "scratchpad_debug.hpp" |
33 | #include "stack_checker.hpp" |
34 | #include "stream.hpp" |
35 | #include "utils.hpp" |
36 | |
37 | using namespace dnnl::impl; |
38 | using namespace dnnl::impl::status; |
39 | using namespace dnnl::impl::primitive_kind; |
40 | |
41 | namespace dnnl { |
42 | namespace impl { |
43 | |
44 | nested_scratchpad_t::nested_scratchpad_t(const exec_ctx_t &master_ctx, int key, |
45 | const std::shared_ptr<primitive_t> &nested_p) { |
46 | auto scratchpad = master_ctx.get_scratchpad_grantor(); |
47 | scratchpad_mem_storage_ = scratchpad.get_memory_storage(key); |
48 | grantor_ = utils::make_unique<memory_tracking::grantor_t>( |
49 | nested_p->pd()->scratchpad_registry().grantor( |
50 | scratchpad_mem_storage_.get(), master_ctx)); |
51 | #ifdef DNNL_ENABLE_MEM_DEBUG |
52 | if (scratchpad_debug::is_protect_scratchpad()) { |
53 | scratchpad_debug::protect_scratchpad_buffer( |
54 | grantor_->get_base_storage(), grantor_->get_registry()); |
55 | } |
56 | #endif |
57 | } |
58 | |
59 | #ifdef DNNL_ENABLE_MEM_DEBUG |
60 | nested_scratchpad_t::~nested_scratchpad_t() { |
61 | if (scratchpad_debug::is_protect_scratchpad()) { |
62 | scratchpad_debug::unprotect_scratchpad_buffer( |
63 | grantor_->get_base_storage(), grantor_->get_registry()); |
64 | } |
65 | } |
66 | #else |
67 | nested_scratchpad_t::~nested_scratchpad_t() = default; |
68 | #endif |
69 | |
70 | } // namespace impl |
71 | } // namespace dnnl |
72 | |