aboutsummaryrefslogtreecommitdiff
path: root/src/core/CL/kernels/CLROIPoolingLayerKernel.cpp
diff options
context:
space:
mode:
authorManuel Bottini <manuel.bottini@arm.com>2019-01-09 17:04:39 +0000
committerGeorgios Pinitas <georgios.pinitas@arm.com>2019-01-11 15:17:31 +0000
commitcc5171b85654b9f19a5f52bbe8abea0572ee0163 (patch)
tree032999b06aeced4f5e2963ab60c833acb951c3c8 /src/core/CL/kernels/CLROIPoolingLayerKernel.cpp
parent587708b05ca63fa88118daec82e2c39d63e60086 (diff)
downloadComputeLibrary-cc5171b85654b9f19a5f52bbe8abea0572ee0163.tar.gz
COMPMID-1677: Change ROIPooling layer interface to accept ROIs as tensors
Change-Id: If16b572a4d906187b77f32133a72a44316fa74e4 Reviewed-on: https://review.mlplatform.org/490 Tested-by: Arm Jenkins <bsgcomp@arm.com> Reviewed-by: Georgios Pinitas <georgios.pinitas@arm.com>
Diffstat (limited to 'src/core/CL/kernels/CLROIPoolingLayerKernel.cpp')
-rw-r--r--src/core/CL/kernels/CLROIPoolingLayerKernel.cpp82
1 files changed, 54 insertions, 28 deletions
diff --git a/src/core/CL/kernels/CLROIPoolingLayerKernel.cpp b/src/core/CL/kernels/CLROIPoolingLayerKernel.cpp
index 23676942a6..df7687edea 100644
--- a/src/core/CL/kernels/CLROIPoolingLayerKernel.cpp
+++ b/src/core/CL/kernels/CLROIPoolingLayerKernel.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2018 ARM Limited.
+ * Copyright (c) 2017-2019 ARM Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -39,29 +39,61 @@
#include <set>
#include <string>
-using namespace arm_compute;
+namespace arm_compute
+{
+namespace
+{
+std::pair<Status, Window> validate_and_configure_window(ITensorInfo *input, ITensorInfo *rois, ITensorInfo *output, const ROIPoolingLayerInfo &pool_info)
+{
+ ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
+
+ // Output auto initialization if not yet initialized
+ TensorShape output_shape(pool_info.pooled_width(), pool_info.pooled_height(), input->dimension(2), rois->dimension(1));
+ auto_init_if_empty((*output), output_shape, 1, input->data_type());
+
+ // Configure kernel window
+ const unsigned int num_elems_processed_per_iteration = 1;
+ Window win = calculate_max_window(*output, Steps(num_elems_processed_per_iteration));
+
+ AccessWindowHorizontal output_access(output, 0, num_elems_processed_per_iteration);
+ AccessWindowHorizontal input_access(input, input->valid_region().start(0), num_elems_processed_per_iteration);
+
+ bool window_changed = update_window_and_padding(win, input_access, output_access);
+ output_access.set_valid_region(win, ValidRegion(Coordinates(), output->tensor_shape()));
+ Status err = (window_changed) ? ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Insufficient Padding!") : Status{};
+ return std::make_pair(err, win);
+}
+} // namespace
CLROIPoolingLayerKernel::CLROIPoolingLayerKernel()
: _input(nullptr), _rois(nullptr), _output(nullptr), _pool_info(0, 0, 0.f)
{
}
-void CLROIPoolingLayerKernel::configure(const ICLTensor *input, const ICLROIArray *rois, ICLTensor *output, const ROIPoolingLayerInfo &pool_info)
+void CLROIPoolingLayerKernel::configure(const ICLTensor *input, const ICLTensor *rois, ICLTensor *output, const ROIPoolingLayerInfo &pool_info)
{
ARM_COMPUTE_ERROR_ON_NULLPTR(input, rois, output);
+
+ //Validate arguments
+ ARM_COMPUTE_ERROR_ON_NULLPTR(input->info(), rois->info(), output->info());
+ ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(rois, 1, DataType::U16);
+ ARM_COMPUTE_ERROR_ON(rois->info()->dimension(0) != 5);
+ ARM_COMPUTE_ERROR_ON(rois->info()->num_dimensions() > 2);
ARM_COMPUTE_ERROR_ON_F16_UNSUPPORTED(input);
- ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::F16, DataType::F32);
+ ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::F32, DataType::F16);
ARM_COMPUTE_ERROR_ON((pool_info.pooled_width() == 0) || (pool_info.pooled_height() == 0));
- ARM_COMPUTE_ERROR_ON(rois->num_values() == 0);
- // Output auto inizialitation if not yet initialized
- TensorShape output_shape(pool_info.pooled_width(), pool_info.pooled_height(), input->info()->dimension(2), rois->num_values());
- auto_init_if_empty(*output->info(), output_shape, 1, input->info()->data_type());
+ if(output->info()->total_size() != 0)
+ {
+ ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES(input, output);
+ ARM_COMPUTE_ERROR_ON((output->info()->dimension(0) != pool_info.pooled_width()) || (output->info()->dimension(1) != pool_info.pooled_height()));
+ ARM_COMPUTE_ERROR_ON(input->info()->dimension(2) != output->info()->dimension(2));
+ ARM_COMPUTE_ERROR_ON(rois->info()->dimension(1) != output->info()->dimension(3));
+ }
- ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES(input, output);
- ARM_COMPUTE_ERROR_ON((output->info()->dimension(0) != pool_info.pooled_width()) || (output->info()->dimension(1) != pool_info.pooled_height()));
- ARM_COMPUTE_ERROR_ON(input->info()->dimension(2) != output->info()->dimension(2));
- ARM_COMPUTE_ERROR_ON(rois->num_values() != output->info()->dimension(3));
+ // Configure kernel window
+ auto win_config = validate_and_configure_window(input->info(), rois->info(), output->info(), pool_info);
+ ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
// Set instance variables
_input = input;
@@ -89,19 +121,7 @@ void CLROIPoolingLayerKernel::configure(const ICLTensor *input, const ICLROIArra
add_argument<cl_uint>(idx, _input->info()->strides_in_bytes()[3]);
add_argument<cl_uint>(idx, _output->info()->strides_in_bytes()[3]);
- // Configure kernel window
- const unsigned int num_elems_processed_per_iteration = 1;
- Window window = calculate_max_window(*output->info(), Steps(num_elems_processed_per_iteration));
- AccessWindowStatic input_access(input->info(),
- input->info()->valid_region().start(0),
- input->info()->valid_region().start(1),
- input->info()->valid_region().end(0),
- input->info()->valid_region().end(1));
- AccessWindowStatic output_access(output->info(), 0, 0, pool_info.pooled_width(), pool_info.pooled_height());
-
- update_window_and_padding(window, input_access, output_access);
- output_access.set_valid_region(window, ValidRegion(Coordinates(), output->info()->tensor_shape()));
- ICLKernel::configure_internal(window);
+ ICLKernel::configure_internal(win_config.second);
}
void CLROIPoolingLayerKernel::run(const Window &window, cl::CommandQueue &queue)
@@ -109,14 +129,20 @@ void CLROIPoolingLayerKernel::run(const Window &window, cl::CommandQueue &queue)
ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(IKernel::window(), window);
- Window slice = window.first_slice_window_3D();
- // Parallelize spatially and across the fourth dimension of the output tensor (also across ROIArray)
+ Window slice = window.first_slice_window_3D();
+ Window slice_rois = slice;
+ // Parallelize spatially and across the fourth dimension of the output tensor (also across ROITensor)
+ slice_rois.set_dimension_step(Window::DimX, _rois->info()->dimension(0));
slice.set(Window::DimZ, window[3]);
// Set arguments
unsigned int idx = 0;
add_3D_tensor_argument(idx, _input, slice);
- add_1D_array_argument<ROI>(idx, _rois, Strides(sizeof(ROI)), 1U, slice);
+ add_2D_tensor_argument(idx, _rois, slice_rois);
add_3D_tensor_argument(idx, _output, slice);
+ add_argument<cl_uint>(idx, _input->info()->strides_in_bytes()[3]);
+ add_argument<cl_uint>(idx, _output->info()->strides_in_bytes()[3]);
+
enqueue(queue, *this, slice);
}
+} // namespace arm_compute \ No newline at end of file