From bae9407e366adf7a5a2fd020a1ccf834f3b77ef6 Mon Sep 17 00:00:00 2001 From: sseung Date: Wed, 7 Aug 2024 11:00:23 +0900 Subject: [PATCH] revert dconv --- .../train/ops/DepthwiseConvolutionLayer.cc | 77 ++++--------------- .../train/ops/DepthwiseConvolutionLayer.h | 12 ++- 2 files changed, 18 insertions(+), 71 deletions(-) diff --git a/runtime/onert/backend/train/ops/DepthwiseConvolutionLayer.cc b/runtime/onert/backend/train/ops/DepthwiseConvolutionLayer.cc index 901e9b792f6..9443d0fe0ea 100644 --- a/runtime/onert/backend/train/ops/DepthwiseConvolutionLayer.cc +++ b/runtime/onert/backend/train/ops/DepthwiseConvolutionLayer.cc @@ -56,11 +56,9 @@ void DepthwiseConvolutionLayer::configureBackward(IPortableTensor *back_prop_inp if (activation != ir::Activation::NONE) { - /* _act_back_prop_output = std::make_unique(_back_prop_output->get_info()); _act_back_prop_output->setBuffer( std::make_shared(_act_back_prop_output->total_size())); - */ } const int64_t k_packet_size = [&]() { @@ -77,20 +75,20 @@ void DepthwiseConvolutionLayer::configureBackward(IPortableTensor *back_prop_inp }(); const auto incoming_shape = getShape(_back_prop_output); - // const auto filter_shape = getShape(_kernel); - // const int batch = incoming_shape.Dims(0); + const auto filter_shape = getShape(_kernel); + const int batch = incoming_shape.Dims(0); const int out_depth = incoming_shape.Dims(3); - // const int filter_rows = filter_shape.Dims(1); - // const int filter_cols = filter_shape.Dims(2); + const int filter_rows = filter_shape.Dims(1); + const int filter_cols = filter_shape.Dims(2); - // const int filter_spatial_size = filter_rows * filter_cols; - // const int padded_filter_inner_dim_size = - // ((out_depth + k_packet_size - 1) / k_packet_size) * k_packet_size; + const int filter_spatial_size = filter_rows * filter_cols; + const int padded_filter_inner_dim_size = + ((out_depth + k_packet_size - 1) / k_packet_size) * k_packet_size; _use_padded_filter = (out_depth % k_packet_size) == 0 ? false : true; // prepare padded_filter buffer for cker - /* auto padded_filter_info = ir::OperandInfo(_kernel->get_info()); + auto padded_filter_info = ir::OperandInfo(_kernel->get_info()); padded_filter_info.shape({batch, filter_spatial_size, padded_filter_inner_dim_size}); _padded_filter = std::make_unique(padded_filter_info); _padded_filter->setBuffer(std::make_shared(_padded_filter->total_size())); @@ -110,55 +108,6 @@ void DepthwiseConvolutionLayer::configureBackward(IPortableTensor *back_prop_inp _filter_dim_buffers = std::make_unique(filter_dim_buffers_info); _filter_dim_buffers->setBuffer( std::make_shared(_filter_dim_buffers->total_size())); - */ -} - -ExtraTensorRequests DepthwiseConvolutionLayer::requestExtraTensors() -{ - ExtraTensorRequests reqs; - - reqs.push_back(ExtraTensorRequest::createLike(_back_prop_output, &_act_back_prop_output)); - - const auto incoming_shape = getShape(_back_prop_output); - const auto batch = incoming_shape.Dims(0); - const auto depth = incoming_shape.Dims(3); - - const auto filter_shape = getShape(_kernel); - const int filter_rows = filter_shape.Dims(1); - const int filter_cols = filter_shape.Dims(2); - const int filter_spatial_size = filter_rows * filter_cols; - - const auto k_packet_size = _dconv_kernel->kPacketSize(); - const int padded_filter_inner_dim_size = - ((depth + k_packet_size - 1) / k_packet_size) * k_packet_size; - - const int thread_count = _dconv_kernel->getThreadCount(); - - // _padded_filter - { - auto type_info = _kernel->get_info().typeInfo(); - ir::Shape shape({batch, filter_spatial_size, padded_filter_inner_dim_size}); - auto info = ir::OperandInfo::createStaticInfo(shape, type_info); - reqs.emplace_back(info, ExtraTensorLifeTime::BACKWARD, &_padded_filter); - } - - // _filter_buffers - { - auto type_info = _kernel->get_info().typeInfo(); - ir::Shape shape({thread_count, filter_spatial_size, padded_filter_inner_dim_size}); - auto info = ir::OperandInfo::createStaticInfo(shape, type_info); - reqs.emplace_back(info, ExtraTensorLifeTime::BACKWARD, &_filter_buffers); - } - - // _filter_dim_buffers - { - auto type = _back_prop_input->get_info().typeInfo(); - ir::Shape shape({thread_count, padded_filter_inner_dim_size}); - auto info = ir::OperandInfo::createStaticInfo(shape, type); - reqs.emplace_back(info, ExtraTensorLifeTime::BACKWARD, &_filter_dim_buffers); - } - - return reqs; } void DepthwiseConvolutionLayer::forward(bool) { cpu::ops::DepthwiseConvolutionLayer::run(); } @@ -187,7 +136,7 @@ void DepthwiseConvolutionLayer::backwardFloat32() try { backprop_act = - backpropActivation(_activation, _output, _back_prop_output, _act_back_prop_output); + backpropActivation(_activation, _output, _back_prop_output, _act_back_prop_output.get()); } catch (const std::exception &e) { @@ -207,15 +156,15 @@ void DepthwiseConvolutionLayer::backwardFloat32() // Calculate gradient for input nnfw::cker::train::backpropInput( dconv_params, getShape(backprop_act), getBuffer(backprop_act), getShape(_kernel), - getBuffer(_kernel), getBuffer(_padded_filter), getShape(_back_prop_input), - getBuffer(_back_prop_input), _use_padded_filter, getBuffer(_filter_buffers), - getBuffer(_filter_dim_buffers)); + getBuffer(_kernel), getBuffer(_padded_filter.get()), getShape(_back_prop_input), + getBuffer(_back_prop_input), _use_padded_filter, getBuffer(_filter_buffers.get()), + getBuffer(_filter_dim_buffers.get())); // Calculate gradient for weights nnfw::cker::train::backpropFilter( dconv_params, getShape(backprop_act), getBuffer(backprop_act), getShape(_input), getBuffer(_input), getShape(_grad_weights), getBuffer(_grad_weights), - getBuffer(_padded_filter), getBuffer(_filter_buffers)); + getBuffer(_padded_filter.get()), getBuffer(_filter_buffers.get())); // Calculate gradient for bias if (_bias) diff --git a/runtime/onert/backend/train/ops/DepthwiseConvolutionLayer.h b/runtime/onert/backend/train/ops/DepthwiseConvolutionLayer.h index 1c98b24e18d..5cd98e56721 100644 --- a/runtime/onert/backend/train/ops/DepthwiseConvolutionLayer.h +++ b/runtime/onert/backend/train/ops/DepthwiseConvolutionLayer.h @@ -42,8 +42,6 @@ class DepthwiseConvolutionLayer : public ::onert::exec::train::ITrainableFunctio void configureBackward(IPortableTensor *back_prop_input, IPortableTensor *grad_weights, IPortableTensor *grad_bias, const IPortableTensor *back_prop_output, const ir::Activation activation); - - ExtraTensorRequests requestExtraTensors() override; void forward(bool training) override; void backward() override; @@ -56,12 +54,12 @@ class DepthwiseConvolutionLayer : public ::onert::exec::train::ITrainableFunctio IPortableTensor *_back_prop_input; const IPortableTensor *_back_prop_output; - ExtraTensor *_act_back_prop_output; - + // TODO Consider if these tensors should be built in TensorBuilder + std::unique_ptr _act_back_prop_output; bool _use_padded_filter; - ExtraTensor *_padded_filter; - ExtraTensor *_filter_buffers; - ExtraTensor *_filter_dim_buffers; + std::unique_ptr _padded_filter; + std::unique_ptr _filter_buffers; + std::unique_ptr _filter_dim_buffers; }; } // namespace ops