ONE - On-device Neural Engine
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
arm_compute::CLPadLayerKernelEx Class Reference

#include <CLPadLayerKernelEx.h>

Collaboration diagram for arm_compute::CLPadLayerKernelEx:

Public Member Functions

 CLPadLayerKernelEx ()
 
 CLPadLayerKernelEx (const CLPadLayerKernelEx &)=delete
 
CLPadLayerKernelExoperator= (const CLPadLayerKernelEx &)=delete
 
 CLPadLayerKernelEx (CLPadLayerKernelEx &&)=default
 
CLPadLayerKernelExoperator= (CLPadLayerKernelEx &&)=default
 
 ~CLPadLayerKernelEx ()=default
 
void configure (const ICLTensor *input, ICLTensor *output, const PaddingList &padding, PixelValue constant_value=PixelValue(), PaddingMode mode=PaddingMode::CONSTANT)
 
void configure (const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output, const PaddingList &padding, PixelValue constant_value=PixelValue(), PaddingMode mode=PaddingMode::CONSTANT)
 
void run (const Window &window, cl::CommandQueue &queue) override
 

Static Public Member Functions

static Status validate (const ITensorInfo *input, const ITensorInfo *output, const PaddingList &padding, PixelValue constant_value=PixelValue(), PaddingMode mode=PaddingMode::CONSTANT)
 

Detailed Description

Interface for the PadLayer function.

Definition at line 51 of file CLPadLayerKernelEx.h.

Constructor & Destructor Documentation

◆ CLPadLayerKernelEx() [1/3]

arm_compute::CLPadLayerKernelEx::CLPadLayerKernelEx ( )

Default constructor

Definition at line 127 of file CLPadLayerKernelEx.cpp.

128 : _input(nullptr), _output(nullptr), _input_start_x(0), _input_start_y(0), _4d_enabled(false)
129{
130}

◆ CLPadLayerKernelEx() [2/3]

arm_compute::CLPadLayerKernelEx::CLPadLayerKernelEx ( const CLPadLayerKernelEx )
delete

Prevent instances of this class from being copied (As this class contains pointers)

◆ CLPadLayerKernelEx() [3/3]

arm_compute::CLPadLayerKernelEx::CLPadLayerKernelEx ( CLPadLayerKernelEx &&  )
default

Allow instances of this class to be moved

◆ ~CLPadLayerKernelEx()

arm_compute::CLPadLayerKernelEx::~CLPadLayerKernelEx ( )
default

Default destructor

References validate().

Member Function Documentation

◆ configure() [1/2]

void arm_compute::CLPadLayerKernelEx::configure ( const CLCompileContext &  compile_context,
const ICLTensor *  input,
ICLTensor *  output,
const PaddingList &  padding,
PixelValue  constant_value = PixelValue(),
PaddingMode  mode = PaddingMode::CONSTANT 
)

Set the input and output tensor.

Parameters
[in]compile_contextThe compile context to be used.
[in]inputSource tensor. Data types supported: All.
[out]outputOutput tensor. Data type supported: same as input
[in]paddingThe padding for each spatial dimension of the input tensor. The pair padding[i] specifies the front and the end padding in the i-th dimension.
[in]constant_value(Optional) Constant value to be used for the padding.
[in]mode(Optional) Controls whether the padding should be filled with constant_value using CONSTANT, or reflect the input, either including the border values (SYMMETRIC) or not (REFLECT).

Definition at line 140 of file CLPadLayerKernelEx.cpp.

