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_Subtraction") 12 { 13 struct SubtractionFixture : public ParserFlatbuffersSerializeFixture 14 { SubtractionFixtureSubtractionFixture15 explicit SubtractionFixture(const std::string & inputShape1, 16 const std::string & inputShape2, 17 const std::string & outputShape, 18 const std::string & dataType) 19 { 20 m_JsonString = R"( 21 { 22 inputIds: [0, 1], 23 outputIds: [3], 24 layers: [ 25 { 26 layer_type: "InputLayer", 27 layer: { 28 base: { 29 layerBindingId: 0, 30 base: { 31 index: 0, 32 layerName: "inputLayer1", 33 layerType: "Input", 34 inputSlots: [{ 35 index: 0, 36 connection: {sourceLayerIndex:0, outputSlotIndex:0 }, 37 }], 38 outputSlots: [ { 39 index: 0, 40 tensorInfo: { 41 dimensions: )" + inputShape1 + R"(, 42 dataType: )" + dataType + R"( 43 }, 44 }], 45 }, 46 }}, 47 }, 48 { 49 layer_type: "InputLayer", 50 layer: { 51 base: { 52 layerBindingId: 1, 53 base: { 54 index:1, 55 layerName: "inputLayer2", 56 layerType: "Input", 57 inputSlots: [{ 58 index: 0, 59 connection: {sourceLayerIndex:0, outputSlotIndex:0 }, 60 }], 61 outputSlots: [ { 62 index: 0, 63 tensorInfo: { 64 dimensions: )" + inputShape2 + R"(, 65 dataType: )" + dataType + R"( 66 }, 67 }], 68 }, 69 }}, 70 }, 71 { 72 layer_type: "SubtractionLayer", 73 layer : { 74 base: { 75 index:2, 76 layerName: "subtractionLayer", 77 layerType: "Subtraction", 78 inputSlots: [{ 79 index: 0, 80 connection: {sourceLayerIndex:0, outputSlotIndex:0 }, 81 }, 82 { 83 index: 1, 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 layer_type: "OutputLayer", 97 layer: { 98 base:{ 99 layerBindingId: 0, 100 base: { 101 index: 3, 102 layerName: "outputLayer", 103 layerType: "Output", 104 inputSlots: [{ 105 index: 0, 106 connection: {sourceLayerIndex:2, outputSlotIndex:0 }, 107 }], 108 outputSlots: [ { 109 index: 0, 110 tensorInfo: { 111 dimensions: )" + outputShape + R"(, 112 dataType: )" + dataType + R"( 113 }, 114 }], 115 }}}, 116 }] 117 } 118 )"; 119 Setup(); 120 } 121 }; 122 123 struct SimpleSubtractionFixture : SubtractionFixture 124 { SimpleSubtractionFixtureSimpleSubtractionFixture125 SimpleSubtractionFixture() : SubtractionFixture("[ 1, 4 ]", 126 "[ 1, 4 ]", 127 "[ 1, 4 ]", 128 "QuantisedAsymm8") {} 129 }; 130 131 struct SimpleSubtractionFixture2 : SubtractionFixture 132 { SimpleSubtractionFixture2SimpleSubtractionFixture2133 SimpleSubtractionFixture2() : SubtractionFixture("[ 1, 4 ]", 134 "[ 1, 4 ]", 135 "[ 1, 4 ]", 136 "Float32") {} 137 }; 138 139 struct SimpleSubtractionFixtureBroadcast : SubtractionFixture 140 { SimpleSubtractionFixtureBroadcastSimpleSubtractionFixtureBroadcast141 SimpleSubtractionFixtureBroadcast() : SubtractionFixture("[ 1, 4 ]", 142 "[ 1, 1 ]", 143 "[ 1, 4 ]", 144 "Float32") {} 145 }; 146 147 TEST_CASE_FIXTURE(SimpleSubtractionFixture, "SubtractionQuantisedAsymm8") 148 { 149 RunTest<2, armnn::DataType::QAsymmU8>( 150 0, 151 {{"inputLayer1", { 4, 5, 6, 7 }}, 152 {"inputLayer2", { 3, 2, 1, 0 }}}, 153 {{"outputLayer", { 1, 3, 5, 7 }}}); 154 } 155 156 TEST_CASE_FIXTURE(SimpleSubtractionFixture2, "SubtractionFloat32") 157 { 158 RunTest<2, armnn::DataType::Float32>( 159 0, 160 {{"inputLayer1", { 4, 5, 6, 7 }}, 161 {"inputLayer2", { 3, 2, 1, 0 }}}, 162 {{"outputLayer", { 1, 3, 5, 7 }}}); 163 } 164 165 TEST_CASE_FIXTURE(SimpleSubtractionFixtureBroadcast, "SubtractionBroadcast") 166 { 167 RunTest<2, armnn::DataType::Float32>( 168 0, 169 {{"inputLayer1", { 4, 5, 6, 7 }}, 170 {"inputLayer2", { 2 }}}, 171 {{"outputLayer", { 2, 3, 4, 5 }}}); 172 } 173 174 } 175