xref: /aosp_15_r20/external/armnn/src/armnnDeserializer/test/DeserializePermute.cpp (revision 89c4ff92f2867872bb9e2354d150bf0c8c502810)
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include "ParserFlatbuffersSerializeFixture.hpp"
7 #include <armnnDeserializer/IDeserializer.hpp>
8 
9 #include <string>
10 
11 TEST_SUITE("Deserializer_Permute")
12 {
13 struct PermuteFixture : public ParserFlatbuffersSerializeFixture
14 {
PermuteFixturePermuteFixture15     explicit PermuteFixture(const std::string &inputShape,
16                             const std::string &dimMappings,
17                             const std::string &outputShape,
18                             const std::string &dataType)
19     {
20         m_JsonString = R"(
21             {
22                 inputIds: [0],
23                 outputIds: [2],
24                 layers: [
25                     {
26                         layer_type: "InputLayer",
27                         layer: {
28                             base: {
29                                 layerBindingId: 0,
30                                 base: {
31                                     index: 0,
32                                     layerName: "InputLayer",
33                                     layerType: "Input",
34                                     inputSlots: [{
35                                         index: 0,
36                                         connection: {sourceLayerIndex:0, outputSlotIndex:0 },
37                                     }],
38                                     outputSlots: [{
39                                         index: 0,
40                                         tensorInfo: {
41                                             dimensions: )" + inputShape + R"(,
42                                             dataType: )" + dataType + R"(
43                                         }
44                                     }]
45                                 }
46                             }
47                         }
48                     },
49                     {
50                         layer_type: "PermuteLayer",
51                         layer: {
52                             base: {
53                                 index: 1,
54                                 layerName: "PermuteLayer",
55                                 layerType: "Permute",
56                                 inputSlots: [{
57                                     index: 0,
58                                     connection: {sourceLayerIndex:0, outputSlotIndex:0 },
59                                 }],
60                                 outputSlots: [{
61                                     index: 0,
62                                     tensorInfo: {
63                                         dimensions: )" + outputShape + R"(,
64                                         dataType: )" + dataType + R"(
65                                     }
66                                 }]
67                             },
68                             descriptor: {
69                                 dimMappings: )" + dimMappings + R"(,
70                             }
71                         }
72                     },
73                     {
74                         layer_type: "OutputLayer",
75                         layer: {
76                             base:{
77                                 layerBindingId: 2,
78                                 base: {
79                                     index: 2,
80                                     layerName: "OutputLayer",
81                                     layerType: "Output",
82                                     inputSlots: [{
83                                         index: 0,
84                                         connection: {sourceLayerIndex:1, outputSlotIndex:0 },
85                                     }],
86                                     outputSlots: [{
87                                         index: 0,
88                                         tensorInfo: {
89                                             dimensions: )" + outputShape + R"(,
90                                             dataType: )" + dataType + R"(
91                                         },
92                                     }],
93                                 }
94                             }
95                         },
96                     }
97                 ]
98             }
99         )";
100         SetupSingleInputSingleOutput("InputLayer", "OutputLayer");
101     }
102 };
103 
104 struct SimplePermute2DFixture : PermuteFixture
105 {
SimplePermute2DFixtureSimplePermute2DFixture106     SimplePermute2DFixture() : PermuteFixture("[ 2, 3 ]",
107                                               "[ 1, 0 ]",
108                                               "[ 3, 2 ]",
109                                               "QuantisedAsymm8") {}
110 };
111 
112 TEST_CASE_FIXTURE(SimplePermute2DFixture, "SimplePermute2DQuantisedAsymm8")
113 {
114     RunTest<2, armnn::DataType::QAsymmU8>(0,
115                                                  { 1, 2, 3, 4, 5, 6 },
116                                                  { 1, 4, 2, 5, 3, 6 });
117 }
118 
119 struct SimplePermute4DFixture : PermuteFixture
120 {
SimplePermute4DFixtureSimplePermute4DFixture121     SimplePermute4DFixture() : PermuteFixture("[ 1, 2, 3, 4 ]",
122                                               "[ 3, 2, 1, 0 ]",
123                                               "[ 4, 3, 2, 1 ]",
124                                               "QuantisedAsymm8") {}
125 };
126 
127 TEST_CASE_FIXTURE(SimplePermute4DFixture, "SimplePermute4DQuantisedAsymm8")
128 {
129     RunTest<4, armnn::DataType::QAsymmU8>(0,
130                                                  {  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12,
131                                                    13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24 },
132                                                  {  1, 13,  5, 17,  9, 21,  2, 14,  6, 18, 10, 22,
133                                                     3, 15,  7, 19, 11, 23,  4, 16,  8, 20, 12, 24 });
134 }
135 
136 }
137