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