aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/NEON/functions
diff options
context:
space:
mode:
authorGeorgios Pinitas <georgios.pinitas@arm.com>2017-09-08 19:47:30 +0100
committerAnthony Barbier <anthony.barbier@arm.com>2018-11-02 16:35:24 +0000
commitbaf174e85ddb5399355281cd34d0f459d92124a7 (patch)
treed69904df66f7e5ad55edd268d16735542445f36f /src/runtime/NEON/functions
parent1c8409d7ce90ea449437076574c98a4ea90d9368 (diff)
downloadComputeLibrary-baf174e85ddb5399355281cd34d0f459d92124a7.tar.gz
COMPMID-485: Memory Manager
Change-Id: Ib421b7622838f050038cd81e7426bb1413a7d6e6 Reviewed-on: http://mpd-gerrit.cambridge.arm.com/87376 Tested-by: Kaizen <jeremy.johnson+kaizengerrit@arm.com> Reviewed-by: Anthony Barbier <anthony.barbier@arm.com>
Diffstat (limited to 'src/runtime/NEON/functions')
-rw-r--r--src/runtime/NEON/functions/NEConvolutionLayer.cpp31
-rw-r--r--src/runtime/NEON/functions/NEFullyConnectedLayer.cpp21
-rw-r--r--src/runtime/NEON/functions/NESoftmaxLayer.cpp13
3 files changed, 47 insertions, 18 deletions
diff --git a/src/runtime/NEON/functions/NEConvolutionLayer.cpp b/src/runtime/NEON/functions/NEConvolutionLayer.cpp
index 1c87f60a29..0466a4a501 100644
--- a/src/runtime/NEON/functions/NEConvolutionLayer.cpp
+++ b/src/runtime/NEON/functions/NEConvolutionLayer.cpp
@@ -34,8 +34,8 @@
using namespace arm_compute;
-NEConvolutionLayerReshapeWeights::NEConvolutionLayerReshapeWeights()
- : _weights_reshape_kernel(), _weights_transposed_kernel(), _weights_reshaped(), _transpose1xW(false)
+NEConvolutionLayerReshapeWeights::NEConvolutionLayerReshapeWeights(std::shared_ptr<IMemoryManager> memory_manager)
+ : _memory_group(std::move(memory_manager)), _weights_reshape_kernel(), _weights_transposed_kernel(), _weights_reshaped(), _transpose1xW(false)
{
}
@@ -68,6 +68,7 @@ void NEConvolutionLayerReshapeWeights::configure(const ITensor *weights, const I
TensorInfo info_wr(shape_wr, 1, weights->info()->data_type(), weights->info()->fixed_point_position());
_weights_reshaped.allocator()->init(info_wr);
+ _memory_group.manage(&_weights_reshaped);
_weights_reshape_kernel.configure(weights, biases, &_weights_reshaped);
_weights_transposed_kernel.configure(&_weights_reshaped, output);
_weights_reshaped.allocator()->allocate();
@@ -80,16 +81,20 @@ void NEConvolutionLayerReshapeWeights::configure(const ITensor *weights, const I
void NEConvolutionLayerReshapeWeights::run()
{
+ _memory_group.acquire();
+
NEScheduler::get().schedule(&_weights_reshape_kernel, 3);
if(_transpose1xW)
{
NEScheduler::get().schedule(&_weights_transposed_kernel, Window::DimY);
}
+
+ _memory_group.release();
}
-NEConvolutionLayer::NEConvolutionLayer()
- : _input_im2col_kernel(), _input_interleave_kernel(), _reshape_weights(), _mm_kernel(), _output_col2im_kernel(), _input_im2col_reshaped(), _input_interleaved_reshaped(), _weights_reshaped(),
- _gemm_output(), _has_bias(false), _is_fully_connected_convolution(false), _are_weights_reshaped(false)
+NEConvolutionLayer::NEConvolutionLayer(std::shared_ptr<IMemoryManager> memory_manager)
+ : _memory_group(std::move(memory_manager)), _input_im2col_kernel(), _input_interleave_kernel(), _reshape_weights(), _mm_kernel(), _output_col2im_kernel(), _input_im2col_reshaped(),
+ _input_interleaved_reshaped(), _weights_reshaped(), _gemm_output(), _has_bias(false), _is_fully_connected_convolution(false), _are_weights_reshaped(false)
{
}
@@ -175,6 +180,7 @@ void NEConvolutionLayer::configure(const ITensor *input, const ITensor *weights,
shape_im2col.set(1, mat_input_rows);
shape_im2col.set(2, 1);
_input_im2col_reshaped.allocator()->init(TensorInfo(shape_im2col, 1, dt, fixed_point_position));
+ _memory_group.manage(&_input_im2col_reshaped);
// Create tensor (interleave) to prepare input tensor for GEMM
if(!_is_fully_connected_convolution)
@@ -183,6 +189,7 @@ void NEConvolutionLayer::configure(const ITensor *input, const ITensor *weights,
shape_interleaved.set(0, shape_interleaved.x() * 4);
shape_interleaved.set(1, std::ceil(shape_interleaved.y() / 4.f));
_input_interleaved_reshaped.allocator()->init(TensorInfo(shape_interleaved, 1, dt, fixed_point_position));
+ _memory_group.manage(&_input_interleaved_reshaped);
}
// Create GEMM output tensor
@@ -190,6 +197,7 @@ void NEConvolutionLayer::configure(const ITensor *input, const ITensor *weights,
shape_gemm.set(0, mat_weights_cols);
shape_gemm.set(1, mat_input_rows);
_gemm_output.allocator()->init(TensorInfo(shape_gemm, 1, dt, fixed_point_position));
+ _memory_group.manage(&_gemm_output);
// Configure kernels
_input_im2col_kernel.configure(input, &_input_im2col_reshaped, Size2D(kernel_width, kernel_height), conv_info, _has_bias);
@@ -201,8 +209,11 @@ void NEConvolutionLayer::configure(const ITensor *input, const ITensor *weights,
{
_input_interleave_kernel.configure(&_input_im2col_reshaped, &_input_interleaved_reshaped);
_mm_kernel.configure(&_input_interleaved_reshaped, weights, &_gemm_output, 1.0f);
+ _input_interleaved_reshaped.allocator()->allocate();
}
+ _input_im2col_reshaped.allocator()->allocate();
_output_col2im_kernel.configure(&_gemm_output, output, std::make_pair(conv_w, conv_h));
+ _gemm_output.allocator()->allocate();
ARM_COMPUTE_ERROR_ON_MSG((output->info()->dimension(0) != conv_w) || (output->info()->dimension(1) != conv_h), "Output shape does not match the expected one");
@@ -211,12 +222,6 @@ void NEConvolutionLayer::configure(const ITensor *input, const ITensor *weights,
{
_weights_reshaped.allocator()->allocate();
}
- _input_im2col_reshaped.allocator()->allocate();
- if(!_is_fully_connected_convolution)
- {
- _input_interleaved_reshaped.allocator()->allocate();
- }
- _gemm_output.allocator()->allocate();
}
void NEConvolutionLayer::run()
@@ -228,6 +233,8 @@ void NEConvolutionLayer::run()
_reshape_weights.run();
}
+ _memory_group.acquire();
+
// Run input reshaping
NEScheduler::get().schedule(&_input_im2col_kernel, Window::DimY);
if(!_is_fully_connected_convolution)
@@ -241,4 +248,6 @@ void NEConvolutionLayer::run()
// Reshape output matrix
NEScheduler::get().schedule(&_output_col2im_kernel, Window::DimY);
+
+ _memory_group.release();
}
diff --git a/src/runtime/NEON/functions/NEFullyConnectedLayer.cpp b/src/runtime/NEON/functions/NEFullyConnectedLayer.cpp
index 39983bf643..2e8d10598d 100644
--- a/src/runtime/NEON/functions/NEFullyConnectedLayer.cpp
+++ b/src/runtime/NEON/functions/NEFullyConnectedLayer.cpp
@@ -32,8 +32,8 @@
namespace arm_compute
{
-NEFullyConnectedLayerReshapeWeights::NEFullyConnectedLayerReshapeWeights()
- : _transpose_kernel(), _transpose1xW_kernel(), _transpose_output(), _transpose_weights(false), _is_batched_fc_layer(false)
+NEFullyConnectedLayerReshapeWeights::NEFullyConnectedLayerReshapeWeights(std::shared_ptr<IMemoryManager> memory_manager)
+ : _memory_group(std::move(memory_manager)), _transpose_kernel(), _transpose1xW_kernel(), _transpose_output(), _transpose_weights(false), _is_batched_fc_layer(false)
{
}
@@ -58,6 +58,7 @@ void NEFullyConnectedLayerReshapeWeights::configure(const ITensor *input, ITenso
// Initialize the output tensor for transpose
TensorShape shape_transposed(input->info()->dimension(1), input->info()->dimension(0));
_transpose_output.allocator()->init(TensorInfo(shape_transposed, 1, data_type, fixed_point_position));
+ _memory_group.manage(&_transpose_output);
_transpose_kernel.configure(input, &_transpose_output);
// Configure transpose 1xW kernel
@@ -87,6 +88,8 @@ void NEFullyConnectedLayerReshapeWeights::configure(const ITensor *input, ITenso
void NEFullyConnectedLayerReshapeWeights::run()
{
+ _memory_group.acquire();
+
if(_transpose_weights)
{
NEScheduler::get().schedule(&_transpose_kernel, Window::DimY);
@@ -96,11 +99,13 @@ void NEFullyConnectedLayerReshapeWeights::run()
{
NEScheduler::get().schedule(&_transpose1xW_kernel, Window::DimY);
}
+
+ _memory_group.release();
}
-NEFullyConnectedLayer::NEFullyConnectedLayer()
- : _im2col_kernel(), _reshape_weights_kernel(), _interleave4x4_kernel(), _mm_kernel(), _accumulate_biases_kernel(), _im2col_output(), _interleave4x4_output(), _reshape_weights_output(),
- _are_weights_reshaped(false), _is_batched_fc_layer(false), _linearize_input(false), _accumulate_biases(false)
+NEFullyConnectedLayer::NEFullyConnectedLayer(std::shared_ptr<IMemoryManager> memory_manager)
+ : _memory_group(std::move(memory_manager)), _im2col_kernel(), _reshape_weights_kernel(), _interleave4x4_kernel(), _mm_kernel(), _accumulate_biases_kernel(), _im2col_output(), _interleave4x4_output(),
+ _reshape_weights_output(), _are_weights_reshaped(false), _is_batched_fc_layer(false), _linearize_input(false), _accumulate_biases(false)
{
}
@@ -191,6 +196,7 @@ void NEFullyConnectedLayer::configure(const ITensor *input, const ITensor *weigh
_im2col_output.allocator()->init(TensorInfo(shape_im2col, 1, data_type, fixed_point_position));
// Configure im2col kernel
+ _memory_group.manage(&_im2col_output);
_im2col_kernel.configure(input, &_im2col_output, Size2D(1, 1), PadStrideInfo(1, 1, 0, 0), false);
multiply_input = &_im2col_output;
@@ -204,6 +210,7 @@ void NEFullyConnectedLayer::configure(const ITensor *input, const ITensor *weigh
_interleave4x4_output.allocator()->init(TensorInfo(shape_interleaved, 1, data_type, fixed_point_position));
// Configure interleave4x4 kernel
+ _memory_group.manage(&_interleave4x4_output);
_interleave4x4_kernel.configure(multiply_input, &_interleave4x4_output);
multiply_input = &_interleave4x4_output;
@@ -248,6 +255,8 @@ void NEFullyConnectedLayer::run()
_reshape_weights_kernel.run();
}
+ _memory_group.acquire();
+
// Linearize input if it comes from a convolutional layer
if(_linearize_input)
{
@@ -268,5 +277,7 @@ void NEFullyConnectedLayer::run()
{
NEScheduler::get().schedule(&_accumulate_biases_kernel, Window::DimY);
}
+
+ _memory_group.release();
}
} // namespace arm_compute
diff --git a/src/runtime/NEON/functions/NESoftmaxLayer.cpp b/src/runtime/NEON/functions/NESoftmaxLayer.cpp
index 13dfa4a51e..cc5d4e91c3 100644
--- a/src/runtime/NEON/functions/NESoftmaxLayer.cpp
+++ b/src/runtime/NEON/functions/NESoftmaxLayer.cpp
@@ -31,8 +31,8 @@
using namespace arm_compute;
-NESoftmaxLayer::NESoftmaxLayer()
- : _max_kernel(), _shift_exp_sum_kernel(), _norm_kernel(), _fill_border_kernel(), _max(), _sum(), _tmp()
+NESoftmaxLayer::NESoftmaxLayer(std::shared_ptr<IMemoryManager> memory_manager)
+ : _memory_group(std::move(memory_manager)), _max_kernel(), _shift_exp_sum_kernel(), _norm_kernel(), _fill_border_kernel(), _max(), _sum(), _tmp()
{
}
@@ -50,6 +50,11 @@ void NESoftmaxLayer::configure(ITensor *input, ITensor *output)
_max.allocator()->init(tensor_info_max_sum);
_sum.allocator()->init(tensor_info_max_sum);
+ // Manage intermediate buffers
+ _memory_group.manage(&_tmp);
+ _memory_group.manage(&_max);
+ _memory_group.manage(&_sum);
+
// Configure Kernels
_max_kernel.configure(input, &_max);
_shift_exp_sum_kernel.configure(input, &_max, &_tmp, &_sum);
@@ -64,8 +69,12 @@ void NESoftmaxLayer::configure(ITensor *input, ITensor *output)
void NESoftmaxLayer::run()
{
+ _memory_group.acquire();
+
NEScheduler::get().schedule(&_fill_border_kernel, Window::DimY);
NEScheduler::get().schedule(&_max_kernel, Window::DimY);
NEScheduler::get().schedule(&_shift_exp_sum_kernel, Window::DimY);
NEScheduler::get().schedule(&_norm_kernel, Window::DimY);
+
+ _memory_group.release();
}