IVGCVSW-3843 Add support of per-axis quantization to BuildArmComputeTensorInfo

Signed-off-by: Aron Virginas-Tar <Aron.Virginas-Tar@arm.com>
Change-Id: I0bb0e9da306eee3e19dc9967a6c8bb01da998deb
diff --git a/src/backends/aclCommon/ArmComputeTensorUtils.cpp b/src/backends/aclCommon/ArmComputeTensorUtils.cpp
index c7d250a..b2955b9 100644
--- a/src/backends/aclCommon/ArmComputeTensorUtils.cpp
+++ b/src/backends/aclCommon/ArmComputeTensorUtils.cpp
@@ -106,9 +106,11 @@
 arm_compute::TensorInfo BuildArmComputeTensorInfo(const armnn::TensorInfo& tensorInfo)
 {
     const arm_compute::TensorShape aclTensorShape = BuildArmComputeTensorShape(tensorInfo.GetShape());
-    const arm_compute::DataType aclDataType = GetArmComputeDataType(tensorInfo.GetDataType());
-    const arm_compute::QuantizationInfo aclQuantizationInfo(tensorInfo.GetQuantizationScale(),
-                                                            tensorInfo.GetQuantizationOffset());
+    const arm_compute::DataType aclDataType       = GetArmComputeDataType(tensorInfo.GetDataType());
+
+    const arm_compute::QuantizationInfo aclQuantizationInfo = tensorInfo.HasMultipleQuantizationScales() ?
+        arm_compute::QuantizationInfo(tensorInfo.GetQuantizationScales()) :
+        arm_compute::QuantizationInfo(tensorInfo.GetQuantizationScale(), tensorInfo.GetQuantizationOffset());
 
     return arm_compute::TensorInfo(aclTensorShape, 1, aclDataType, aclQuantizationInfo);
 }
@@ -116,15 +118,10 @@
 arm_compute::TensorInfo BuildArmComputeTensorInfo(const armnn::TensorInfo& tensorInfo,
                                                   armnn::DataLayout dataLayout)
 {
-    const arm_compute::TensorShape aclTensorShape = BuildArmComputeTensorShape(tensorInfo.GetShape());
-    const arm_compute::DataType aclDataType = GetArmComputeDataType(tensorInfo.GetDataType());
-    const arm_compute::QuantizationInfo aclQuantizationInfo(tensorInfo.GetQuantizationScale(),
-                                                            tensorInfo.GetQuantizationOffset());
+    arm_compute::TensorInfo aclTensorInfo = BuildArmComputeTensorInfo(tensorInfo);
+    aclTensorInfo.set_data_layout(ConvertDataLayout(dataLayout));
 
-    arm_compute::TensorInfo clTensorInfo(aclTensorShape, 1, aclDataType, aclQuantizationInfo);
-    clTensorInfo.set_data_layout(ConvertDataLayout(dataLayout));
-
-    return clTensorInfo;
+    return aclTensorInfo;
 }
 
 arm_compute::DataLayout ConvertDataLayout(armnn::DataLayout dataLayout)
diff --git a/src/backends/aclCommon/common.mk b/src/backends/aclCommon/common.mk
index cebceaf..0ba966a 100644
--- a/src/backends/aclCommon/common.mk
+++ b/src/backends/aclCommon/common.mk
@@ -16,4 +16,5 @@
 # up by the Android.mk file in the root of ArmNN
 
 COMMON_TEST_SOURCES := \
+    test/ArmComputeTensorUtilsTests.cpp \
     test/MemCopyTests.cpp
diff --git a/src/backends/aclCommon/test/ArmComputeTensorUtilsTests.cpp b/src/backends/aclCommon/test/ArmComputeTensorUtilsTests.cpp
new file mode 100644
index 0000000..1e2f0db
--- /dev/null
+++ b/src/backends/aclCommon/test/ArmComputeTensorUtilsTests.cpp
@@ -0,0 +1,46 @@
+//
+// Copyright © 2019 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include <aclCommon/ArmComputeTensorUtils.hpp>
+
+#include <boost/test/unit_test.hpp>
+
+using namespace armnn::armcomputetensorutils;
+
+BOOST_AUTO_TEST_SUITE(ArmComputeTensorUtils)
+
+BOOST_AUTO_TEST_CASE(BuildArmComputeTensorInfoTest)
+{
+
+    const armnn::TensorShape tensorShape = { 1, 2, 3, 4 };
+    const armnn::DataType dataType = armnn::DataType::QuantisedAsymm8;
+
+    const std::vector<float> quantScales = { 1.5f, 2.5f, 3.5f, 4.5f };
+    const float quantScale = quantScales[0];
+    const int32_t quantOffset = 128;
+
+    // Tensor info with per-tensor quantization
+    const armnn::TensorInfo tensorInfo0(tensorShape, dataType, quantScale, quantOffset);
+    const arm_compute::TensorInfo aclTensorInfo0 = BuildArmComputeTensorInfo(tensorInfo0);
+
+    const arm_compute::TensorShape& aclTensorShape = aclTensorInfo0.tensor_shape();
+    BOOST_CHECK(aclTensorShape.num_dimensions() == tensorShape.GetNumDimensions());
+    for(unsigned int i = 0u; i < tensorShape.GetNumDimensions(); ++i)
+    {
+        // NOTE: arm_compute tensor dimensions are stored in the opposite order
+        BOOST_CHECK(aclTensorShape[i] == tensorShape[tensorShape.GetNumDimensions() - i - 1]);
+    }
+
+    BOOST_CHECK(aclTensorInfo0.data_type() == arm_compute::DataType::QASYMM8);
+    BOOST_CHECK(aclTensorInfo0.quantization_info().scale()[0] == quantScale);
+
+    // Tensor info with per-axis quantization
+    const armnn::TensorInfo tensorInfo1(tensorShape, dataType, quantScales, 0);
+    const arm_compute::TensorInfo aclTensorInfo1 = BuildArmComputeTensorInfo(tensorInfo1);
+
+    BOOST_CHECK(aclTensorInfo1.quantization_info().scale() == quantScales);
+}
+
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/src/backends/aclCommon/test/CMakeLists.txt b/src/backends/aclCommon/test/CMakeLists.txt
index 637b724..7ba9306 100644
--- a/src/backends/aclCommon/test/CMakeLists.txt
+++ b/src/backends/aclCommon/test/CMakeLists.txt
@@ -4,6 +4,7 @@
 #
 
 list(APPEND armnnAclCommonUnitTests_sources
+    ArmComputeTensorUtilsTests.cpp
     CreateWorkloadClNeon.hpp
     MemCopyTests.cpp
     MemCopyTestImpl.hpp