Compute Library
 22.08
ClMulKernel Class Reference

Interface for the pixelwise multiplication kernel. More...

#include <ClMulKernel.h>

Collaboration diagram for ClMulKernel:
[legend]

Public Member Functions

 ClMulKernel ()
 
 ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE (ClMulKernel)
 
void configure (const CLCompileContext &compile_context, ITensorInfo *src1, ITensorInfo *src2, ITensorInfo *dst, float scale, ConvertPolicy overflow_policy, RoundingPolicy rounding_policy, const ActivationLayerInfo &act_info=ActivationLayerInfo())
 Initialise the kernel's src and dst. More...
 
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. More...
 
- Public Member Functions inherited from ICLKernel
 ICLKernel ()
 Constructor. More...
 
cl::Kernel & kernel ()
 Returns a reference to the OpenCL kernel of this object. More...
 
CLKernelType type () const
 Returns the CL kernel type. More...
 
template<typename T >
void add_1D_array_argument (unsigned int &idx, const ICLArray< T > *array, const Strides &strides, unsigned int num_dimensions, const Window &window)
 Add the passed 1D array's parameters to the object's kernel's arguments starting from the index idx. More...
 
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. More...
 
void add_1D_tensor_argument_if (bool cond, 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 if the condition is true. More...
 
void add_2D_tensor_argument (unsigned int &idx, const ICLTensor *tensor, const Window &window)
 Add the passed 2D tensor's parameters to the object's kernel's arguments starting from the index idx. More...
 
void add_2D_tensor_argument_if (bool cond, unsigned int &idx, const ICLTensor *tensor, const Window &window)
 Add the passed 2D tensor's parameters to the object's kernel's arguments starting from the index idx if the condition is true. More...
 
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. More...
 
void add_4D_tensor_argument (unsigned int &idx, const ICLTensor *tensor, const Window &window)
 Add the passed 4D tensor's parameters to the object's kernel's arguments starting from the index idx. More...
 
void add_5D_tensor_argument (unsigned int &idx, const ICLTensor *tensor, const Window &window)
 Add the passed 5D tensor's parameters to the object's kernel's arguments starting from the index idx. More...
 
void add_3d_tensor_nhw_argument (unsigned int &idx, const ICLTensor *tensor)
 Add the passed NHW 3D tensor's parameters to the object's kernel's arguments by passing strides, dimensions and the offset to the first valid element in bytes. More...
 
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, dimensions and the offset to the first valid element in bytes. More...
 
virtual void run (const Window &window, cl::CommandQueue &queue)
 Enqueue the OpenCL kernel to process the given window on the passed OpenCL command queue. More...
 
virtual void run_composite_op (ITensorPack &tensors, const Window &window, cl::CommandQueue &queue, const experimental::dynamic_fusion::ClExecutionDescriptor &exec_desc)
 The execution is carried out through run_op method. But the run_op method needs to be extended to include ClExecutionDescriptor as now LWS GWS tuning will be separated from the IKernel. More...
 
template<typename T >
void add_argument (unsigned int &idx, T value)
 Add the passed parameters to the object's kernel's arguments starting from the index idx. More...
 
void set_lws_hint (const cl::NDRange &lws_hint)
 Set the Local-Workgroup-Size hint. More...
 
cl::NDRange lws_hint () const
 Return the Local-Workgroup-Size hint. More...
 
void set_wbsm_hint (const cl_int &wbsm_hint)
 Set the workgroup batch size modifier hint. More...
 
cl_int wbsm_hint () const
 Return the workgroup batch size modifier hint. More...
 
const std::string & config_id () const
 Get the configuration ID. More...
 
void set_target (GPUTarget target)
 Set the targeted GPU architecture. More...
 
void set_target (cl::Device &device)
 Set the targeted GPU architecture according to the CL device. More...
 
GPUTarget get_target () const
 Get the targeted GPU architecture. More...
 
size_t get_max_workgroup_size ()
 Get the maximum workgroup size for the device the CLKernelLibrary uses. More...
 
template<unsigned int dimension_size>
void add_tensor_argument (unsigned &idx, const ICLTensor *tensor, const Window &window)
 
template<typename T , unsigned int dimension_size>
void add_array_argument (unsigned &idx, const ICLArray< T > *array, const Strides &strides, unsigned int num_dimensions, const Window &window)
 Add the passed array's parameters to the object's kernel's arguments starting from the index idx. More...
 
- Public Member Functions inherited from IKernel
 IKernel ()
 Constructor. More...
 
virtual ~IKernel ()=default
 Destructor. More...
 
virtual bool is_parallelisable () const
 Indicates whether or not the kernel is parallelisable. More...
 
virtual BorderSize border_size () const
 The size of the border for that kernel. More...
 
const Windowwindow () const
 The maximum window the kernel can be executed on. More...
 
bool is_window_configured () const
 Function to check if the embedded window of this kernel has been configured. More...
 

Static Public Member Functions

static Status validate (const ITensorInfo *src1, const ITensorInfo *src2, const ITensorInfo *dst, float scale, ConvertPolicy overflow_policy, RoundingPolicy rounding_policy, const ActivationLayerInfo &act_info=ActivationLayerInfo())
 Static function to check if given info will lead to a valid configuration. More...
 
- Static Public Member Functions inherited from ICLKernel
static constexpr unsigned int num_arguments_per_3d_tensor_nhw ()
 Returns the number of arguments enqueued per NHW 3D Tensor object. More...
 
static constexpr unsigned int num_arguments_per_4d_tensor_nhwc ()
 Returns the number of arguments enqueued per NHWC 4D Tensor object. More...
 
static constexpr unsigned int num_arguments_per_1D_array ()
 Returns the number of arguments enqueued per 1D array object. More...
 
static constexpr unsigned int num_arguments_per_1D_tensor ()
 Returns the number of arguments enqueued per 1D tensor object. More...
 
static constexpr unsigned int num_arguments_per_2D_tensor ()
 Returns the number of arguments enqueued per 2D tensor object. More...
 
static constexpr unsigned int num_arguments_per_3D_tensor ()
 Returns the number of arguments enqueued per 3D tensor object. More...
 
static constexpr unsigned int num_arguments_per_4D_tensor ()
 Returns the number of arguments enqueued per 4D tensor object. More...
 
static cl::NDRange gws_from_window (const Window &window)
 Get the global work size given an execution window. More...
 

Detailed Description

Interface for the pixelwise multiplication kernel.

For binary elementwise ops in-place cannot be enabled by passing nullptr to dst, it can only be enabled by passing either src1 or src2 to dst instead.

Definition at line 42 of file ClMulKernel.h.

Constructor & Destructor Documentation

◆ ClMulKernel()

Definition at line 108 of file ClMulKernel.cpp.

References arm_compute::ELEMENTWISE.

109 {
111 }
Elementwise CL kernel type.
Definition: CLTypes.h:85

Member Function Documentation

◆ ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE()

ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE ( ClMulKernel  )

◆ configure()

void configure ( const CLCompileContext compile_context,
ITensorInfo src1,
ITensorInfo src2,
ITensorInfo dst,
float  scale,
ConvertPolicy  overflow_policy,
RoundingPolicy  rounding_policy,
const ActivationLayerInfo act_info = ActivationLayerInfo() 
)

Initialise the kernel's src and dst.

Valid configurations (Input1,Input2) -> Output :

  • (U8,U8) -> U8
  • (U8,U8) -> S16
  • (U8,S16) -> S16
  • (S16,U8) -> S16
  • (S16,S16) -> S16
  • (S32,S32) -> S32
  • (F16,F16) -> F16
  • (F32,F32) -> F32
  • (QASYMM8,QASYMM8) -> QASYMM8
  • (QASYMM8_SIGNED,QASYMM8_SIGNED) -> QASYMM8_SIGNED
  • (QSYMM16,QSYMM16) -> QSYMM16
  • (QSYMM16,QSYMM16) -> S32
Parameters
[in]compile_contextThe compile context to be used.
[in]src1An src tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/QSYMM16/F16/F32/S32
[in]src2An src tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/QSYMM16/F16/F32/S32
[out]dstThe dst tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/QSYMM16/F16/F32/S32
[in]scaleScale to apply after multiplication. Scale must be positive and its value must be either 1/255 or 1/2^n where n is between 0 and 15.
[in]overflow_policyOverflow policy. Supported overflow policies: Wrap, Saturate
[in]rounding_policyRounding policy. Supported rounding modes: to zero, to nearest even.
[in]act_info(Optional) Activation layer information in case of a fused activation.

Definition at line 113 of file ClMulKernel.cpp.

References ActivationLayerInfo::a(), ActivationLayerInfo::activation(), CLBuildOptions::add_option(), CLBuildOptions::add_option_if(), CLBuildOptions::add_option_if_else(), arm_compute::adjust_vec_size(), ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, arm_compute::auto_init_if_empty(), ActivationLayerInfo::b(), TensorShape::broadcast_shape(), arm_compute::calculate_max_window(), ICloneable< T >::clone(), arm_compute::create_kernel(), ITensorInfo::data_type(), ITensorInfo::dimension(), arm_compute::test::validation::dst, ITensorInfo::element_size(), ActivationLayerInfo::enabled(), arm_compute::F32, arm_compute::float_to_string_with_full_precision(), arm_compute::get_cl_type_from_data_type(), arm_compute::get_padding_info(), arm_compute::has_padding_changed(), arm_compute::is_data_type_float(), arm_compute::is_data_type_quantized(), arm_compute::is_data_type_quantized_asymmetric(), kernel_name, arm_compute::lower_string(), ICLKernel::num_arguments_per_3D_tensor(), UniformQuantizationInfo::offset, CLBuildOptions::options(), ITensorInfo::quantization_info(), arm_compute::S32, UniformQuantizationInfo::scale, arm_compute::string_from_activation_func(), arm_compute::string_from_data_type(), ITensorInfo::tensor_shape(), arm_compute::support::cpp11::to_string(), arm_compute::TO_ZERO, QuantizationInfo::uniform(), arm_compute::cpu::kernels::validate_arguments(), and arm_compute::WRAP.

115 {
116  ARM_COMPUTE_ERROR_ON_NULLPTR(src1, src2, dst);
118  scale, overflow_policy, rounding_policy, act_info));
119 
120  auto padding_info = get_padding_info({ src1, src2, dst });
121 
122  const TensorShape &out_shape = TensorShape::broadcast_shape(src1->tensor_shape(), src2->tensor_shape());
123  auto_init_if_empty(*dst, src1->clone()->set_tensor_shape(out_shape));
124 
125  int scale_int = -1;
126  // Extract sign, exponent and mantissa
127  int exponent = 0;
128  float normalized_mantissa = std::frexp(scale, &exponent);
129  // Use int scaling if factor is equal to 1/2^n for 0 <= n <= 15
130  // frexp returns 0.5 as mantissa which means that the exponent will be in the range of -1 <= e <= 14
131  // Moreover, it will be negative as we deal with 1/2^n
132  if((normalized_mantissa == 0.5f) && (-14 <= exponent) && (exponent <= 1))
133  {
134  // Store the positive exponent. We know that we compute 1/2^n
135  // Additionally we need to subtract 1 to compensate that frexp used a mantissa of 0.5
136  scale_int = std::abs(exponent - 1);
137  }
138 
139  std::string acc_type;
140  // Check if it has float src and dst
141  if(is_data_type_float(src1->data_type()) || is_data_type_float(src2->data_type()))
142  {
143  scale_int = -1;
144  acc_type = (src1->data_type() == DataType::F32 || src2->data_type() == DataType::F32) ? "float" : "half";
145  }
146  else
147  {
148  if(src1->element_size() == 4 || src2->element_size() == 4)
149  {
150  // use 64 bit accumulator for 32-bit input
151  acc_type = "long";
152  }
153  else if(src1->element_size() == 2 || src2->element_size() == 2)
154  {
155  // Use 32-bit accumulator for 16-bit input
156  acc_type = "int";
157  }
158  else
159  {
160  // Use 16-bit accumulator for 8-bit input
161  acc_type = "ushort";
162  }
163  }
164 
165  const bool is_quantized = is_data_type_quantized(src1->data_type());
166  const unsigned int vec_size = adjust_vec_size(16 / dst->element_size(), dst->dimension(0));
167  const unsigned int vec_size_leftover = dst->dimension(0) % vec_size;
168 
169  // Set kernel build options
170  std::string kernel_name = "pixelwise_mul";
171  CLBuildOptions build_opts;
172  build_opts.add_option("-DDATA_TYPE_IN1=" + get_cl_type_from_data_type(src1->data_type()));
173  build_opts.add_option("-DDATA_TYPE_IN2=" + get_cl_type_from_data_type(src2->data_type()));
174  build_opts.add_option("-DDATA_TYPE_OUT=" + get_cl_type_from_data_type(dst->data_type()));
175  build_opts.add_option("-DVEC_SIZE_IN1=" + ((dst->dimension(0) != 1 && src1->dimension(0) == 1) ? "1" : support::cpp11::to_string(vec_size)));
176  build_opts.add_option("-DVEC_SIZE_IN2=" + ((dst->dimension(0) != 1 && src2->dimension(0) == 1) ? "1" : support::cpp11::to_string(vec_size)));
177  build_opts.add_option("-DVEC_SIZE_OUT=" + support::cpp11::to_string(vec_size));
178  build_opts.add_option("-DVEC_SIZE_LEFTOVER=" + support::cpp11::to_string(vec_size_leftover));
179  if(is_quantized && (dst->data_type() != DataType::S32))
180  {
181  const UniformQuantizationInfo iq1_info = src1->quantization_info().uniform();
182  const UniformQuantizationInfo iq2_info = src2->quantization_info().uniform();
183  const UniformQuantizationInfo oq_info = dst->quantization_info().uniform();
184 
185  build_opts.add_option_if(is_data_type_quantized_asymmetric(src1->data_type()),
186  "-DOFFSET_IN1=" + support::cpp11::to_string(iq1_info.offset));
187  build_opts.add_option_if(is_data_type_quantized_asymmetric(src2->data_type()),
188  "-DOFFSET_IN2=" + support::cpp11::to_string(iq2_info.offset));
189  build_opts.add_option_if(is_data_type_quantized_asymmetric(dst->data_type()),
190  "-DOFFSET_OUT=" + support::cpp11::to_string(oq_info.offset));
191  build_opts.add_option("-DSCALE_IN1=" + float_to_string_with_full_precision(iq1_info.scale));
192  build_opts.add_option("-DSCALE_IN2=" + float_to_string_with_full_precision(iq2_info.scale));
193  build_opts.add_option("-DSCALE_OUT=" + float_to_string_with_full_precision(oq_info.scale));
194  kernel_name += "_quantized";
195  }
196  else
197  {
198  kernel_name += (scale_int >= 0) ? "_int" : "_float";
199  build_opts.add_option_if_else(overflow_policy == ConvertPolicy::WRAP || is_data_type_float(dst->data_type()), "-DWRAP", "-DSATURATE");
200  build_opts.add_option_if_else(rounding_policy == RoundingPolicy::TO_ZERO, "-DROUND=_rtz", "-DROUND=_rte");
201  build_opts.add_option("-DACC_DATA_TYPE=" + acc_type);
202  if(act_info.enabled())
203  {
204  build_opts.add_option("-DACTIVATION_TYPE=" + lower_string(string_from_activation_func(act_info.activation())));
205  build_opts.add_option("-DA_VAL=" + float_to_string_with_full_precision(act_info.a()));
206  build_opts.add_option("-DB_VAL=" + float_to_string_with_full_precision(act_info.b()));
207  }
208  }
209 
210  // Check whether it is in_place calculation
211  const bool in_place = (src1 == dst) || (src2 == dst);
212  const bool src1_in_place = in_place && (src1 == dst);
213  build_opts.add_option_if(in_place, "-DIN_PLACE");
214  build_opts.add_option_if(src1_in_place, "-DSRC1_IN_PLACE");
215 
216  // Create kernel
217  _kernel = create_kernel(compile_context, kernel_name, build_opts.options());
218 
219  // Set scale argument
220  unsigned int idx = (in_place ? 2 : 3) * num_arguments_per_3D_tensor(); // Skip the src and dst parameters
221 
222  if(scale_int >= 0 && !is_quantized)
223  {
224  _kernel.setArg(idx++, scale_int);
225  }
226  else
227  {
228  _kernel.setArg(idx++, scale);
229  }
230 
231  Window win = calculate_max_window(*dst, Steps(vec_size));
232  ICLKernel::configure_internal(win);
233 
235 
236  // Set config_id for enabling LWS tuning
237  _config_id = kernel_name;
238  _config_id += "_";
239  _config_id += lower_string(string_from_data_type(dst->data_type()));
240  _config_id += "_";
241  _config_id += support::cpp11::to_string(src1->dimension(0));
242  _config_id += "_";
243  _config_id += support::cpp11::to_string(src1->dimension(1));
244  _config_id += "_";
245  _config_id += support::cpp11::to_string(src1->dimension(2));
246  _config_id += "_";
247  _config_id += support::cpp11::to_string(src2->dimension(0));
248  _config_id += "_";
249  _config_id += support::cpp11::to_string(src2->dimension(1));
250  _config_id += "_";
251  _config_id += support::cpp11::to_string(src2->dimension(2));
252  _config_id += "_";
253  _config_id += support::cpp11::to_string(dst->dimension(0));
254  _config_id += "_";
255  _config_id += support::cpp11::to_string(dst->dimension(1));
256  _config_id += "_";
257  _config_id += support::cpp11::to_string(dst->dimension(2));
258 }
bool is_data_type_quantized(DataType dt)
Check if a given data type is of quantized type.
Definition: Utils.h:1030
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
std::string to_string(T &&value)
Convert integer and float values to string.
1 channel, 1 F32 per channel
static TensorShape broadcast_shape(const Shapes &... shapes)
If shapes are broadcast compatible, return the broadcasted shape.
Definition: TensorShape.h:211
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
const std::string & string_from_activation_func(ActivationLayerInfo::ActivationFunction act)
Translates a given activation function to a string.
Definition: Utils.cpp:163
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:455
std::string lower_string(const std::string &val)
Lower a given string.
Definition: Utils.cpp:351
Status validate_arguments(const ITensorInfo *src, const ITensorInfo *weights, const ITensorInfo *dst, const PadStrideInfo &conv_info)
1 channel, 1 S32 per channel
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.
Definition: CLHelpers.cpp:404
const std::string & string_from_data_type(DataType dt)
Convert a data type identity into a string.
Definition: Utils.cpp:135
static constexpr unsigned int num_arguments_per_3D_tensor()
Returns the number of arguments enqueued per 3D tensor object.
Definition: ICLKernel.h:314
std::string float_to_string_with_full_precision(float val)
Create a string with the float in full precision.
Definition: Utils.h:1124
std::string get_cl_type_from_data_type(const DataType &dt)
Translates a tensor data type to the appropriate OpenCL type.
Definition: CLHelpers.cpp:39
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...
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.
Definition: Utils.cpp:601
bool is_data_type_quantized_asymmetric(DataType dt)
Check if a given data type is of asymmetric quantized type.
Definition: Utils.h:1052
std::unordered_map< const ITensorInfo *, PaddingSize > get_padding_info(std::initializer_list< const ITensorInfo *> infos)
Stores padding information before configuring a kernel.
Definition: Utils.cpp:586
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:157
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&#39;s first dimension, getting rounded down to its closest valid vector size.
Definition: Utils.h:1222
std::string kernel_name
Truncates the least significant values that are lost in operations.
bool is_data_type_float(DataType dt)
Check if a given data type is of floating point type.
Definition: Utils.h:1010

