From 62385bce6baacfa194cff9e6be6d8eaa73bc3fab Mon Sep 17 00:00:00 2001 From: John Richardson Date: Fri, 20 Apr 2018 13:11:36 +0100 Subject: COMPMID-948: Add validation to CLL2NormalizeLayer Change-Id: I452a718a60b81da51cd3e98641fd99c86c4debab Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/129451 Tested-by: Jenkins Reviewed-by: Gian Marco Iodice --- src/runtime/CL/functions/CLReductionOperation.cpp | 61 ++++++++++++++++++++--- 1 file changed, 53 insertions(+), 8 deletions(-) (limited to 'src/runtime/CL/functions/CLReductionOperation.cpp') diff --git a/src/runtime/CL/functions/CLReductionOperation.cpp b/src/runtime/CL/functions/CLReductionOperation.cpp index d02afb4e90..3a5133d91f 100644 --- a/src/runtime/CL/functions/CLReductionOperation.cpp +++ b/src/runtime/CL/functions/CLReductionOperation.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 ARM Limited. + * Copyright (c) 2017-2018 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -35,19 +35,64 @@ using namespace arm_compute; +namespace +{ +unsigned int calculate_number_of_stages(const ITensorInfo *input) +{ + // Calculate number of WGs. 16 elements per thread, 8 threads per WG + const unsigned int num_of_wg = ceil(input->dimension(0) / 128.f); + + // Calculate number of stages. First stage performs op and the rest reduction sum + // depending on the size of the input. Last stage should have only 1 WG. + const unsigned int num_of_stages = num_of_wg / 128 + 2; + + return num_of_stages; +} +} // namespace + CLReductionOperation::CLReductionOperation(std::shared_ptr memory_manager) : _memory_group(std::move(memory_manager)), _sums_vector(), _reduction_kernels_vector(), _border_handlers_vector(), _num_of_stages() { } -void CLReductionOperation::configure(ICLTensor *input, ICLTensor *output, unsigned int axis, ReductionOperation op) +Status CLReductionOperation::validate(const ITensorInfo *input, const ITensorInfo *output, unsigned int axis, ReductionOperation op) { - // Calculate number of WGs. 16 elements per thread, 8 threads per WG - unsigned int num_of_wg = ceil(input->info()->dimension(0) / 128.f); + const unsigned int num_of_stages = calculate_number_of_stages(input); - // Calculate number of stages. First stage performs op and the rest reduction sum - // depending on the size of the input. Last stage should have only 1 WG. - _num_of_stages = num_of_wg / 128 + 2; + // Create temporary tensor infos + auto sums_vector = arm_compute::support::cpp14::make_unique(num_of_stages - 1); + + // Create intermediate tensor info + TensorShape shape{ input->tensor_shape() }; + + for(unsigned int i = 0; i < num_of_stages - 1; i++) + { + shape.set(0, ceil(shape.x() / 128.f)); + sums_vector[i].set_data_type(input->data_type()); + sums_vector[i].set_tensor_shape(shape); + sums_vector[i].set_num_channels(input->num_channels()); + sums_vector[i].set_fixed_point_position(input->fixed_point_position()); + } + + // Validate ReductionOperation only on first kernel + ARM_COMPUTE_RETURN_ON_ERROR(CLReductionOperationKernel::validate(input, sums_vector.get(), axis, op)); + + // Validate ReductionOperation on intermediate stages + for(unsigned int i = 1; i < num_of_stages - 1; ++i) + { + ARM_COMPUTE_RETURN_ON_ERROR(CLReductionOperationKernel::validate(sums_vector.get() + i - 1, sums_vector.get() + i, axis, op)); + } + + // Validate ReductionOperation on the last stage + const unsigned int last_stage = num_of_stages - 1; + ARM_COMPUTE_RETURN_ON_ERROR(CLReductionOperationKernel::validate(sums_vector.get() + last_stage - 1, output, axis, op)); + + return Status{}; +} + +void CLReductionOperation::configure(ICLTensor *input, ICLTensor *output, unsigned int axis, ReductionOperation op) +{ + _num_of_stages = calculate_number_of_stages(input->info()); // Create temporary tensors _sums_vector = arm_compute::support::cpp14::make_unique(_num_of_stages - 1); @@ -95,4 +140,4 @@ void CLReductionOperation::run() } _memory_group.release(); -} \ No newline at end of file +} -- cgit v1.2.1