1 // 2 // Copyright © 2020 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_Transpose") 12 { 13 struct TransposeFixture : public ParserFlatbuffersSerializeFixture 14 { TransposeFixtureTransposeFixture15 explicit TransposeFixture(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: "TransposeLayer", 51 layer: { 52 base: { 53 index: 1, 54 layerName: "TransposeLayer", 55 layerType: "Transpose", 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 SimpleTranspose2DFixture : TransposeFixture 105 { SimpleTranspose2DFixtureSimpleTranspose2DFixture106 SimpleTranspose2DFixture() : TransposeFixture("[ 2, 3 ]", 107 "[ 1, 0 ]", 108 "[ 3, 2 ]", 109 "QuantisedAsymm8") {} 110 }; 111 112 TEST_CASE_FIXTURE(SimpleTranspose2DFixture, "SimpleTranspose2DQuantisedAsymm8") 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 SimpleTranspose4DFixture : TransposeFixture 120 { SimpleTranspose4DFixtureSimpleTranspose4DFixture121 SimpleTranspose4DFixture() : TransposeFixture("[ 1, 2, 3, 4 ]", 122 "[ 3, 2, 1, 0 ]", 123 "[ 4, 3, 2, 1 ]", 124 "QuantisedAsymm8") {} 125 }; 126 127 TEST_CASE_FIXTURE(SimpleTranspose4DFixture, "SimpleTranspose4DQuantisedAsymm8") 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