Compute Library
 21.08
CpuDirectConv2dOutputStageKernel Class Reference

Kernel to accumulate the biases, if provided, or downscale in case of quantized input. More...

#include <CpuDirectConv2dOutputStageKernel.h>

Collaboration diagram for CpuDirectConv2dOutputStageKernel:
[legend]

Public Member Functions

 CpuDirectConv2dOutputStageKernel ()=default
 
 ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE (CpuDirectConv2dOutputStageKernel)
 
void configure (ITensorInfo *src, const ITensorInfo *bias=nullptr, ITensorInfo *dst=nullptr, const DirectConvolutionLayerOutputStageKernelInfo &info=DirectConvolutionLayerOutputStageKernelInfo())
 Set the accumulate buffer and the biases of the kernel. More...
 
void run_op (ITensorPack &tensors, const Window &window, const ThreadInfo &info) override
 Execute the kernel on the passed window. More...
 
const char * name () const override
 Name of the kernel. More...
 
- Public Member Functions inherited from ICPPKernel
virtual ~ICPPKernel ()=default
 Default destructor. More...
 
virtual void run (const Window &window, const ThreadInfo &info)
 Execute the kernel on the passed window. More...
 
virtual void run_nd (const Window &window, const ThreadInfo &info, const Window &thread_locator)
 legacy compatibility layer for implemantions which do not support thread_locator In these cases we simply narrow the interface down the legacy version 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 *src, const ITensorInfo *bias=nullptr, const ITensorInfo *dst=nullptr, const DirectConvolutionLayerOutputStageKernelInfo &info=DirectConvolutionLayerOutputStageKernelInfo())
 Static function to check if given info will lead to a valid configuration. More...
 

Detailed Description

Kernel to accumulate the biases, if provided, or downscale in case of quantized input.

Note
We assume bias to be shared
For quantized computations (i.e. src of S32 type) the output data type for auto-initialization must be passed as part of the DirectConvolutionLayerOutputStageKernelInfo.

Definition at line 43 of file CpuDirectConv2dOutputStageKernel.h.

Constructor & Destructor Documentation

◆ CpuDirectConv2dOutputStageKernel()

Member Function Documentation

◆ ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE()

ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE ( CpuDirectConv2dOutputStageKernel  )

◆ configure()

void configure ( ITensorInfo src,
const ITensorInfo bias = nullptr,
ITensorInfo dst = nullptr,
const DirectConvolutionLayerOutputStageKernelInfo info = DirectConvolutionLayerOutputStageKernelInfo() 
)

Set the accumulate buffer and the biases of the kernel.

Parameters
[in,out]srcInput to add the bias to. If dst is not specified then accumulation is done in-place. Data type supported: F16/F32/S32
[in]bias(Optional) The shared bias tensor to add. It must be 1D Tensor. Data type supported: Same as src
[out]dst(Optional) If the dst tensor is specified the accumulation is done out-of-place. (Defaults to nullptr) Note that in-place computation is only supported for F16/F32. For S32 this must not be nullptr. Data type supported: F16/F32 or QASYMM8/QASYMM8_SIGNED if src is S32
[in]info(Optional) DirectConvolutionLayerOutputStageKernel descriptor metadata

Definition at line 387 of file CpuDirectConv2dOutputStageKernel.cpp.

References ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, ARM_COMPUTE_UNUSED, arm_compute::auto_init_if_empty(), arm_compute::calculate_max_window(), ICloneable< T >::clone(), ITensorInfo::data_layout(), ITensorInfo::data_type(), arm_compute::F16, arm_compute::F32, arm_compute::is_data_type_quantized_asymmetric_signed(), arm_compute::NCHW, DirectConvolutionLayerOutputStageKernelInfo::output_data_type, DirectConvolutionLayerOutputStageKernelInfo::result_fixedpoint_multiplier, DirectConvolutionLayerOutputStageKernelInfo::result_offset_after_shift, DirectConvolutionLayerOutputStageKernelInfo::result_shift, and arm_compute::S32.

