telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
David Beck | ecb56cd | 2018-09-05 12:52:57 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 4 | // |
| 5 | #pragma once |
| 6 | |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 7 | #include "QuantizeHelper.hpp" |
Aron Virginas-Tar | 5caf907 | 2018-11-14 18:35:18 +0000 | [diff] [blame] | 8 | #include "WorkloadTestUtils.hpp" |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 9 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 10 | #include <armnn/ArmNN.hpp> |
| 11 | #include <armnn/Tensor.hpp> |
| 12 | #include <armnn/TypesUtils.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 13 | |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 14 | #include <backendsCommon/CpuTensorHandle.hpp> |
Aron Virginas-Tar | 5caf907 | 2018-11-14 18:35:18 +0000 | [diff] [blame] | 15 | #include <backendsCommon/IBackendInternal.hpp> |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 16 | #include <backendsCommon/WorkloadFactory.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 17 | |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 18 | #include <test/TensorHelpers.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 19 | |
| 20 | template<typename T> |
| 21 | LayerTestResult<T, 4> SimpleReshapeTestImpl( |
| 22 | armnn::IWorkloadFactory& workloadFactory, |
Aron Virginas-Tar | 5caf907 | 2018-11-14 18:35:18 +0000 | [diff] [blame] | 23 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 24 | armnn::TensorInfo inputTensorInfo, |
| 25 | armnn::TensorInfo outputTensorInfo, |
| 26 | const std::vector<T>& inputData, |
| 27 | const std::vector<T>& outputExpectedData) |
| 28 | { |
| 29 | auto input = MakeTensor<T, 4>(inputTensorInfo, inputData); |
| 30 | |
| 31 | LayerTestResult<T, 4> ret(outputTensorInfo); |
| 32 | ret.outputExpected = MakeTensor<T, 4>(outputTensorInfo, outputExpectedData); |
| 33 | |
| 34 | std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo); |
| 35 | std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo); |
| 36 | |
| 37 | armnn::ReshapeQueueDescriptor data; |
| 38 | armnn::WorkloadInfo info; |
| 39 | AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get()); |
| 40 | AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get()); |
| 41 | |
| 42 | std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateReshape(data, info); |
| 43 | |
| 44 | inputHandle->Allocate(); |
| 45 | outputHandle->Allocate(); |
| 46 | |
| 47 | CopyDataToITensorHandle(inputHandle.get(), &input[0][0][0][0]); |
| 48 | |
| 49 | workload->Execute(); |
| 50 | |
| 51 | CopyDataFromITensorHandle(&ret.output[0][0][0][0], outputHandle.get()); |
| 52 | |
| 53 | return ret; |
| 54 | } |
| 55 | |
Aron Virginas-Tar | 5caf907 | 2018-11-14 18:35:18 +0000 | [diff] [blame] | 56 | LayerTestResult<float, 4> SimpleReshapeFloat32Test( |
| 57 | armnn::IWorkloadFactory& workloadFactory, |
| 58 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 59 | { |
| 60 | armnn::TensorInfo inputTensorInfo; |
| 61 | armnn::TensorInfo outputTensorInfo; |
| 62 | |
| 63 | unsigned int inputShape[] = { 2, 2, 3, 3 }; |
| 64 | unsigned int outputShape[] = { 2, 2, 9, 1 }; |
| 65 | |
| 66 | inputTensorInfo = armnn::TensorInfo(4, inputShape, armnn::DataType::Float32); |
| 67 | outputTensorInfo = armnn::TensorInfo(4, outputShape, armnn::DataType::Float32); |
| 68 | |
| 69 | std::vector<float> input = std::vector<float>( |
| 70 | { |
| 71 | 0.0f, 1.0f, 2.0f, |
| 72 | 3.0f, 4.0f, 5.0f, |
| 73 | 6.0f, 7.0f, 8.0f, |
| 74 | |
| 75 | 9.0f, 10.0f, 11.0f, |
| 76 | 12.0f, 13.0f, 14.0f, |
| 77 | 15.0f, 16.0f, 17.0f, |
| 78 | |
| 79 | 18.0f, 19.0f, 20.0f, |
| 80 | 21.0f, 22.0f, 23.0f, |
| 81 | 24.0f, 25.0f, 26.0f, |
| 82 | |
| 83 | 27.0f, 28.0f, 29.0f, |
| 84 | 30.0f, 31.0f, 32.0f, |
| 85 | 33.0f, 34.0f, 35.0f, |
| 86 | }); |
| 87 | |
| 88 | std::vector<float> outputExpected = std::vector<float>( |
| 89 | { |
| 90 | 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, |
| 91 | |
| 92 | 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, |
| 93 | |
| 94 | 18.0f, 19.0f, 20.0f, 21.0f, 22.0f, 23.0f, 24.0f, 25.0f, 26.0f, |
| 95 | |
| 96 | 27.0f, 28.0f, 29.0f, 30.0f, 31.0f, 32.0f, 33.0f, 34.0f, 35.0f, |
| 97 | }); |
| 98 | |
Aron Virginas-Tar | 5caf907 | 2018-11-14 18:35:18 +0000 | [diff] [blame] | 99 | return SimpleReshapeTestImpl<float>( |
| 100 | workloadFactory, memoryManager, inputTensorInfo, outputTensorInfo, input, outputExpected); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 101 | } |
| 102 | |
Aron Virginas-Tar | 5caf907 | 2018-11-14 18:35:18 +0000 | [diff] [blame] | 103 | LayerTestResult<float, 4> SimpleFloorTest( |
| 104 | armnn::IWorkloadFactory& workloadFactory, |
| 105 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 106 | { |
| 107 | const armnn::TensorInfo inputTensorInfo({1, 3, 2, 3}, armnn::DataType::Float32); |
| 108 | const armnn::TensorInfo outputTensorInfo(inputTensorInfo); |
| 109 | |
| 110 | auto input = MakeTensor<float, 4>(inputTensorInfo, |
| 111 | { -37.5f, -15.2f, -8.76f, -2.0f, -1.5f, -1.3f, -0.5f, -0.4f, 0.0f, |
| 112 | 1.0f, 0.4f, 0.5f, 1.3f, 1.5f, 2.0f, 8.76f, 15.2f, 37.5f }); |
| 113 | |
| 114 | LayerTestResult<float, 4> ret(outputTensorInfo); |
| 115 | ret.outputExpected = MakeTensor<float, 4>(outputTensorInfo, |
| 116 | { -38.0f, -16.0f, -9.0f, -2.0f, -2.0f, -2.0f, -1.0f, -1.0f, 0.0f, |
| 117 | 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 2.0f, 8.0f, 15.0f, 37.0f }); |
| 118 | |
| 119 | std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo); |
| 120 | std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo); |
| 121 | |
| 122 | armnn::FloorQueueDescriptor data; |
| 123 | armnn::WorkloadInfo info; |
| 124 | AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get()); |
| 125 | AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get()); |
| 126 | |
| 127 | std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateFloor(data, info); |
| 128 | |
| 129 | inputHandle->Allocate(); |
| 130 | outputHandle->Allocate(); |
| 131 | |
| 132 | CopyDataToITensorHandle(inputHandle.get(), &input[0][0][0][0]); |
| 133 | |
| 134 | workload->Execute(); |
| 135 | |
| 136 | CopyDataFromITensorHandle(&ret.output[0][0][0][0], outputHandle.get()); |
| 137 | |
| 138 | return ret; |
| 139 | } |
| 140 | |
Aron Virginas-Tar | 5caf907 | 2018-11-14 18:35:18 +0000 | [diff] [blame] | 141 | LayerTestResult<uint8_t, 4> SimpleReshapeUint8Test( |
| 142 | armnn::IWorkloadFactory& workloadFactory, |
| 143 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 144 | { |
| 145 | armnn::TensorInfo inputTensorInfo; |
| 146 | armnn::TensorInfo outputTensorInfo; |
| 147 | |
| 148 | unsigned int inputShape[] = { 2, 2, 3, 3 }; |
| 149 | unsigned int outputShape[] = { 2, 2, 9, 1 }; |
| 150 | |
| 151 | inputTensorInfo = armnn::TensorInfo(4, inputShape, armnn::DataType::QuantisedAsymm8); |
| 152 | inputTensorInfo.SetQuantizationScale(1.0f); |
| 153 | outputTensorInfo = armnn::TensorInfo(4, outputShape, armnn::DataType::QuantisedAsymm8); |
| 154 | outputTensorInfo.SetQuantizationScale(1.0f); |
| 155 | |
| 156 | std::vector<uint8_t> input = std::vector<uint8_t>( |
| 157 | { |
| 158 | 0, 1, 2, |
| 159 | 3, 4, 5, |
| 160 | 6, 7, 8, |
| 161 | |
| 162 | 9, 10, 11, |
| 163 | 12, 13, 14, |
| 164 | 15, 16, 17, |
| 165 | |
| 166 | 18, 19, 20, |
| 167 | 21, 22, 23, |
| 168 | 24, 25, 26, |
| 169 | |
| 170 | 27, 28, 29, |
| 171 | 30, 31, 32, |
| 172 | 33, 34, 35, |
| 173 | }); |
| 174 | |
| 175 | std::vector<uint8_t> outputExpected = std::vector<uint8_t>( |
| 176 | { |
| 177 | 0, 1, 2, 3, 4, 5, 6, 7, 8, |
| 178 | |
| 179 | 9, 10, 11, 12, 13, 14, 15, 16, 17, |
| 180 | |
| 181 | 18, 19, 20, 21, 22, 23, 24, 25, 26, |
| 182 | |
| 183 | 27, 28, 29, 30, 31, 32, 33, 34, 35, |
| 184 | }); |
| 185 | |
Aron Virginas-Tar | 5caf907 | 2018-11-14 18:35:18 +0000 | [diff] [blame] | 186 | return SimpleReshapeTestImpl<uint8_t>( |
| 187 | workloadFactory, memoryManager, inputTensorInfo, outputTensorInfo, input, outputExpected); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 188 | } |