blob: f65e15bb976d97d86c13dfd7f147e2288002ed5d [file] [log] [blame]
James Conroy39825482021-05-27 17:44:50 +01001//
Teresa Charlinad1b3d72023-03-14 12:10:28 +00002// Copyright © 2021, 2023 Arm Ltd and Contributors. All rights reserved.
James Conroy39825482021-05-27 17:44:50 +01003// 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>
Teresa Charlinad1b3d72023-03-14 12:10:28 +000014#include <schema_generated.h>
James Conroy39825482021-05-27 17:44:50 +010015#include <tensorflow/lite/version.h>
16
17#include <doctest/doctest.h>
18
19namespace armnnDelegate {
20
Matthew Sloyanebe392d2023-03-30 10:12:08 +010021void PreluFloatSimpleTest(std::vector <armnn::BackendId>& backends, bool isAlphaConst, bool isDynamicOutput = false)
22{
James Conroy39825482021-05-27 17:44:50 +010023 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
48TEST_SUITE("Prelu_CpuRefTests")
49{
50
51TEST_CASE ("PreluFp32SimpleConstTest_CpuRef_Test")
52{
53 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
54 PreluFloatSimpleTest(backends, true);
55}
56
57TEST_CASE ("PreluFp32SimpleTest_CpuRef_Test")
58{
59 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
60 PreluFloatSimpleTest(backends, false);
61}
62
63TEST_CASE ("PreluFp32SimpleConstDynamicTest_CpuRef_Test")
64{
65 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
66 PreluFloatSimpleTest(backends, true, true);
67}
68
69TEST_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
77TEST_SUITE("Prelu_CpuAccTests")
78{
79
80TEST_CASE ("PreluFp32SimpleConstTest_CpuAcc_Test")
81{
82 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc };
83 PreluFloatSimpleTest(backends, true);
84}
85
86TEST_CASE ("PreluFp32SimpleTest_CpuAcc_Test")
87{
88 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc };
89 PreluFloatSimpleTest(backends, false);
90}
91
92TEST_CASE ("PreluFp32SimpleConstDynamicTest_CpuAcc_Test")
93{
94 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc };
95 PreluFloatSimpleTest(backends, true, true);
96}
97
98TEST_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
106TEST_SUITE("Prelu_GpuAccTests")
107{
108
109TEST_CASE ("PreluFp32SimpleConstTest_GpuAcc_Test")
110{
111 std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc };
112 PreluFloatSimpleTest(backends, true);
113}
114
115TEST_CASE ("PreluFp32SimpleTest_GpuAcc_Test")
116{
117 std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc };
118 PreluFloatSimpleTest(backends, false);
119}
120
121TEST_CASE ("PreluFp32SimpleConstDynamicTest_GpuAcc_Test")
122{
123 std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc };
124 PreluFloatSimpleTest(backends, true, true);
125}
126
127TEST_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}