Compute Library
 23.11
CLGEMMConvolutionLayer Class Reference

Basic function to compute the convolution layer. More...

#include <CLGEMMConvolutionLayer.h>

Collaboration diagram for CLGEMMConvolutionLayer:
[legend]

Public Member Functions

 CLGEMMConvolutionLayer (std::shared_ptr< IMemoryManager > memory_manager=nullptr, IWeightsManager *weights_manager=nullptr)
 Constructor. More...
 
 CLGEMMConvolutionLayer (const CLGEMMConvolutionLayer &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 CLGEMMConvolutionLayer (CLGEMMConvolutionLayer &&)=default
 Default move constructor. More...
 
CLGEMMConvolutionLayeroperator= (const CLGEMMConvolutionLayer &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
CLGEMMConvolutionLayeroperator= (CLGEMMConvolutionLayer &&)=default
 Default move assignment operator. More...
 
 ~CLGEMMConvolutionLayer ()
 Default destructor. More...
 
void configure (const ICLTensor *input, const ICLTensor *weights, const ICLTensor *biases, ICLTensor *output, const PadStrideInfo &conv_info, const WeightsInfo &weights_info=WeightsInfo(), const Size2D &dilation=Size2D(1U, 1U), const ActivationLayerInfo &act_info=ActivationLayerInfo(), unsigned int num_groups=1)
 Set the input and output tensors. More...
 
void configure (const CLCompileContext &compile_context, const ICLTensor *input, const ICLTensor *weights, const ICLTensor *biases, ICLTensor *output, const PadStrideInfo &conv_info, const WeightsInfo &weights_info=WeightsInfo(), const Size2D &dilation=Size2D(1U, 1U), const ActivationLayerInfo &act_info=ActivationLayerInfo(), unsigned int num_groups=1)
 Set the input and output tensors. More...
 
void run () override
 Run the kernels contained in the function. More...
 
void prepare () override
 Prepare the function for executing. More...
 
- Public Member Functions inherited from IFunction
virtual ~IFunction ()=default
 Destructor. More...
 

Static Public Member Functions

static Status validate (const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const PadStrideInfo &conv_info, const WeightsInfo &weights_info=WeightsInfo(), const Size2D &dilation=Size2D(1U, 1U), const ActivationLayerInfo &act_info=ActivationLayerInfo(), unsigned int num_groups=1)
 Static function to check if given info will lead to a valid configuration of CLGEMMConvolutionLayer. More...
 

Detailed Description

Basic function to compute the convolution layer.

This function calls the following OpenCL kernels/functions:

  1. opencl::ClGemmConv2d

Definition at line 47 of file CLGEMMConvolutionLayer.h.

Constructor & Destructor Documentation

◆ CLGEMMConvolutionLayer() [1/3]

CLGEMMConvolutionLayer ( std::shared_ptr< IMemoryManager memory_manager = nullptr,
IWeightsManager weights_manager = nullptr 
)

Constructor.

Parameters
[in]memory_manager(Optional) Memory manager.
[in]weights_manager(Optional) Weights manager.

Definition at line 62 of file CLGEMMConvolutionLayer.cpp.

64  : _impl(std::make_unique<Impl>())
65 {
66  _impl->memory_group = MemoryGroup(memory_manager);
67  _impl->weights_manager = weights_manager;
68 }

◆ CLGEMMConvolutionLayer() [2/3]

Prevent instances of this class from being copied (As this class contains pointers)

◆ CLGEMMConvolutionLayer() [3/3]

Default move constructor.

◆ ~CLGEMMConvolutionLayer()

~CLGEMMConvolutionLayer ( )
default

Default destructor.

Member Function Documentation

◆ configure() [1/2]

void configure ( const CLCompileContext compile_context,
const ICLTensor input,
const ICLTensor weights,
const ICLTensor biases,
ICLTensor output,
const PadStrideInfo conv_info,
const WeightsInfo weights_info = WeightsInfo(),
const Size2D dilation = Size2D(1U, 1U),
const ActivationLayerInfo act_info = ActivationLayerInfo(),
unsigned int  num_groups = 1 
)

Set the input and output tensors.

Parameters
[in]compile_contextThe compile context to be used.
[in]inputSource tensor. 3 lower dimensions represent a single input [width, height, IFM], while every optional dimension from 4 and above represent a batch of inputs. Data types supported: QASYMM8/QASYMM8_SIGNED/F16/F32.
[in]weightsWeights tensor. Weights are 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM]. Data type supported: Same as input or QASYMM8/QSYMM8_PER_CHANNEL when input is QASYMM8 or QASYMM8_SIGNED/QSYMM8_PER_CHANNEL when input is QASYMM8_SIGNED.
[in]biasesBiases tensor. Shared biases supported. Biases are 1D tensor with dimensions [OFM]. Data type supported: Should match input data type, except for input of quantized type where biases should be of S32 type.
[out]outputDestination tensor. 3 lower dimensions represent a single output [width, height, OFM], while the rest represent batch of outputs. Data types supported: Same as input.
[in]conv_infoContains padding and stride information described in PadStrideInfo.
[in]weights_infoSpecifies if the weights tensor has been reshaped with CLWeightsReshapeKernel. If this is not part of the fully connected layer the weights tensor has also been transposed with CLGEMMReshapeRHSMatrixKernel. Data type supported: Same as input.
[in]dilation(Optional) Dilation, in elements, across x and y. Defaults to (1, 1).
[in]act_info(Optional) Activation layer information in case of a fused activation.
[in]num_groups(Optional) Number of groups when performing a grouped convolution. num_groups != 1 is only supported for NCHW data layout

Definition at line 86 of file CLGEMMConvolutionLayer.cpp.

96 {
97  ARM_COMPUTE_ERROR_ON_NULLPTR(input, weights, output);
98  _impl->weights = weights;
99  _impl->op = std::make_unique<opencl::ClGemmConv2d>();
100  const Conv2dInfo conv2d_info = Conv2dInfo(conv_info, dilation, act_info, false, num_groups);
101  _impl->op->configure(compile_context, input->info(), weights->info(),
102  (biases != nullptr ? biases->info() : nullptr), output->info(), conv2d_info, weights_info);
103 
104  _impl->run_pack = {{TensorType::ACL_SRC_0, input},
105  {TensorType::ACL_SRC_1, weights},
106  {TensorType::ACL_SRC_2, biases},
107  {TensorType::ACL_DST, output}};
108  _impl->prep_pack = {
109  {TensorType::ACL_SRC_1, weights},
110  {TensorType::ACL_SRC_2, biases},
111  };
112  _impl->aux_mem_req = _impl->op->workspace();
113  _impl->workspace_tensors =
114  manage_workspace<CLTensor>(_impl->aux_mem_req, _impl->memory_group, _impl->run_pack, _impl->prep_pack);
115 }

References arm_compute::ACL_DST, arm_compute::ACL_SRC_0, arm_compute::ACL_SRC_1, arm_compute::ACL_SRC_2, arm_compute::test::validation::act_info, ARM_COMPUTE_ERROR_ON_NULLPTR, arm_compute::test::validation::conv_info, ITensor::info(), arm_compute::test::validation::input, arm_compute::test::validation::num_groups, and arm_compute::test::validation::weights_info.

◆ configure() [2/2]

void configure ( const ICLTensor input,
const ICLTensor weights,
const ICLTensor biases,
ICLTensor output,
const PadStrideInfo conv_info,
const WeightsInfo weights_info = WeightsInfo(),
const Size2D dilation = Size2D(1U, 1U),
const ActivationLayerInfo act_info = ActivationLayerInfo(),
unsigned int  num_groups = 1 
)

Set the input and output tensors.

Valid data layouts:

  • NHWC
  • NCHW

Valid data type configurations:

src0 src1 src2 dst
F16 F16 F16 F16
F32 F32 F32 F32
QASYMM8 QASYMM8 S32 QASYMM8
QASYMM8 QSYMM8_PER_CHANNEL S32 QASYMM8
QASYMM8_SIGNED QASYMM8_SIGNED S32 QASYMM8_SIGNED
QASYMM8_SIGNED QSYMM8_PER_CHANNEL S32 QASYMM8_SIGNED
Parameters
[in]inputSource tensor. 3 lower dimensions represent a single input [width, height, IFM], while every optional dimension from 4 and above represent a batch of inputs. Data types supported: QASYMM8/QASYMM8_SIGNED/F16/F32.
[in]weightsWeights tensor. Weights are 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM]. Data type supported: Same as input or QASYMM8/QSYMM8_PER_CHANNEL when input is QASYMM8 or QASYMM8_SIGNED/QSYMM8_PER_CHANNEL when input is QASYMM8_SIGNED.
[in]biasesBiases tensor. Shared biases supported. Biases are 1D tensor with dimensions [OFM]. Data type supported: Should match input data type, except for input of quantized type where biases should be of S32 type.
[out]outputDestination tensor. 3 lower dimensions represent a single output [width, height, OFM], while the rest represent batch of outputs. Data types supported: Same as input.
[in]conv_infoContains padding and stride information described in PadStrideInfo.
[in]weights_infoSpecifies if the weights tensor has been reshaped with CLWeightsReshapeKernel. If this is not part of the fully connected layer the weights tensor has also been transposed with CLGEMMReshapeRHSMatrixKernel. Data type supported: Same as input.
[in]dilation(Optional) Dilation, in elements, across x and y. Defaults to (1, 1).
[in]act_info(Optional) Activation layer information in case of a fused activation.
[in]num_groups(Optional) Number of groups when performing a grouped convolution. num_groups != 1 is only supported for NCHW data layout

