1 /*******************************************************************************
2 * Copyright 2019 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_BINARIZATION_HPP
18 #define CPU_REF_BINARIZATION_HPP
22 #include "cpu_binarization_pd.hpp"
23 #include "cpu_engine.hpp"
24 #include "type_helpers.hpp"
26 #include "c_types_map.hpp"
32 template <impl::data_type_t src_type>
33 struct ref_binarization_fwd_t: public cpu_primitive_t {
34 struct pd_t: public cpu_binarization_fwd_pd_t {
35 pd_t(engine_t *engine, const binarization_desc_t *adesc,
36 const primitive_attr_t *attr,
37 const binarization_fwd_pd_t *hint_fwd_pd)
38 : cpu_binarization_fwd_pd_t(engine, adesc, attr, hint_fwd_pd) {}
40 DECLARE_COMMON_PD_T("ref:any", ref_binarization_fwd_t);
42 virtual status_t init() override {
43 using namespace prop_kind;
44 assert(engine()->kind() == engine_kind::cpu);
47 && utils::one_of(desc()->prop_kind, forward_training, forward_inference)
48 && utils::everyone_is(src_type, desc()->src_desc.data_type, desc()->weights_desc.data_type,
49 desc()->output_mask_desc.data_type)
50 && utils::everyone_is(data_type::bin, desc()->dst_desc.data_type)
51 && utils::one_of(desc()->alg_kind, mkldnn_binarization_depthwise)
52 && attr()->has_default_values();
53 if (!ok) return status::unimplemented;
55 return status::success;
59 ref_binarization_fwd_t(const pd_t *apd, const input_vector &inputs,
60 const output_vector &outputs)
61 : cpu_primitive_t(apd, inputs, outputs) {}
63 typedef typename prec_traits<src_type>::type src_data_t;
65 virtual void execute(event_t *e) const {
67 e->set_state(event_t::ready);
71 void execute_forward() const;
72 const pd_t *pd() const { return (const pd_t *)primitive_t::pd(); }