James Conroy | 3982548 | 2021-05-27 17:44:50 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2021 Arm Ltd and Contributors. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "PreluTestHelper.hpp" |
| 7 | |
| 8 | #include <armnn_delegate.hpp> |
| 9 | |
| 10 | #include <flatbuffers/flatbuffers.h> |
| 11 | #include <tensorflow/lite/interpreter.h> |
| 12 | #include <tensorflow/lite/kernels/register.h> |
| 13 | #include <tensorflow/lite/model.h> |
| 14 | #include <tensorflow/lite/schema/schema_generated.h> |
| 15 | #include <tensorflow/lite/version.h> |
| 16 | |
| 17 | #include <doctest/doctest.h> |
| 18 | |
| 19 | namespace armnnDelegate { |
| 20 | |
| 21 | void PreluFloatSimpleTest(std::vector <armnn::BackendId>& backends, bool isAlphaConst, bool isDynamicOutput = false) { |
| 22 | std::vector<int32_t> inputShape { 1, 2, 3 }; |
| 23 | std::vector<int32_t> alphaShape { 1 }; |
| 24 | std::vector<int32_t> outputShape { 1, 2, 3 }; |
| 25 | |
| 26 | if (isDynamicOutput) |
| 27 | { |
| 28 | outputShape.clear(); |
| 29 | } |
| 30 | |
| 31 | std::vector<float> inputData = { -14.f, 2.f, 0.f, 1.f, -5.f, 14.f }; |
| 32 | std::vector<float> alphaData = { 0.5f }; |
| 33 | std::vector<float> expectedOutput = { -7.f, 2.f, 0.f, 1.f, -2.5f, 14.f }; |
| 34 | |
| 35 | PreluTest(tflite::BuiltinOperator_PRELU, |
| 36 | ::tflite::TensorType_FLOAT32, |
| 37 | backends, |
| 38 | inputShape, |
| 39 | alphaShape, |
| 40 | outputShape, |
| 41 | inputData, |
| 42 | alphaData, |
| 43 | expectedOutput, |
| 44 | isAlphaConst); |
| 45 | } |
| 46 | |
| 47 | TEST_SUITE("Prelu_CpuRefTests") |
| 48 | { |
| 49 | |
| 50 | TEST_CASE ("PreluFp32SimpleConstTest_CpuRef_Test") |
| 51 | { |
| 52 | std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef }; |
| 53 | PreluFloatSimpleTest(backends, true); |
| 54 | } |
| 55 | |
| 56 | TEST_CASE ("PreluFp32SimpleTest_CpuRef_Test") |
| 57 | { |
| 58 | std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef }; |
| 59 | PreluFloatSimpleTest(backends, false); |
| 60 | } |
| 61 | |
| 62 | TEST_CASE ("PreluFp32SimpleConstDynamicTest_CpuRef_Test") |
| 63 | { |
| 64 | std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef }; |
| 65 | PreluFloatSimpleTest(backends, true, true); |
| 66 | } |
| 67 | |
| 68 | TEST_CASE ("PreluFp32SimpleDynamicTest_CpuRef_Test") |
| 69 | { |
| 70 | std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef }; |
| 71 | PreluFloatSimpleTest(backends, false, true); |
| 72 | } |
| 73 | |
| 74 | } // TEST_SUITE("Prelu_CpuRefTests") |
| 75 | |
| 76 | TEST_SUITE("Prelu_CpuAccTests") |
| 77 | { |
| 78 | |
| 79 | TEST_CASE ("PreluFp32SimpleConstTest_CpuAcc_Test") |
| 80 | { |
| 81 | std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc }; |
| 82 | PreluFloatSimpleTest(backends, true); |
| 83 | } |
| 84 | |
| 85 | TEST_CASE ("PreluFp32SimpleTest_CpuAcc_Test") |
| 86 | { |
| 87 | std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc }; |
| 88 | PreluFloatSimpleTest(backends, false); |
| 89 | } |
| 90 | |
| 91 | TEST_CASE ("PreluFp32SimpleConstDynamicTest_CpuAcc_Test") |
| 92 | { |
| 93 | std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc }; |
| 94 | PreluFloatSimpleTest(backends, true, true); |
| 95 | } |
| 96 | |
| 97 | TEST_CASE ("PreluFp32SimpleDynamicTest_CpuAcc_Test") |
| 98 | { |
| 99 | std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc }; |
| 100 | PreluFloatSimpleTest(backends, false, true); |
| 101 | } |
| 102 | |
| 103 | } // TEST_SUITE("Prelu_CpuAccTests") |
| 104 | |
| 105 | TEST_SUITE("Prelu_GpuAccTests") |
| 106 | { |
| 107 | |
| 108 | TEST_CASE ("PreluFp32SimpleConstTest_GpuAcc_Test") |
| 109 | { |
| 110 | std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc }; |
| 111 | PreluFloatSimpleTest(backends, true); |
| 112 | } |
| 113 | |
| 114 | TEST_CASE ("PreluFp32SimpleTest_GpuAcc_Test") |
| 115 | { |
| 116 | std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc }; |
| 117 | PreluFloatSimpleTest(backends, false); |
| 118 | } |
| 119 | |
| 120 | TEST_CASE ("PreluFp32SimpleConstDynamicTest_GpuAcc_Test") |
| 121 | { |
| 122 | std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc }; |
| 123 | PreluFloatSimpleTest(backends, true, true); |
| 124 | } |
| 125 | |
| 126 | TEST_CASE ("PreluFp32SimpleDynamicTest_GpuAcc_Test") |
| 127 | { |
| 128 | std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc }; |
| 129 | PreluFloatSimpleTest(backends, false, true); |
| 130 | } |
| 131 | |
| 132 | } // TEST_SUITE("Prelu_GpuAccTests") |
| 133 | |
| 134 | } |