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