Compute Library
 23.08
CpuDirectConv2d Class Reference

Function to run the direct convolution. More...

#include <CpuDirectConv2d.h>

Collaboration diagram for CpuDirectConv2d:
[legend]

Public Member Functions

 CpuDirectConv2d (std::shared_ptr< IMemoryManager > memory_manager=nullptr)
 
 ~CpuDirectConv2d ()
 
void configure (ITensorInfo *src, ITensorInfo *weights, const ITensorInfo *bias, ITensorInfo *dst, const PadStrideInfo &conv_info, const ActivationLayerInfo &act_info=ActivationLayerInfo())
 Set the input, weights, biases and output tensors. More...
 
void run (ITensorPack &tensors) override
 Run the kernels contained in the function. More...
 
- Public Member Functions inherited from INEOperator
 INEOperator (IRuntimeContext *ctx=nullptr)
 Constructor. More...
 
 INEOperator (const INEOperator &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 INEOperator (INEOperator &&)=default
 Default move constructor. More...
 
INEOperatoroperator= (const INEOperator &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
INEOperatoroperator= (INEOperator &&)=default
 Default move assignment operator. More...
 
 ~INEOperator ()
 Default destructor. 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 *bias, 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

Function to run the direct convolution.

This function calls the following kernels:

  1. NEFillBorderKernel for the input
  2. kernels::CpuDirectConv2dOutputStageKernel
  3. kernels::CpuDirectConv2dKernel

Definition at line 55 of file CpuDirectConv2d.h.

Constructor & Destructor Documentation

◆ CpuDirectConv2d()

CpuDirectConv2d ( std::shared_ptr< IMemoryManager memory_manager = nullptr)

Definition at line 38 of file CpuDirectConv2d.cpp.

39  : _memory_group(std::move(memory_manager)), _output_stage_kernel(), _conv_kernel(), _input_border_handler(), _activationlayer_function(), _accumulator(), _has_bias(false),
40  _is_activationlayer_enabled(false), _dim_split(Window::DimZ), _is_padding_required()
41 {
42 }

◆ ~CpuDirectConv2d()

~CpuDirectConv2d ( )
default

Member Function Documentation

◆ configure()

void configure ( ITensorInfo src,
ITensorInfo weights,
const ITensorInfo bias,
ITensorInfo dst,
const PadStrideInfo conv_info,
const ActivationLayerInfo act_info = ActivationLayerInfo() 
)

Set the input, weights, biases and output tensors.

Note
: DirectConvolution only works in the following configurations: 1x1 convolution with stride_x = 1/2/3, stride_y = 1/2/3 data type = F16/F32 3x3 convolution with stride_x = 1/2/3, stride_y = 1/2/3 data type = F16/F32 5x5 convolution with stride_x = 1/2/3, stride_y = 1/2/3 data type = F32
Parameters
[in,out]srcInput tensor info. Data types supported: F16/F32.
[in]weightsSet of kernels to convolve the input volume. Supported sizes: 1x1, 3x3 and 5x5. The 3rd dimension must be the same as the input's volume 3rd dimension. Data type supported: Same as src.
[in]biasSet of biases. Can be nullptr. Data type supported: Same as src.
[out]dstOutput tensor info. The 3rd dimensions must be equal to the 4th dimension of the kernels tensor. Data types supported: Same as input.
[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 44 of file CpuDirectConv2d.cpp.

45 {
46  ARM_COMPUTE_ERROR_ON(src->data_layout() == DataLayout::UNKNOWN);
48 
49  _output_stage_kernel = std::make_unique<kernels::CpuDirectConv2dOutputStageKernel>();
50  _conv_kernel = std::make_unique<kernels::CpuDirectConv2dKernel>();
51  _input_border_handler = std::make_unique<NEFillBorderKernel>();
52 
53  // Free accumulator
54  if(_accumulator.buffer() != nullptr)
55  {
56  _accumulator.allocator()->free();
57  }
58 
59  _dim_split = src->data_layout() == DataLayout::NCHW ? Window::DimZ : Window::DimY;
60 
61  // Check if bias should be added in the convolution result
62  _has_bias = (bias != nullptr);
63 
64  _conv_kernel->configure(src, weights, dst, conv_info);
65  if(_has_bias)
66  {
67  _output_stage_kernel->configure(dst, bias);
68  }
69  _is_padding_required = !_conv_kernel->border_size().empty();
70 
71  if(_is_padding_required)
72  {
73  // Add zero padding XY
74  _input_border_handler->configure(src, _conv_kernel->border_size(), BorderMode::CONSTANT, PixelValue(static_cast<float>(0.f)));
75  }
76 
77  //Configure Activation Layer
78  _is_activationlayer_enabled = act_info.enabled();
79  if(_is_activationlayer_enabled)
80  {
81  _activationlayer_function = std::make_unique<CpuActivation>();
82  _activationlayer_function->configure(dst, dst, act_info);
83  }
84 }

References arm_compute::test::validation::act_info, Tensor::allocator(), ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_LOG_PARAMS, bias, Tensor::buffer(), arm_compute::CONSTANT, arm_compute::test::validation::conv_info, Window::DimY, Window::DimZ, arm_compute::test::validation::dst, TensorAllocator::free(), arm_compute::NCHW, arm_compute::test::validation::src, and arm_compute::UNKNOWN.

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

Definition at line 117 of file CpuDirectConv2d.cpp.

118 {
119  MemoryGroupResourceScope scope_mg(_memory_group);
120 
121  auto src = tensors.get_tensor(TensorType::ACL_SRC_0);
122  auto bias = tensors.get_const_tensor(TensorType::ACL_SRC_2);
123  auto dst = tensors.get_tensor(TensorType::ACL_DST);
124 
125  if(_is_padding_required)
126  {
127  ITensorPack pack;
129  NEScheduler::get().schedule_op(_input_border_handler.get(), Window::DimZ, _input_border_handler->window(), pack);
130  }
131  NEScheduler::get().schedule_op(_conv_kernel.get(), _dim_split, _conv_kernel->window(), tensors);
132  if(_has_bias)
133  {
134  ITensorPack pack;
138  NEScheduler::get().schedule_op(_output_stage_kernel.get(), Window::DimY, _output_stage_kernel->window(), pack);
139  }
140 
141  if(_is_activationlayer_enabled)
142  {
143  ITensorPack pack;
146  _activationlayer_function->run(pack);
147  }
148 }

References arm_compute::ACL_DST, arm_compute::ACL_SRC, arm_compute::ACL_SRC_0, arm_compute::ACL_SRC_1, arm_compute::ACL_SRC_2, arm_compute::ACL_SRC_DST, ITensorPack::add_tensor(), bias, Window::DimY, Window::DimZ, arm_compute::test::validation::dst, Scheduler::get(), ITensorPack::get_const_tensor(), ITensorPack::get_tensor(), arm_compute::test::validation::pack, IScheduler::schedule_op(), and arm_compute::test::validation::src.

◆ validate()

Status validate ( const ITensorInfo src,
const ITensorInfo weights,
const ITensorInfo bias,
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 CpuDirectConv2d::configure()

Returns
a status

Definition at line 86 of file CpuDirectConv2d.cpp.

88 {
90 
91  // output might not be initialized since it can be an intermediate tensor of another layer
92  DataType data_type = src->data_type();
93  TensorInfo accumulator(dst->clone()->set_is_resizable(true).reset_padding().set_data_type(data_type));
94 
95  // Validate Convolution kernel
97 
98  if(bias != nullptr)
99  {
101  ARM_COMPUTE_RETURN_ERROR_ON_MSG(bias->dimension(0) != weights->dimension(3),
102  "Biases size and number of input feature maps should match");
103  ARM_COMPUTE_RETURN_ERROR_ON_MSG(bias->num_dimensions() > 1, "Biases should be one dimensional");
104  }
105 
106  // Validate bias kernel
108 
109  if(act_info.enabled())
110  {
112  }
113 
114  return Status{};
115 }

References arm_compute::test::validation::act_info, ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES, ARM_COMPUTE_RETURN_ERROR_ON_MSG, ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR, ARM_COMPUTE_RETURN_ON_ERROR, bias, arm_compute::test::validation::conv_info, arm_compute::test::validation::data_type, ITensorInfo::dimension(), arm_compute::test::validation::dst, arm_compute::test::validation::src, CpuActivation::validate(), CpuDirectConv2dOutputStageKernel::validate(), and CpuDirectConv2dKernel::validate().

Referenced by CpuConv2d::get_convolution_method(), NEDirectConvolutionLayer::validate(), and CpuConv2d::validate().


The documentation for this class was generated from the following files:
arm_compute::DataLayout::NCHW
@ NCHW
Num samples, channels, height, width.
arm_compute::ACL_SRC_DST
@ ACL_SRC_DST
Definition: Types.h:41
arm_compute::BorderMode::CONSTANT
@ CONSTANT
Pixels outside the image are assumed to have a constant value.
arm_compute::test::validation::src
SimpleTensor< float > src
Definition: DFT.cpp:155
arm_compute::IScheduler::schedule_op
virtual void schedule_op(ICPPKernel *kernel, const Hints &hints, const Window &window, ITensorPack &tensors)=0
Runs the kernel in the same thread as the caller synchronously.
arm_compute::test::validation::dst
auto dst
Definition: DFT.cpp:170
arm_compute::cpu::CpuActivation::validate
static Status validate(const ITensorInfo *input, const ITensorInfo *output, const ActivationLayerInfo &act_info)
Static function to check if given info will lead to a valid configuration.
Definition: CpuActivation.cpp:45
arm_compute::ITensorPack::add_tensor
void add_tensor(int id, ITensor *tensor)
Add tensor to the pack.
Definition: ITensorPack.cpp:39
arm_compute::ACL_SRC_0
@ ACL_SRC_0
Definition: Types.h:45
arm_compute::ACL_SRC_1
@ ACL_SRC_1
Definition: Types.h:46
ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(...)
Definition: Validate.h:630
arm_compute::ACL_SRC_2
@ ACL_SRC_2
Definition: Types.h:47
ARM_COMPUTE_RETURN_ON_ERROR
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204
arm_compute::test::validation::act_info
act_info
Definition: DirectConvolutionLayer.cpp:547
ARM_COMPUTE_ERROR_ON
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:467
arm_compute::Tensor::allocator
TensorAllocator * allocator()
Return a pointer to the tensor's allocator.
Definition: Tensor.cpp:48
arm_compute::ACL_DST
@ ACL_DST
Definition: Types.h:55
arm_compute::Scheduler::get
static IScheduler & get()
Access the scheduler singleton.
Definition: Scheduler.cpp:94
arm_compute::Tensor::buffer
uint8_t * buffer() const override
Interface to be implemented by the child class to return a pointer to CPU memory.
Definition: Tensor.cpp:43
bias
const int32_t * bias
Definition: working_space.hpp:322
arm_compute::test::validation::pack
ITensorPack pack
Definition: Im2Col.cpp:188
arm_compute::cpu::kernels::CpuDirectConv2dOutputStageKernel::validate
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.
Definition: CpuDirectConv2dOutputStageKernel.cpp:486
arm_compute::Window::DimY
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
Definition: Window.h:45
arm_compute::test::validation::data_type
data_type
Definition: Cast.cpp:223
ARM_COMPUTE_RETURN_ERROR_ON_MSG
#define ARM_COMPUTE_RETURN_ERROR_ON_MSG(cond, msg)
If the condition is true, an error is returned.
Definition: Error.h:245
arm_compute::test::validation::conv_info
const auto conv_info
Definition: ConvolutionLayer.cpp:407
arm_compute::cpu::kernels::CpuDirectConv2dKernel::validate
static Status validate(const ITensorInfo *src, const ITensorInfo *weights, const ITensorInfo *dst, const PadStrideInfo &conv_info)
Static function to check if given info will lead to a valid configuration.
Definition: CpuDirectConv2dKernel.cpp:132
arm_compute::Window::DimZ
static constexpr size_t DimZ
Alias for dimension 2 also known as Z dimension.
Definition: Window.h:47
ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
Definition: Validate.h:163
arm_compute::TensorAllocator::free
void free() override
Free allocated CPU memory.
Definition: TensorAllocator.cpp:147
arm_compute::DataLayout::UNKNOWN
@ UNKNOWN
Unknown data layout.
arm_compute::ACL_SRC
@ ACL_SRC
Definition: Types.h:44
ARM_COMPUTE_LOG_PARAMS
#define ARM_COMPUTE_LOG_PARAMS(...)
Definition: Log.h:35
arm_compute::DataType
DataType
Available data types.
Definition: CoreTypes.h:82