◆ run_op()

void run_op ( ITensorPack tensors,
const Window window,
cl::CommandQueue &  queue 
)
overridevirtual

Enqueue the OpenCL kernel to process the given window on the passed OpenCL command queue.

Note
The queue is not flushed by this method, and therefore the kernel will not have been executed by the time this method returns.
Parameters
[in]tensorsA vector containing the tensors to operato on.
[in]windowRegion on which to execute the kernel. (Must be a valid region of the window returned by window()).
[in,out]queueCommand queue on which to enqueue the kernel.

Reimplemented from ICLKernel.

Definition at line 269 of file ClMulKernel.cpp.

References arm_compute::ACL_DST, arm_compute::ACL_SRC_0, arm_compute::ACL_SRC_1, ICLKernel::add_3D_tensor_argument(), ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_RETURN_ERROR_ON, ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN, ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES, ARM_COMPUTE_RETURN_ERROR_ON_MSG, ARM_COMPUTE_UNUSED, Window::broadcast_if_dimension_le_one(), TensorShape::broadcast_shape(), Window::collapse_if_possible(), TensorShape::collapsed_from(), ITensorInfo::data_type(), Window::DimZ, arm_compute::test::validation::dst, ActivationLayerInfo::enabled(), arm_compute::enqueue(), arm_compute::F16, arm_compute::F32, Window::first_slice_window_3D(), ITensorPack::get_const_tensor(), ITensorPack::get_tensor(), arm_compute::detail::have_different_dimensions(), arm_compute::is_data_type_float(), ICLKernel::lws_hint(), Dimensions< T >::num_dimensions(), arm_compute::test::validation::reference::slice(), Window::slide_window_slice_3D(), ITensorInfo::tensor_shape(), TensorShape::total_size(), ITensorInfo::total_size(), and IKernel::window().

