diff options
author | Derek Lamberti <derek.lamberti@arm.com> | 2019-02-20 13:57:42 +0000 |
---|---|---|
committer | Derek Lamberti <derek.lamberti@arm.com> | 2019-02-20 15:41:32 +0000 |
commit | 0028d1b0ce5f4c2c6a6eb3c66f38111c21eb47a3 (patch) | |
tree | 894d7ac05ef1610bad636e24489248e6c472b313 /src/armnnDeserializer/test | |
parent | be25fc18f7e55bc39f537601e42a9d5c9d0c111f (diff) | |
download | armnn-0028d1b0ce5f4c2c6a6eb3c66f38111c21eb47a3.tar.gz |
IVGSVSW-2736 Rename DeserializeParser => Deserializer & fix namespaces
Change-Id: I4166c0bbb5ba7f8b8884e71134c21f43d1fc27b0
Signed-off-by: Derek Lamberti <derek.lamberti@arm.com>
Diffstat (limited to 'src/armnnDeserializer/test')
-rw-r--r-- | src/armnnDeserializer/test/DeserializeAdd.cpp | 161 | ||||
-rw-r--r-- | src/armnnDeserializer/test/DeserializeConvolution2d.cpp | 142 | ||||
-rw-r--r-- | src/armnnDeserializer/test/DeserializeMultiplication.cpp | 161 | ||||
-rw-r--r-- | src/armnnDeserializer/test/DeserializePooling2d.cpp | 162 | ||||
-rw-r--r-- | src/armnnDeserializer/test/DeserializeReshape.cpp | 128 | ||||
-rw-r--r-- | src/armnnDeserializer/test/ParserFlatbuffersSerializeFixture.hpp | 199 | ||||
-rw-r--r-- | src/armnnDeserializer/test/SchemaSerialize.hpp | 9 | ||||
-rw-r--r-- | src/armnnDeserializer/test/SchemaSerialize.s | 13 |
8 files changed, 975 insertions, 0 deletions
diff --git a/src/armnnDeserializer/test/DeserializeAdd.cpp b/src/armnnDeserializer/test/DeserializeAdd.cpp new file mode 100644 index 0000000000..b053b10efa --- /dev/null +++ b/src/armnnDeserializer/test/DeserializeAdd.cpp @@ -0,0 +1,161 @@ +// +// Copyright © 2017 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include <boost/test/unit_test.hpp> +#include "ParserFlatbuffersSerializeFixture.hpp" +#include "../Deserializer.hpp" + +#include <string> +#include <iostream> + +BOOST_AUTO_TEST_SUITE(Deserializer) + +struct AddFixture : public ParserFlatbuffersSerializeFixture +{ + explicit AddFixture(const std::string & inputShape1, + const std::string & inputShape2, + const std::string & outputShape, + const std::string & dataType, + const std::string & activation="NONE") + { + m_JsonString = R"( + { + inputIds: [0, 1], + outputIds: [3], + layers: [ + { + layer_type: "InputLayer", + layer: { + base: { + layerBindingId: 0, + base: { + index: 0, + layerName: "InputLayer1", + layerType: "Input", + inputSlots: [{ + index: 0, + connection: {sourceLayerIndex:0, outputSlotIndex:0 }, + }], + outputSlots: [ { + index: 0, + tensorInfo: { + dimensions: )" + inputShape1 + R"(, + dataType: )" + dataType + R"( + }, + }], + },}}, + }, + { + layer_type: "InputLayer", + layer: { + base: { + layerBindingId: 1, + base: { + index:1, + layerName: "InputLayer2", + layerType: "Input", + inputSlots: [{ + index: 0, + connection: {sourceLayerIndex:0, outputSlotIndex:0 }, + }], + outputSlots: [ { + index: 0, + tensorInfo: { + dimensions: )" + inputShape2 + R"(, + dataType: )" + dataType + R"( + }, + }], + },}}, + }, + { + layer_type: "AdditionLayer", + layer : { + base: { + index:2, + layerName: "AdditionLayer", + layerType: "Addition", + inputSlots: [ + { + index: 0, + connection: {sourceLayerIndex:0, outputSlotIndex:0 }, + }, + { + index: 1, + connection: {sourceLayerIndex:1, outputSlotIndex:0 }, + } + ], + outputSlots: [ { + index: 0, + tensorInfo: { + dimensions: )" + outputShape + R"(, + dataType: )" + dataType + R"( + }, + }], + }}, + }, + { + layer_type: "OutputLayer", + layer: { + base:{ + layerBindingId: 0, + base: { + index: 3, + layerName: "OutputLayer", + layerType: "Output", + inputSlots: [{ + index: 0, + connection: {sourceLayerIndex:2, outputSlotIndex:0 }, + }], + outputSlots: [ { + index: 0, + tensorInfo: { + dimensions: )" + outputShape + R"(, + dataType: )" + dataType + R"( + }, + }], + }}}, + }] + } + )"; + Setup(); + } +}; + + +struct SimpleAddFixture : AddFixture +{ + SimpleAddFixture() : AddFixture("[ 2, 2 ]", + "[ 2, 2 ]", + "[ 2, 2 ]", + "QuantisedAsymm8") {} +}; + +struct SimpleAddFixture2 : AddFixture +{ + SimpleAddFixture2() : AddFixture("[ 2, 2, 1, 1 ]", + "[ 2, 2, 1, 1 ]", + "[ 2, 2, 1, 1 ]", + "Float32") {} +}; + +BOOST_FIXTURE_TEST_CASE(AddQuantisedAsymm8, SimpleAddFixture) +{ + RunTest<2, armnn::DataType::QuantisedAsymm8>( + 0, + {{"InputLayer1", { 0, 1, 2, 3 }}, + {"InputLayer2", { 4, 5, 6, 7 }}}, + {{"OutputLayer", { 4, 6, 8, 10 }}}); +} + +BOOST_FIXTURE_TEST_CASE(AddFloat32, SimpleAddFixture2) +{ + RunTest<4, armnn::DataType::Float32>( + 0, + {{"InputLayer1", { 111, 85, 226, 3 }}, + {"InputLayer2", { 5, 8, 10, 12 }}}, + {{"OutputLayer", { 116, 93, 236, 15 }}}); +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/src/armnnDeserializer/test/DeserializeConvolution2d.cpp b/src/armnnDeserializer/test/DeserializeConvolution2d.cpp new file mode 100644 index 0000000000..86f7cac3bb --- /dev/null +++ b/src/armnnDeserializer/test/DeserializeConvolution2d.cpp @@ -0,0 +1,142 @@ +// +// Copyright © 2017 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include <boost/test/unit_test.hpp> +#include "ParserFlatbuffersSerializeFixture.hpp" +#include "../Deserializer.hpp" + +#include <string> +#include <iostream> + +BOOST_AUTO_TEST_SUITE(Deserializer) + +struct Convolution2dFixture : public ParserFlatbuffersSerializeFixture +{ + explicit Convolution2dFixture(const std::string & inputShape1, + const std::string & outputShape, + const std::string & weightsShape, + const std::string & dataType) + { + m_JsonString = R"( + { + inputIds: [0], + outputIds: [2], + layers: [{ + layer_type: "InputLayer", + layer: { + base: { + layerBindingId: 0, + base: { + index: 0, + layerName: "InputLayer", + layerType: "Input", + inputSlots: [{ + index: 0, + connection: {sourceLayerIndex:0, outputSlotIndex:0 }, + }], + outputSlots: [{ + index: 0, + tensorInfo: { + dimensions: )" + inputShape1 + R"(, + dataType: )" + dataType + R"(, + quantizationScale: 0.5, + quantizationOffset: 0 + }, + }] + }, + } + }, + }, + { + layer_type: "Convolution2dLayer", + layer : { + base: { + index:1, + layerName: "Convolution2dLayer", + layerType: "Convolution2d", + inputSlots: [{ + index: 0, + connection: {sourceLayerIndex:0, outputSlotIndex:0 }, + }], + outputSlots: [{ + index: 0, + tensorInfo: { + dimensions: )" + outputShape + R"(, + dataType: )" + dataType + R"( + }, + }], + }, + descriptor: { + padLeft: 1, + padRight: 1, + padTop: 1, + padBottom: 1, + strideX: 2, + strideY: 2, + biasEnabled: false, + dataLayout: NHWC + }, + weights: { + info: { + dimensions: )" + weightsShape + R"(, + dataType: )" + dataType + R"( + }, + data_type: IntData, + data: { + data: [ + 1082130432, 1084227584, 1086324736, + 0 ,0 ,0 , + 1077936128, 1073741824, 1065353216 + ], + } + } + }, + }, + { + layer_type: "OutputLayer", + layer: { + base:{ + layerBindingId: 0, + base: { + index: 2, + layerName: "OutputLayer", + layerType: "Output", + inputSlots: [{ + index: 0, + connection: {sourceLayerIndex:1, outputSlotIndex:0 }, + }], + outputSlots: [ { + index: 0, + tensorInfo: { + dimensions: )" + outputShape + R"(, + dataType: )" + dataType + R"( + }, + }], + } + }}, + }] + } + )"; + Setup(); + } +}; + +struct SimpleConvolution2dFixture : Convolution2dFixture +{ + SimpleConvolution2dFixture() : Convolution2dFixture("[ 1, 5, 5, 1 ]", + "[ 1, 3, 3, 1 ]", + "[ 1, 3, 3, 1 ]", + "Float32") {} +}; + +BOOST_FIXTURE_TEST_CASE(Convolution2dFloat32, SimpleConvolution2dFixture) +{ + RunTest<4, armnn::DataType::Float32>( + 0, + {{"InputLayer", {1, 5, 2, 3, 5, 8, 7, 3, 6, 3, 3, 3, 9, 1, 9, 4, 1, 8, 1, 3, 6, 8, 1, 9, 2}}}, + {{"OutputLayer", {23, 33, 24, 91, 99, 48, 26, 50, 19}}}); +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/src/armnnDeserializer/test/DeserializeMultiplication.cpp b/src/armnnDeserializer/test/DeserializeMultiplication.cpp new file mode 100644 index 0000000000..a9dbfbf7da --- /dev/null +++ b/src/armnnDeserializer/test/DeserializeMultiplication.cpp @@ -0,0 +1,161 @@ +// +// Copyright © 2017 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include <boost/test/unit_test.hpp> +#include "ParserFlatbuffersSerializeFixture.hpp" +#include "../Deserializer.hpp" + +#include <string> +#include <iostream> + +BOOST_AUTO_TEST_SUITE(Deserializer) + +struct MultiplicationFixture : public ParserFlatbuffersSerializeFixture +{ + explicit MultiplicationFixture(const std::string & inputShape1, + const std::string & inputShape2, + const std::string & outputShape, + const std::string & dataType, + const std::string & activation="NONE") + { + m_JsonString = R"( + { + inputIds: [0, 1], + outputIds: [3], + layers: [ + { + layer_type: "InputLayer", + layer: { + base: { + layerBindingId: 0, + base: { + index: 0, + layerName: "InputLayer1", + layerType: "Input", + inputSlots: [{ + index: 0, + connection: {sourceLayerIndex:0, outputSlotIndex:0 }, + }], + outputSlots: [ { + index: 0, + tensorInfo: { + dimensions: )" + inputShape1 + R"(, + dataType: )" + dataType + R"( + }, + }], + },}}, + }, + { + layer_type: "InputLayer", + layer: { + base: { + layerBindingId: 1, + base: { + index:1, + layerName: "InputLayer2", + layerType: "Input", + inputSlots: [{ + index: 0, + connection: {sourceLayerIndex:0, outputSlotIndex:0 }, + }], + outputSlots: [ { + index: 0, + tensorInfo: { + dimensions: )" + inputShape2 + R"(, + dataType: )" + dataType + R"( + }, + }], + },}}, + }, + { + layer_type: "MultiplicationLayer", + layer : { + base: { + index:2, + layerName: "MultiplicationLayer", + layerType: "Multiplication", + inputSlots: [ + { + index: 0, + connection: {sourceLayerIndex:0, outputSlotIndex:0 }, + }, + { + index: 1, + connection: {sourceLayerIndex:1, outputSlotIndex:0 }, + } + ], + outputSlots: [ { + index: 0, + tensorInfo: { + dimensions: )" + outputShape + R"(, + dataType: )" + dataType + R"( + }, + }], + }}, + }, + { + layer_type: "OutputLayer", + layer: { + base:{ + layerBindingId: 0, + base: { + index: 3, + layerName: "OutputLayer", + layerType: "Output", + inputSlots: [{ + index: 0, + connection: {sourceLayerIndex:2, outputSlotIndex:0 }, + }], + outputSlots: [ { + index: 0, + tensorInfo: { + dimensions: )" + outputShape + R"(, + dataType: )" + dataType + R"( + }, + }], + }}}, + }] + } + )"; + Setup(); + } +}; + + +struct SimpleMultiplicationFixture : MultiplicationFixture +{ + SimpleMultiplicationFixture() : MultiplicationFixture("[ 2, 2 ]", + "[ 2, 2 ]", + "[ 2, 2 ]", + "QuantisedAsymm8") {} +}; + +struct SimpleMultiplicationFixture2 : MultiplicationFixture +{ + SimpleMultiplicationFixture2() : MultiplicationFixture("[ 2, 2, 1, 1 ]", + "[ 2, 2, 1, 1 ]", + "[ 2, 2, 1, 1 ]", + "Float32") {} +}; + +BOOST_FIXTURE_TEST_CASE(MultiplicationQuantisedAsymm8, SimpleMultiplicationFixture) +{ + RunTest<2, armnn::DataType::QuantisedAsymm8>( + 0, + {{"InputLayer1", { 0, 1, 2, 3 }}, + {"InputLayer2", { 4, 5, 6, 7 }}}, + {{"OutputLayer", { 0, 5, 12, 21 }}}); +} + +BOOST_FIXTURE_TEST_CASE(MultiplicationFloat32, SimpleMultiplicationFixture2) +{ + RunTest<4, armnn::DataType::Float32>( + 0, + {{"InputLayer1", { 100, 40, 226, 9 }}, + {"InputLayer2", { 5, 8, 1, 12 }}}, + {{"OutputLayer", { 500, 320, 226, 108 }}}); +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/src/armnnDeserializer/test/DeserializePooling2d.cpp b/src/armnnDeserializer/test/DeserializePooling2d.cpp new file mode 100644 index 0000000000..ef30a84342 --- /dev/null +++ b/src/armnnDeserializer/test/DeserializePooling2d.cpp @@ -0,0 +1,162 @@ +// +// Copyright © 2017 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include <boost/test/unit_test.hpp> +#include "ParserFlatbuffersSerializeFixture.hpp" +#include "../Deserializer.hpp" + +#include <string> +#include <iostream> + +BOOST_AUTO_TEST_SUITE(Deserializer) + +struct Pooling2dFixture : public ParserFlatbuffersSerializeFixture +{ + explicit Pooling2dFixture(const std::string &inputShape, + const std::string &outputShape, + const std::string &dataType, + const std::string &dataLayout, + const std::string &poolingAlgorithm) + { + m_JsonString = R"( + { + inputIds: [0], + outputIds: [2], + layers: [ + { + layer_type: "InputLayer", + layer: { + base: { + layerBindingId: 0, + base: { + index: 0, + layerName: "InputLayer", + layerType: "Input", + inputSlots: [{ + index: 0, + connection: {sourceLayerIndex:0, outputSlotIndex:0 }, + }], + outputSlots: [ { + index: 0, + tensorInfo: { + dimensions: )" + inputShape + R"(, + dataType: )" + dataType + R"( + }}] + } + }}}, + { + layer_type: "Pooling2dLayer", + layer: { + base: { + index: 1, + layerName: "Pooling2dLayer", + layerType: "Pooling2d", + inputSlots: [{ + index: 0, + connection: {sourceLayerIndex:0, outputSlotIndex:0 }, + }], + outputSlots: [ { + index: 0, + tensorInfo: { + dimensions: )" + outputShape + R"(, + dataType: )" + dataType + R"( + + }}]}, + descriptor: { + poolType: )" + poolingAlgorithm + R"(, + outputShapeRounding: "Floor", + paddingMethod: Exclude, + dataLayout: )" + dataLayout + R"(, + padLeft: 0, + padRight: 0, + padTop: 0, + padBottom: 0, + poolWidth: 2, + poolHeight: 2, + strideX: 2, + strideY: 2 + } + }}, + { + layer_type: "OutputLayer", + layer: { + base:{ + layerBindingId: 0, + base: { + index: 2, + layerName: "OutputLayer", + layerType: "Output", + inputSlots: [{ + index: 0, + connection: {sourceLayerIndex:1, outputSlotIndex:0 }, + }], + outputSlots: [ { + index: 0, + tensorInfo: { + dimensions: )" + outputShape + R"(, + dataType: )" + dataType + R"( + }, + }], + }}}, + }] + } + )"; + SetupSingleInputSingleOutput("InputLayer", "OutputLayer"); + } +}; + +struct SimpleAvgPoolingFixture : Pooling2dFixture +{ + SimpleAvgPoolingFixture() : Pooling2dFixture("[ 1, 2, 2, 1 ]", "[ 1, 1, 1, 1 ]", + "Float32", "NHWC", "Average") {} +}; + +struct SimpleAvgPoolingFixture2 : Pooling2dFixture +{ + SimpleAvgPoolingFixture2() : Pooling2dFixture("[ 1, 2, 2, 1 ]", + "[ 1, 1, 1, 1 ]", + "QuantisedAsymm8", "NHWC", "Average") {} +}; + +struct SimpleMaxPoolingFixture : Pooling2dFixture +{ + SimpleMaxPoolingFixture() : Pooling2dFixture("[ 1, 1, 2, 2 ]", + "[ 1, 1, 1, 1 ]", + "Float32", "NCHW", "Max") {} +}; + +struct SimpleMaxPoolingFixture2 : Pooling2dFixture +{ + SimpleMaxPoolingFixture2() : Pooling2dFixture("[ 1, 1, 2, 2 ]", + "[ 1, 1, 1, 1 ]", + "QuantisedAsymm8", "NCHW", "Max") {} +}; + +BOOST_FIXTURE_TEST_CASE(PoolingQuantisedAsymm8Avg, SimpleAvgPoolingFixture) +{ + RunTest<4, armnn::DataType::Float32>(0, { 2, 3, 5, 2 }, { 3 }); +} + +BOOST_FIXTURE_TEST_CASE(PoolingFloat32Avg, SimpleAvgPoolingFixture2) +{ + RunTest<4, armnn::DataType::QuantisedAsymm8>(0, + { 20, 40, 60, 80 }, + { 50 }); +} + +BOOST_FIXTURE_TEST_CASE(PoolingQuantisedAsymm8Max, SimpleMaxPoolingFixture) +{ + RunTest<4, armnn::DataType::Float32>(0, { 2, 5, 5, 2 }, { 5 }); +} + +BOOST_FIXTURE_TEST_CASE(PoolingFloat32Max, SimpleMaxPoolingFixture2) +{ + RunTest<4, armnn::DataType::QuantisedAsymm8>(0, + { 20, 40, 60, 80 }, + { 80 }); +} + +BOOST_AUTO_TEST_SUITE_END() + diff --git a/src/armnnDeserializer/test/DeserializeReshape.cpp b/src/armnnDeserializer/test/DeserializeReshape.cpp new file mode 100644 index 0000000000..301d8986c0 --- /dev/null +++ b/src/armnnDeserializer/test/DeserializeReshape.cpp @@ -0,0 +1,128 @@ +// +// Copyright © 2017 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include <boost/test/unit_test.hpp> +#include "ParserFlatbuffersSerializeFixture.hpp" +#include "../Deserializer.hpp" + +#include <string> +#include <iostream> + +BOOST_AUTO_TEST_SUITE(Deserializer) + +struct ReshapeFixture : public ParserFlatbuffersSerializeFixture +{ + explicit ReshapeFixture(const std::string &inputShape, + const std::string &targetShape, + const std::string &outputShape, + const std::string &dataType) + { + m_JsonString = R"( + { + inputIds: [0], + outputIds: [2], + layers: [ + { + layer_type: "InputLayer", + layer: { + base: { + layerBindingId: 0, + base: { + index: 0, + layerName: "InputLayer", + layerType: "Input", + inputSlots: [{ + index: 0, + connection: {sourceLayerIndex:0, outputSlotIndex:0 }, + }], + outputSlots: [ { + index: 0, + tensorInfo: { + dimensions: )" + inputShape + R"(, + dataType: )" + dataType + R"( + }}] + } + }}}, + { + layer_type: "ReshapeLayer", + layer: { + base: { + index: 1, + layerName: "ReshapeLayer", + layerType: "Reshape", + inputSlots: [{ + index: 0, + connection: {sourceLayerIndex:0, outputSlotIndex:0 }, + }], + outputSlots: [ { + index: 0, + tensorInfo: { + dimensions: )" + inputShape + R"(, + dataType: )" + dataType + R"( + + }}]}, + descriptor: { + targetShape: )" + targetShape + R"(, + } + + }}, + { + layer_type: "OutputLayer", + layer: { + base:{ + layerBindingId: 2, + base: { + index: 2, + layerName: "OutputLayer", + layerType: "Output", + inputSlots: [{ + index: 0, + connection: {sourceLayerIndex:0, outputSlotIndex:0 }, + }], + outputSlots: [ { + index: 0, + tensorInfo: { + dimensions: )" + outputShape + R"(, + dataType: )" + dataType + R"( + }, + }], + }}}, + }] + } + )"; + SetupSingleInputSingleOutput("InputLayer", "OutputLayer"); + } +}; + +struct SimpleReshapeFixture : ReshapeFixture +{ + SimpleReshapeFixture() : ReshapeFixture("[ 1, 9 ]", "[ 3, 3 ]", "[ 3, 3 ]", + "QuantisedAsymm8") {} +}; + +struct SimpleReshapeFixture2 : ReshapeFixture +{ + SimpleReshapeFixture2() : ReshapeFixture("[ 2, 2, 1, 1 ]", + "[ 2, 2, 1, 1 ]", + "[ 2, 2, 1, 1 ]", + "Float32") {} +}; + +BOOST_FIXTURE_TEST_CASE(ReshapeQuantisedAsymm8, SimpleReshapeFixture) +{ + RunTest<2, armnn::DataType::QuantisedAsymm8>(0, + { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, + { 1, 2, 3, 4, 5, 6, 7, 8, 9 }); +} + +BOOST_FIXTURE_TEST_CASE(ReshapeFloat32, SimpleReshapeFixture2) +{ + RunTest<4, armnn::DataType::Float32>(0, + { 111, 85, 226, 3 }, + { 111, 85, 226, 3 }); +} + + +BOOST_AUTO_TEST_SUITE_END()
\ No newline at end of file diff --git a/src/armnnDeserializer/test/ParserFlatbuffersSerializeFixture.hpp b/src/armnnDeserializer/test/ParserFlatbuffersSerializeFixture.hpp new file mode 100644 index 0000000000..42ab2b17d6 --- /dev/null +++ b/src/armnnDeserializer/test/ParserFlatbuffersSerializeFixture.hpp @@ -0,0 +1,199 @@ +// +// Copyright © 2017 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#pragma once + +#include "SchemaSerialize.hpp" + +#include <armnn/IRuntime.hpp> +#include <armnnDeserializer/IDeserializer.hpp> + +#include <boost/assert.hpp> +#include <boost/format.hpp> + +#include "TypeUtils.hpp" +#include "test/TensorHelpers.hpp" + +#include "flatbuffers/idl.h" +#include "flatbuffers/util.h" + +#include <Schema_generated.h> + +using armnnDeserializer::IDeserializer; +using TensorRawPtr = armnnSerializer::TensorInfo*; + +struct ParserFlatbuffersSerializeFixture +{ + ParserFlatbuffersSerializeFixture() : + m_Parser(IDeserializer::Create()), + m_Runtime(armnn::IRuntime::Create(armnn::IRuntime::CreationOptions())), + m_NetworkIdentifier(-1) + { + } + + std::vector<uint8_t> m_GraphBinary; + std::string m_JsonString; + std::unique_ptr<IDeserializer, void (*)(IDeserializer* parser)> m_Parser; + armnn::IRuntimePtr m_Runtime; + armnn::NetworkId m_NetworkIdentifier; + + /// If the single-input-single-output overload of Setup() is called, these will store the input and output name + /// so they don't need to be passed to the single-input-single-output overload of RunTest(). + std::string m_SingleInputName; + std::string m_SingleOutputName; + + void Setup() + { + bool ok = ReadStringToBinary(); + if (!ok) + { + throw armnn::Exception("LoadNetwork failed while reading binary input"); + } + + armnn::INetworkPtr network = + m_Parser->CreateNetworkFromBinary(m_GraphBinary); + + if (!network) + { + throw armnn::Exception("The parser failed to create an ArmNN network"); + } + + auto optimized = Optimize(*network, {armnn::Compute::CpuRef}, + m_Runtime->GetDeviceSpec()); + + std::string errorMessage; + armnn::Status ret = m_Runtime->LoadNetwork(m_NetworkIdentifier, move(optimized), errorMessage); + + if (ret != armnn::Status::Success) + { + throw armnn::Exception( + boost::str( + boost::format("The runtime failed to load the network. " + "Error was: %1%. in %2% [%3%:%4%]") % + errorMessage % + __func__ % + __FILE__ % + __LINE__)); + } + + } + + void SetupSingleInputSingleOutput(const std::string& inputName, const std::string& outputName) + { + // Store the input and output name so they don't need to be passed to the single-input-single-output RunTest(). + m_SingleInputName = inputName; + m_SingleOutputName = outputName; + Setup(); + } + + bool ReadStringToBinary() + { + std::string schemafile(&deserialize_schema_start, &deserialize_schema_end); + + // parse schema first, so we can use it to parse the data after + flatbuffers::Parser parser; + + bool ok = parser.Parse(schemafile.c_str()); + BOOST_ASSERT_MSG(ok, "Failed to parse schema file"); + + ok &= parser.Parse(m_JsonString.c_str()); + BOOST_ASSERT_MSG(ok, "Failed to parse json input"); + + if (!ok) + { + return false; + } + + { + const uint8_t* bufferPtr = parser.builder_.GetBufferPointer(); + size_t size = static_cast<size_t>(parser.builder_.GetSize()); + m_GraphBinary.assign(bufferPtr, bufferPtr+size); + } + return ok; + } + + /// Executes the network with the given input tensor and checks the result against the given output tensor. + /// This overload assumes the network has a single input and a single output. + template <std::size_t NumOutputDimensions, + armnn::DataType ArmnnType, + typename DataType = armnn::ResolveType<ArmnnType>> + void RunTest(unsigned int layersId, + const std::vector<DataType>& inputData, + const std::vector<DataType>& expectedOutputData); + + /// Executes the network with the given input tensors and checks the results against the given output tensors. + /// This overload supports multiple inputs and multiple outputs, identified by name. + template <std::size_t NumOutputDimensions, + armnn::DataType ArmnnType, + typename DataType = armnn::ResolveType<ArmnnType>> + void RunTest(unsigned int layersId, + const std::map<std::string, std::vector<DataType>>& inputData, + const std::map<std::string, std::vector<DataType>>& expectedOutputData); + + void CheckTensors(const TensorRawPtr& tensors, size_t shapeSize, const std::vector<int32_t>& shape, + armnnSerializer::TensorInfo tensorType, const std::string& name, + const float scale, const int64_t zeroPoint) + { + BOOST_CHECK_EQUAL(shapeSize, tensors->dimensions()->size()); + BOOST_CHECK_EQUAL_COLLECTIONS(shape.begin(), shape.end(), + tensors->dimensions()->begin(), tensors->dimensions()->end()); + BOOST_CHECK_EQUAL(tensorType.dataType(), tensors->dataType()); + BOOST_CHECK_EQUAL(scale, tensors->quantizationScale()); + BOOST_CHECK_EQUAL(zeroPoint, tensors->quantizationOffset()); + } +}; + +template <std::size_t NumOutputDimensions, + armnn::DataType ArmnnType, + typename DataType> +void ParserFlatbuffersSerializeFixture::RunTest(unsigned int layersId, + const std::vector<DataType>& inputData, + const std::vector<DataType>& expectedOutputData) +{ + RunTest<NumOutputDimensions, ArmnnType>(layersId, + { { m_SingleInputName, inputData } }, + { { m_SingleOutputName, expectedOutputData } }); +} + +template <std::size_t NumOutputDimensions, + armnn::DataType ArmnnType, + typename DataType> +void ParserFlatbuffersSerializeFixture::RunTest(unsigned int layersId, + const std::map<std::string, std::vector<DataType>>& inputData, + const std::map<std::string, std::vector<DataType>>& expectedOutputData) +{ + using BindingPointInfo = std::pair<armnn::LayerBindingId, armnn::TensorInfo>; + + // Setup the armnn input tensors from the given vectors. + armnn::InputTensors inputTensors; + for (auto&& it : inputData) + { + BindingPointInfo bindingInfo = m_Parser->GetNetworkInputBindingInfo(layersId, it.first); + armnn::VerifyTensorInfoDataType<ArmnnType>(bindingInfo.second); + inputTensors.push_back({ bindingInfo.first, armnn::ConstTensor(bindingInfo.second, it.second.data()) }); + } + + // Allocate storage for the output tensors to be written to and setup the armnn output tensors. + std::map<std::string, boost::multi_array<DataType, NumOutputDimensions>> outputStorage; + armnn::OutputTensors outputTensors; + for (auto&& it : expectedOutputData) + { + BindingPointInfo bindingInfo = m_Parser->GetNetworkOutputBindingInfo(layersId, it.first); + armnn::VerifyTensorInfoDataType<ArmnnType>(bindingInfo.second); + outputStorage.emplace(it.first, MakeTensor<DataType, NumOutputDimensions>(bindingInfo.second)); + outputTensors.push_back( + { bindingInfo.first, armnn::Tensor(bindingInfo.second, outputStorage.at(it.first).data()) }); + } + + m_Runtime->EnqueueWorkload(m_NetworkIdentifier, inputTensors, outputTensors); + + // Compare each output tensor to the expected values + for (auto&& it : expectedOutputData) + { + BindingPointInfo bindingInfo = m_Parser->GetNetworkOutputBindingInfo(layersId, it.first); + auto outputExpected = MakeTensor<DataType, NumOutputDimensions>(bindingInfo.second, it.second); + BOOST_TEST(CompareTensors(outputExpected, outputStorage[it.first])); + } +} diff --git a/src/armnnDeserializer/test/SchemaSerialize.hpp b/src/armnnDeserializer/test/SchemaSerialize.hpp new file mode 100644 index 0000000000..ec7e6bab6a --- /dev/null +++ b/src/armnnDeserializer/test/SchemaSerialize.hpp @@ -0,0 +1,9 @@ +// +// Copyright © 2017 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +extern "C" { +extern const char deserialize_schema_start; +extern const char deserialize_schema_end; +} diff --git a/src/armnnDeserializer/test/SchemaSerialize.s b/src/armnnDeserializer/test/SchemaSerialize.s new file mode 100644 index 0000000000..dbbb7db3e5 --- /dev/null +++ b/src/armnnDeserializer/test/SchemaSerialize.s @@ -0,0 +1,13 @@ +// +// Copyright © 2017 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +.section .rodata + +.global deserialize_schema_start +.global deserialize_schema_end + +deserialize_schema_start: +.incbin ARMNN_SERIALIZER_SCHEMA_PATH +deserialize_schema_end: |