23.11
|
Go to the documentation of this file.
56 const ITensorInfo *weights,
57 const ITensorInfo *biases,
58 const ITensorInfo *
dst,
61 const DirectConvComputeKernelInfo &desc)
74 "Weights feature map dimension should match the respective src's one");
78 "Export to CLImage is not supported for the input tensor");
80 "Export to CLImage is not supported for the output tensor");
85 "Weights should have same width and height");
87 "Strides larger than 3 not supported for 1x1 convolution.");
91 "Strides larger than 2 not supported for 3x3, 5x5, 9x9 convolution.");
99 "Kernel sizes other than 1x1, 3x3, 5x5 or 9x9 are not supported with quantized data types");
106 "Kernel sizes other than 1x1, 3x3 or 5x5 are not supported with float data types");
113 "Fused activation in NHWC is only supported for floating point.");
115 "M0 can only be greater than 0 and less than or equal to 8");
118 "N0 can only be: 1, 2, 3, 4, 8, and 16");
121 "K0 can only be: 1, 2, 3, 4, 8, and 16");
122 if (desc.export_weights_to_cl_image)
125 "K0 can only be: 4, 8, and 16");
127 "Export to CLImage is not supported for this weight configuration");
131 if (biases !=
nullptr)
142 "Biases size and number of dst feature maps should match");
147 if (
dst->total_size() != 0)
157 const UniformQuantizationInfo iqinfo =
src->quantization_info().uniform();
158 const UniformQuantizationInfo wqinfo = weights->quantization_info().uniform();
159 const UniformQuantizationInfo oqinfo =
dst->quantization_info().uniform();
161 float multiplier = iqinfo.scale * wqinfo.scale / oqinfo.scale;
162 int output_multiplier = 0;
163 int output_shift = 0;
190 const int conv_stride_x = std::get<0>(
conv_info.stride());
191 const int conv_stride_y = std::get<1>(
conv_info.stride());
203 unsigned int _num_elems_processed_per_iteration = 0;
224 _num_elems_processed_per_iteration = 1u;
228 ICLKernel::configure_internal(win);
237 const unsigned int n0 = win.
x().
step();
238 const unsigned int m0 = win.
y().
step();
240 const unsigned int partial_store_n0 =
dst->dimension(
channel_idx) % n0;
241 const unsigned int pad_left =
conv_info.pad_left();
242 const unsigned int pad_top =
conv_info.pad_top();
264 if (biases !=
nullptr)
271 const auto act_function =
act_info.activation();
272 const auto dst_data_type =
dst->data_type();
275 (act_function == ActivationLayerInfo::ActivationFunction::BOUNDED_RELU ||
276 act_function == ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU) &&
289 "-DSRC_TENSOR_TYPE=BUFFER");
298 "-DDST_TENSOR_TYPE=BUFFER");
301 "-DWEI_TENSOR_TYPE=BUFFER");
324 zero_value.
get(zero_value_s32);
327 int output_multiplier = 0;
328 int output_shift = 0;
362 build_options.add_option_if(biases !=
nullptr, std::string(
"-DHAS_BIAS"));
381 std::string(
"-DVEC_SIZE_LEFTOVER=" +
391 int output_multiplier = 0;
392 int output_shift = 0;
473 cl::Image2D weights_cl_image;
474 cl::Image2D output_cl_image;
475 cl::Image2D input_cl_image;
495 unsigned int idx = 0;
498 _kernel.setArg(idx++, input_cl_image);
503 _kernel.setArg(idx++, output_cl_image);
508 _kernel.setArg(idx++, weights_cl_image);
511 if (biases !=
nullptr)
522 if (biases !=
nullptr)
529 _kernel.setArg(idx1++,
static_cast<unsigned int>(weights->info()->strides_in_bytes()[3]));
533 unsigned int idx = 0;
Class to describe a number of elements in each dimension.
@ NCHW
Num samples, channels, height, width.
std::string to_string(T &&value)
Convert integer and float values to string.
void configure(const CLCompileContext &compile_context, ITensorInfo *src, ITensorInfo *weights, ITensorInfo *biases, ITensorInfo *dst, const PadStrideInfo &conv_info, const ActivationLayerInfo &act_info, const DirectConvComputeKernelInfo &desc)
Set the src, weights, biases and dst tensors info.
void add_1D_tensor_argument(unsigned int &idx, const ICLTensor *tensor, const Window &window)
Add the passed 1D tensor's parameters to the object's kernel's arguments starting from the index idx.
SimpleTensor< float > src
bool export_to_cl_image(const ITensorInfo *tensor)
Class describing the value of a pixel for any image format.
DataLayout
[DataLayout enum definition]
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
cl::Image2D create_image2d_from_tensor(const ICLTensor *tensor, CLImage2DType image_type)
Create a cl::Image2D object from a tensor.
@ NHWC
Num samples, height, width, channels.
constexpr int step() const
Return the step of the dimension.
@ QASYMM8
quantized, asymmetric fixed-point 8-bit number unsigned
void get(uint8_t &v) const
Interpret the pixel value as a U8.
std::string lower_string(const std::string &val)
Lower a given string.
Status validate_arguments(const ITensorInfo *src, const ITensorInfo *weights, const ITensorInfo *dst, const PadStrideInfo &conv_info)
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
bool _export_input_to_cl_image
bool export_output_to_cl_image
Flag to export the output to cl_image.
void use_tensor_dimensions(const TensorShape &shape, size_t first_dimension=Window::DimX)
Use the tensor's dimensions to fill the window dimensions.
ITensor * get_tensor(int id)
Get tensor of a given id from the pac.
const std::string & string_from_data_type(DataType dt)
Convert a data type identity into a string.
virtual BorderSize border_size() const
The size of the border for that kernel.
GPUTarget get_target() const
Get the targeted GPU architecture.
int32_t get_ddk_version() const
Return the DDK version.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(...)
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Manages all the OpenCL kernels compilation and caching, provides accessors for the OpenCL Context.
constexpr auto data_layout
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
Activation Layer Information class.
@ DIRECT
Direct Convolution CL kernel type.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
int32_t n0
Number of columns to be processed by the kernel.
std::string get_data_size_from_data_type(const DataType &dt)
Get the size of a data type in number of bits.
const ITensor * get_const_tensor(int id) const
Get constant tensor of a given id.
#define ARM_COMPUTE_ERROR_THROW_ON(status)
bool auto_init_if_empty(ITensorInfo &info, const TensorShape &shape, int num_channels, DataType data_type, QuantizationInfo quantization_info=QuantizationInfo())
Auto initialize the tensor info (shape, number of channels and data type) if the current assignment i...
#define ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED(tensor)
cl::Kernel create_kernel(const CLCompileContext &ctx, const std::string &kernel_name, const std::set< std::string > &build_opts=std::set< std::string >())
Creates an opencl kernel using a compile context.
@ QASYMM8_SIGNED
quantized, asymmetric fixed-point 8-bit number signed
constexpr const Dimension & y() const
Alias to access the second dimension of the window.
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
std::string float_to_string_with_full_precision(float val)
Create a string with the float in full precision.
virtual DataType data_type() const =0
Data type used for each element of the tensor.
void run_op(ITensorPack &tensors, const Window &window, cl::CommandQueue &queue) override
Enqueue the OpenCL kernel to process the given window on the passed OpenCL command queue.
bool slide_window_slice_3D(Window &slice) const
Slide the passed 3D window slice.
int32_t m0
Number of rows to be processed by the kernel.
UniformQuantizationInfo uniform() const
Return per layer quantization info.
void update_padding_for_cl_image(ITensorInfo *tensor)
Update padding required to export the OpenCL buffer to OpenCL image2d.
virtual QuantizationInfo quantization_info() const =0
Get the quantization settings (scale and offset) of the tensor.
Window first_slice_window_3D() const
First 3D slice of the window.
const Window & window() const
The maximum window the kernel can be executed on.
const std::string & string_from_data_layout(DataLayout dl)
Convert a data layout identity into a string.
std::string get_cl_type_from_data_type(const DataType &dt)
Translates a tensor data type to the appropriate OpenCL type.
GPUTarget
Available GPU Targets.
void add_3D_tensor_argument(unsigned int &idx, const ICLTensor *tensor, const Window &window)
Add the passed 3D tensor's parameters to the object's kernel's arguments starting from the index idx.
size_t get_data_layout_dimension_index(const DataLayout &data_layout, const DataLayoutDimension &data_layout_dimension)
Get the index of the given dimension.
void add_4d_tensor_nhwc_argument(unsigned int &idx, const ICLTensor *tensor)
Add the passed NHWC 4D tensor's parameters to the object's kernel's arguments by passing strides,...
Describe a multidimensional execution window.
constexpr static unsigned int num_arguments_per_3D_tensor()
Returns the number of arguments enqueued per 3D tensor object.
#define ARM_COMPUTE_RETURN_ERROR_ON_MSG(cond, msg)
If the condition is true, an error is returned.
Copyright (c) 2017-2023 Arm Limited.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DIMENSIONS(...)
@ F16
16-bit floating-point number
unsigned int adjust_vec_size(unsigned int vec_size, size_t dim0)
Returns the adjusted vector size in case it is less than the input's first dimension,...
bool export_weights_to_cl_image
Flag to export the weights to cl_image.
bool is_data_type_float(DataType dt)
Check if a given data type is of floating point type.
static Status validate(const ITensorInfo *src, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *dst, const PadStrideInfo &conv_info, const ActivationLayerInfo &act_info, const DirectConvComputeKernelInfo &desc)
Static function to check if given info will lead to a valid configuration.
@ S32
signed 32-bit number
cl::NDRange lws_hint() const
Return the Local-Workgroup-Size hint.
bool is_data_type_quantized_asymmetric(DataType dt)
Check if a given data type is of asymmetric quantized type.
Status calculate_quantized_multiplier(float multiplier, int32_t *quant_multiplier, int32_t *shift, bool ignore_epsilon=false)
Calculate quantized representation of multiplier.
const std::string & string_from_activation_func(const ActivationFunction &act)
Translates a given activation function to a string.
bool export_input_to_cl_image
Flag to export the input to cl_image.
bool is_data_type_quantized(DataType dt)
Check if a given data type is of quantized type.
Store the tensor's metadata.
bool _export_output_to_cl_image
@ F32
32-bit floating-point number
TensorShape compute_deep_convolution_shape(const TensorShape &input_shape, DataLayout input_data_layout, const TensorShape &weights_shape, const PadStrideInfo &conv_info)
Calculate the deep convolution shape output shape of a tensor.
bool _export_weights_to_cl_image
int32_t k0
Number of partial accumulations to be processed in a single iteration by the kernel.
constexpr const Dimension & x() const
Alias to access the first dimension of the window.
DataType
Available data types.
SimpleTensor< T > slice(const SimpleTensor< T > &src, Coordinates starts, Coordinates ends)
Compute descriptor used by the direct convolution kernel.
std::set< std::string > build_options
void collapse(size_t n, size_t first=0)
Collapse the first n dimensions.
void enqueue(cl::CommandQueue &queue, ICLKernel &kernel, const Window &window, const cl::NDRange &lws_hint=CLKernelLibrary::get().default_ndrange(), bool use_dummy_work_items=false)
Add the kernel to the command queue with the given window.