270 {
273 
274  const auto src_0 = utils::cast::polymorphic_downcast<const ICLTensor *>(tensors.get_const_tensor(TensorType::ACL_SRC_0));
275  const auto src_1 = utils::cast::polymorphic_downcast<const ICLTensor *>(tensors.get_const_tensor(TensorType::ACL_SRC_1));
276  auto dst = utils::cast::polymorphic_downcast<ICLTensor *>(tensors.get_tensor(TensorType::ACL_DST));
277 
278  ARM_COMPUTE_ERROR_ON_NULLPTR(src_0, src_1, dst);
279 
280  const TensorShape &in_shape1 = src_0->info()->tensor_shape();
281  const TensorShape &in_shape2 = src_1->info()->tensor_shape();
282  const TensorShape &out_shape = dst->info()->tensor_shape();
283 
284  bool can_collapse = true;
285  if(std::min(in_shape1.total_size(), in_shape2.total_size()) > 1)
286  {
287  can_collapse = (std::min(in_shape1.num_dimensions(), in_shape2.num_dimensions()) > Window::DimZ);
288  for(size_t d = Window::DimZ; can_collapse && (d < out_shape.num_dimensions()); ++d)
289  {
290  can_collapse = (in_shape1[d] == in_shape2[d]);
291  }
292  }
293 
294  bool has_collapsed = false;
295  Window collapsed = can_collapse ? window.collapse_if_possible(ICLKernel::window(), Window::DimZ, &has_collapsed) : window;
296 
297  const TensorShape &in_shape1_collapsed = has_collapsed ? in_shape1.collapsed_from(Window::DimZ) : in_shape1;
298  const TensorShape &in_shape2_collapsed = has_collapsed ? in_shape2.collapsed_from(Window::DimZ) : in_shape2;
299 
300  Window slice = collapsed.first_slice_window_3D();
301  Window slice_input1 = slice.broadcast_if_dimension_le_one(in_shape1_collapsed);
302  Window slice_input2 = slice.broadcast_if_dimension_le_one(in_shape2_collapsed);
303 
304  // Check whether it is in_place calculation
305  const bool in_place = (src_0 == dst) || (src_1 == dst);
306  do
307  {
308  unsigned int idx = 0;
309  add_3D_tensor_argument(idx, src_0, slice_input1);
310  add_3D_tensor_argument(idx, src_1, slice_input2);
311  if(!in_place)
312  {
313  add_3D_tensor_argument(idx, dst, slice);
314  }
315  enqueue(queue, *this, slice, lws_hint());
316 
317  ARM_COMPUTE_UNUSED(collapsed.slide_window_slice_3D(slice_input1));
318  ARM_COMPUTE_UNUSED(collapsed.slide_window_slice_3D(slice_input2));
319  }
320  while(collapsed.slide_window_slice_3D(slice));
321 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
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.
Definition: ICLKernel.cpp:32
cl::NDRange lws_hint() const
Return the Local-Workgroup-Size hint.
Definition: ICLKernel.h:384
void add_3D_tensor_argument(unsigned int &idx, const ICLTensor *tensor, const Window &window)
Add the passed 3D tensor&#39;s parameters to the object&#39;s kernel&#39;s arguments starting from the index idx...
Definition: ICLKernel.h:227
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
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.
Definition: Window.inl:68
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:915
static constexpr size_t DimZ
Alias for dimension 2 also known as Z dimension.
Definition: Window.h:47
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:157
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:201
SimpleTensor< T > slice(const SimpleTensor< T > &src, Coordinates starts, Coordinates ends)

◆ validate()

Status validate ( const ITensorInfo src1,
const ITensorInfo src2,
const ITensorInfo dst,
float  scale,
ConvertPolicy  overflow_policy,
RoundingPolicy  rounding_policy,
const ActivationLayerInfo act_info = ActivationLayerInfo() 
)
static

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

Similar to ClMulKernel::configure()

Returns
a status

Definition at line 260 of file ClMulKernel.cpp.

References ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_RETURN_ON_ERROR, and arm_compute::cpu::kernels::validate_arguments().

Referenced by ClMul::validate().

262 {
263  ARM_COMPUTE_ERROR_ON_NULLPTR(src1, src2, dst);
264  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(src1, src2, dst, scale, overflow_policy, rounding_policy, act_info));
265 
266  return Status{};
267 }
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204
Status validate_arguments(const ITensorInfo *src, const ITensorInfo *weights, const ITensorInfo *dst, const PadStrideInfo &conv_info)
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:157

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