Compute Library
 21.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 48 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().

50 {
52  ARM_COMPUTE_LOG_PARAMS(src, weights, biases, dst, conv_info, act_info);
53 
54  // Configure direct convolution kernel
55  const ActivationLayerInfo conv2d_act_info = (src->data_layout() == DataLayout::NHWC && is_data_type_float(src->data_type())) ? act_info : ActivationLayerInfo();
56  auto k = std::make_unique<kernels::ClDirectConv2dKernel>();
57  k->set_target(CLScheduler::get().target());
58  k->configure(compile_context, src, weights, biases, dst, conv_info, conv2d_act_info);
59  _direct_conv_kernel = std::move(k);
60 
61  // Configure border handler
62  PixelValue zero_value(0.f);
63  if(is_data_type_quantized_asymmetric(src->data_type()))
64  {
65  zero_value = PixelValue(0, src->data_type(), src->quantization_info());
66  }
67  auto b = std::make_unique<CLFillBorderKernel>();
68  b->configure(compile_context, src, _direct_conv_kernel->border_size(), BorderMode::CONSTANT, zero_value);
69  _src_border_handler = std::move(b);
70 
71  // Fused activation is currently supported for NHWC and floating point types
72  if(act_info.enabled() && !conv2d_act_info.enabled())
73  {
74  auto a = std::make_unique<kernels::ClActivationKernel>();
75  a->configure(compile_context, dst, dst, act_info);
76  _activation_kernel = std::move(a);
77  }
78 
79  // Tune kernels
80  CLScheduler::get().tune_kernel_static(*_direct_conv_kernel);
81 }
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:1003
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:82
bool is_data_type_float(DataType dt)
Check if a given data type is of floating point type.
Definition: Utils.h:961

◆ 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 94 of file ClDirectConv2d.cpp.

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

95 {
96  // Run border handler
97  CLScheduler::get().enqueue_op(*_src_border_handler.get(), tensors, false);
98  // Run direct convolution
99  CLScheduler::get().enqueue_op(*_direct_conv_kernel.get(), tensors, false);
100  // Run activation kernel
101  if(_activation_kernel)
102  {
103  auto act_pack = select_activation_src_dst(tensors);
104  CLScheduler::get().enqueue_op(*_activation_kernel.get(), act_pack, false);
105  }
106 }
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 83 of file ClDirectConv2d.cpp.

References ARM_COMPUTE_RETURN_ON_ERROR, ActivationLayerInfo::enabled(), CLScheduler::get(), ClActivationKernel::validate(), and ClDirectConv2dKernel::validate().

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

85 {
86  ARM_COMPUTE_RETURN_ON_ERROR(kernels::ClDirectConv2dKernel::validate(src, weights, biases, dst, conv_info, ActivationLayerInfo(), CLScheduler::get().target()));
87  if(act_info.enabled())
88  {
90  }
91  return Status{};
92 }
static CLScheduler & get()
Access the scheduler singleton.
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204
static Status validate(const ITensorInfo *src, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *dst, const PadStrideInfo &conv_info, const ActivationLayerInfo &act_info, const GPUTarget target)
Static function to check if given info will lead to a valid configuration.
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: