clDNN
scale.hpp
1 /*
2 // Copyright (c) 2016 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 
18 #pragma once
19 #include "../C/scale.h"
20 #include "primitive.hpp"
21 
22 namespace cldnn
23 {
30 
44 struct scale : public primitive_base<scale, CLDNN_PRIMITIVE_DESC(scale)>
45 {
46  CLDNN_DECLATE_PRIMITIVE(scale)
47 
48 
49  scale(
53  const primitive_id& id,
54  const primitive_id& input,
55  const primitive_id& scale_input, //should be bfyx or yxfb, where each dimension can be 1, if all dimensions are 1 then this is scalar
56  const padding& output_padding = padding()
57  )
58  :primitive_base(id, { input, scale_input }, output_padding)
59  , bias("")
60  {
61  }
62 
69  const primitive_id& id,
70  const primitive_id& input,
71  const primitive_id& scale_input, //should be bfyx or yxfb, where each dimension can be 1, if all dimensions are 1 then this is scalar
72  const primitive_id& bias, //should be same size as scale_input
73  const padding& output_padding = padding()
74  )
75  :primitive_base(id, { input, scale_input }, output_padding)
76  , bias(bias)
77  {
78  }
79 
81  scale(const dto* dto)
83  , bias(dto->bias)
84  {
85  if (dto->input.size != 2)
86  throw std::invalid_argument("scale dto should contains exactly 2 inputs");
87  }
88 
91 
92 protected:
93  std::vector<std::reference_wrapper<const primitive_id>> get_dependencies() const override
94  {
95  if (bias.empty())
96  return{};
97  else
98  return{ bias };
99  }
100 
101  void update_dto(dto& dto) const override
102  {
103  dto.bias = bias.c_str();
104  }
105 };
109 }
scale(const primitive_id &id, const primitive_id &input, const primitive_id &scale_input, const padding &output_padding=padding())
Constructs scale primitive without adding bias.
Definition: scale.hpp:52
Represents data padding information.
Definition: layout.hpp:125
Performs elementwise product of input and scale_input.
Definition: scale.hpp:44
size_t size
Number of ids in the array.
Definition: cldnn.h:338
scale(const dto *dto)
Constructs a copy from C API cldnn_scale_desc.
Definition: scale.hpp:81
Performs elementwise product of input and scale_input.
Definition: scale.h:46
const primitive_id id
Primitive&#39;s id.
Definition: primitive.hpp:143
scale(const primitive_id &id, const primitive_id &input, const primitive_id &scale_input, const primitive_id &bias, const padding &output_padding=padding())
Constructs scale primitive with optional adding bias.
Definition: scale.hpp:68
std::string primitive_id
Unique id of a primitive within a topology.
Definition: primitive.hpp:42
primitive_id bias
Primitive id containing bias data.
Definition: scale.hpp:90
fixed_size_vector_ref input
List of ids of input primitives.
Definition: primitive.hpp:146
base class for all primitives implementations.
Definition: primitive.hpp:190
padding output_padding
Requested output padding.
Definition: primitive.hpp:149
cldnn_primitive_id_arr input
Input primitives ids.
Definition: scale.h:46