1 /*******************************************************************************
2 * Copyright 2016-2018 Intel Corporation
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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 *******************************************************************************/
17 #ifndef CPU_LRN_FWD_PD_HPP
18 #define CPU_LRN_FWD_PD_HPP
22 #include "c_types_map.hpp"
24 #include "cpu_engine.hpp"
25 #include "cpu_memory.hpp"
26 #include "cpu_primitive.hpp"
27 #include "type_helpers.hpp"
34 struct cpu_lrn_fwd_pd_t: public lrn_fwd_pd_t {
35 using cpu_memory_pd_t = cpu_memory_t::pd_t;
37 cpu_lrn_fwd_pd_t(engine_t *engine, const lrn_desc_t *adesc,
38 const primitive_attr_t *attr, const lrn_fwd_pd_t *hint_fwd_pd)
39 : lrn_fwd_pd_t(engine, adesc, attr, hint_fwd_pd)
40 , data_pd_(engine_, &desc_.data_desc), ws_pd_(engine_) {}
41 virtual ~cpu_lrn_fwd_pd_t() {}
43 virtual const cpu_memory_pd_t *src_pd(int index = 0) const override
44 { return index == 0 ? &data_pd_ : nullptr; }
45 virtual const cpu_memory_pd_t *dst_pd(int index = 0) const override
46 { return index == 0 ? &data_pd_ : nullptr; }
47 virtual const cpu_memory_pd_t *workspace_pd(int index = 0) const override
48 { return (index == 0 && !ws_pd_.is_zero()) ? &ws_pd_ : nullptr; }
51 cpu_memory_pd_t data_pd_;
52 cpu_memory_pd_t ws_pd_;
54 virtual status_t init() = 0;
57 struct cpu_lrn_bwd_pd_t: public lrn_bwd_pd_t {
58 using cpu_memory_pd_t = cpu_memory_t::pd_t;
60 cpu_lrn_bwd_pd_t(engine_t *engine, const lrn_desc_t *adesc,
61 const primitive_attr_t *attr, const lrn_fwd_pd_t *hint_fwd_pd)
62 : lrn_bwd_pd_t(engine, adesc, attr, hint_fwd_pd)
63 , data_pd_(engine_, &desc_.data_desc)
64 , diff_data_pd_(engine_, &desc_.diff_data_desc), ws_pd_(engine_) {}
65 virtual ~cpu_lrn_bwd_pd_t() {}
67 virtual const cpu_memory_pd_t *src_pd(int index = 0) const override
68 { return index == 0 ? &data_pd_ : nullptr; }
69 virtual const cpu_memory_pd_t *diff_src_pd(int index = 0) const override
70 { return index == 0 ? &diff_data_pd_ : nullptr; }
71 virtual const cpu_memory_pd_t *diff_dst_pd(int index = 0) const override
72 { return index == 0 ? &diff_data_pd_ : nullptr; }
73 virtual const cpu_memory_pd_t *workspace_pd(int index = 0) const override
74 { return (index == 0 && !ws_pd_.is_zero()) ? &ws_pd_ : nullptr; }
77 cpu_memory_pd_t data_pd_;
78 cpu_memory_pd_t diff_data_pd_;
79 cpu_memory_pd_t ws_pd_;
81 virtual status_t init() = 0;
90 // vim: et ts=4 sw=4 cindent cino^=l0,\:0,N-s