clDNN
deconvolution.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/deconvolution.h"
20 #include "primitive.hpp"
21 
22 namespace cldnn
23 {
30 
34 struct deconvolution : public primitive_base<deconvolution, CLDNN_PRIMITIVE_DESC(deconvolution)>
35 {
36  CLDNN_DECLATE_PRIMITIVE(deconvolution)
37 
38 
48  const primitive_id& id,
49  const primitive_id& input,
50  const std::vector<primitive_id>& weights,
51  const std::vector<primitive_id>& bias,
52  tensor stride = { 1, 1, 1, 1 },
53  tensor input_offset = { 0,0,0,0 },
54  bool with_activation = false,
55  float activation_slp = 0.0f,
56  const padding& output_padding = padding()
57  )
59  , weights(_weights.cpp_ids)
60  , bias(_bias.cpp_ids)
62  , stride(stride)
64  , activation_negative_slope(activation_slp)
65  , with_output_size(false)
66  , _weights(weights)
67  , _bias(bias)
68  {
69  }
70 
80  const primitive_id& id,
81  const primitive_id& input,
82  const std::vector<primitive_id>& weights,
83  tensor stride = { 1, 1, 1, 1 },
84  tensor input_offset = { 0,0,0,0 },
85  bool with_activation = false,
86  float activation_slp = 0.0f,
87  const padding& output_padding = padding()
88  )
89  :primitive_base(id, { input }, output_padding)
90  , weights(_weights.cpp_ids)
91  , bias(_bias.cpp_ids)
93  , stride(stride)
95  , activation_negative_slope(activation_slp)
96  , with_output_size(false)
97  , _weights(weights)
98  , _bias(std::vector<primitive_id>(0))
99  {
100  }
101 
113  const primitive_id& id,
114  const primitive_id& input,
115  const std::vector<primitive_id>& weights,
116  const std::vector<primitive_id>& bias,
117  tensor stride,
119  bool with_activation,
120  float activation_slp,
122  const padding& output_padding = padding()
123  )
125  , weights(_weights.cpp_ids)
126  , bias(_bias.cpp_ids)
128  , stride(stride)
130  , activation_negative_slope(activation_slp)
131  , with_output_size(true)
133  , _weights(weights)
134  , _bias(bias)
135  {
136  }
137 
148  const primitive_id& id,
149  const primitive_id& input,
150  const std::vector<primitive_id>& weights,
151  tensor stride,
153  bool with_activation,
154  float activation_slp,
156  const padding& output_padding = padding()
157  )
159  , weights(_weights.cpp_ids)
160  , bias(_bias.cpp_ids)
162  , stride(stride)
164  , activation_negative_slope(activation_slp)
165  , with_output_size(true)
167  , _weights(weights)
168  , _bias(std::vector<primitive_id>(0))
169  {
170  }
171 
175  , weights(_weights.cpp_ids)
176  , bias(_bias.cpp_ids)
178  , stride(dto->stride)
183  , _weights(dto->weights)
184  , _bias(dto->bias)
185  {
186  if (!dto->split || (weights.size() != bias.size() && bias.size() != 0) || dto->split != weights.size())
187  throw std::invalid_argument("Invalid deconvolution dto: bad split value");
188  }
189 
202  const primitive_id& id,
203  const primitive_id& input,
204  const std::vector<primitive_id>& weights,
205  const std::vector<primitive_id>& bias,
207  tensor stride = { 1, 1, 1, 1 },
208  tensor input_offset = { 0,0,0,0 },
209  bool with_activation = false,
210  float activation_slp = 0.0f,
211  const padding& output_padding = padding()
212  )
213  {
215  activation_slp, output_size, output_padding);
216  }
217 
229  const primitive_id& id,
230  const primitive_id& input,
231  const std::vector<primitive_id>& weights,
233  tensor stride = { 1, 1, 1, 1 },
234  tensor input_offset = { 0,0,0,0 },
235  bool with_activation = false,
236  float activation_slp = 0.0f,
237  const padding& output_padding = padding()
238  )
239  {
241  activation_slp, output_size, output_padding);
242  }
243 
260 
262  int32_t split() const { return static_cast<int32_t>(weights.size()); }
263 
264 protected:
265  primitive_id_arr _weights;
266  primitive_id_arr _bias;
267 
268  std::vector<std::reference_wrapper<const primitive_id>> get_dependencies() const override
269  {
270  std::vector<std::reference_wrapper<const primitive_id>> ret;
271  ret.reserve(weights.size() + bias.size());
272  for (auto& w : weights)
273  ret.push_back(w);
274  for (auto& b : bias)
275  ret.push_back(b);
276 
277  return ret;
278  }
279 
280  void update_dto(dto& dto) const override
281  {
282  dto.weights = _weights.ref();
283  dto.bias = _bias.ref();
284  dto.input_offset = input_offset;
285  dto.split = split();
286  dto.stride = stride;
287  dto.with_activation = with_activation;
288  dto.activation_negative_slope = activation_negative_slope;
289  dto.with_output_size = with_output_size;
290  dto.output_size = output_size;
291  }
292 };
296 }
deconvolution(const primitive_id &id, const primitive_id &input, const std::vector< primitive_id > &weights, tensor stride={ 1, 1, 1, 1 }, tensor input_offset={ 0, 0, 0, 0 }, bool with_activation=false, float activation_slp=0.0f, const padding &output_padding=padding())
Constructs deconvolution primitive (w/o bias).
deconvolution(const primitive_id &id, const primitive_id &input, const std::vector< primitive_id > &weights, const std::vector< primitive_id > &bias, tensor stride, tensor input_offset, bool with_activation, float activation_slp, tensor output_size, const padding &output_padding=padding())
Constructs deconvolution primitive (computes input paddings to match output size).
Performs transposed convolution. Also supports built-in Relu activation available by setting it in ar...
fixed_size_vector_ref bias
List of primitive ids containing bias data.
Represents data padding information.
Definition: layout.hpp:125
tensor stride
Defines shift in input buffer between adjacent calculations of output values.
static deconvolution create_with_output_size(const primitive_id &id, const primitive_id &input, const std::vector< primitive_id > &weights, const std::vector< primitive_id > &bias, tensor output_size, tensor stride={ 1, 1, 1, 1 }, tensor input_offset={ 0, 0, 0, 0 }, bool with_activation=false, float activation_slp=0.0f, const padding &output_padding=padding())
Constructs deconvolution primitive (computes input paddings to match output size).
tensor output_size
User-defined output data size of the primitive (w/o padding).
deconvolution(const primitive_id &id, const primitive_id &input, const std::vector< primitive_id > &weights, const std::vector< primitive_id > &bias, tensor stride={ 1, 1, 1, 1 }, tensor input_offset={ 0, 0, 0, 0 }, bool with_activation=false, float activation_slp=0.0f, const padding &output_padding=padding())
Constructs deconvolution primitive.
deconvolution(const dto *dto)
Constructs a copy from C API cldnn_deconvolution_desc.
N-dimensional vector. Mostly used to represent memory size.
Definition: tensor.hpp:256
Performs transposed convolution. Also supports built-in Relu cldnn_activation_desc available by setti...
Definition: deconvolution.h:36
int32_t split() const
On how many cards split the computation to.
deconvolution(const primitive_id &id, const primitive_id &input, const std::vector< primitive_id > &weights, tensor stride, tensor input_offset, bool with_activation, float activation_slp, tensor output_size, const padding &output_padding=padding())
Constructs deconvolution primitive (w/o bias, computes input paddings to match output size)...
const primitive_id id
Primitive&#39;s id.
Definition: primitive.hpp:143
tensor input_offset
Defines a shift, relative to (0,0) position of the input buffer, where (0,0) point of the deconvoluti...
fixed_size_vector_ref weights
List of primitive ids containing weights data.
float activation_negative_slope
Relu activation slope.
static deconvolution create_with_output_size(const primitive_id &id, const primitive_id &input, const std::vector< primitive_id > &weights, tensor output_size, tensor stride={ 1, 1, 1, 1 }, tensor input_offset={ 0, 0, 0, 0 }, bool with_activation=false, float activation_slp=0.0f, const padding &output_padding=padding())
Constructs deconvolution primitive (w/o bias; computes input paddings to match output size)...
bool with_output_size
Indicates that the primitive has user-defined output size (non-zero value).
std::string primitive_id
Unique id of a primitive within a topology.
Definition: primitive.hpp:42
uint32_t split
On how many cards split the computation to.
Definition: deconvolution.h:46
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
Initialize fields common for all primitives.
Definition: primitive.hpp:64
bool with_activation
Enables Relu activation.