aboutsummaryrefslogtreecommitdiff
path: root/src/armnnDeserializer
diff options
context:
space:
mode:
authorTracy Narine <tracy.narine@arm.com>2023-07-13 16:50:54 +0100
committerTracy Narine <tracy.narine@arm.com>2023-07-17 14:19:36 +0100
commitbb8d7591a35bd95480b39001f8b7e41a6671f3a6 (patch)
treeabf2871aa1bb86378f423df405164b0d4521db3f /src/armnnDeserializer
parent688268328c69e7d4181cdd31fe4717c80a6d1685 (diff)
downloadarmnn-bb8d7591a35bd95480b39001f8b7e41a6671f3a6.tar.gz
IVGCVSW-7879 Change REVERSE_V2 from LayerWithParameters with 1 input, to Layer with 2 inputs
* Changing ReverseV2 to use two inputs * This is required by the backends * The ReverseV2Descriptor was removed * Tests updated * Added a Run<> templatefor inputs with different data types Signed-off-by: Tracy Narine <tracy.narine@arm.com> Change-Id: I22f947de829b4b3da6bda3a74f4ffdef4052cc25
Diffstat (limited to 'src/armnnDeserializer')
-rw-r--r--src/armnnDeserializer/Deserializer.cpp11
-rw-r--r--src/armnnDeserializer/test/DeserializeReverseV2.cpp442
-rw-r--r--src/armnnDeserializer/test/ParserFlatbuffersSerializeFixture.hpp79
3 files changed, 381 insertions, 151 deletions
diff --git a/src/armnnDeserializer/Deserializer.cpp b/src/armnnDeserializer/Deserializer.cpp
index d125ef56dd..1e40c637cc 100644
--- a/src/armnnDeserializer/Deserializer.cpp
+++ b/src/armnnDeserializer/Deserializer.cpp
@@ -2749,20 +2749,13 @@ void IDeserializer::DeserializerImpl::ParseReverseV2(GraphPtr graph, unsigned in
CHECK_LAYERS(graph, 0, layerIndex);
TensorRawPtrVector inputs = GetInputs(graph, layerIndex);
- CHECK_VALID_SIZE(inputs.size(), 1);
+ CHECK_VALID_SIZE(inputs.size(), 2);
TensorRawPtrVector outputs = GetOutputs(graph, layerIndex);
CHECK_VALID_SIZE(outputs.size(), 1);
- auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_ReverseV2Layer()->descriptor();
- auto flatBufferAxis = flatBufferDescriptor->axis();
-
- armnn::ReverseV2Descriptor descriptor;
- descriptor.m_Axis =
- std::vector<int32_t>(flatBufferAxis->begin(), flatBufferAxis->end());
-
auto layerName = GetLayerName(graph, layerIndex);
- IConnectableLayer* layer = m_Network->AddReverseV2Layer(descriptor, layerName.c_str());
+ IConnectableLayer* layer = m_Network->AddReverseV2Layer(layerName.c_str());
armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]);
layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo);
diff --git a/src/armnnDeserializer/test/DeserializeReverseV2.cpp b/src/armnnDeserializer/test/DeserializeReverseV2.cpp
index 73816f8588..b6f207c9d1 100644
--- a/src/armnnDeserializer/test/DeserializeReverseV2.cpp
+++ b/src/armnnDeserializer/test/DeserializeReverseV2.cpp
@@ -14,61 +14,96 @@ TEST_SUITE("Deserializer_ReverseV2")
{
struct ReverseV2Fixture : public ParserFlatbuffersSerializeFixture
{
- explicit ReverseV2Fixture(const std::string& inputShape,
+ explicit ReverseV2Fixture(const std::string& inputShape0,
+ const std::string& inputShape1,
const std::string& outputShape,
- const std::string& dataType,
- const std::string& axis)
+ const std::string& dataType0,
+ const std::string& dataType1)
{
m_JsonString = R"(
{
- inputIds: [0],
- outputIds: [2],
- layers: [
+ inputIds: [0, 1],
+ outputIds: [3],
+ layers:
+ [
{
layer_type: "InputLayer",
layer: {
- base: {
- layerBindingId: 0,
- base: {
- index: 0,
- layerName: "InputLayer",
- layerType: "Input",
- inputSlots: [{
- index: 0,
- connection: {sourceLayerIndex:0, outputSlotIndex:0 },
- }],
- outputSlots: [{
+ base: {
+ layerBindingId: 0,
+ base: {
index: 0,
- tensorInfo: {
- dimensions: )" + inputShape + R"(,
- dataType: )" + dataType + R"(
- }
- }]
- }
- }
+ layerName: "InputLayer0",
+ layerType: "Input",
+ inputSlots:
+ [{
+ index: 0,
+ connection: {sourceLayerIndex:0, outputSlotIndex:0 },
+ }],
+ outputSlots:
+ [ {
+ index: 0,
+ tensorInfo: {
+ dimensions: )" + inputShape0 + R"(,
+ dataType: )" + dataType0 + R"(
+ }
+ }]
+ }
+ }
}
},
{
- layer_type: "ReverseV2Layer",
+ layer_type: "InputLayer",
layer: {
- base: {
- index: 1,
- layerName: "ReverseV2Layer",
- layerType: "ReverseV2",
- inputSlots: [{
- index: 0,
- connection: {sourceLayerIndex:0, outputSlotIndex:0 },
- }],
- outputSlots: [{
- index: 0,
- tensorInfo: {
- dimensions: )" + outputShape + R"(,
- dataType: )" + dataType + R"(
+ base: {
+ layerBindingId: 1,
+ base: {
+ index:1,
+ layerName: "InputLayer1",
+ layerType: "Input",
+ inputSlots:
+ [{
+ index: 0,
+ connection: {sourceLayerIndex:0, outputSlotIndex:0 },
+ }],
+ outputSlots:
+ [{
+ index: 0,
+ tensorInfo: {
+ dimensions: )" + inputShape1 + R"(,
+ dataType: )" + dataType1 + R"(
+ }
+ }]
}
+ }
+ }
+ },
+ {
+ layer_type: "ReverseV2Layer",
+ layer : {
+ base: {
+ index:2,
+ layerName: "ReverseV2Layer",
+ layerType: "ReverseV2",
+ inputSlots:
+ [
+ {
+ index: 0,
+ connection: {sourceLayerIndex:0, outputSlotIndex:0 },
+ },
+ {
+ index: 1,
+ connection: {sourceLayerIndex:1, outputSlotIndex:0 },
+ }
+ ],
+ outputSlots:
+ [{
+ index: 0,
+ tensorInfo: {
+ dimensions: )" + outputShape + R"(,
+ dataType: )" + dataType0 + R"(
+ }
}]
- },
- descriptor: {
- axis: )" + axis + R"(
}
}
},
@@ -76,31 +111,32 @@ TEST_SUITE("Deserializer_ReverseV2")
layer_type: "OutputLayer",
layer: {
base:{
- layerBindingId: 2,
- 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"(
- },
- }],
- }
+ 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: )" + dataType0 + R"(
+ }
+ }]
+ }
}
}
}
]
- }
- )";
+ } )";
- SetupSingleInputSingleOutput("InputLayer", "OutputLayer");
+ Setup();
}
};
@@ -109,65 +145,155 @@ TEST_SUITE("Deserializer_ReverseV2")
struct SimpleReverseV2FixtureFloat32 : ReverseV2Fixture
{
SimpleReverseV2FixtureFloat32()
+ : ReverseV2Fixture("[ 2, 2 ]",
+ "[ 1 ]",
+ "[ 2, 2 ]",
+ "Float32",
+ "Signed32")
+ {}
+ };
+
+ TEST_CASE_FIXTURE(SimpleReverseV2FixtureFloat32, "SimpleReverseV2TestFloat32")
+ {
+ RunTest<2, armnn::DataType::Float32, armnn::DataType::Signed32, armnn::DataType::Float32>(
+ 0,
+ {
+ {
+ "InputLayer0",
+ { 1.0f, 2.0f,
+ 3.0f, 4.0f }
+ }
+ },
+ {
+ {
+ "InputLayer1",
+ { 1 }
+ }
+ },
+ {
+ {
+ "OutputLayer",
+ { 2.0f, 1.0f,
+ 4.0f, 3.0f }
+ }
+ }
+ );
+ }
+
+ struct SimpleReverseV2FixtureFloat32OtherAxis : ReverseV2Fixture
+ {
+ SimpleReverseV2FixtureFloat32OtherAxis()
: ReverseV2Fixture("[ 2, 2 ]",
+ "[ 1 ]",
"[ 2, 2 ]",
"Float32",
- "[1]")
+ "Signed32")
{}
};
- TEST_CASE_FIXTURE(SimpleReverseV2FixtureFloat32, "SimpleReverseV2TestFloat32")
+ TEST_CASE_FIXTURE(SimpleReverseV2FixtureFloat32OtherAxis, "SimpleReverseV2FixtureFloat32OtherAxis")
{
- RunTest<4, armnn::DataType::Float32>(
+ RunTest<2, armnn::DataType::Float32, armnn::DataType::Signed32, armnn::DataType::Float32>(
0,
- { 1.0f, 2.0f,
- 3.0f, 4.0f },
- { 2.0f, 1.0f,
- 4.0f, 3.0f }
- );
+ {
+ {
+ "InputLayer0",
+ { 1.0f, 2.0f,
+ 3.0f, 4.0f }
+ }
+ },
+ {
+ {
+ "InputLayer1",
+ { 1 }
+ }
+ },
+ {
+ {
+ "OutputLayer",
+ { 2.0f, 1.0f,
+ 4.0f, 3.0f }
+ }
+ }
+ );
}
- struct SimpleReverseV2FixtureFloat32ZeroAxis : ReverseV2Fixture
+ struct SimpleReverseV2FixtureFloat32NegativeFirstAxis : ReverseV2Fixture
{
- SimpleReverseV2FixtureFloat32ZeroAxis()
+ SimpleReverseV2FixtureFloat32NegativeFirstAxis()
: ReverseV2Fixture("[ 2, 2 ]",
+ "[ 1 ]",
"[ 2, 2 ]",
"Float32",
- "[0]")
+ "Signed32")
{}
};
- TEST_CASE_FIXTURE(SimpleReverseV2FixtureFloat32ZeroAxis, "SimpleReverseV2TestFloat32ZeroAxis")
+ TEST_CASE_FIXTURE(SimpleReverseV2FixtureFloat32NegativeFirstAxis, "SimpleReverseV2FixtureFloat32NegativeFirstAxis")
{
- RunTest<4, armnn::DataType::Float32>(
- 0,
- { 1.0f, 2.0f,
- 3.0f, 4.0f },
- { 3.0f, 4.0f,
- 1.0f, 2.0f }
+ RunTest<2, armnn::DataType::Float32, armnn::DataType::Signed32, armnn::DataType::Float32>(
+ 0,
+ {
+ {
+ "InputLayer0",
+ { 1.0f, 2.0f,
+ 3.0f, 4.0f }
+ }
+ },
+ {
+ {
+ "InputLayer1",
+ { -2 }
+ }
+ },
+ {
+ {
+ "OutputLayer",
+ { 3.0f, 4.0f,
+ 1.0f, 2.0f }
+ }
+ }
);
}
- struct SimpleReverseV2FixtureFloat32NegativeAxis : ReverseV2Fixture
+ struct SimpleReverseV2FixtureFloat32NegativeSecondAxis : ReverseV2Fixture
{
- SimpleReverseV2FixtureFloat32NegativeAxis()
+ SimpleReverseV2FixtureFloat32NegativeSecondAxis()
: ReverseV2Fixture("[ 3, 3 ]",
+ "[ 1 ]",
"[ 3, 3 ]",
"Float32",
- "[-1]")
+ "Signed32")
{}
};
- TEST_CASE_FIXTURE(SimpleReverseV2FixtureFloat32NegativeAxis, "SimpleReverseV2TestFloat32NegativeAxis")
+ TEST_CASE_FIXTURE(SimpleReverseV2FixtureFloat32NegativeSecondAxis,
+ "SimpleReverseV2FixtureFloat32NegativeSecondAxis")
{
- RunTest<4, armnn::DataType::Float32>(
- 0,
- { 1.0f, 2.0f, 3.0f,
- 4.0f, 5.0f, 6.0f,
- 7.0f, 8.0f, 9.0f },
- { 3.0f, 2.0f, 1.0f,
- 6.0f, 5.0f, 4.0f,
- 9.0f, 8.0f, 7.0f }
+ RunTest<2, armnn::DataType::Float32, armnn::DataType::Signed32, armnn::DataType::Float32>(
+ 0,
+ {
+ {
+ "InputLayer0",
+ { 1.0f, 2.0f, 3.0f,
+ 4.0f, 5.0f, 6.0f,
+ 7.0f, 8.0f, 9.0f }
+ }
+ },
+ {
+ {
+ "InputLayer1",
+ { -1 }
+ }
+ },
+ {
+ {
+ "OutputLayer",
+ { 3.0f, 2.0f, 1.0f,
+ 6.0f, 5.0f, 4.0f,
+ 9.0f, 8.0f, 7.0f }
+ }
+ }
);
}
@@ -175,38 +301,55 @@ TEST_SUITE("Deserializer_ReverseV2")
{
SimpleReverseV2FixtureFloat32ThreeAxis()
: ReverseV2Fixture("[ 3, 3, 3 ]",
+ "[ 3 ]",
"[ 3, 3, 3 ]",
"Float32",
- "[0, 2, 1]")
+ "Signed32")
{}
};
TEST_CASE_FIXTURE(SimpleReverseV2FixtureFloat32ThreeAxis, "SimpleReverseV2TestFloat32ThreeAxis")
{
- RunTest<4, armnn::DataType::Float32>(
- 0,
- { 1.0f, 2.0f, 3.0f,
- 4.0f, 5.0f, 6.0f,
- 7.0f, 8.0f, 9.0f,
-
- 11.0f, 12.0f, 13.0f,
- 14.0f, 15.0f, 16.0f,
- 17.0f, 18.0f, 19.0f,
-
- 21.0f, 22.0f, 23.0f,
- 24.0f, 25.0f, 26.0f,
- 27.0f, 28.0f, 29.0f },
- { 29.0f, 28.0f, 27.0f,
- 26.0f, 25.0f, 24.0f,
- 23.0f, 22.0f, 21.0f,
-
- 19.0f, 18.0f, 17.0f,
- 16.0f, 15.0f, 14.0f,
- 13.0f, 12.0f, 11.0f,
-
- 9.0f, 8.0f, 7.0f,
- 6.0f, 5.0f, 4.0f,
- 3.0f, 2.0f, 1.0f }
+ RunTest<2, armnn::DataType::Float32, armnn::DataType::Signed32, armnn::DataType::Float32>(
+ 0,
+ {
+ {
+ "InputLayer0",
+ { 1.0f, 2.0f, 3.0f,
+ 4.0f, 5.0f, 6.0f,
+ 7.0f, 8.0f, 9.0f,
+
+ 11.0f, 12.0f, 13.0f,
+ 14.0f, 15.0f, 16.0f,
+ 17.0f, 18.0f, 19.0f,
+
+ 21.0f, 22.0f, 23.0f,
+ 24.0f, 25.0f, 26.0f,
+ 27.0f, 28.0f, 29.0f },
+ }
+ },
+ {
+ {
+ "InputLayer1",
+ { 0, 2, 1 }
+ }
+ },
+ {
+ {
+ "OutputLayer",
+ { 29.0f, 28.0f, 27.0f,
+ 26.0f, 25.0f, 24.0f,
+ 23.0f, 22.0f, 21.0f,
+
+ 19.0f, 18.0f, 17.0f,
+ 16.0f, 15.0f, 14.0f,
+ 13.0f, 12.0f, 11.0f,
+
+ 9.0f, 8.0f, 7.0f,
+ 6.0f, 5.0f, 4.0f,
+ 3.0f, 2.0f, 1.0f }
+ }
+ }
);
}
@@ -214,38 +357,55 @@ TEST_SUITE("Deserializer_ReverseV2")
{
SimpleReverseV2FixtureQuantisedAsymm8ThreeAxis()
: ReverseV2Fixture("[ 3, 3, 3 ]",
+ "[ 3 ]",
"[ 3, 3, 3 ]",
"QuantisedAsymm8",
- "[0, 2, 1]")
+ "Signed32")
{}
};
TEST_CASE_FIXTURE(SimpleReverseV2FixtureQuantisedAsymm8ThreeAxis, "SimpleReverseV2TestQuantisedAsymm8ThreeAxis")
{
- RunTest<4, armnn::DataType::QAsymmU8>(
- 0,
- { 1, 2, 3,
- 4, 5, 6,
- 7, 8, 9,
-
- 11, 12, 13,
- 14, 15, 16,
- 17, 18, 19,
-
- 21, 22, 23,
- 24, 25, 26,
- 27, 28, 29 },
- { 29, 28, 27,
- 26, 25, 24,
- 23, 22, 21,
-
- 19, 18, 17,
- 16, 15, 14,
- 13, 12, 11,
-
- 9, 8, 7,
- 6, 5, 4,
- 3, 2, 1 }
+ RunTest<2, armnn::DataType::QAsymmU8, armnn::DataType::Signed32, armnn::DataType::QAsymmU8>(
+ 0,
+ {
+ {
+ "InputLayer0",
+ { 1, 2, 3,
+ 4, 5, 6,
+ 7, 8, 9,
+
+ 11, 12, 13,
+ 14, 15, 16,
+ 17, 18, 19,
+
+ 21, 22, 23,
+ 24, 25, 26,
+ 27, 28, 29 },
+ }
+ },
+ {
+ {
+ "InputLayer1",
+ { 0, 2, 1 }
+ }
+ },
+ {
+ {
+ "OutputLayer",
+ { 29, 28, 27,
+ 26, 25, 24,
+ 23, 22, 21,
+
+ 19, 18, 17,
+ 16, 15, 14,
+ 13, 12, 11,
+
+ 9, 8, 7,
+ 6, 5, 4,
+ 3, 2, 1 }
+ }
+ }
);
}
}
diff --git a/src/armnnDeserializer/test/ParserFlatbuffersSerializeFixture.hpp b/src/armnnDeserializer/test/ParserFlatbuffersSerializeFixture.hpp
index 31ff026887..0b717bc0fd 100644
--- a/src/armnnDeserializer/test/ParserFlatbuffersSerializeFixture.hpp
+++ b/src/armnnDeserializer/test/ParserFlatbuffersSerializeFixture.hpp
@@ -1,5 +1,5 @@
//
-// Copyright © 2017 Arm Ltd. All rights reserved.
+// Copyright © 2019-2023 Arm Ltd. All rights reserved.
// SPDX-License-Identifier: MIT
//
@@ -150,6 +150,18 @@ struct ParserFlatbuffersSerializeFixture
const std::map<std::string, std::vector<InputDataType>>& inputData,
const std::map<std::string, std::vector<OutputDataType>>& expectedOutputData);
+ template<std::size_t NumOutputDimensions,
+ armnn::DataType ArmnnInputType0,
+ armnn::DataType ArmnnInputType1,
+ armnn::DataType ArmnnOutputType,
+ typename InputDataType0 = armnn::ResolveType<ArmnnInputType0>,
+ typename InputDataType1 = armnn::ResolveType<ArmnnInputType1>,
+ typename OutputDataType = armnn::ResolveType<ArmnnOutputType>>
+ void RunTest(unsigned int layersId,
+ const std::map<std::string, std::vector<InputDataType0>>& inputData0,
+ const std::map<std::string, std::vector<InputDataType1>>& inputData1,
+ const std::map<std::string, std::vector<OutputDataType>>& 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)
@@ -246,3 +258,68 @@ void ParserFlatbuffersSerializeFixture::RunTest(
CHECK_MESSAGE(result.m_Result, result.m_Message.str());
}
}
+
+template<std::size_t NumOutputDimensions,
+ armnn::DataType ArmnnInputType0,
+ armnn::DataType ArmnnInputType1,
+ armnn::DataType ArmnnOutputType,
+ typename InputDataType0,
+ typename InputDataType1,
+ typename OutputDataType>
+void ParserFlatbuffersSerializeFixture::RunTest(
+ unsigned int layersId,
+ const std::map<std::string, std::vector<InputDataType0>>& inputData0,
+ const std::map<std::string, std::vector<InputDataType1>>& inputData1,
+ const std::map<std::string, std::vector<OutputDataType>>& expectedOutputData)
+{
+ auto ConvertBindingInfo = [](const armnnDeserializer::BindingPointInfo& bindingInfo)
+ {
+ return std::make_pair(bindingInfo.m_BindingId, bindingInfo.m_TensorInfo);
+ };
+
+ // Setup the armnn input tensors from the given vectors.
+ armnn::InputTensors inputTensors;
+ for (auto&& it : inputData0)
+ {
+ armnn::BindingPointInfo bindingInfo = ConvertBindingInfo(
+ m_Parser->GetNetworkInputBindingInfo(layersId, it.first));
+ bindingInfo.second.SetConstant(true);
+ armnn::VerifyTensorInfoDataType(bindingInfo.second, ArmnnInputType0);
+ inputTensors.push_back({ bindingInfo.first, armnn::ConstTensor(bindingInfo.second, it.second.data()) });
+ }
+
+ for (auto&& it : inputData1)
+ {
+ armnn::BindingPointInfo bindingInfo = ConvertBindingInfo(
+ m_Parser->GetNetworkInputBindingInfo(layersId, it.first));
+ bindingInfo.second.SetConstant(true);
+ armnn::VerifyTensorInfoDataType(bindingInfo.second, ArmnnInputType1);
+ 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, std::vector<OutputDataType>> outputStorage;
+ armnn::OutputTensors outputTensors;
+ for (auto&& it : expectedOutputData)
+ {
+ armnn::BindingPointInfo bindingInfo = ConvertBindingInfo(
+ m_Parser->GetNetworkOutputBindingInfo(layersId, it.first));
+ armnn::VerifyTensorInfoDataType(bindingInfo.second, ArmnnOutputType);
+ outputStorage.emplace(it.first, std::vector<OutputDataType>(bindingInfo.second.GetNumElements()));
+ 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)
+ {
+ armnn::BindingPointInfo bindingInfo = ConvertBindingInfo(
+ m_Parser->GetNetworkOutputBindingInfo(layersId, it.first));
+ auto outputExpected = it.second;
+ auto result = CompareTensors(outputExpected, outputStorage[it.first],
+ bindingInfo.second.GetShape(), bindingInfo.second.GetShape());
+ CHECK_MESSAGE(result.m_Result, result.m_Message.str());
+ }
+}