Nattapat Chaimanowong | 8a54ac0 | 2019-03-29 15:25:04 +0000 | [diff] [blame] | 1 | // |
Teresa Charlin | fbf0e5b | 2020-08-17 01:01:06 +0100 | [diff] [blame] | 2 | // Copyright © 2017 Arm Ltd and Contributors. All rights reserved. |
Nattapat Chaimanowong | 8a54ac0 | 2019-03-29 15:25:04 +0000 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
Nattapat Chaimanowong | 8a54ac0 | 2019-03-29 15:25:04 +0000 | [diff] [blame] | 5 | |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 6 | #include "DequantizeTestImpl.hpp" |
| 7 | |
| 8 | #include <ResolveType.hpp> |
Nattapat Chaimanowong | 8a54ac0 | 2019-03-29 15:25:04 +0000 | [diff] [blame] | 9 | |
Nattapat Chaimanowong | 8a54ac0 | 2019-03-29 15:25:04 +0000 | [diff] [blame] | 10 | |
Sadik Armagan | a097d2a | 2021-11-24 15:47:28 +0000 | [diff] [blame] | 11 | #include <armnnTestUtils/TensorCopyUtils.hpp> |
Colm Donelan | 0c47974 | 2021-12-10 12:43:54 +0000 | [diff] [blame] | 12 | #include <armnnTestUtils/WorkloadTestUtils.hpp> |
Nattapat Chaimanowong | 8a54ac0 | 2019-03-29 15:25:04 +0000 | [diff] [blame] | 13 | |
Sadik Armagan | a097d2a | 2021-11-24 15:47:28 +0000 | [diff] [blame] | 14 | #include <TensorHelpers.hpp> |
Nattapat Chaimanowong | 8a54ac0 | 2019-03-29 15:25:04 +0000 | [diff] [blame] | 15 | |
| 16 | namespace |
| 17 | { |
| 18 | |
Jan Eilers | f710793 | 2019-11-01 11:09:36 +0000 | [diff] [blame] | 19 | template<typename T, std::size_t Dim, typename T1=float> |
| 20 | LayerTestResult<T1, Dim> DequantizeTestImpl( |
| 21 | armnn::IWorkloadFactory& workloadFactory, |
| 22 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 23 | const armnn::TensorInfo& inputTensorInfo, |
| 24 | const armnn::TensorInfo& outputTensorInfo, |
| 25 | const std::vector<T>& inputData, |
| 26 | const std::vector<T1>& expectedOutputData, |
| 27 | armnn::DequantizeQueueDescriptor descriptor) |
Nattapat Chaimanowong | 8a54ac0 | 2019-03-29 15:25:04 +0000 | [diff] [blame] | 28 | { |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 29 | IgnoreUnused(memoryManager); |
Nattapat Chaimanowong | 8a54ac0 | 2019-03-29 15:25:04 +0000 | [diff] [blame] | 30 | |
Sadik Armagan | 483c811 | 2021-06-01 09:24:52 +0100 | [diff] [blame] | 31 | std::vector<T1> actualOutput(outputTensorInfo.GetNumElements()); |
Nattapat Chaimanowong | 8a54ac0 | 2019-03-29 15:25:04 +0000 | [diff] [blame] | 32 | |
Teresa Charlin | fbf0e5b | 2020-08-17 01:01:06 +0100 | [diff] [blame] | 33 | ARMNN_NO_DEPRECATE_WARN_BEGIN |
Nattapat Chaimanowong | 8a54ac0 | 2019-03-29 15:25:04 +0000 | [diff] [blame] | 34 | std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo); |
| 35 | std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo); |
Teresa Charlin | fbf0e5b | 2020-08-17 01:01:06 +0100 | [diff] [blame] | 36 | ARMNN_NO_DEPRECATE_WARN_END |
Nattapat Chaimanowong | 8a54ac0 | 2019-03-29 15:25:04 +0000 | [diff] [blame] | 37 | |
| 38 | armnn::WorkloadInfo info; |
| 39 | AddInputToWorkload(descriptor, info, inputTensorInfo, inputHandle.get()); |
| 40 | AddOutputToWorkload(descriptor, info, outputTensorInfo, outputHandle.get()); |
| 41 | |
| 42 | std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateDequantize(descriptor, info); |
| 43 | |
| 44 | inputHandle->Allocate(); |
| 45 | outputHandle->Allocate(); |
| 46 | |
Sadik Armagan | 483c811 | 2021-06-01 09:24:52 +0100 | [diff] [blame] | 47 | CopyDataToITensorHandle(inputHandle.get(), inputData.data()); |
Nattapat Chaimanowong | 8a54ac0 | 2019-03-29 15:25:04 +0000 | [diff] [blame] | 48 | |
| 49 | ExecuteWorkload(*workload, memoryManager); |
| 50 | |
Sadik Armagan | 483c811 | 2021-06-01 09:24:52 +0100 | [diff] [blame] | 51 | CopyDataFromITensorHandle(actualOutput.data(), outputHandle.get()); |
Nattapat Chaimanowong | 8a54ac0 | 2019-03-29 15:25:04 +0000 | [diff] [blame] | 52 | |
Sadik Armagan | 483c811 | 2021-06-01 09:24:52 +0100 | [diff] [blame] | 53 | return LayerTestResult<T1, Dim>(actualOutput, |
| 54 | expectedOutputData, |
| 55 | outputHandle->GetShape(), |
| 56 | outputTensorInfo.GetShape()); |
Nattapat Chaimanowong | 8a54ac0 | 2019-03-29 15:25:04 +0000 | [diff] [blame] | 57 | } |
| 58 | |
Jan Eilers | f710793 | 2019-11-01 11:09:36 +0000 | [diff] [blame] | 59 | template <armnn::DataType ArmnnInputType, |
| 60 | armnn::DataType ArmnnOutputType=armnn::DataType::Float32, |
| 61 | typename OutType=armnn::ResolveType<ArmnnOutputType>> |
| 62 | LayerTestResult<OutType, 4> DequantizeSimpleTest( |
Nattapat Chaimanowong | 8a54ac0 | 2019-03-29 15:25:04 +0000 | [diff] [blame] | 63 | armnn::IWorkloadFactory& workloadFactory, |
| 64 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 65 | { |
| 66 | using T = armnn::ResolveType<ArmnnInputType>; |
| 67 | |
| 68 | armnn::DequantizeQueueDescriptor desc; |
| 69 | |
Nattapat Chaimanowong | afa4e3a | 2019-04-02 11:41:45 +0100 | [diff] [blame] | 70 | const armnn::TensorInfo inputTensorInfo({1, 2, 2, 3}, ArmnnInputType, 0.5f, 0); |
Jan Eilers | f710793 | 2019-11-01 11:09:36 +0000 | [diff] [blame] | 71 | const armnn::TensorInfo outputTensorInfo({1, 2, 2, 3}, ArmnnOutputType); |
Nattapat Chaimanowong | afa4e3a | 2019-04-02 11:41:45 +0100 | [diff] [blame] | 72 | |
| 73 | std::vector<T> inputData = std::vector<T>( |
| 74 | { |
| 75 | 2, 4, 6, |
| 76 | 8, 10, 12, |
| 77 | 14, 16, 18, |
| 78 | 20, 22, 24, |
| 79 | }); |
| 80 | |
Jan Eilers | f710793 | 2019-11-01 11:09:36 +0000 | [diff] [blame] | 81 | std::vector<OutType> expectedOutputData; |
| 82 | for (OutType i = OutType(1); i <= OutType(12); ++i) |
Nattapat Chaimanowong | afa4e3a | 2019-04-02 11:41:45 +0100 | [diff] [blame] | 83 | { |
Jan Eilers | f710793 | 2019-11-01 11:09:36 +0000 | [diff] [blame] | 84 | expectedOutputData.push_back(i); |
| 85 | } |
Nattapat Chaimanowong | afa4e3a | 2019-04-02 11:41:45 +0100 | [diff] [blame] | 86 | |
Jan Eilers | f710793 | 2019-11-01 11:09:36 +0000 | [diff] [blame] | 87 | return DequantizeTestImpl<T, 4, OutType>(workloadFactory, |
| 88 | memoryManager, |
| 89 | inputTensorInfo, |
| 90 | outputTensorInfo, |
| 91 | inputData, |
| 92 | expectedOutputData, |
| 93 | desc); |
Nattapat Chaimanowong | afa4e3a | 2019-04-02 11:41:45 +0100 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | template <armnn::DataType ArmnnInputType> |
| 97 | LayerTestResult<float, 4> DequantizeOffsetTest( |
| 98 | armnn::IWorkloadFactory& workloadFactory, |
| 99 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 100 | { |
| 101 | using T = armnn::ResolveType<ArmnnInputType>; |
| 102 | |
| 103 | armnn::DequantizeQueueDescriptor desc; |
| 104 | |
Nattapat Chaimanowong | 8a54ac0 | 2019-03-29 15:25:04 +0000 | [diff] [blame] | 105 | const armnn::TensorInfo inputTensorInfo({1, 2, 2, 3}, ArmnnInputType, 0.5f, 1); |
| 106 | const armnn::TensorInfo outputTensorInfo({1, 2, 2, 3}, armnn::DataType::Float32); |
| 107 | |
| 108 | std::vector<T> inputData = std::vector<T>( |
| 109 | { |
| 110 | 3, 5, 7, |
| 111 | 9, 11, 13, |
| 112 | 15, 17, 19, |
| 113 | 21, 23, 25, |
| 114 | }); |
| 115 | |
| 116 | std::vector<float> expectedOutputData = std::vector<float>( |
| 117 | { |
| 118 | 1.0f, 2.0f, 3.0f, |
| 119 | 4.0f, 5.0f, 6.0f, |
| 120 | 7.0f, 8.0f, 9.0f, |
| 121 | 10.0f, 11.0f, 12.0f, |
| 122 | }); |
| 123 | |
| 124 | return DequantizeTestImpl<T, 4>(workloadFactory, |
| 125 | memoryManager, |
| 126 | inputTensorInfo, |
| 127 | outputTensorInfo, |
| 128 | inputData, |
| 129 | expectedOutputData, |
| 130 | desc); |
| 131 | } |
| 132 | |
| 133 | } // anonymous namespace |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 134 | |
| 135 | LayerTestResult<float, 4> DequantizeSimpleUint8Test( |
| 136 | armnn::IWorkloadFactory& workloadFactory, |
| 137 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 138 | { |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 139 | return DequantizeSimpleTest<armnn::DataType::QAsymmU8>(workloadFactory, memoryManager); |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | LayerTestResult<float, 4> DequantizeOffsetUint8Test( |
| 143 | armnn::IWorkloadFactory& workloadFactory, |
| 144 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 145 | { |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 146 | return DequantizeOffsetTest<armnn::DataType::QAsymmU8>(workloadFactory, memoryManager); |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 147 | } |
| 148 | |
Ryan OShea | 9add120 | 2020-02-07 10:06:33 +0000 | [diff] [blame] | 149 | LayerTestResult<float, 4> DequantizeSimpleAsymmInt8Test( |
| 150 | armnn::IWorkloadFactory& workloadFactory, |
| 151 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 152 | { |
| 153 | return DequantizeSimpleTest<armnn::DataType::QAsymmS8>(workloadFactory, memoryManager); |
| 154 | } |
| 155 | |
| 156 | LayerTestResult<float, 4> DequantizeOffsetAsymmInt8Test( |
| 157 | armnn::IWorkloadFactory& workloadFactory, |
| 158 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 159 | { |
| 160 | return DequantizeOffsetTest<armnn::DataType::QAsymmS8>(workloadFactory, memoryManager); |
| 161 | } |
| 162 | |
Finn Williams | fd27106 | 2019-12-04 14:27:27 +0000 | [diff] [blame] | 163 | LayerTestResult<float, 4> DequantizeSimpleInt8Test( |
| 164 | armnn::IWorkloadFactory& workloadFactory, |
| 165 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 166 | { |
| 167 | return DequantizeSimpleTest<armnn::DataType::QSymmS8>(workloadFactory, memoryManager); |
| 168 | } |
| 169 | |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 170 | LayerTestResult<float, 4> DequantizeSimpleInt16Test( |
| 171 | armnn::IWorkloadFactory& workloadFactory, |
| 172 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 173 | { |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 174 | return DequantizeSimpleTest<armnn::DataType::QSymmS16>(workloadFactory, memoryManager); |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 175 | } |
Jan Eilers | f710793 | 2019-11-01 11:09:36 +0000 | [diff] [blame] | 176 | |
| 177 | LayerTestResult<armnn::Half, 4> DequantizeSimpleUint8ToFp16Test( |
| 178 | armnn::IWorkloadFactory& workloadFactory, |
| 179 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 180 | { |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 181 | return DequantizeSimpleTest<armnn::DataType::QAsymmU8, armnn::DataType::Float16>(workloadFactory, |
Jan Eilers | f710793 | 2019-11-01 11:09:36 +0000 | [diff] [blame] | 182 | memoryManager); |
| 183 | } |
| 184 | |
Finn Williams | fd27106 | 2019-12-04 14:27:27 +0000 | [diff] [blame] | 185 | LayerTestResult<armnn::Half, 4> DequantizeSimpleInt8ToFp16Test( |
| 186 | armnn::IWorkloadFactory& workloadFactory, |
| 187 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 188 | { |
| 189 | return DequantizeSimpleTest<armnn::DataType::QSymmS8, armnn::DataType::Float16>(workloadFactory, memoryManager); |
| 190 | } |
| 191 | |
Jan Eilers | f710793 | 2019-11-01 11:09:36 +0000 | [diff] [blame] | 192 | LayerTestResult<armnn::Half, 4> DequantizeSimpleInt16ToFp16Test( |
| 193 | armnn::IWorkloadFactory& workloadFactory, |
| 194 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 195 | { |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 196 | return DequantizeSimpleTest<armnn::DataType::QSymmS16, armnn::DataType::Float16>(workloadFactory, |
Jan Eilers | f710793 | 2019-11-01 11:09:36 +0000 | [diff] [blame] | 197 | memoryManager); |
| 198 | } |