Compute Library
 22.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 }
static constexpr size_t DimZ
Alias for dimension 2 also known as Z dimension.
Definition: Window.h:47

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

References Tensor::allocator(), ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_LOG_PARAMS, Tensor::buffer(), arm_compute::CONSTANT, ITensorInfo::data_layout(), Window::DimY, Window::DimZ, ActivationLayerInfo::enabled(), TensorAllocator::free(), arm_compute::NCHW, and arm_compute::UNKNOWN.

45 {
46  ARM_COMPUTE_ERROR_ON(src->data_layout() == DataLayout::UNKNOWN);
47  ARM_COMPUTE_LOG_PARAMS(src, weights, bias, dst, conv_info, act_info);
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 }
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
SimpleTensor< float > src
Definition: DFT.cpp:155
TensorAllocator * allocator()
Return a pointer to the tensor&#39;s allocator.
Definition: Tensor.cpp:48
void free() override
Free allocated CPU memory.
Num samples, channels, height, width.
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
Definition: Window.h:45
static constexpr size_t DimZ
Alias for dimension 2 also known as Z dimension.
Definition: Window.h:47
uint8_t * buffer() const override
Interface to be implemented by the child class to return a pointer to CPU memory. ...
Definition: Tensor.cpp:43
#define ARM_COMPUTE_LOG_PARAMS(...)
const int32_t * bias

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

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.

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;
136  pack.add_tensor(TensorType::ACL_SRC_1, bias);
137  pack.add_tensor(TensorType::ACL_DST, dst);
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;
145  pack.add_tensor(TensorType::ACL_DST, dst);
146  _activationlayer_function->run(pack);
147  }
148 }
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.
SimpleTensor< float > src
Definition: DFT.cpp:155
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
Definition: Window.h:45
static constexpr size_t DimZ
Alias for dimension 2 also known as Z dimension.
Definition: Window.h:47
void add_tensor(int id, ITensor *tensor)
Add tensor to the pack.
Definition: ITensorPack.cpp:39
static IScheduler & get()
Access the scheduler singleton.
Definition: Scheduler.cpp:94
const int32_t * bias

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

References 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, ICloneable< T >::clone(), arm_compute::test::validation::data_type, ITensorInfo::data_type(), ITensorInfo::dimension(), ActivationLayerInfo::enabled(), ITensorInfo::num_dimensions(), CpuActivation::validate(), CpuDirectConv2dOutputStageKernel::validate(), and CpuDirectConv2dKernel::validate().

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

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 }
#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 *bias=nullptr, const ITensorInfo *dst=nullptr, const DirectConvolutionLayerOutputStageKernelInfo &info=DirectConvolutionLayerOutputStageKernelInfo())
Static function to check if given info will lead to a valid configuration.
SimpleTensor< float > src
Definition: DFT.cpp:155
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
Definition: Validate.h:159
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.
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.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(...)
Definition: Validate.h:541
#define ARM_COMPUTE_RETURN_ERROR_ON_MSG(cond, msg)
If the condition is true, an error is returned.
Definition: Error.h:244
DataType
Available data types.
Definition: Types.h:79
const int32_t * bias

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