Teresa Charlin | 98427a1 | 2020-11-25 18:22:57 +0000 | [diff] [blame] | 1 | // |
Teresa Charlin | ad1b3d7 | 2023-03-14 12:10:28 +0000 | [diff] [blame] | 2 | // Copyright © 2020, 2023 Arm Ltd and Contributors. All rights reserved. |
Teresa Charlin | 98427a1 | 2020-11-25 18:22:57 +0000 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "GatherTestHelper.hpp" |
| 7 | |
| 8 | #include <armnn_delegate.hpp> |
| 9 | |
| 10 | #include <flatbuffers/flatbuffers.h> |
Teresa Charlin | 98427a1 | 2020-11-25 18:22:57 +0000 | [diff] [blame] | 11 | |
| 12 | #include <doctest/doctest.h> |
| 13 | |
| 14 | namespace armnnDelegate |
| 15 | { |
| 16 | |
| 17 | // GATHER Operator |
| 18 | void GatherUint8Test(std::vector<armnn::BackendId>& backends) |
| 19 | { |
| 20 | |
| 21 | std::vector<int32_t> paramsShape{8}; |
| 22 | std::vector<int32_t> indicesShape{3}; |
| 23 | std::vector<int32_t> expectedOutputShape{3}; |
| 24 | |
| 25 | int32_t axis = 0; |
| 26 | std::vector<uint8_t> paramsValues{1, 2, 3, 4, 5, 6, 7, 8}; |
| 27 | std::vector<int32_t> indicesValues{7, 6, 5}; |
| 28 | std::vector<uint8_t> expectedOutputValues{8, 7, 6}; |
| 29 | |
| 30 | GatherTest<uint8_t>(::tflite::TensorType_UINT8, |
| 31 | backends, |
| 32 | paramsShape, |
| 33 | indicesShape, |
| 34 | expectedOutputShape, |
| 35 | axis, |
| 36 | paramsValues, |
| 37 | indicesValues, |
| 38 | expectedOutputValues); |
| 39 | } |
| 40 | |
| 41 | void GatherFp32Test(std::vector<armnn::BackendId>& backends) |
| 42 | { |
| 43 | std::vector<int32_t> paramsShape{8}; |
| 44 | std::vector<int32_t> indicesShape{3}; |
| 45 | std::vector<int32_t> expectedOutputShape{3}; |
| 46 | |
| 47 | int32_t axis = 0; |
| 48 | std::vector<float> paramsValues{1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f}; |
| 49 | std::vector<int32_t> indicesValues{7, 6, 5}; |
| 50 | std::vector<float> expectedOutputValues{8.8f, 7.7f, 6.6f}; |
| 51 | |
| 52 | GatherTest<float>(::tflite::TensorType_FLOAT32, |
| 53 | backends, |
| 54 | paramsShape, |
| 55 | indicesShape, |
| 56 | expectedOutputShape, |
| 57 | axis, |
| 58 | paramsValues, |
| 59 | indicesValues, |
| 60 | expectedOutputValues); |
| 61 | } |
| 62 | |
| 63 | // GATHER Test Suite |
| 64 | TEST_SUITE("GATHER_CpuRefTests") |
| 65 | { |
| 66 | |
| 67 | TEST_CASE ("GATHER_Uint8_CpuRef_Test") |
| 68 | { |
| 69 | std::vector<armnn::BackendId> backends = {armnn::Compute::CpuRef}; |
| 70 | GatherUint8Test(backends); |
| 71 | } |
| 72 | |
| 73 | TEST_CASE ("GATHER_Fp32_CpuRef_Test") |
| 74 | { |
| 75 | std::vector<armnn::BackendId> backends = {armnn::Compute::CpuRef}; |
| 76 | GatherFp32Test(backends); |
| 77 | } |
| 78 | |
| 79 | } |
| 80 | |
| 81 | TEST_SUITE("GATHER_CpuAccTests") |
| 82 | { |
| 83 | |
| 84 | TEST_CASE ("GATHER_Uint8_CpuAcc_Test") |
| 85 | { |
| 86 | std::vector<armnn::BackendId> backends = {armnn::Compute::CpuAcc}; |
| 87 | GatherUint8Test(backends); |
| 88 | } |
| 89 | |
| 90 | TEST_CASE ("GATHER_Fp32_CpuAcc_Test") |
| 91 | { |
| 92 | std::vector<armnn::BackendId> backends = {armnn::Compute::CpuAcc}; |
| 93 | GatherFp32Test(backends); |
| 94 | } |
| 95 | |
| 96 | } |
| 97 | |
| 98 | TEST_SUITE("GATHER_GpuAccTests") |
| 99 | { |
| 100 | |
| 101 | TEST_CASE ("GATHER_Uint8_GpuAcc_Test") |
| 102 | { |
| 103 | std::vector<armnn::BackendId> backends = {armnn::Compute::GpuAcc}; |
| 104 | GatherUint8Test(backends); |
| 105 | } |
| 106 | |
| 107 | TEST_CASE ("GATHER_Fp32_GpuAcc_Test") |
| 108 | { |
| 109 | std::vector<armnn::BackendId> backends = {armnn::Compute::GpuAcc}; |
| 110 | GatherFp32Test(backends); |
| 111 | } |
| 112 | |
| 113 | } |
| 114 | // End of GATHER Test Suite |
| 115 | |
| 116 | } // namespace armnnDelegate |