aboutsummaryrefslogtreecommitdiff
path: root/delegate/test/SliceTest.cpp
blob: 9e54f735f816f136b0e20079477f0d5bffaa8846 (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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
//
// Copyright © 2022-2023 Arm Ltd and Contributors. All rights reserved.
// SPDX-License-Identifier: MIT
//

#include "SliceTestHelper.hpp"

#include <armnn_delegate.hpp>

#include <flatbuffers/flatbuffers.h>

#include <doctest/doctest.h>

namespace armnnDelegate
{

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

    std::vector<int32_t> beginData { 1, 0, 0 };
    std::vector<int32_t> sizeData  { 2, 1, 3 };
    std::vector<float> inputData  { 1.0f, 1.0f, 1.0f, 2.0f, 2.0f, 2.0f,
                                    3.0f, 3.0f, 3.0f, 4.0f, 4.0f, 4.0f,
                                    5.0f, 5.0f, 5.0f, 6.0f, 6.0f, 6.0f };
    std::vector<float> outputData { 3.0f, 3.0f, 3.0f,
                                    5.0f, 5.0f, 5.0f };

    SliceTestImpl<float>(
        backends,
        inputData,
        outputData,
        beginData,
        sizeData,
        inputShape,
        beginShape,
        sizeShape,
        outputShape);
}

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

    std::vector<int32_t> beginData { 1, 0, 0 };
    std::vector<int32_t> sizeData  { 2, 1, -1 };
    std::vector<float> inputData  { 1.0f, 1.0f, 1.0f, 2.0f, 2.0f, 2.0f,
                                    3.0f, 3.0f, 3.0f, 4.0f, 4.0f, 4.0f,
                                    5.0f, 5.0f, 5.0f, 6.0f, 6.0f, 6.0f };
    std::vector<float> outputData { 3.0f, 3.0f, 3.0f,
                                    5.0f, 5.0f, 5.0f };

    SliceTestImpl<float>(
            backends,
            inputData,
            outputData,
            beginData,
            sizeData,
            inputShape,
            beginShape,
            sizeShape,
            outputShape);
}

TEST_SUITE("Slice_CpuRefTests")
{

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

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

} // Slice_CpuRefTests TestSuite

TEST_SUITE("Slice_CpuAccTests")
{

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

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

} // Slice_CpuAccTests TestSuite

TEST_SUITE("StridedSlice_GpuAccTests")
{

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

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

} // Slice_GpuAccTests TestSuite

} // namespace armnnDelegate