Definition at line 72 of file CLGEMMConvolutionLayer.cpp.

81 {
82  configure(CLKernelLibrary::get().get_compile_context(), input, weights, biases, output, conv_info, weights_info,
83  dilation, act_info, num_groups);
84 }

References arm_compute::test::validation::act_info, arm_compute::test::validation::conv_info, CLKernelLibrary::get(), arm_compute::test::validation::input, arm_compute::test::validation::num_groups, and arm_compute::test::validation::weights_info.

◆ operator=() [1/2]

CLGEMMConvolutionLayer& operator= ( CLGEMMConvolutionLayer &&  )
default

Default move assignment operator.

◆ operator=() [2/2]

CLGEMMConvolutionLayer& operator= ( const CLGEMMConvolutionLayer )
delete

Prevent instances of this class from being copied (As this class contains pointers)

◆ prepare()

void prepare ( )
overridevirtual

Prepare the function for executing.

Any one off pre-processing step required by the function is handled here

Note
Prepare stage might not need all the function's buffers' backing memory to be available in order to execute

Reimplemented from IFunction.

Definition at line 138 of file CLGEMMConvolutionLayer.cpp.

139 {
140  if (!_impl->is_prepared)
141  {
142  _impl->op->prepare(_impl->prep_pack);
143  auto has_reshape =
144  std::find_if(_impl->aux_mem_req.begin(), _impl->aux_mem_req.end(),
145  [](const MemoryInfo &m) -> bool { return m.lifetime == MemoryLifetime::Persistent; });
146 
147  if (has_reshape != std::end(_impl->aux_mem_req))
148  {
149  _impl->weights->mark_as_unused();
150  }
151  else
152  {
153  // Pack the B matrix to be used as the underlying GEMM performs no reshapes
154  _impl->run_pack.add_const_tensor(ACL_SRC_1, _impl->weights);
155  }
156  release_temporaries(_impl->aux_mem_req, _impl->workspace_tensors);
157  _impl->is_prepared = true;
158  }
159 }