143{
144 ARM_COMPUTE_UNUSED(compile_context);
145 // Perform validation step
146 ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
147 ARM_COMPUTE_ERROR_THROW_ON(
148 validate_arguments(input->info(), output->info(), padding, constant_value, mode));
149
150 _input = input;
151 _output = output;
152 _4d_enabled = (mode == PaddingMode::CONSTANT) && (padding.size() > 3);
153
154 // Configure window
155 unsigned int vec_size;
156 auto [error, window] = validate_and_configure_window(input->info(), output->info(), padding,
157 constant_value, mode, vec_size);
158 ARM_COMPUTE_ERROR_THROW_ON(error);
159 ICLKernel::configure_internal(window);
160
161 // Set build options
162 std::string kernel_name = "pad_layer_";
163
164 const DataType &data_type = input->info()->data_type();
165 const unsigned int input_width = input->info()->dimension(0);
166 const unsigned int input_height = input->info()->dimension(1);
167 const unsigned int input_depth = input->info()->dimension(2);
168 const unsigned int pad_x_before = padding.at(0).first;
169 const unsigned int pad_y_before = padding.size() > 1 ? padding.at(1).first : 0;
170 const unsigned int pad_z_before = padding.size() > 2 ? padding.at(2).first : 0;
171 const unsigned int pad_right_start = input_width + pad_x_before;
172
173 _input_start_x = mode == PaddingMode::CONSTANT ? -(pad_x_before % vec_size) : 0;
174 _input_start_y = (mode == PaddingMode::CONSTANT && padding.size() > 1) ? -padding.at(1).first : 0;
175
176 CLBuildOptions build_opts;
177 build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(data_type));
178 build_opts.add_option("-DSELECT_DT=" + get_cl_select_type_from_data_type(data_type));
179 build_opts.add_option("-DVEC_SIZE=" + support::cpp11::to_string(vec_size));
180 build_opts.add_option("-DPAD_X_BEFORE=" + support::cpp11::to_string(pad_x_before));
181 build_opts.add_option("-DSRC_WIDTH=" + support::cpp11::to_string(input_width));
182 if (padding.size() > 1)
183 {
184 build_opts.add_option("-DPAD_Y_BEFORE=" + support::cpp11::to_string(pad_y_before));
185 build_opts.add_option("-DSRC_HEIGHT=" + support::cpp11::to_string(input_height));
186
187 if (padding.size() > 2)
188 {
189 build_opts.add_option("-DPAD_Z_BEFORE=" + support::cpp11::to_string(pad_z_before));
190 build_opts.add_option("-DSRC_DEPTH=" + support::cpp11::to_string(input_depth));
191 }
192 }
193
194 switch (mode)
195 {
196 case PaddingMode::CONSTANT:
197 {
198 kernel_name += "constant";
199
200 build_opts.add_option("-DCONST_VAL=" + string_from_pixel_value(constant_value, data_type));
201 build_opts.add_option_if(pad_x_before >= vec_size,
202 "-DNUM_THREADS_TO_SKIP_X=" +
203 support::cpp11::to_string(pad_x_before / vec_size));
204
205 if (_4d_enabled)
206 {
207 build_opts.add_option("-DPAD_W_BEFORE=" + support::cpp11::to_string(padding.at(3).first));
208 build_opts.add_option("-DSRC_BATCH=" +
209 support::cpp11::to_string(input->info()->dimension(3)));
210 }
211
212 break;
213 }
214 case PaddingMode::SYMMETRIC:
215 case PaddingMode::REFLECT:
216 {
217 kernel_name += "symmetric_reflect";
218
219 const auto is_reflect = static_cast<unsigned int>(mode == PaddingMode::REFLECT);
220
221 const unsigned int pad_x_before_remainder = pad_x_before % vec_size;
222 const unsigned int pad_x_after_remainder = pad_right_start % vec_size;
223 const unsigned int after_pad_fact_x = (2 * input_width + pad_x_before) - is_reflect;
224 const unsigned int output_last_x =
225 ceil_to_multiple(pad_right_start + padding.at(0).second, vec_size);
226
227 build_opts.add_option("-DIS_REFLECT=" + support::cpp11::to_string(is_reflect));
228 build_opts.add_option("-DPAD_X_BEFORE_REMAINDER=" +
229 support::cpp11::to_string(pad_x_before_remainder));
230 build_opts.add_option("-DPAD_X_AFTER_REMAINDER=" +
231 support::cpp11::to_string(pad_x_after_remainder));
232 build_opts.add_option(
233 "-DPAD_X_BEFORE_REMAINDER_REFL=" +
234 support::cpp11::to_string((pad_x_before_remainder + is_reflect) % vec_size));
235 build_opts.add_option(
236 "-DPAD_X_AFTER_REMAINDER_REFL=" +
237 support::cpp11::to_string((pad_x_after_remainder - is_reflect) % vec_size));
238 build_opts.add_option("-DAFTER_PAD_FACT_X=" + support::cpp11::to_string(after_pad_fact_x));
239 build_opts.add_option_if(after_pad_fact_x < output_last_x,
240 "-DAFTER_PAD_REM=" +
241 support::cpp11::to_string(after_pad_fact_x % vec_size));
242
243 break;
244 }
245 default:
246 ARM_COMPUTE_ERROR("Padding mode not supported.");
247 }
248
249 // Create kernel
250 _kernel = static_cast<cl::Kernel>(
251 CLKernelLibraryEx::get().create_kernel(kernel_name, build_opts.options()));
252}
static CLKernelLibraryEx & get()
Get the KernelLibrary singleton.
Kernel create_kernel(const std::string &kernel_name, const StringSet &build_options_set={}) const
Create a kernel from the kernel library.
Severity error(void)
Definition Severity.h:76
DataType
"scalar" value type
Definition DataType.h:27

