30 _back_prop_input{nullptr}, _back_prop_output{nullptr}, _act_back_prop_output{nullptr},
31 _filter_dim_buffers{nullptr}
42 _back_prop_input = back_prop_input;
43 _back_prop_output = back_prop_output;
44 _grad_weights = grad_weights;
45 _grad_bias = grad_bias;
48 throw std::runtime_error(
"train DepthwiseConvolutionLayer: Unsupported dilation yet");
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()));
57 const int64_t k_packet_size = [&]() {
58 const auto data_type = _back_prop_output->
data_type();
61 case OperandType::FLOAT32:
63 return nnfw::cker::eigen_support::kPacketSize<float>();
66 throw std::runtime_error(
"train DepthwiseConvolutionLayer: unsupported data type");
70 const auto incoming_shape =
getShape(_back_prop_output);
71 const int out_depth = incoming_shape.Dims(3);
73 const int padded_filter_inner_dim_size =
74 ((out_depth + k_packet_size - 1) / k_packet_size) * k_packet_size;
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()));
92 const auto data_type = _back_prop_output->
data_type();
96 case OperandType::FLOAT32:
98 assert(data_type == _grad_bias->
data_type());
103 throw std::runtime_error{
"train DepthwiseConvolutionLayer: unsupported data type"};
107void DepthwiseConvolutionLayer::backwardFloat32()
116 catch (
const std::exception &e)
118 throw std::runtime_error{
"train DepthwiseConvolutionLayer: " + std::string(e.what())};
120 assert(backprop_act !=
nullptr);
136 getBuffer<float>(_filter_dim_buffers.get()));
141 getBuffer<float>(
_input),
getShape(_grad_weights), getBuffer<float>(_grad_weights),
A tensor class that is portable for other backends.
const ir::OperandInfo & get_info() const
ir::DataType data_type() const override final
std::unique_ptr< Tensor > _padded_filter
const IPortableTensor * _input
const IPortableTensor * _bias
ir::Activation _activation
std::unique_ptr< Tensor > _filter_buffers
const IPortableTensor * _kernel
IPortableTensor * _output
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
DepthwiseConvolutionLayer()
Class to save tensor's shape and type.
void backpropFilter(const DepthwiseConvParams ¶ms, const Shape &incoming_shape, const T *incoming_data, const Shape &input_shape, const T *input_data, const Shape &filter_grad_shape, T *filter_grad_data, T *padded_filter_data, T *filter_buffers_data)
void backpropInput(const DepthwiseConvParams ¶ms, const Shape &incoming_shape, const T *incoming_data, const Shape &filter_shape, const T *filter_data, T *padded_filter_data, const Shape &grad_shape, T *grad_data, bool pad_filter, T *filter_buffers_data, T *filter_dim_buffers_data)
void biasGrad(const IPortableTensor *input_backprop, IPortableTensor *bias_grad)
backpropagate bias
const IPortableTensor * backpropActivation(const ir::Activation &activation, const IPortableTensor *output, const IPortableTensor *input_backprop, IPortableTensor *output_backprop)
backpropagate acitvation
nnfw::cker::Shape getShape(const IPortableTensor *tensor)
Get shape of tensor.
int16_t dilation_height_factor
int16_t dilation_width_factor
PaddingValues padding_values