Compute Library
 22.11
ClDirectConv2d Class Reference

Basic function to simulate a directly convolution layer. More...

#include <ClDirectConv2d.h>

Collaboration diagram for ClDirectConv2d:
[legend]

Public Member Functions

 ClDirectConv2d ()=default
 
void configure (const CLCompileContext &compile_context, ITensorInfo *src, ITensorInfo *weights, ITensorInfo *biases, ITensorInfo *dst, const PadStrideInfo &conv_info, const ActivationLayerInfo &act_info=ActivationLayerInfo())
 Set the src and dst tensors. More...
 
void run (ITensorPack &tensors) override
 Run the kernels contained in the function. More...
 
- Public Member Functions inherited from ICLOperator
 ICLOperator (IRuntimeContext *ctx=nullptr)
 Constructor. More...
 
 ICLOperator (const ICLOperator &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 ICLOperator (ICLOperator &&)=default
 Default move constructor. More...
 
ICLOperatoroperator= (const ICLOperator &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
ICLOperatoroperator= (ICLOperator &&)=default
 Default move assignment operator. More...
 
void prepare (ITensorPack &constants) override
 Prepare the function for executing. More...
 
MemoryRequirements workspace () const override
 Return the memory requirements required by the workspace. More...
 
- Public Member Functions inherited from IOperator
virtual ~IOperator ()=default
 Destructor. More...
 

Static Public Member Functions

static Status validate (const ITensorInfo *src, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *dst, const PadStrideInfo &conv_info, const ActivationLayerInfo &act_info=ActivationLayerInfo())
 Static function to check if given info will lead to a valid configuration. More...
 

Detailed Description

Basic function to simulate a directly convolution layer.

This function calls the following OpenCL kernels:

  1. CLFillBorderKernel (executed if padding size is different from zero)
  2. opencl::ClDirectConv2d

Definition at line 42 of file ClDirectConv2d.h.

Constructor & Destructor Documentation

◆ ClDirectConv2d()

ClDirectConv2d ( )
default

Member Function Documentation

◆ configure()

void configure ( const CLCompileContext compile_context,
ITensorInfo src,
ITensorInfo weights,
ITensorInfo biases,
ITensorInfo dst,
const PadStrideInfo conv_info,
const ActivationLayerInfo act_info = ActivationLayerInfo() 
)

Set the src and dst tensors.

Parameters
[in]compile_contextThe compile context to be used.
[in]srcSource tensor. 3 lower dimensions represent a single src [width, height, IFM], while every optional dimension from 4 and above represent a batch of srcs. Data types supported: QASYMM8_SIGNED/QASYMM8/F16/F32.
[in]weightsWeights tensor. Weights are 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM]. Data type supported:Same as src.
[in]biasesBiases tensor. Shared biases supported. Biases are 1D tensor with dimensions [OFM]. Data type supported: Should match src data type, except for src of QASYMM8 and QASYMM8_SIGNED type where biases should be of S32 type.
[out]dstDestination tensor. 3 lower dimensions represent a single dst [width, height, OFM], while the rest represent batch of dsts. Data types supported: Same as src.
[in]conv_infoContains padding and stride information described in PadStrideInfo.
[in]act_info(Optional) Activation layer information in case of a fused activation.

Definition at line 68 of file ClDirectConv2d.cpp.

References ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_LOG_PARAMS, arm_compute::test::validation::b, arm_compute::CONSTANT, ITensorInfo::data_layout(), ITensorInfo::data_type(), ActivationLayerInfo::enabled(), CLScheduler::get(), arm_compute::is_data_type_float(), arm_compute::is_data_type_quantized_asymmetric(), arm_compute::test::validation::k, arm_compute::NHWC, ITensorInfo::quantization_info(), and CLScheduler::tune_kernel_static().

70 {
72  ARM_COMPUTE_LOG_PARAMS(src, weights, biases, dst, conv_info, act_info);
73 
74  // Initialize the direct convolution descriptor
75  const DirectConvComputeKernelInfo desc = config_direct_convolution_nhwc(src, weights, conv_info);
76 
77  // Configure direct convolution kernel
78  const ActivationLayerInfo conv2d_act_info = (src->data_layout() == DataLayout::NHWC && is_data_type_float(src->data_type())) ? act_info : ActivationLayerInfo();
79  auto k = std::make_unique<kernels::ClDirectConv2dKernel>();
80  k->set_target(CLScheduler::get().target());
81  k->configure(compile_context, src, weights, biases, dst, conv_info, conv2d_act_info, desc);
82  _direct_conv_kernel = std::move(k);
83 
84  // Configure border handler
85  PixelValue zero_value(0.f);
86  if(is_data_type_quantized_asymmetric(src->data_type()))
87  {
88  zero_value = PixelValue(0, src->data_type(), src->quantization_info());
89  }
90  auto b = std::make_unique<CLFillBorderKernel>();
91  b->configure(compile_context, src, _direct_conv_kernel->border_size(), BorderMode::CONSTANT, zero_value);
92  _src_border_handler = std::move(b);
93 
94  // Fused activation is currently supported for NHWC and floating point types
95  if(act_info.enabled() && !conv2d_act_info.enabled())
96  {
97  auto a = std::make_unique<kernels::ClActivationKernel>();
98  a->configure(compile_context, dst, dst, act_info);
99  _activation_kernel = std::move(a);
100  }
101 
102  // Tune kernels
103  CLScheduler::get().tune_kernel_static(*_direct_conv_kernel);
104 }
SimpleTensor< float > b
Definition: DFT.cpp:157
static CLScheduler & get()
Access the scheduler singleton.
SimpleTensor< float > src
Definition: DFT.cpp:155
bool is_data_type_quantized_asymmetric(DataType dt)
Check if a given data type is of asymmetric quantized type.
Definition: Utils.h:1052
Num samples, height, width, channels.
#define ARM_COMPUTE_LOG_PARAMS(...)
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:157
void tune_kernel_static(ICLKernel &kernel)
Tunes OpenCL kernel.
Definition: CLScheduler.cpp:86
bool is_data_type_float(DataType dt)
Check if a given data type is of floating point type.
Definition: Utils.h:1010

◆ run()

void run ( ITensorPack tensors)
overridevirtual

Run the kernels contained in the function.

Parameters
[in]tensorsVector that contains the tensors to operate on.

Reimplemented from ICLOperator.

Definition at line 120 of file ClDirectConv2d.cpp.

References CLScheduler::enqueue_op(), and CLScheduler::get().

121 {
122  // Run border handler
123  CLScheduler::get().enqueue_op(*_src_border_handler.get(), tensors, false);
124  // Run direct convolution
125  CLScheduler::get().enqueue_op(*_direct_conv_kernel.get(), tensors, false);
126  // Run activation kernel
127  if(_activation_kernel)
128  {
129  auto act_pack = select_activation_src_dst(tensors);
130  CLScheduler::get().enqueue_op(*_activation_kernel.get(), act_pack, false);
131  }
132 }
static CLScheduler & get()
Access the scheduler singleton.
void enqueue_op(ICLKernel &kernel, ITensorPack &tensors, bool flush=true)
Schedule the execution of the passed kernel if possible.

◆ validate()

Status validate ( const ITensorInfo src,
const ITensorInfo weights,
const ITensorInfo biases,
const ITensorInfo dst,
const PadStrideInfo conv_info,
const ActivationLayerInfo act_info = ActivationLayerInfo() 
)
static

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

Similar to ClDirectConv2d::configure()

Returns
a status

Definition at line 106 of file ClDirectConv2d.cpp.

References ARM_COMPUTE_RETURN_ON_ERROR, ActivationLayerInfo::enabled(), and arm_compute::experimental::dynamic_fusion::validate().

Referenced by ClConv2d::get_convolution_method(), CLDirectConvolutionLayer::validate(), and ClConv2d::validate().

108 {
109  // Initialize the direct convolution descriptor
110  const DirectConvComputeKernelInfo desc = config_direct_convolution_nhwc(src, weights, conv_info);
111 
112  ARM_COMPUTE_RETURN_ON_ERROR(kernels::ClDirectConv2dKernel::validate(src, weights, biases, dst, conv_info, ActivationLayerInfo(), desc));
113  if(act_info.enabled())
114  {
116  }
117  return Status{};
118 }
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.
#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
static Status validate(const ITensorInfo *src, const ITensorInfo *dst, const ActivationLayerInfo &act_info)
Static function to check if given info will lead to a valid configuration.

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