aboutsummaryrefslogtreecommitdiff
path: root/delegate/src/test/CastTest.cpp
blob: 623c04524766bd60c26877766c40c254522887c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//
// Copyright © 2021 Arm Ltd and Contributors. All rights reserved.
// SPDX-License-Identifier: MIT
//

#include "CastTestHelper.hpp"

#include <armnn_delegate.hpp>

#include <flatbuffers/flatbuffers.h>
#include <tensorflow/lite/schema/schema_generated.h>

#include <doctest/doctest.h>

namespace armnnDelegate
{

void CastUint8ToFp32Test(std::vector<armnn::BackendId>& backends)
{
    std::vector<int32_t> inputShape  {1, 3, 2, 3};

    std::vector<uint8_t> inputValues { 1, 3, 1, 3, 1, 3, 1, 3, 1,
                                        3, 1, 3, 1, 2, 1, 3, 1, 3 };

    std::vector<float> expectedOutputValues { 1.0f, 3.0f, 1.0f, 3.0f, 1.0f, 3.0f, 1.0f, 3.0f, 1.0f,
                                              3.0f, 1.0f, 3.0f, 1.0f, 2.0f, 1.0f, 3.0f, 1.0f, 3.0f };

    CastTest<uint8_t, float>(::tflite::TensorType_UINT8,
                             ::tflite::TensorType_FLOAT32,
                             backends,
                             inputShape,
                             inputValues,
                             expectedOutputValues);
}

void CastInt32ToFp32Test(std::vector<armnn::BackendId>& backends)
{
    std::vector<int32_t> inputShape  {1, 3, 2, 3};

    std::vector<int32_t> inputValues { -1, -3, -1, -3, -1, -3, -1, -3, 1,
                                       3, 1, 3, 1, 2, 1, 3, 1, 3 };

    std::vector<float> expectedOutputValues { -1.0f, -3.0f, -1.0f, -3.0f, -1.0f, -3.0f, -1.0f, -3.0f, 1.0f,
                                              3.0f, 1.0f, 3.0f, 1.0f, 2.0f, 1.0f, 3.0f, 1.0f, 3.0f };

    CastTest<int32_t, float>(::tflite::TensorType_INT32,
                             ::tflite::TensorType_FLOAT32,
                             backends,
                             inputShape,
                             inputValues,
                             expectedOutputValues);
}

// CAST Test Suite
TEST_SUITE("CAST_CpuRefTests")
{

TEST_CASE ("CAST_UINT8_TO_FP32_CpuRef_Test")
{
    std::vector<armnn::BackendId> backends = {armnn::Compute::CpuRef};
    CastUint8ToFp32Test(backends);
}

TEST_CASE ("CAST_INT32_TO_FP32_CpuRef_Test")
{
    std::vector<armnn::BackendId> backends = {armnn::Compute::CpuRef};
    CastInt32ToFp32Test(backends);
}

}

TEST_SUITE("CAST_CpuAccTests")
{

TEST_CASE ("CAST_UINT8_TO_FP32_CpuAcc_Test")
{
    std::vector<armnn::BackendId> backends = {armnn::Compute::CpuAcc};
    CastUint8ToFp32Test(backends);
}

TEST_CASE ("CAST_INT32_TO_FP32_CpuAcc_Test")
{
    std::vector<armnn::BackendId> backends = {armnn::Compute::CpuAcc};
    CastInt32ToFp32Test(backends);
}

}

TEST_SUITE("CAST_GpuAccTests")
{

TEST_CASE ("CAST_UINT8_TO_FP32_GpuAcc_Test")
{
    std::vector<armnn::BackendId> backends = {armnn::Compute::GpuAcc};
    CastUint8ToFp32Test(backends);
}

TEST_CASE ("CAST_INT32_TO_FP32_GpuAcc_Test")
{
    std::vector<armnn::BackendId> backends = {armnn::Compute::GpuAcc};
    CastInt32ToFp32Test(backends);
}

}
// End of CAST Test Suite

} // namespace armnnDelegate