389 {
390  ARM_COMPUTE_UNUSED(bias);
391  // Perform validation step
393  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(src, bias, dst, info));
394 
395  _func = nullptr;
396  _result_fixedpoint_multiplier = info.result_fixedpoint_multiplier;
397  _result_shift = info.result_shift;
398  _result_offset_after_shift = info.result_offset_after_shift;
399 
400  // Auto-initialize output output if required
401  if(dst != nullptr)
402  {
403  // Work out expected output data type
404  const DataType output_dt = (src->data_type() == DataType::S32) ? info.output_data_type : DataType::S32;
405  // Output tensor auto initialization if not yet initialized
406  auto_init_if_empty(*dst, src->clone()->set_data_type(output_dt));
407  }
408 
409  Window win = calculate_max_window(*src, Steps());
410 
411  ICpuKernel::configure(win);
412 
413  const bool is_qasymm8_signed = (dst != nullptr) ? is_data_type_quantized_asymmetric_signed(dst->data_type()) : false;
414 
415  // Set appropriate function
416  if(src->data_layout() == DataLayout::NCHW)
417  {
418  switch(src->data_type())
419  {
420  case DataType::S32:
421  {
422  if(is_qasymm8_signed)
423  {
424  _func = &output_stage_nchw<int8_t>;
425  }
426  else
427  {
428  _func = &output_stage_nchw<uint8_t>;
429  }
430  break;
431  }
432 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
433  case DataType::F16:
434  {
435  _func = &output_stage_nchw<float16_t>;
436  break;
437  }
438 #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
439  case DataType::F32:
440  {
441  _func = &output_stage_nchw<float>;
442  break;
443  }
444  default:
445  {
446  ARM_COMPUTE_ERROR("Unsupported combination of types among the inputs.");
447  }
448  }
449  }
450  else
451  {
452  switch(src->data_type())
453  {
454  case DataType::S32:
455  {
456  if(is_qasymm8_signed)
457  {
458  _func = &output_stage_nhwc<int8_t>;
459  }
460  else
461  {
462  _func = &output_stage_nhwc<uint8_t>;
463  }
464  break;
465  }
466 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
467  case DataType::F16:
468  {
469  _func = &output_stage_nhwc<float16_t>;
470  break;
471  }
472 #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
473  case DataType::F32:
474  {
475  _func = &output_stage_nhwc<float>;
476  break;
477  }
478  default:
479  {
480  ARM_COMPUTE_ERROR("Unsupported combination of types among the inputs.");
481  }
482  }
483  }
484 }
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
1 channel, 1 F32 per channel
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:455
SimpleTensor< float > src
Definition: DFT.cpp:155
1 channel, 1 F16 per channel
1 channel, 1 S32 per channel
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
bool is_data_type_quantized_asymmetric_signed(DataType dt)
Check if a given data type is of asymmetric quantized signed type.
Definition: Utils.h:1022
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...
Num samples, channels, height, width.
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:157
DataType
Available data types.
Definition: Types.h:77

◆ name()

const char * name ( ) const
overridevirtual

Name of the kernel.

Returns
Kernel name

Implements ICPPKernel.

Definition at line 507 of file CpuDirectConv2dOutputStageKernel.cpp.

508 {
509  return "CpuDirectConv2dOutputStageKernel";
510 }

◆ run_op()

void run_op ( ITensorPack tensors,
const Window window,
const ThreadInfo info 
)
overridevirtual

Execute the kernel on the passed window.

Warning
If is_parallelisable() returns false then the passed window must be equal to window()
Note
The window has to be a region within the window returned by the window() method
The width of the window has to be a multiple of num_elems_processed_per_iteration().
Parameters
[in]tensorsA vector containing the tensors to operate on.
[in]windowRegion on which to execute the kernel. (Must be a region of the window returned by window())
[in]infoInfo about executing thread and CPU.

Reimplemented from ICPPKernel.

Definition at line 493 of file CpuDirectConv2dOutputStageKernel.cpp.

References arm_compute::ACL_DST, arm_compute::ACL_SRC_0, arm_compute::ACL_SRC_1, ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, arm_compute::test::validation::dst, ITensorPack::get_const_tensor(), ITensorPack::get_tensor(), arm_compute::test::validation::src, and IKernel::window().

494 {
498  ARM_COMPUTE_ERROR_ON(_func == nullptr);
499 
500  auto src = tensors.get_tensor(TensorType::ACL_SRC_0);
501  auto bias = tensors.get_const_tensor(TensorType::ACL_SRC_1);
502  auto dst = tensors.get_tensor(TensorType::ACL_DST);
503 
504  (*_func)(src, bias, window, dst, _result_fixedpoint_multiplier, _result_shift, _result_offset_after_shift);
505 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
#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
SimpleTensor< float > src
Definition: DFT.cpp:155
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:915
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:201

◆ validate()

Status validate ( const ITensorInfo src,
const ITensorInfo bias = nullptr,
const ITensorInfo dst = nullptr,
const DirectConvolutionLayerOutputStageKernelInfo info = DirectConvolutionLayerOutputStageKernelInfo() 
)
static

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

Similar to CpuDirectConv2dOutputStageKernel::configure()

Returns
a status

Definition at line 486 of file CpuDirectConv2dOutputStageKernel.cpp.

References ARM_COMPUTE_RETURN_ON_ERROR.

Referenced by CpuDirectConv2d::validate().

488 {
489  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(src, bias, dst, info));
490  return Status{};
491 }
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204
SimpleTensor< float > src
Definition: DFT.cpp:155
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)

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