mathad01 | b392e98 | 2021-04-07 12:07:30 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2021 Arm Ltd and Contributors. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "ParserFlatbuffersSerializeFixture.hpp" |
| 7 | #include <armnnDeserializer/IDeserializer.hpp> |
| 8 | |
| 9 | #include <QuantizeHelper.hpp> |
| 10 | #include <ResolveType.hpp> |
| 11 | |
| 12 | #include <boost/test/unit_test.hpp> |
| 13 | |
| 14 | #include <string> |
| 15 | |
| 16 | BOOST_AUTO_TEST_SUITE(Deserializer) |
| 17 | |
| 18 | |
| 19 | struct CastFixture : public ParserFlatbuffersSerializeFixture |
| 20 | { |
| 21 | explicit CastFixture(const std::string& inputShape, |
| 22 | const std::string& outputShape, |
| 23 | const std::string& inputDataType, |
| 24 | const std::string& outputDataType) |
| 25 | { |
| 26 | m_JsonString = R"( |
| 27 | { |
| 28 | inputIds: [0], |
| 29 | outputIds: [2], |
| 30 | layers: [ |
| 31 | { |
| 32 | layer_type: "InputLayer", |
| 33 | layer: { |
| 34 | base: { |
| 35 | layerBindingId: 0, |
| 36 | base: { |
| 37 | index: 0, |
| 38 | layerName: "inputTensor", |
| 39 | layerType: "Input", |
| 40 | inputSlots: [{ |
| 41 | index: 0, |
| 42 | connection: { sourceLayerIndex:0, outputSlotIndex:0 }, |
| 43 | }], |
| 44 | outputSlots: [{ |
| 45 | index: 0, |
| 46 | tensorInfo: { |
| 47 | dimensions: )" + inputShape + R"(, |
| 48 | dataType: )" + inputDataType + R"( |
| 49 | } |
| 50 | }] |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | }, |
| 55 | { |
| 56 | layer_type: "CastLayer", |
| 57 | layer: { |
| 58 | base: { |
| 59 | index:1, |
| 60 | layerName: "CastLayer", |
| 61 | layerType: "Cast", |
| 62 | inputSlots: [{ |
| 63 | index: 0, |
| 64 | connection: { sourceLayerIndex:0, outputSlotIndex:0 }, |
| 65 | }], |
| 66 | outputSlots: [{ |
| 67 | index: 0, |
| 68 | tensorInfo: { |
| 69 | dimensions: )" + outputShape + R"(, |
| 70 | dataType: )" + outputDataType + R"( |
| 71 | }, |
| 72 | }], |
| 73 | }, |
| 74 | }, |
| 75 | }, |
| 76 | { |
| 77 | layer_type: "OutputLayer", |
| 78 | layer: { |
| 79 | base:{ |
| 80 | layerBindingId: 2, |
| 81 | base: { |
| 82 | index: 2, |
| 83 | layerName: "outputTensor", |
| 84 | layerType: "Output", |
| 85 | inputSlots: [{ |
| 86 | index: 0, |
| 87 | connection: { sourceLayerIndex:1, outputSlotIndex:0 }, |
| 88 | }], |
| 89 | outputSlots: [{ |
| 90 | index: 0, |
| 91 | tensorInfo: { |
| 92 | dimensions: )" + outputShape + R"(, |
| 93 | dataType: )" + outputDataType + R"( |
| 94 | }, |
| 95 | }], |
| 96 | } |
| 97 | } |
| 98 | }, |
| 99 | } |
| 100 | ] |
| 101 | } |
| 102 | )"; |
| 103 | Setup(); |
| 104 | } |
| 105 | }; |
| 106 | |
| 107 | struct SimpleCastFixture : CastFixture |
| 108 | { |
| 109 | SimpleCastFixture() : CastFixture("[ 1, 6 ]", |
| 110 | "[ 1, 6 ]", |
| 111 | "Signed32", |
| 112 | "Float32") {} |
| 113 | }; |
| 114 | |
| 115 | BOOST_FIXTURE_TEST_CASE(SimpleCast, SimpleCastFixture) |
| 116 | { |
| 117 | RunTest<2, armnn::DataType::Signed32 , armnn::DataType::Float32>( |
| 118 | 0, |
| 119 | {{"inputTensor", { 0, -1, 5, -100, 200, -255 }}}, |
| 120 | {{"outputTensor", { 0.0f, -1.0f, 5.0f, -100.0f, 200.0f, -255.0f }}}); |
| 121 | } |
| 122 | |
| 123 | BOOST_AUTO_TEST_SUITE_END() |