Sadik Armagan | 89c5a9e | 2021-01-20 17:48:07 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2021 Arm Ltd and Contributors. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "SpaceDepthTestHelper.hpp" |
| 7 | |
| 8 | #include <armnn_delegate.hpp> |
| 9 | |
| 10 | #include <flatbuffers/flatbuffers.h> |
| 11 | #include <tensorflow/lite/schema/schema_generated.h> |
| 12 | |
| 13 | #include <doctest/doctest.h> |
| 14 | |
| 15 | namespace armnnDelegate |
| 16 | { |
| 17 | |
| 18 | void DepthToSpaceFp32Test(std::vector<armnn::BackendId>& backends, int blockSize) |
| 19 | { |
| 20 | // Set input data |
| 21 | std::vector<int32_t> inputShape { 1, 2, 2, 4 }; |
| 22 | std::vector<int32_t> outputShape { 1, 4, 4, 1 }; |
| 23 | |
| 24 | std::vector<float> inputValues = { 1.f, 2.f, 3.f, 4.f, |
| 25 | 5.f, 6.f, 7.f, 8.f, |
| 26 | 9.f, 10.f, 11.f, 12.f, |
| 27 | 13.f, 14.f, 15.f, 16.f }; |
| 28 | |
| 29 | std::vector<float> expectedOutputValues = { 1.f, 2.f, 5.f, 6.f, |
| 30 | 3.f, 4.f, 7.f, 8.f, |
| 31 | 9.f, 10.f, 13.f, 14.f, |
| 32 | 11.f, 12.f, 15.f, 16.f }; |
| 33 | |
| 34 | SpaceDepthTest<float>(tflite::BuiltinOperator_DEPTH_TO_SPACE, |
| 35 | ::tflite::TensorType_FLOAT32, |
| 36 | backends, |
| 37 | inputShape, |
| 38 | outputShape, |
| 39 | inputValues, |
| 40 | expectedOutputValues, |
| 41 | blockSize); |
| 42 | } |
| 43 | |
| 44 | void DepthToSpaceUint8Test(std::vector<armnn::BackendId>& backends, int blockSize) |
| 45 | { |
| 46 | // Set input data |
| 47 | std::vector<int32_t> inputShape { 2, 1, 1, 4 }; |
| 48 | std::vector<int32_t> outputShape { 2, 2, 2, 1 }; |
| 49 | |
| 50 | std::vector<uint8_t> inputValues = { 1, 2, 3, 4, |
| 51 | 5, 6, 7, 8 }; |
| 52 | |
| 53 | std::vector<uint8_t> expectedOutputValues = { 1, 2, 3, 4, |
| 54 | 5, 6, 7, 8 }; |
| 55 | |
| 56 | SpaceDepthTest<uint8_t>(tflite::BuiltinOperator_DEPTH_TO_SPACE, |
| 57 | ::tflite::TensorType_UINT8, |
| 58 | backends, |
| 59 | inputShape, |
| 60 | outputShape, |
| 61 | inputValues, |
| 62 | expectedOutputValues, |
| 63 | blockSize); |
| 64 | } |
| 65 | |
| 66 | void SpaceToDepthFp32Test(std::vector<armnn::BackendId>& backends, int blockSize) |
| 67 | { |
| 68 | // Set input data |
| 69 | std::vector<int32_t> inputShape { 1, 2, 2, 2 }; |
| 70 | std::vector<int32_t> outputShape { 1, 1, 1, 8 }; |
| 71 | |
| 72 | std::vector<float> inputValues = { 1.4f, 2.3f, 3.2f, 4.1f, 5.4f, 6.3f, 7.2f, 8.1f }; |
| 73 | std::vector<float> expectedOutputValues = { 1.4f, 2.3f, 3.2f, 4.1f, 5.4f, 6.3f, 7.2f, 8.1f }; |
| 74 | |
| 75 | SpaceDepthTest<float>(tflite::BuiltinOperator_SPACE_TO_DEPTH, |
| 76 | ::tflite::TensorType_FLOAT32, |
| 77 | backends, |
| 78 | inputShape, |
| 79 | outputShape, |
| 80 | inputValues, |
| 81 | expectedOutputValues, |
| 82 | blockSize); |
| 83 | } |
| 84 | |
| 85 | void SpaceToDepthUint8Test(std::vector<armnn::BackendId>& backends, int blockSize) |
| 86 | { |
| 87 | // Set input data |
| 88 | std::vector<int32_t> inputShape { 1, 2, 2, 1 }; |
| 89 | std::vector<int32_t> outputShape { 1, 1, 1, 4 }; |
| 90 | |
| 91 | std::vector<uint8_t> inputValues = { 1, 2, 3, 2 }; |
| 92 | std::vector<uint8_t> expectedOutputValues = { 1, 2, 3, 2 }; |
| 93 | |
| 94 | SpaceDepthTest<uint8_t>(tflite::BuiltinOperator_SPACE_TO_DEPTH, |
| 95 | ::tflite::TensorType_UINT8, |
| 96 | backends, |
| 97 | inputShape, |
| 98 | outputShape, |
| 99 | inputValues, |
| 100 | expectedOutputValues, |
| 101 | blockSize); |
| 102 | } |
| 103 | |
| 104 | TEST_SUITE("DepthToSpace_CpuRefTests") |
| 105 | { |
| 106 | |
| 107 | TEST_CASE ("DepthToSpaceFp32Test_CpuRef_Test") |
| 108 | { |
| 109 | std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef }; |
| 110 | DepthToSpaceFp32Test(backends, 2); |
| 111 | } |
| 112 | |
| 113 | TEST_CASE ("DepthToSpaceUint8Test_CpuRef_Test") |
| 114 | { |
| 115 | std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef }; |
| 116 | DepthToSpaceUint8Test(backends, 2); |
| 117 | } |
| 118 | |
| 119 | } // TEST_SUITE("DepthToSpace_CpuRefTests") |
| 120 | |
| 121 | |
| 122 | TEST_SUITE("DepthToSpace_CpuAccTests") |
| 123 | { |
| 124 | |
| 125 | TEST_CASE ("DepthToSpaceFp32Test_CpuAcc_Test") |
| 126 | { |
| 127 | std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc }; |
| 128 | DepthToSpaceFp32Test(backends, 2); |
| 129 | } |
| 130 | |
| 131 | TEST_CASE ("DepthToSpaceUint8Test_CpuAcc_Test") |
| 132 | { |
| 133 | std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc }; |
| 134 | DepthToSpaceUint8Test(backends, 2); |
| 135 | } |
| 136 | |
| 137 | } // TEST_SUITE("DepthToSpace_CpuAccTests") |
| 138 | |
| 139 | TEST_SUITE("DepthToSpace_GpuAccTests") |
| 140 | { |
| 141 | |
| 142 | TEST_CASE ("DepthToSpaceFp32Test_GpuAcc_Test") |
| 143 | { |
| 144 | std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc }; |
| 145 | DepthToSpaceFp32Test(backends, 2); |
| 146 | } |
| 147 | |
| 148 | TEST_CASE ("DepthToSpaceUint8Test_GpuAcc_Test") |
| 149 | { |
| 150 | std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc }; |
| 151 | DepthToSpaceUint8Test(backends, 2); |
| 152 | } |
| 153 | |
| 154 | } // TEST_SUITE("DepthToSpace_GpuAccTests") |
| 155 | |
| 156 | TEST_SUITE("SpaceToDepth_CpuRefTests") |
| 157 | { |
| 158 | |
| 159 | TEST_CASE ("SpaceToDepthFp32Test_CpuRef_Test") |
| 160 | { |
| 161 | std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef }; |
| 162 | SpaceToDepthFp32Test(backends, 2); |
| 163 | } |
| 164 | |
| 165 | TEST_CASE ("SpaceToDepthUint8Test_CpuRef_Test") |
| 166 | { |
| 167 | std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef }; |
| 168 | SpaceToDepthUint8Test(backends, 2); |
| 169 | } |
| 170 | |
| 171 | } // TEST_SUITE("SpaceToDepth_CpuRefTests") |
| 172 | |
| 173 | TEST_SUITE("SpaceToDepth_CpuAccTests") |
| 174 | { |
| 175 | |
| 176 | TEST_CASE ("SpaceToDepthFp32Test_CpuAcc_Test") |
| 177 | { |
| 178 | std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc }; |
| 179 | SpaceToDepthFp32Test(backends, 2); |
| 180 | } |
| 181 | |
| 182 | TEST_CASE ("SpaceToDepthUint8Test_CpuAcc_Test") |
| 183 | { |
| 184 | std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc }; |
| 185 | SpaceToDepthUint8Test(backends, 2); |
| 186 | } |
| 187 | |
| 188 | } // TEST_SUITE("SpaceToDepth_CpuAccTests") |
| 189 | |
| 190 | TEST_SUITE("SpaceToDepth_GpuAccTests") |
| 191 | { |
| 192 | |
| 193 | TEST_CASE ("SpaceToDepthFp32Test_GpuAcc_Test") |
| 194 | { |
| 195 | std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc }; |
| 196 | SpaceToDepthFp32Test(backends, 2); |
| 197 | } |
| 198 | |
| 199 | TEST_CASE ("SpaceToDepthUint8Test_GpuAcc_Test") |
| 200 | { |
| 201 | std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc }; |
| 202 | SpaceToDepthUint8Test(backends, 2); |
| 203 | } |
| 204 | |
| 205 | } // TEST_SUITE("SpaceToDepth_GpuAccTests") |
| 206 | |
| 207 | } // namespace armnnDelegate |