From 7e20e29904c98adae5a91c6492fd78da88b7a9bf Mon Sep 17 00:00:00 2001 From: Sheri Zhang Date: Tue, 2 Feb 2021 11:49:34 +0000 Subject: Make memset/copy functions state-less Port following functions: - CLCopy - CLFill - CLPermute - CLReshapeLayer - CLCropResize Resolves: COMPMID-4002 Signed-off-by: Sheri Zhang Change-Id: I8392aa515aaeb5b44dab6122be6a795d08376d5f Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/5003 Comments-Addressed: Arm Jenkins Reviewed-by: Michele Di Giorgio Tested-by: Arm Jenkins --- src/runtime/CL/functions/CLCropResize.cpp | 46 ++++++++++++++++--------------- 1 file changed, 24 insertions(+), 22 deletions(-) (limited to 'src/runtime/CL/functions/CLCropResize.cpp') diff --git a/src/runtime/CL/functions/CLCropResize.cpp b/src/runtime/CL/functions/CLCropResize.cpp index ed31446cf9..77c44d539b 100644 --- a/src/runtime/CL/functions/CLCropResize.cpp +++ b/src/runtime/CL/functions/CLCropResize.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2020 Arm Limited. + * Copyright (c) 2019-2021 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -25,10 +25,7 @@ #include "arm_compute/core/CL/CLHelpers.h" #include "arm_compute/runtime/CL/CLScheduler.h" -#include "src/core/CL/kernels/CLCopyKernel.h" -#include "src/core/CL/kernels/CLCropKernel.h" #include "src/core/CL/kernels/CLFillBorderKernel.h" -#include "src/core/CL/kernels/CLMemsetKernel.h" #include "src/core/helpers/AutoConfiguration.h" #include "src/core/helpers/WindowHelpers.h" @@ -59,7 +56,7 @@ inline void configure_crop(const ICLTensor *input, ICLTensor *crop_boxes, ICLTen } // namespace CLCropResize::CLCropResize() - : _input(nullptr), _boxes(nullptr), _box_ind(nullptr), _output(nullptr), _num_boxes(0), _method(), _extrapolation_value(0), _scale(), _copy(), _crop_results(), _scaled_results(), _internal_kernels() + : _input(nullptr), _boxes(nullptr), _box_ind(nullptr), _output(nullptr), _num_boxes(0), _method(), _extrapolation_value(0), _scale(), _copy(), _crop_results(), _scaled_results(), _internal_functions() { } @@ -73,7 +70,7 @@ Status CLCropResize::validate(const ITensorInfo *input, ITensorInfo *boxes, ITen ARM_COMPUTE_RETURN_ERROR_ON(boxes->tensor_shape()[0] != 4); ARM_COMPUTE_RETURN_ERROR_ON(boxes->tensor_shape()[1] != box_ind->tensor_shape()[0]); TensorInfo temp_info; - ARM_COMPUTE_RETURN_ON_ERROR(CLCropKernel::validate(input->clone().get(), &temp_info, { 0, 0 }, { 1, 1 }, input->dimension(3) - 1, extrapolation_value)); + ARM_COMPUTE_RETURN_ON_ERROR(CLCrop::validate(input->clone().get(), &temp_info, { 0, 0 }, { 1, 1 }, input->dimension(3) - 1, extrapolation_value)); if(output->total_size() > 0) { ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_NOT_IN(output, DataType::F32); @@ -111,11 +108,11 @@ void CLCropResize::configure(const CLCompileContext &compile_context, const ICLT // For each crop box: // - The initial cropped image is produced as specified by boxes[i] from the 3D image input[box_ind[i]]. - // Possibly using a CLCropKernel and up to four CLMemsetKernels. + // Possibly using a CLCrop and up to four CLFills. // - A tensor is required to hold this initial cropped image. // - A scale function is used to resize the cropped image to the size specified by crop_size. // - A tensor is required to hold the final scaled image before it is copied into the 4D output - // that will hold all final cropped and scaled 3D images using CLCopyKernel. + // that will hold all final cropped and scaled 3D images using CLCopy. // The contents of _boxes and _box_ind are required to calculate the shape // of the initial cropped image and thus are required to configure the @@ -149,7 +146,7 @@ void CLCropResize::configure(const CLCompileContext &compile_context, const ICLT Window win = calculate_max_window(*_output->info()); win.set(3, Window::Dimension(num_box, num_box + 1, 1)); - auto copy_kernel = std::make_unique(); + auto copy_kernel = std::make_unique(); copy_kernel->configure(compile_context, _scaled_results[num_box].get(), _output, &win); _copy.emplace_back(std::move(copy_kernel)); @@ -207,9 +204,10 @@ void CLCropResize::configure(const CLCompileContext &compile_context, const ICLT { Window slice_fill_rows_before(full_window); slice_fill_rows_before.set(2, Window::Dimension(0, rows_out_of_bounds[0], 1)); - auto kernel = std::make_unique(); + auto kernel = std::make_unique(); kernel->configure(compile_context, _crop_results[num_box].get(), extrapolation_value, &slice_fill_rows_before); - _internal_kernels.push_back(std::move(kernel)); + //_internal_functions.emplace_back(std::move(kernel)); + _internal_functions.push_back(std::move(kernel)); } Window slice_in(full_window); @@ -224,18 +222,20 @@ void CLCropResize::configure(const CLCompileContext &compile_context, const ICLT { Window slice_fill_cols_before(slice_in); slice_fill_cols_before.set(1, Window::Dimension(0, cols_out_of_bounds[0], 1)); - auto kernel = std::make_unique(); + auto kernel = std::make_unique(); kernel->configure(compile_context, _crop_results[num_box].get(), extrapolation_value, &slice_fill_cols_before); - _internal_kernels.push_back(std::move(kernel)); + //_internal_functions.emplace_back(std::move(kernel)); + _internal_functions.push_back(std::move(kernel)); } if(cols_out_of_bounds[1] > 0) { Window slice_fill_cols_after(slice_in); slice_fill_cols_after.set(1, Window::Dimension(_crop_results[num_box].get()->info()->dimension(1) - cols_out_of_bounds[1], _crop_results[num_box].get()->info()->dimension(1), 1)); - auto kernel = std::make_unique(); + auto kernel = std::make_unique(); kernel->configure(compile_context, _crop_results[num_box].get(), extrapolation_value, &slice_fill_cols_after); - _internal_kernels.push_back(std::move(kernel)); + //_internal_functions.emplace_back(std::move(kernel)); + _internal_functions.push_back(std::move(kernel)); } // Copy all elements within the input bounds from the input tensor. @@ -246,10 +246,11 @@ void CLCropResize::configure(const CLCompileContext &compile_context, const ICLT is_height_flipped ? start[1] - rows_out_of_bounds[0] : start[1] + rows_out_of_bounds[0] }; Coordinates2D end_in{ is_width_flipped ? start_in.x - cols_in_bounds + 1 : start_in.x + cols_in_bounds - 1, is_height_flipped ? start_in.y - rows_in_bounds + 1 : start_in.y + rows_in_bounds - 1 }; - auto kernel = std::make_unique(); + auto kernel = std::make_unique(); kernel->configure(compile_context, _input, _crop_results[num_box].get(), start_in, end_in, batch_index, extrapolation_value, &slice_in); - _internal_kernels.push_back(std::move(kernel)); + //_internal_functions.emplace_back(std::move(kernel)); + _internal_functions.push_back(std::move(kernel)); } } @@ -258,9 +259,10 @@ void CLCropResize::configure(const CLCompileContext &compile_context, const ICLT { Window slice_fill_rows_after(full_window); slice_fill_rows_after.set(2, Window::Dimension(_crop_results[num_box].get()->info()->dimension(2) - rows_out_of_bounds[1], _crop_results[num_box].get()->info()->dimension(2), 1)); - auto kernel = std::make_unique(); + auto kernel = std::make_unique(); kernel->configure(compile_context, _crop_results[num_box].get(), extrapolation_value, &slice_fill_rows_after); - _internal_kernels.push_back(std::move(kernel)); + //_internal_functions.emplace_back(std::move(kernel)); + _internal_functions.push_back(std::move(kernel)); } } _boxes->unmap(CLScheduler::get().queue()); @@ -272,9 +274,9 @@ void CLCropResize::run() { ARM_COMPUTE_ERROR_ON_MSG(_output == nullptr, "Unconfigured function"); - for(unsigned int i = 0; i < _internal_kernels.size(); ++i) + for(unsigned int i = 0; i < _internal_functions.size(); ++i) { - CLScheduler::get().enqueue(*(_internal_kernels[i])); + _internal_functions[i]->run(); } CLScheduler::get().sync(); @@ -285,7 +287,7 @@ void CLCropResize::run() CLScheduler::get().sync(); for(auto &kernel : _copy) { - CLScheduler::get().enqueue(*kernel, true); + kernel->run(); } CLScheduler::get().sync(); } -- cgit v1.2.1