clDNN
reorder.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/reorder.h"
20 #include "primitive.hpp"
21 #include "memory.hpp"
22 
23 namespace cldnn
24 {
31 
36 struct reorder : public primitive_base<reorder, CLDNN_PRIMITIVE_DESC(reorder)>
37 {
38  CLDNN_DECLATE_PRIMITIVE(reorder)
39 
40 
41  reorder(
46  const primitive_id& id,
47  const primitive_id& input,
48  const layout& output_layout,
49  const std::vector<float>& values_to_subtract = {}
50  )
51  : primitive_base(id, { input }, output_layout.data_padding)
52  , output_format(output_layout.format)
53  , output_data_type(output_layout.data_type)
54  , mean("")
55  , subtract_per_feature(values_to_subtract)
56  {
57  }
58 
65  const primitive_id& id,
66  const primitive_id& input,
67  const layout& output_layout,
68  primitive_id const& mean
69  )
70  : primitive_base(id, { input }, output_layout.data_padding)
71  , output_format(output_layout.format)
72  , output_data_type(output_layout.data_type)
73  , mean(mean)
75  {
76  }
77 
84  const primitive_id& id,
85  const primitive_id& input,
88  const std::vector<float>& values_to_subtract = {},
89  const padding& output_padding = padding()
90  )
94  , mean("")
95  , subtract_per_feature(values_to_subtract)
96  {
97  }
98 
105  const primitive_id& id,
106  const primitive_id& input,
109  primitive_id const& mean,
110  const padding& output_padding = padding()
111  )
115  , mean(mean)
117  {
118  }
119 
121  reorder(const dto* dto)
125  , mean(dto->mean_subtract)
126  , subtract_per_feature(float_arr_to_vector(dto->subtract_per_feature))
127  {
128  }
129 
137  std::vector<float> subtract_per_feature;
138 
139 protected:
140  std::vector<std::reference_wrapper<const primitive_id>> get_dependencies() const override
141  {
142  if (mean.empty())
143  return{};
144  return{ mean };
145  }
146 
147  void update_dto(dto& dto) const override
148  {
149  dto.output_format = static_cast<cldnn_format_type>(output_format.value);
150  dto.output_data_type = static_cast<cldnn_data_type>(output_data_type);
151  dto.mean_subtract = mean.c_str();
152  dto.subtract_per_feature = float_vector_to_arr(subtract_per_feature);
153  }
154 };
158 }
reorder(const primitive_id &id, const primitive_id &input, format output_format, data_types output_data_type, const std::vector< float > &values_to_subtract={}, const padding &output_padding=padding())
Constructs reorder primitive with directly provided mean subtract values.
Definition: reorder.hpp:83
reorder(const primitive_id &id, const primitive_id &input, const layout &output_layout, const std::vector< float > &values_to_subtract={})
Constructs reorder primitive with directly provided mean subtract values.
Definition: reorder.hpp:45
Changes how data is ordered in memory. Value type is not changed & all information is preserved...
Definition: reorder.h:37
Represents data padding information.
Definition: layout.hpp:125
std::vector< float > subtract_per_feature
Array of mean subtract values.
Definition: reorder.hpp:137
cldnn_format_type
Represents memory formats (orders). In CNN most of data is describe as 4 dimensional blocks...
Definition: cldnn.h:233
data_types output_data_type
Requested memory data type.
Definition: reorder.hpp:133
data_types data_type
Data type stored in memory (see. data_types)
Definition: layout.hpp:373
reorder(const primitive_id &id, const primitive_id &input, const layout &output_layout, primitive_id const &mean)
Constructs reorder primitive which takes mean subtract values from another primitive.
Definition: reorder.hpp:64
Changes how data is ordered in memory. Value type is not changed & all information is preserved...
Definition: reorder.hpp:36
data_types
Possible data types could be stored in memory.
Definition: layout.hpp:32
primitive_id mean
Primitive id to get mean subtract values. Ignored if subtract_per_featrue is set. ...
Definition: reorder.hpp:135
const primitive_id id
Primitive&#39;s id.
Definition: primitive.hpp:143
cldnn_data_type
Data type stored in memory.
Definition: cldnn.h:285
format output_format
Requested memory format.
Definition: reorder.hpp:131
padding data_padding
Explicit padding of the memory.
Definition: layout.hpp:382
Represents memory formats (orders). In CNN most of data is described as 4 dimensional blocks...
Definition: tensor.hpp:75
cldnn::format format
Format stored in memory (see. format)
Definition: layout.hpp:376
std::string primitive_id
Unique id of a primitive within a topology.
Definition: primitive.hpp:42
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
Describes memory layout.
Definition: layout.hpp:223
reorder(const dto *dto)
Constructs a copy from basic C API cldnn_reorder_desc.
Definition: reorder.hpp:121
reorder(const primitive_id &id, const primitive_id &input, format output_format, data_types output_data_type, primitive_id const &mean, const padding &output_padding=padding())
Constructs reorder primitive which takes mean subtract values from another primitive.
Definition: reorder.hpp:104