36 _back_prop_input{nullptr}, _back_prop_output{nullptr}, _act_back_prop_output{nullptr},
37 _filter_dim_buffers{nullptr}
48 _back_prop_input = back_prop_input;
49 _back_prop_output = back_prop_output;
50 _grad_weights = grad_weights;
51 _grad_bias = grad_bias;
54 throw std::runtime_error(
"train DepthwiseConvolutionLayer: Unsupported dilation yet");
58 _act_back_prop_output = std::make_unique<BackPropTensor>(_back_prop_output->
get_info());
59 _act_back_prop_output->setBuffer(
60 std::make_shared<basic::Allocator>(_act_back_prop_output->total_size()));
63 const int64_t k_packet_size = [&]() {
64 const auto data_type = _back_prop_output->
data_type();
67 case OperandType::FLOAT32:
69 return nnfw::cker::eigen_support::kPacketSize<float>();
72 throw std::runtime_error(
"train DepthwiseConvolutionLayer: unsupported data type");
76 const auto incoming_shape =
getShape(_back_prop_output);
77 const int out_depth = incoming_shape.Dims(3);
79 const int padded_filter_inner_dim_size =
80 ((out_depth + k_packet_size - 1) / k_packet_size) * k_packet_size;
88 filter_dim_buffers_info.shape({thread_count, padded_filter_inner_dim_size});
89 _filter_dim_buffers = std::make_unique<Tensor>(filter_dim_buffers_info);
90 _filter_dim_buffers->setBuffer(
91 std::make_shared<basic::Allocator>(_filter_dim_buffers->total_size()));
98 const auto data_type = _back_prop_output->
data_type();
102 case OperandType::FLOAT32:
104 assert(data_type == _grad_bias->
data_type());
109 throw std::runtime_error{
"train DepthwiseConvolutionLayer: unsupported data type"};
113void DepthwiseConvolutionLayer::backwardFloat32()
122 catch (
const std::exception &e)
124 throw std::runtime_error{
"train DepthwiseConvolutionLayer: " + std::string(e.what())};
126 assert(backprop_act !=
nullptr);
142 getBuffer<float>(_filter_dim_buffers.get()));
147 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