24.02.1
|
Go to the documentation of this file.
52 std::map<ArithmeticOperation, std::string> supported_arithmetic_ops = {
59 std::map<ArithmeticOperation, std::string> supported_sat_arithmetic_ops = {
65 generate_id_for_tuning_common(
const std::string &
kernel_name,
const ITensorInfo &src1,
const ITensorInfo &
dst)
67 std::string config_id;
79 Status validate_in_place_output_shape(
const bool in_place,
80 const bool src1_in_place,
81 const ITensorInfo &src1,
82 const ITensorInfo &src2,
83 const ITensorInfo &
dst,
84 const TensorShape &out_shape)
90 "Wrong shape for dst, cannot do in_place calculation");
95 "Wrong shape for dst");
100 Status validate_arguments_with_float_only_supported_rules(
const ITensorInfo &src1,
101 const ITensorInfo &src2,
102 const ITensorInfo &
dst)
110 const bool in_place = (&src1 == &
dst) || (&src2 == &
dst);
111 const bool src1_in_place = in_place && (&src1 == &
dst);
118 if (
dst.total_size() > 0)
123 validate_in_place_output_shape(in_place, src1_in_place, src1, src2,
dst, out_shape));
129 Status validate_arguments_divide_operation(
const ITensorInfo *src1,
const ITensorInfo *src2,
const ITensorInfo *
dst)
137 const bool in_place = (src1 ==
dst) || (src2 ==
dst);
138 const bool src1_in_place = in_place && (src1 ==
dst);
145 if (
dst->total_size() > 0)
150 validate_in_place_output_shape(in_place, src1_in_place, *src1, *src2, *
dst, out_shape));
157 validate_arguments_with_arithmetic_rules(
const ITensorInfo &src1,
const ITensorInfo &src2,
const ITensorInfo &
dst)
167 const int32_t in1_offset = src1.quantization_info().uniform().offset;
168 const int32_t in2_offset = src2.quantization_info().uniform().offset;
174 const bool in_place = (&src1 == &
dst) || (&src2 == &
dst);
175 const bool src1_in_place = in_place && (&src1 == &
dst);
181 if (
dst.total_size() > 0)
185 "Wrong shape for dst");
187 validate_in_place_output_shape(in_place, src1_in_place, src1, src2,
dst, out_shape));
191 const int32_t
offset =
dst.quantization_info().uniform().offset;
198 CLBuildOptions generate_build_options_with_arithmetic_rules(
const ITensorInfo &src1,
199 const ITensorInfo &src2,
200 const ITensorInfo &
dst,
201 const std::string &operation_string)
203 CLBuildOptions build_opts;
209 build_opts.add_option(
"-DVEC_SIZE_IN1=" +
211 build_opts.add_option(
"-DVEC_SIZE_IN2=" +
214 build_opts.add_option(
"-DVEC_SIZE_LEFTOVER=" +
216 build_opts.add_option(
"-DOP=" + operation_string);
219 const UniformQuantizationInfo iq1info = src1.quantization_info().uniform();
220 const UniformQuantizationInfo iq2info = src2.quantization_info().uniform();
221 const UniformQuantizationInfo oqinfo =
dst.quantization_info().uniform();
230 build_opts.add_option_if(src1.data_type() ==
DataType::S32,
"-DS32");
233 const bool in_place = (&src1 == &
dst) || (&src2 == &
dst);
234 const bool src1_in_place = in_place && (&src1 == &
dst);
235 build_opts.add_option_if(in_place,
"-DIN_PLACE");
236 build_opts.add_option_if(src1_in_place,
"-DSRC1_IN_PLACE");
241 std::pair<Status, Window> configure_window_arithmetic_common(ITensorInfo &
dst)
246 return std::make_pair(Status{}, win);
249 std::pair<Status, Window>
250 validate_and_configure_window_for_arithmetic_operators(ITensorInfo &src1, ITensorInfo &src2, ITensorInfo &
dst)
252 const std::pair<TensorShape, ValidRegion> broadcast_pair =
254 const TensorShape &out_shape = broadcast_pair.first;
258 return configure_window_arithmetic_common(
dst);
261 std::pair<Status, Window>
262 validate_and_configure_window_for_logical_binary_operators(ITensorInfo &src1, ITensorInfo &src2, ITensorInfo &
dst)
264 const std::pair<TensorShape, ValidRegion> broadcast_pair =
266 const TensorShape &out_shape = broadcast_pair.first;
271 return configure_window_arithmetic_common(
dst);
274 std::pair<Status, Window>
275 validate_and_configure_window_for_division(ITensorInfo &src1, ITensorInfo &src2, ITensorInfo &
dst)
277 const std::pair<TensorShape, ValidRegion> broadcast_pair =
279 const TensorShape &out_shape = broadcast_pair.first;
283 return configure_window_arithmetic_common(
dst);
292 void ClElementwiseKernel::configure_common(
const ClCompileContext &compile_context,
298 auto win_config = validate_and_configure_window(*src1, *src2, *
dst);
301 std::string
kernel_name =
"elementwise_operation_" + name();
319 ICLKernel::configure_internal(win_config.second);
337 const TensorShape &in_shape1 = src_0->info()->tensor_shape();
338 const TensorShape &in_shape2 = src_1->info()->tensor_shape();
341 bool can_collapse =
true;
348 can_collapse = (in_shape1[d] == in_shape2[d]);
352 bool has_collapsed =
false;
360 Window slice_src1 =
slice.broadcast_if_dimension_le_one(in_shape1_collapsed);
361 Window slice_src2 =
slice.broadcast_if_dimension_le_one(in_shape2_collapsed);
364 const bool in_place = (src_0 ==
dst) || (src_1 ==
dst);
367 unsigned int idx = 0;
392 configure_common(compile_context, src1, src2,
dst);
409 validate_and_configure_window_for_logical_binary_operators(*src1->
clone(), *src2->
clone(), *
dst->clone())
415 std::string ClLogicalBinaryKernel::name()
431 std::pair<Status, Window>
434 return validate_and_configure_window_for_logical_binary_operators(src1, src2,
dst);
438 ClLogicalBinaryKernel::generate_build_options(
const ITensorInfo &src1,
const ITensorInfo &src2,
const ITensorInfo &
dst)
441 return generate_build_options_with_arithmetic_rules(src1, src2,
dst, name());
444 std::string ClLogicalBinaryKernel::generate_id_for_tuning(
const std::string &
kernel_name,
445 const ITensorInfo &src1,
446 const ITensorInfo &
dst)
467 configure_common(compile_context, input1, input2, output);
482 validate_and_configure_window_for_arithmetic_operators(*input1->
clone(), *input2->
clone(), *output->
clone())
489 std::pair<Status, Window> ClSaturatedArithmeticKernel::validate_and_configure_window(
ITensorInfo &input1,
493 return validate_and_configure_window_for_arithmetic_operators(input1, input2, output);
501 auto build_options = generate_build_options_with_arithmetic_rules(input1, input2, output, name());
506 std::string ClSaturatedArithmeticKernel::generate_id_for_tuning(
const std::string &
kernel_name,
516 std::string ClSaturatedArithmeticKernel::name()
518 return supported_sat_arithmetic_ops[_op];
535 configure_common(compile_context, src1, src2,
dst);
551 validate_and_configure_window_for_division(*src1->
clone(), *src2->
clone(), *
dst->clone()).first);
558 validate_and_configure_window_for_division(*src1->
clone(), *src2->
clone(), *
dst->clone()).first);
564 validate_and_configure_window_for_arithmetic_operators(*src1->
clone(), *src2->
clone(), *
dst->clone())
571 std::pair<Status, Window>
577 return validate_and_configure_window_for_division(src1, src2,
dst);
581 return validate_and_configure_window_for_arithmetic_operators(src1, src2,
dst);
586 ClArithmeticKernel::generate_build_options(
const ITensorInfo &src1,
const ITensorInfo &src2,
const ITensorInfo &
dst)
588 return generate_build_options_with_arithmetic_rules(src1, src2,
dst, name());
590 std::string ClArithmeticKernel::generate_id_for_tuning(
const std::string &
kernel_name,
591 const ITensorInfo &src1,
592 const ITensorInfo &
dst)
597 std::string ClArithmeticKernel::name()
599 return supported_arithmetic_ops[_op];
std::string to_string(T &&value)
Convert integer and float values to string.
static Status validate(ArithmeticOperation op, const ITensorInfo *src1, const ITensorInfo *src2, const ITensorInfo *dst, const ActivationLayerInfo &act_info=ActivationLayerInfo())
Static function to check if given info will lead to a valid configuration.
virtual DataLayout data_layout() const =0
Get the data layout of the tensor.
constexpr unsigned int vector_size_byte_opencl
const StringSet & options() const
Gets the current options list set.
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
@ QASYMM8
quantized, asymmetric fixed-point 8-bit number unsigned
std::string lower_string(const std::string &val)
Lower a given string.
bool set_data_type_if_unknown(ITensorInfo &info, DataType data_type)
Set the data type and number of channels to the specified value if the current data type is unknown.
@ PRELU
y*x if x < 0, x otherwise
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Window collapse_if_possible(const Window &full_window, size_t first, size_t last, bool *has_collapsed=nullptr) const
Collapse the dimensions between first and last if possible.
bool is_data_type_quantized_symmetric(DataType dt)
Check if a given data type is of symmetric quantized type.
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.
ActivationFunction activation() const
Get the type of activation function.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(...)
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
@ QSYMM16
quantized, symmetric fixed-point 16-bit number
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Activation Layer Information class.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
const std::string & config_id() const
Get the configuration ID.
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
const ITensor * get_const_tensor(int id) const
Get constant tensor of a given id.
void configure(const ClCompileContext &compile_context, LogicalOperation op, ITensorInfo *src1, ITensorInfo *src2, ITensorInfo *dst)
Function to configure kernel.
#define ARM_COMPUTE_ERROR_THROW_ON(status)
bool enabled() const
Check if initialised.
void add_option(std::string option)
Adds option to the existing build option list.
void configure(const ClCompileContext &compile_context, ArithmeticOperation op, ITensorInfo *input1, ITensorInfo *input2, ITensorInfo *output, const ConvertPolicy &policy, const ActivationLayerInfo &act_info=ActivationLayerInfo())
Static function to check if given info will lead to a valid configuration of ClSaturatedArithmeticKer...
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
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...
size_t total_size() const
Collapses all dimensions to a single linear total size.
@ U8
unsigned 8-bit number
#define ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED(tensor)
@ S16
signed 16-bit number
bool have_different_dimensions(const Dimensions< T > &dim1, const Dimensions< T > &dim2, unsigned int upper_dim)
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
#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.
#define ARM_COMPUTE_ASSERT(cond)
__global uchar * offset(const Image *img, int x, int y)
Get the pointer position of a Image.
bool slide_window_slice_3D(Window &slice) const
Slide the passed 3D window slice.
void run_op(ITensorPack &tensors, const Window &window, ::cl::CommandQueue &queue) override
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
static std::pair< TensorShape, ValidRegion > broadcast_shape_and_valid_region(const Infos &...infos)
If infos are broadcast compatible tensor info's, return the broadcasted shape and the intersection of...
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.
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.
virtual std::unique_ptr< T > clone() const =0
Provide a clone of the current object of class T.
float a() const
Get the alpha value.
bool set_shape_if_empty(ITensorInfo &info, const TensorShape &shape)
Set the shape to the specified value if the current assignment is empty.
Describe a multidimensional execution window.
@ ELEMENTWISE
Elementwise CL kernel type.
#define ARM_COMPUTE_RETURN_ERROR_ON_MSG(cond, msg)
If the condition is true, an error is returned.
Copyright (c) 2017-2024 Arm Limited.
ConvertPolicy
Policy to handle integer overflow.
@ 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 has_padding_changed(const std::unordered_map< const ITensorInfo *, PaddingSize > &padding_map)
Check if the previously stored padding info has changed after configuring a kernel.
static constexpr size_t DimZ
Alias for dimension 2 also known as Z dimension.
bool is_data_type_float(DataType dt)
Check if a given data type is of floating point type.
@ S32
signed 32-bit number
cl::NDRange lws_hint() const
Return the Local-Workgroup-Size hint.
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
static Status validate(LogicalOperation op, const ITensorInfo *src1, const ITensorInfo *src2, const ITensorInfo *dst)
Static function to check if given info will lead to a valid configuration.
static Status validate(ArithmeticOperation op, const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ConvertPolicy &policy, const ActivationLayerInfo &act_info=ActivationLayerInfo())
Static function to check if given info will lead to a valid configuration.
const std::string & string_from_activation_func(const ActivationFunction &act)
Translates a given activation function to a string.
bool is_data_type_quantized(DataType dt)
Check if a given data type is of quantized type.
Store the tensor's metadata.
@ F32
32-bit floating-point number
static TensorShape broadcast_shape(const Shapes &...shapes)
If shapes are broadcast compatible, return the broadcasted shape.
void configure(const ClCompileContext &compile_context, ArithmeticOperation op, ITensorInfo *src1, ITensorInfo *src2, ITensorInfo *dst, const ActivationLayerInfo &act_info=ActivationLayerInfo())
Static function to check if given info will lead to a valid configuration of ClArithmeticKernel.
TensorShape collapsed_from(size_t start) const
Return a copy with collapsed dimensions starting from a given point.
float b() const
Get the beta value.
unsigned int num_dimensions() const
Returns the effective dimensionality of the tensor.
unsigned int num_elems_processed_per_iteration
std::unordered_map< const ITensorInfo *, PaddingSize > get_padding_info(std::initializer_list< const ITensorInfo * > infos)
Stores padding information before configuring a kernel.
SimpleTensor< T > slice(const SimpleTensor< T > &src, Coordinates starts, Coordinates ends)
LogicalOperation
List of supported logical operations.
std::set< std::string > build_options
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.
ArithmeticOperation
Available element-wise operations.