From fd899966cb881f5bb1ccce7903253a32d360419d Mon Sep 17 00:00:00 2001 From: Matthew Bentham Date: Mon, 31 Dec 2018 15:49:42 +0000 Subject: MLCE-82 Add Neon Mean support and unit tests Factor out new BuildArmComputeReductionCoordinates function from CL backend into ArmComputeTensorUtils. Update NEON LayerSupport and WorkloadFactory objects Change-Id: Icc975ec699199bffafbdb207323df509d35e1e04 --- src/backends/aclCommon/ArmComputeTensorUtils.cpp | 42 ++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'src/backends/aclCommon/ArmComputeTensorUtils.cpp') diff --git a/src/backends/aclCommon/ArmComputeTensorUtils.cpp b/src/backends/aclCommon/ArmComputeTensorUtils.cpp index 6b55948693..a2d7d8c797 100644 --- a/src/backends/aclCommon/ArmComputeTensorUtils.cpp +++ b/src/backends/aclCommon/ArmComputeTensorUtils.cpp @@ -31,6 +31,48 @@ arm_compute::DataType GetArmComputeDataType(armnn::DataType dataType) } } +arm_compute::Coordinates BuildArmComputeReductionCoordinates(size_t inputDimensions, + unsigned int originalInputRank, + const std::vector& armnnAxes) +{ + arm_compute::Coordinates outAclCoords; + + if (armnnAxes.empty()) + { + // If no reduction axes were provided, then the input must be reduced along all dimensions. + // Since Compute Library does not accept an empty vector as the reduction dimensions, we then + // manually create a vector including all the input dimensions (in reversed order) as: + // + // { inputDimensions - 1, inputDimensions - 2, ..., 1, 0 } + // + outAclCoords.set_num_dimensions(inputDimensions); + std::generate(outAclCoords.begin(), outAclCoords.end(), [d = inputDimensions - 1] () mutable { return d--; }); + } + else + { + // Create a vector of reduction dimensions (in reversed order) with the given reduction axes. + // + // Adjust the given reduction axes according to the original rank of the input tensor (before ACL applied any + // dimension correction). + // For example, if the input tensor originally had 4 dimensions, and one of the reduction axes was 2, then the + // new value for that reduction axis should be 1. + // + // Example: + // ArmNN input shape = { 1, 1, 3, 2 } -> ACL input shape = { 2, 3 } + // ArmNN reduction axis = { 2 } -> ACL reduction axis = { 1 } + // ArmNN reduction axis = { 3 } -> ACL reduction axis = { 0 } + // + // The transformation: ACL reduction axis index = original rank - ArmNN reduction axis index - 1 + // + outAclCoords.set_num_dimensions(armnnAxes.size()); + std::transform(armnnAxes.begin(), armnnAxes.end(), + outAclCoords.begin(), + [originalInputRank](unsigned int i){ return originalInputRank - i - 1; }); + } + + return outAclCoords; +} + arm_compute::TensorShape BuildArmComputeTensorShape(const armnn::TensorShape& tensorShape) { arm_compute::TensorShape shape; -- cgit v1.2.1