References arm_compute::ACL_SRC_1, arm_compute::mlgo::parser::end(), and arm_compute::release_temporaries().

Referenced by CLGEMMConvolutionLayer::run().

◆ run()

void run ( )
overridevirtual

Run the kernels contained in the function.

For CPU kernels:

  • Multi-threading is used for the kernels which are parallelisable.
  • By default std::thread::hardware_concurrency() threads are used.
Note
CPPScheduler::set_num_threads() can be used to manually set the number of threads

For OpenCL kernels:

  • All the kernels are enqueued on the queue associated with CLScheduler.
  • The queue is then flushed.
Note
The function will not block until the kernels are executed. It is the user's responsibility to wait.
Will call prepare() on first run if hasn't been done

Implements IFunction.

Definition at line 131 of file CLGEMMConvolutionLayer.cpp.

132 {
133  prepare();
134  MemoryGroupResourceScope scope_mg(_impl->memory_group);
135  _impl->op->run(_impl->run_pack);
136 }

References CLGEMMConvolutionLayer::prepare().

◆ validate()

Status validate ( const ITensorInfo input,
const ITensorInfo weights,
const ITensorInfo biases,
const ITensorInfo output,
const PadStrideInfo conv_info,
const WeightsInfo weights_info = WeightsInfo(),
const Size2D dilation = Size2D(1U, 1U),
const ActivationLayerInfo act_info = ActivationLayerInfo(),
unsigned int  num_groups = 1 
)
static

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

