Compute Library
GCDirectConvolutionLayer Class Reference

Basic function to execute direct convolution function. More...

#include <GCDirectConvolutionLayer.h>

Collaboration diagram for GCDirectConvolutionLayer:

Public Member Functions

 GCDirectConvolutionLayer ()
 Default constructor. More...
void configure (IGCTensor *input, const IGCTensor *weights, const IGCTensor *biases, IGCTensor *output, const PadStrideInfo &conv_info, const ActivationLayerInfo &act_info=ActivationLayerInfo())
 Set the input and output tensors. More...
void run () override final
 Run the kernels contained in the function. More...
- Public Member Functions inherited from IFunction
virtual ~IFunction ()=default
 Destructor. More...
virtual void prepare ()
 Prepare the function for executing. More...

Detailed Description

Basic function to execute direct convolution function.

This function calls the following kernels:

  1. GCDirectConvolutionLayerKernel
  2. GCFillBorderKernel
  3. GCTensorShiftKernel
Supported kernel size: 1x1, 3x3, and 5x5
This OpenGL ES implementation works with stride_x = 1 and 2

Definition at line 50 of file GCDirectConvolutionLayer.h.

Constructor & Destructor Documentation

◆ GCDirectConvolutionLayer()

Default constructor.

Definition at line 37 of file GCDirectConvolutionLayer.cpp.

38  : _kernel(nullptr), _border_handler(), _shift_handler()
39 {
40 }

Member Function Documentation

◆ configure()

void configure ( IGCTensor input,
const IGCTensor weights,
const IGCTensor biases,
IGCTensor output,
const PadStrideInfo conv_info,
const ActivationLayerInfo act_info = ActivationLayerInfo() 

Set the input and output tensors.

[in,out]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: F16/F32. input will be written to only if it is currently left aligned.
[in]weightsWeights tensor. Weights are 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM]. Data type supported:Same as input.
[in]biasesBiases tensor. Shared biases supported. Biases are 1D tensor with dimensions [OFM]. Data type supported:Same as input.
[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]act_info(Optional) Activation layer information in case of a fused activation.

Definition at line 42 of file GCDirectConvolutionLayer.cpp.

44 {
45  int kernel_size = weights->info()->dimension(0);
47  if(kernel_size == 1)
48  {
49  auto k = arm_compute::support::cpp14::make_unique<GCDirectConvolutionLayer1x1Kernel>();
50  k->configure(input, weights, biases, output, conv_info, act_info);
51  _kernel = std::move(k);
52  }
53  else if(kernel_size == 3)
54  {
55  auto k = arm_compute::support::cpp14::make_unique<GCDirectConvolutionLayer3x3Kernel>();
56  k->configure(input, weights, biases, output, conv_info, act_info);
57  _kernel = std::move(k);
58  }
59  else if(kernel_size == 5)
60  {
61  auto k = arm_compute::support::cpp14::make_unique<GCDirectConvolutionLayer5x5Kernel>();
62  k->configure(input, weights, biases, output, conv_info, act_info);
63  _kernel = std::move(k);
64  }
65  else
66  {
67  ARM_COMPUTE_ERROR("kernel size unsupported!");
68  return;
69  }
71  _border_handler.configure(input, _kernel->border_size(), BorderMode::CONSTANT, PixelValue());
73  _shift_handler.configure(input);
74 }
Class describing the value of a pixel for any image format.
Definition: PixelValue.h:34
TensorInfo * info() const override
Interface to be implemented by the child class to return the tensor's metadata.
Definition: CLTensor.cpp:41
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
size_t dimension(size_t index) const override
Return the size of the requested dimension.
Definition: TensorInfo.h:232
void configure(const IGCTensor *tensor, BorderSize border_size, BorderMode border_mode, const PixelValue &constant_border_value=PixelValue())
Initialise the kernel's input, output and border mode.
void configure(IGCTensor *input)
Set the input of the kernel.

References arm_compute::test::validation::act_info, ARM_COMPUTE_ERROR, GCFillBorderKernel::configure(), GCTensorShiftKernel::configure(), arm_compute::CONSTANT, arm_compute::test::validation::conv_info, TensorInfo::dimension(), CLTensor::info(), arm_compute::test::validation::input, and arm_compute::test::validation::weights.

◆ run()

void run ( )

Run the kernels contained in the function.

For NEON kernels:

  • Multi-threading is used for the kernels which are parallelisable.
  • By default std::thread::hardware_concurrency() threads are used.
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.
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 76 of file GCDirectConvolutionLayer.cpp.

77 {
78  GCScheduler::get().dispatch(_shift_handler, false);
80  GCScheduler::get().dispatch(_border_handler, false);
82  GCScheduler::get().dispatch(*_kernel);
84  GCScheduler::get().dispatch(_shift_handler);
85 }
void dispatch(IGCKernel &kernel, bool flush=true)
Schedule the execution of the passed kernel if possible.
Definition: GCScheduler.cpp:77
void memory_barrier()
Defines a barrier ordering memory transactions.
Definition: GCScheduler.cpp:86
static GCScheduler & get()
Access the scheduler singleton.
Definition: GCScheduler.cpp:70

References GCScheduler::dispatch(), GCScheduler::get(), and GCScheduler::memory_barrier().

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