aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/CL/functions/CLReductionOperation.cpp
diff options
context:
space:
mode:
authorJohn Richardson <john.richardson@arm.com>2018-04-20 13:11:36 +0100
committerAnthony Barbier <anthony.barbier@arm.com>2018-11-02 16:51:50 +0000
commit62385bce6baacfa194cff9e6be6d8eaa73bc3fab (patch)
tree81d72e49e487ae972423cd57d181ebc53efe487b /src/runtime/CL/functions/CLReductionOperation.cpp
parent657bdb358c95ccd6bb07594a01625a7d7bacd32f (diff)
downloadComputeLibrary-62385bce6baacfa194cff9e6be6d8eaa73bc3fab.tar.gz
COMPMID-948: Add validation to CLL2NormalizeLayer
Change-Id: I452a718a60b81da51cd3e98641fd99c86c4debab Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/129451 Tested-by: Jenkins <bsgcomp@arm.com> Reviewed-by: Gian Marco Iodice <gianmarco.iodice@arm.com>
Diffstat (limited to 'src/runtime/CL/functions/CLReductionOperation.cpp')
-rw-r--r--src/runtime/CL/functions/CLReductionOperation.cpp61
1 files changed, 53 insertions, 8 deletions
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<IMemoryManager> 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<TensorInfo[]>(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<CLTensor[]>(_num_of_stages - 1);
@@ -95,4 +140,4 @@ void CLReductionOperation::run()
}
_memory_group.release();
-} \ No newline at end of file
+}