Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / src / include / eltwise_inst.h
1 /*
2 // Copyright (c) 2016-2019 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 ///////////////////////////////////////////////////////////////////////////////////////////////////
18 #pragma once
19 #include "api/CPP/eltwise.hpp"
20 #include "primitive_inst.h"
21 #include <memory>
22 #include "topology_impl.h"
23
24 namespace cldnn
25 {
26 template <>
27 struct typed_program_node<eltwise> : public typed_program_node_base<eltwise>
28 {
29     using parent = typed_program_node_base<eltwise>;
30
31 public:
32     typed_program_node(std::shared_ptr<primitive> prim, program_impl& prog)
33         :parent(prim, prog)
34         , output_qf(get_primitive()->output_quantization_factor)
35         , output_cf(!get_primitive()->output_calibration_factors.empty())
36     {
37     }
38
39
40     program_node& input(size_t idx = 0) const { return get_dependency(idx); }
41     size_t inputs_count() const { return get_dependencies().size() - (output_cf ? 1 : 0); }
42     program_node& output_calibration_factors() const { return get_dependency(inputs_count()); }
43     bool output_calibration_term() const { return !get_primitive()->output_calibration_factors.empty(); }
44     float get_output_qf() const { return output_qf; }
45
46 private:
47     float output_qf;
48     bool output_cf; // to know if we have calibration factors
49 };
50
51 using eltwise_node = typed_program_node<eltwise>;
52
53 template <>
54 class typed_primitive_inst<eltwise> : public typed_primitive_inst_base<eltwise>
55 {
56     using parent = typed_primitive_inst_base<eltwise>;
57     static void check_inputs_count(eltwise_node const &node);
58
59 public:
60     static layout calc_output_layout(eltwise_node const& node);
61     static std::string to_string(eltwise_node const& node);
62
63 public:
64     typed_primitive_inst(network_impl& network, eltwise_node const& node);
65
66     memory_impl& output_calibration_factors_memory() const { return dep_memory(node.inputs_count()); } // because last place should be reserved for calibration factors
67     bool output_calibration_factors_term() const { return node.output_calibration_term(); }
68 };
69
70 using eltwise_inst = typed_primitive_inst<eltwise>;
71
72 }