ONE - On-device Neural Engine
Loading...
Searching...
No Matches
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 126 of file CLPadLayerKernelEx.cpp.

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

◆ 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 139 of file CLPadLayerKernelEx.cpp.

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

134{
135 configure(CLKernelLibrary::get().get_compile_context(), input, output, padding, constant_value,
136 mode);
137}
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 267 of file CLPadLayerKernelEx.cpp.

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

Referenced by package.infer.session::inference().

◆ 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 253 of file CLPadLayerKernelEx.cpp.

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

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


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