ONE - On-device Neural Engine
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
onert::backend::train::ops::DepthwiseConvolutionLayer Class Reference

#include <DepthwiseConvolutionLayer.h>

Collaboration diagram for onert::backend::train::ops::DepthwiseConvolutionLayer:

Public Member Functions

 DepthwiseConvolutionLayer ()
 
void configureBackward (IPortableTensor *back_prop_input, IPortableTensor *grad_weights, IPortableTensor *grad_bias, const IPortableTensor *back_prop_output, const ir::Activation activation)
 
void forward (bool training) override
 
void backward () override
 
- Public Member Functions inherited from onert::exec::train::ITrainableFunction
virtual ~ITrainableFunction ()=default
 
virtual std::optional< backend::train::LayerScopeTensorsregisterLayerScopeTensors ()
 
- Public Member Functions inherited from onert::backend::cpu::ops::DepthwiseConvolutionLayer
 DepthwiseConvolutionLayer ()=default
 
void convFloat32 ()
 
void convQ8uPerTensor ()
 
void convQ8uPerChannel ()
 
void convQ8i ()
 
void convQ8iHybridPerChannel ()
 
void configure (const IPortableTensor *input, const IPortableTensor *kernel, const IPortableTensor *bias, const uint32_t paddingLeft, const uint32_t paddingRight, const uint32_t paddingTop, const uint32_t paddingBottom, const uint32_t strideW, const uint32_t strideH, const uint32_t multiplier, const uint32_t dilationWidth, const uint32_t dilationHeight, const ir::Activation activation, IPortableTensor *output, const std::shared_ptr< ExternalContext > &external_context)
 
void run () override
 
- Public Member Functions inherited from onert::exec::IFunction
virtual ~IFunction ()=default
 
virtual void prepare ()
 

Additional Inherited Members

- Protected Attributes inherited from onert::backend::cpu::ops::DepthwiseConvolutionLayer
const IPortableTensor_input {nullptr}
 
const IPortableTensor_kernel {nullptr}
 
const IPortableTensor_bias {nullptr}
 
IPortableTensor_output {nullptr}
 
uint32_t _paddingLeft {0}
 
uint32_t _paddingTop {0}
 
uint32_t _paddingRight {0}
 
uint32_t _paddingBottom {0}
 
uint32_t _strideWidth {0}
 
uint32_t _strideHeight {0}
 
uint32_t _multiplier {0}
 
uint32_t _dilationWidth {1}
 
uint32_t _dilationHeight {1}
 
ir::Activation _activation {ir::Activation::NONE}
 
bool _use_padded_filter {false}
 
std::unique_ptr< Tensor_padded_filter {nullptr}
 
std::unique_ptr< Tensor_filter_buffers {nullptr}
 

Detailed Description

Definition at line 30 of file DepthwiseConvolutionLayer.h.

Constructor & Destructor Documentation

◆ DepthwiseConvolutionLayer()

onert::backend::train::ops::DepthwiseConvolutionLayer::DepthwiseConvolutionLayer ( )

Definition at line 28 of file DepthwiseConvolutionLayer.cc.

29 : cpu::ops::DepthwiseConvolutionLayer(), _grad_weights{nullptr}, _grad_bias{nullptr},
30 _back_prop_input{nullptr}, _back_prop_output{nullptr}, _act_back_prop_output{nullptr},
31 _filter_dim_buffers{nullptr}
32{
33 // DO NOTHING
34}

Member Function Documentation

◆ backward()

void onert::backend::train::ops::DepthwiseConvolutionLayer::backward ( )
overridevirtual

Implements onert::exec::train::ITrainableFunction.

Definition at line 90 of file DepthwiseConvolutionLayer.cc.

91{
92 const auto data_type = _back_prop_output->data_type();
93 assert(data_type == _input->data_type());
94 switch (data_type)
95 {
96 case OperandType::FLOAT32:
97 {
98 assert(data_type == _grad_bias->data_type());
99 backwardFloat32();
100 break;
101 }
102 default:
103 throw std::runtime_error{"train DepthwiseConvolutionLayer: unsupported data type"};
104 }
105}
ir::DataType data_type() const override final

References onert::backend::cpu::ops::DepthwiseConvolutionLayer::_input, and onert::backend::IPortableTensor::data_type().

◆ configureBackward()

void onert::backend::train::ops::DepthwiseConvolutionLayer::configureBackward ( IPortableTensor back_prop_input,
IPortableTensor grad_weights,
IPortableTensor grad_bias,
const IPortableTensor back_prop_output,
const ir::Activation  activation 
)

Definition at line 36 of file DepthwiseConvolutionLayer.cc.

41{
42 _back_prop_input = back_prop_input;
43 _back_prop_output = back_prop_output;
44 _grad_weights = grad_weights;
45 _grad_bias = grad_bias;
46
47 if (_dilationWidth != 1 || _dilationHeight != 1)
48 throw std::runtime_error("train DepthwiseConvolutionLayer: Unsupported dilation yet");
49
50 if (activation != ir::Activation::NONE)
51 {
52 _act_back_prop_output = std::make_unique<BackPropTensor>(_back_prop_output->get_info());
53 _act_back_prop_output->setBuffer(
54 std::make_shared<basic::Allocator>(_act_back_prop_output->total_size()));
55 }
56
57 const int64_t k_packet_size = [&]() {
58 const auto data_type = _back_prop_output->data_type();
59 switch (data_type)
60 {
61 case OperandType::FLOAT32:
62 {
63 return nnfw::cker::eigen_support::kPacketSize<float>();
64 }
65 default:
66 throw std::runtime_error("train DepthwiseConvolutionLayer: unsupported data type");
67 }
68 }();
69
70 const auto incoming_shape = getShape(_back_prop_output);
71 const int out_depth = incoming_shape.Dims(3);
72
73 const int padded_filter_inner_dim_size =
74 ((out_depth + k_packet_size - 1) / k_packet_size) * k_packet_size;
75
76 // prepare out_bprop and in_bprop buffer for cker
77 // NOTE The Eigen library uses both main thread as well as a thread pool.
78 // Therefore, it needs to add an additional memory buffer for main thread.
79 const int thread_count = nnfw::cker::eigen_support::getThreadCount() + 1;
80
81 auto filter_dim_buffers_info = ir::OperandInfo(_back_prop_input->get_info());
82 filter_dim_buffers_info.shape({thread_count, padded_filter_inner_dim_size});
83 _filter_dim_buffers = std::make_unique<Tensor>(filter_dim_buffers_info);
84 _filter_dim_buffers->setBuffer(
85 std::make_shared<basic::Allocator>(_filter_dim_buffers->total_size()));
86}
const ir::OperandInfo & get_info() const
nnfw::cker::Shape getShape(const IPortableTensor *tensor)
Get shape of tensor.

References onert::backend::cpu::ops::DepthwiseConvolutionLayer::_dilationHeight, onert::backend::cpu::ops::DepthwiseConvolutionLayer::_dilationWidth, onert::backend::IPortableTensor::data_type(), onert::backend::IPortableTensor::get_info(), onert::backend::train::ops::getShape(), nnfw::cker::eigen_support::getThreadCount(), and onert::ir::NONE.

◆ forward()

void onert::backend::train::ops::DepthwiseConvolutionLayer::forward ( bool  training)
overridevirtual

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