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