References arm_compute::CLKernelLibraryEx::create_kernel(), and arm_compute::CLKernelLibraryEx::get().

◆ configure() [2/2]

void arm_compute::CLPadLayerKernelEx::configure ( const ICLTensor *  input,
ICLTensor *  output,
const PaddingList &  padding,
PixelValue  constant_value = PixelValue(),
PaddingMode  mode = PaddingMode::CONSTANT 
)

Set the input and output tensor.

Parameters
[in]inputSource tensor. Data types supported: U8, S8, QASYMM8, QASYMM8_SIGNED, U16, S16, U32, S32, F16, F32.
[out]outputOutput tensor. Data type supported: same as input
[in]paddingThe padding for each spatial dimension of the input tensor. The pair padding[i] specifies the front and the end padding in the i-th dimension.
[in]constant_value(Optional) Constant value to be used for the padding.
[in]mode(Optional) Controls whether the padding should be filled with constant_value using CONSTANT, or reflect the input, either including the border values (SYMMETRIC) or not (REFLECT).

Definition at line 132 of file CLPadLayerKernelEx.cpp.

135{
136 configure(CLKernelLibrary::get().get_compile_context(), input, output, padding, constant_value,
137 mode);
138}
void configure(const ICLTensor *input, ICLTensor *output, const PaddingList &padding, PixelValue constant_value=PixelValue(), PaddingMode mode=PaddingMode::CONSTANT)

References configure().

Referenced by configure().

◆ operator=() [1/2]

CLPadLayerKernelEx & arm_compute::CLPadLayerKernelEx::operator= ( CLPadLayerKernelEx &&  )
default

Allow instances of this class to be moved

◆ operator=() [2/2]

CLPadLayerKernelEx & arm_compute::CLPadLayerKernelEx::operator= ( const CLPadLayerKernelEx )
delete

Prevent instances of this class from being copied (As this class contains pointers)

◆ run()

void arm_compute::CLPadLayerKernelEx::run ( const Window &  window,
cl::CommandQueue &  queue 
)
override

Definition at line 268 of file CLPadLayerKernelEx.cpp.

269{
270 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
271 ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(ICLKernel::window(), window);
272
273 Window win_in = window;
274 win_in.adjust(Window::DimX, _input_start_x, true);
275 win_in.adjust(Window::DimY, _input_start_y, true);
276
277 Window slice_out = window.first_slice_window_3D();
278 Window slice_in = win_in.first_slice_window_3D();
279 unsigned int batch = 0;
280 do
281 {
282 unsigned int idx = 0;
283 add_3D_tensor_argument(idx, _input, slice_in);
284 add_3D_tensor_argument(idx, _output, slice_out);
285 if (_4d_enabled)
286 {
287 add_argument<unsigned int>(idx, batch++);
288 }
289
290 enqueue(queue, *this, slice_out, lws_hint());
291 } while (window.slide_window_slice_3D(slice_out) && win_in.slide_window_slice_3D(slice_in));
292}

◆ validate()

Status arm_compute::CLPadLayerKernelEx::validate ( const ITensorInfo *  input,
const ITensorInfo *  output,
const PaddingList &  padding,
PixelValue  constant_value = PixelValue(),
PaddingMode  mode = PaddingMode::CONSTANT 
)
static

Static function to check if given info will lead to a valid configuration of CLPadLayerKernelEx

Parameters
[in]inputSource tensor info. Data types supported: U8, S8, QASYMM8, QASYMM8_SIGNED, U16, S16, U32, S32, F16, F32.
[in]outputOutput tensor info. Data type supported: same as input
[in]paddingThe padding for each spatial dimension of the input tensor. The pair padding[i] specifies the front and the end padding in the i-th dimension.
[in]constant_value(Optional) Constant value to be used for the padding.
[in]mode(Optional) Controls whether the padding should be filled with constant_value using CONSTANT, or reflect the input, either including the border values (SYMMETRIC) or not (REFLECT).

Definition at line 254 of file CLPadLayerKernelEx.cpp.

257{
258 unsigned int vec_size;
259 ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output, padding, constant_value, mode));
260 ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(),
261 output->clone().get(), padding,
262 constant_value, mode, vec_size)
263 .first);
264
265 return Status{};
266}

Referenced by arm_compute::CLPadLayerEx::validate(), and ~CLPadLayerKernelEx().


The documentation for this class was generated from the following files: