1 /*******************************************************************************
2 * Copyright 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_REF_DEPTHWISE_HPP
18 #define CPU_REF_DEPTHWISE_HPP
22 #include "c_types_map.hpp"
23 #include "cpu_depthwise_pd.hpp"
24 #include "cpu_engine.hpp"
25 #include "type_helpers.hpp"
32 struct ref_depthwise_scalar_fwd_t {
34 explicit ref_depthwise_scalar_fwd_t(alg_kind_t alg);
35 float compute_scalar(float s, const float* weights, const float* bias);
41 template <impl::data_type_t data_type>
42 struct ref_depthwise_fwd_t: public cpu_primitive_t {
43 struct pd_t: public cpu_depthwise_fwd_pd_t {
44 pd_t(engine_t *engine, const depthwise_desc_t *adesc,
45 const primitive_attr_t *attr,
46 const depthwise_fwd_pd_t *hint_fwd_pd)
47 : cpu_depthwise_fwd_pd_t(engine, adesc, attr, hint_fwd_pd) {}
49 DECLARE_COMMON_PD_T("ref:any", ref_depthwise_fwd_t);
51 virtual status_t init() override {
52 using namespace prop_kind;
53 assert(engine()->kind() == engine_kind::cpu);
56 && utils::one_of(desc()->prop_kind, forward_training,
58 && utils::everyone_is(data_type, desc()->src_desc.data_type, desc()->dst_desc.data_type)
59 && attr()->has_default_values();
60 if (!ok) return status::unimplemented;
62 return status::success;
66 ref_depthwise_fwd_t(const pd_t *apd, const input_vector &inputs,
67 const output_vector &outputs)
68 : cpu_primitive_t(apd, inputs, outputs) {}
69 typedef typename prec_traits<data_type>::type data_t;
71 virtual void execute(event_t *e) const {
73 e->set_state(event_t::ready);
77 void execute_forward() const;
78 const pd_t *pd() const { return (const pd_t *)primitive_t::pd(); }