Compute Library
 22.05
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, const experimental::PostOpList< ICLTensor *> &post_ops=experimental::PostOpList< ICLTensor *> {})
 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, const experimental::PostOpList< ICLTensor *> &post_ops=experimental::PostOpList< ICLTensor *> {})
 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, const experimental::PostOpList< ITensorInfo *> &post_ops=experimental::PostOpList< ITensorInfo *> {})
 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.

References CLGEMMConvolutionLayer::~CLGEMMConvolutionLayer().

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

◆ 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.

Referenced by CLGEMMConvolutionLayer::CLGEMMConvolutionLayer().

Member Function Documentation

◆ configure() [1/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,
const experimental::PostOpList< ICLTensor *> &  post_ops = experimental::PostOpList<ICLTensor *> {} 
)

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
[in]post_ops(Optional) A sequence of post operations that are performed after the main operation.

Definition at line 71 of file CLGEMMConvolutionLayer.cpp.

References CLKernelLibrary::get().

73 {
74  configure(CLKernelLibrary::get().get_compile_context(), input, weights, biases, output, conv_info, weights_info, dilation, act_info, num_groups, post_ops);
75 }
experimental::PostOpList< ITensorInfo * > post_ops
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
const unsigned int num_groups
Definition: Im2Col.cpp:153
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, const experimental::PostOpList< ICLTensor *> &post_ops=experimental::PostOpList< ICLTensor *> {})
Set the input and output tensors.

◆ configure() [2/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,
const experimental::PostOpList< ICLTensor *> &  post_ops = experimental::PostOpList<ICLTensor *> {} 
)

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
[in]post_ops(Optional) A sequence of post operations that are performed after the main operation.

Definition at line 77 of file CLGEMMConvolutionLayer.cpp.

References arm_compute::ACL_DST, arm_compute::ACL_SRC_0, arm_compute::ACL_SRC_1, arm_compute::ACL_SRC_2, ARM_COMPUTE_ERROR_ON_NULLPTR, arm_compute::experimental::get_post_op_arg_type(), ITensor::info(), arm_compute::test::validation::post_ops, and arm_compute::test::validation::weights_info.

80 {
81  ARM_COMPUTE_ERROR_ON_NULLPTR(input, weights, output);
82  _impl->weights = weights;
83  _impl->op = std::make_unique<opencl::ClGemmConv2d>();
84  // Convert post op arguments to ITensorInfo
85  auto transformed_post_ops = experimental::transform_post_op_list_arguments<ICLTensor *, ITensorInfo *>(post_ops, [](auto tensor)
86  {
87  return tensor->info();
88  });
89  const Conv2dInfo conv2d_info = Conv2dInfo(conv_info, dilation, act_info, false, num_groups, transformed_post_ops);
90  _impl->op->configure(compile_context, input->info(), weights->info(), (biases != nullptr ? biases->info() : nullptr), output->info(), conv2d_info, weights_info);
91 
92  _impl->run_pack =
93  {
95  { TensorType::ACL_SRC_1, weights },
96  { TensorType::ACL_SRC_2, biases },
97  { TensorType::ACL_DST, output }
98  };
99  // Add post op tensors
100  size_t post_op_tensor_index = 0;
101  for(const auto &op : post_ops.get_list())
102  {
103  for(auto &tensor : op->arguments())
104  {
105  _impl->run_pack.add_const_tensor(experimental::get_post_op_arg_type(post_op_tensor_index++), *tensor);
106  }
107  }
108  _impl->prep_pack =
109  {
110  { TensorType::ACL_SRC_1, weights },
111  { TensorType::ACL_SRC_2, biases },
112  };
113  _impl->aux_mem_req = _impl->op->workspace();
114  _impl->workspace_tensors = manage_workspace<CLTensor>(_impl->aux_mem_req, _impl->memory_group, _impl->run_pack, _impl->prep_pack);
115 }
experimental::PostOpList< ITensorInfo * > post_ops
TensorType get_post_op_arg_type(size_t index)
Get post op argument TensorType from post op argument index in a flattened, ordered post op argument ...
Definition: PostOpUtils.h:79
const unsigned int num_groups
Definition: Im2Col.cpp:153
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:157

◆ operator=() [1/2]

CLGEMMConvolutionLayer& operator= ( const CLGEMMConvolutionLayer )
delete

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

◆ operator=() [2/2]

CLGEMMConvolutionLayer& operator= ( CLGEMMConvolutionLayer &&  )
default

Default move assignment operator.

◆ 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 131 of file CLGEMMConvolutionLayer.cpp.

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

Referenced by CLGEMMConvolutionLayer::run().

132 {
133  if(!_impl->is_prepared)
134  {
135  _impl->op->prepare(_impl->prep_pack);
136  auto has_reshape = std::find_if(_impl->aux_mem_req.begin(),
137  _impl->aux_mem_req.end(),
138  [](const MemoryInfo & m) -> bool { return m.lifetime == MemoryLifetime::Persistent; });
139 
140  if(has_reshape != std::end(_impl->aux_mem_req))
141  {
142  _impl->weights->mark_as_unused();
143  }
144  else
145  {
146  // Pack the B matrix to be used as the underlying GEMM performs no reshapes
147  _impl->run_pack.add_const_tensor(ACL_SRC_1, _impl->weights);
148  }
149  release_temporaries(_impl->aux_mem_req, _impl->workspace_tensors);
150  _impl->is_prepared = true;
151  }
152 }
void end(TokenStream &in, bool &valid)
Definition: MLGOParser.cpp:290
void release_temporaries(const experimental::MemoryRequirements &mem_reqs, WorkspaceData< TensorType > &workspace)
Utility function to release tensors with lifetime marked as Prepare.

◆ 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 124 of file CLGEMMConvolutionLayer.cpp.

References CLGEMMConvolutionLayer::prepare().

125 {
126  prepare();
127  MemoryGroupResourceScope scope_mg(_impl->memory_group);
128  _impl->op->run(_impl->run_pack);
129 }
void prepare() override
Prepare the function for executing.

◆ 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,
const experimental::PostOpList< ITensorInfo *> &  post_ops = experimental::PostOpList<ITensorInfo *> {} 
)
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
[in]post_ops(Optional) A sequence of post operations that are performed after the main operation.
Returns
a status

Definition at line 117 of file CLGEMMConvolutionLayer.cpp.

References ClGemmConv2d::validate().

119 {
120  const Conv2dInfo conv2d_info = Conv2dInfo(conv_info, dilation, act_info, false, num_groups, post_ops);
121  return opencl::ClGemmConv2d::validate(input, weights, biases, output, conv2d_info, weights_info);
122 }
experimental::PostOpList< ITensorInfo * > post_ops
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.
const unsigned int num_groups
Definition: Im2Col.cpp:153

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