Parameters
[in]inputSource tensor. 3 lower dimensions represent a single input [width, height, IFM], while every optional dimension from 4 and above represent a batch of inputs. Data types supported: QASYMM8/QASYMM8_SIGNED/F16/F32.
[in]weightsWeights tensor. Weights are 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM]. Data type supported: Same as input or QASYMM8/QSYMM8_PER_CHANNEL when input is QASYMM8 or QASYMM8_SIGNED/QSYMM8_PER_CHANNEL when input is QASYMM8_SIGNED.
[in]biasesBiases tensor. Shared biases supported. Biases are 1D tensor with dimensions [OFM]. Data type supported: Should match input data type, except for input of quantized type where biases should be of S32 type.
[out]outputDestination tensor. 3 lower dimensions represent a single output [width, height, OFM], while the rest represent batch of outputs. Data types supported: Same as input.
[in]conv_infoContains padding and stride information described in PadStrideInfo.
[in]weights_infoSpecifies if the weights tensor has been reshaped with CLWeightsReshapeKernel. If this is not part of the fully connected layer the weights tensor has also been transposed with CLGEMMReshapeRHSMatrixKernel. Data type supported: Same as input.
[in]dilation(Optional) Dilation, in elements, across x and y. Defaults to (1, 1).
[in]act_info(Optional) Activation layer information in case of a fused activation.
[in]num_groups(Optional) Number of groups when performing a grouped convolution. num_groups != 1 is only supported for NCHW data layout
Returns
a status

Definition at line 117 of file CLGEMMConvolutionLayer.cpp.

126 {
127  const Conv2dInfo conv2d_info = Conv2dInfo(conv_info, dilation, act_info, false, num_groups);
128  return opencl::ClGemmConv2d::validate(input, weights, biases, output, conv2d_info, weights_info);
129 }

References arm_compute::test::validation::act_info, arm_compute::test::validation::conv_info, arm_compute::test::validation::input, arm_compute::test::validation::num_groups, ClGemmConv2d::validate(), and arm_compute::test::validation::weights_info.


The documentation for this class was generated from the following files:
arm_compute::test::validation::weights_info
weights_info
Definition: BatchNormalizationLayer.cpp:165
arm_compute::ACL_SRC_0
@ ACL_SRC_0
Definition: Types.h:45
arm_compute::CLGEMMConvolutionLayer::configure
void configure(const ICLTensor *input, const ICLTensor *weights, const ICLTensor *biases, ICLTensor *output, const PadStrideInfo &conv_info, const WeightsInfo &weights_info=WeightsInfo(), const Size2D &dilation=Size2D(1U, 1U), const ActivationLayerInfo &act_info=ActivationLayerInfo(), unsigned int num_groups=1)
Set the input and output tensors.
Definition: CLGEMMConvolutionLayer.cpp:72
arm_compute::ACL_SRC_1
@ ACL_SRC_1
Definition: Types.h:46
arm_compute::CLKernelLibrary::get
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
Definition: CLKernelLibrary.cpp:41
arm_compute::ACL_SRC_2
@ ACL_SRC_2
Definition: Types.h:47
arm_compute::CLGEMMConvolutionLayer::prepare
void prepare() override
Prepare the function for executing.
Definition: CLGEMMConvolutionLayer.cpp:138
arm_compute::test::validation::act_info
act_info
Definition: DirectConvolutionLayer.cpp:547
ARM_COMPUTE_ERROR_ON_NULLPTR
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:159
arm_compute::experimental::MemoryInfo
Definition: Types.h:91
arm_compute::release_temporaries
void release_temporaries(const experimental::MemoryRequirements &mem_reqs, WorkspaceData< TensorType > &workspace)
Utility function to release tensors with lifetime marked as Prepare.
Definition: MemoryHelpers.h:122
arm_compute::ACL_DST
@ ACL_DST
Definition: Types.h:55
arm_compute::opencl::ClGemmConv2d::validate
static Status validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const Conv2dInfo &conv2d_info, const WeightsInfo &weights_info=WeightsInfo())
Static function to check if given info will lead to a valid configuration.
Definition: ClGemmConv2d.cpp:379
arm_compute::test::validation::num_groups
const unsigned int num_groups
Definition: Im2Col.cpp:153
arm_compute::test::validation::conv_info
conv_info
Definition: DirectConvolutionLayer.cpp:547
arm_compute::mlgo::parser::end
void end(TokenStream &in, bool &valid)
Definition: MLGOParser.cpp:283
arm_compute::test::validation::input
auto input
Definition: LSTMLayerQuantized.cpp:486