aboutsummaryrefslogtreecommitdiff
path: root/src/armnnDeserializer
diff options
context:
space:
mode:
Diffstat (limited to 'src/armnnDeserializer')
-rw-r--r--src/armnnDeserializer/Deserializer.cpp23
-rw-r--r--src/armnnDeserializer/Deserializer.hpp1
-rw-r--r--src/armnnDeserializer/test/DeserializeGatherNd.cpp146
3 files changed, 170 insertions, 0 deletions
diff --git a/src/armnnDeserializer/Deserializer.cpp b/src/armnnDeserializer/Deserializer.cpp
index 11d3542405..75c60cc906 100644
--- a/src/armnnDeserializer/Deserializer.cpp
+++ b/src/armnnDeserializer/Deserializer.cpp
@@ -234,6 +234,7 @@ m_ParserFunctions(Layer_MAX+1, &IDeserializer::DeserializerImpl::ParseUnsupporte
m_ParserFunctions[Layer_FillLayer] = &DeserializerImpl::ParseFill;
m_ParserFunctions[Layer_FloorLayer] = &DeserializerImpl::ParseFloor;
m_ParserFunctions[Layer_GatherLayer] = &DeserializerImpl::ParseGather;
+ m_ParserFunctions[Layer_GatherNdLayer] = &DeserializerImpl::ParseGatherNd;
m_ParserFunctions[Layer_GreaterLayer] = &DeserializerImpl::ParseGreater;
m_ParserFunctions[Layer_InstanceNormalizationLayer] = &DeserializerImpl::ParseInstanceNormalization;
m_ParserFunctions[Layer_L2NormalizationLayer] = &DeserializerImpl::ParseL2Normalization;
@@ -331,6 +332,8 @@ LayerBaseRawPtr IDeserializer::DeserializerImpl::GetBaseLayer(const GraphPtr& gr
return graphPtr->layers()->Get(layerIndex)->layer_as_FloorLayer()->base();
case Layer::Layer_GatherLayer:
return graphPtr->layers()->Get(layerIndex)->layer_as_GatherLayer()->base();
+ case Layer::Layer_GatherNdLayer:
+ return graphPtr->layers()->Get(layerIndex)->layer_as_GatherNdLayer()->base();
case Layer::Layer_GreaterLayer:
return graphPtr->layers()->Get(layerIndex)->layer_as_GreaterLayer()->base();
case Layer::Layer_InputLayer:
@@ -2933,6 +2936,26 @@ void IDeserializer::DeserializerImpl::ParseGather(GraphPtr graph, unsigned int l
RegisterOutputSlots(graph, layerIndex, layer);
}
+void IDeserializer::DeserializerImpl::ParseGatherNd(GraphPtr graph, unsigned int layerIndex)
+{
+ CHECK_LAYERS(graph, 0, layerIndex);
+
+ TensorRawPtrVector inputs = GetInputs(graph, layerIndex);
+ CHECK_VALID_SIZE(inputs.size(), 2);
+
+ TensorRawPtrVector outputs = GetOutputs(graph, layerIndex);
+ CHECK_VALID_SIZE(outputs.size(), 1);
+
+ auto layerName = GetLayerName(graph, layerIndex);
+ IConnectableLayer* layer = m_Network->AddGatherNdLayer(layerName.c_str());
+
+ armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]);
+ layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo);
+
+ RegisterInputSlots(graph, layerIndex, layer);
+ RegisterOutputSlots(graph, layerIndex, layer);
+}
+
void IDeserializer::DeserializerImpl::ParseMean(GraphPtr graph, unsigned int layerIndex)
{
CHECK_LAYERS(graph, 0, layerIndex);
diff --git a/src/armnnDeserializer/Deserializer.hpp b/src/armnnDeserializer/Deserializer.hpp
index 8de492ed5f..277c09ae48 100644
--- a/src/armnnDeserializer/Deserializer.hpp
+++ b/src/armnnDeserializer/Deserializer.hpp
@@ -108,6 +108,7 @@ private:
void ParseFloor(GraphPtr graph, unsigned int layerIndex);
void ParseFullyConnected(GraphPtr graph, unsigned int layerIndex);
void ParseGather(GraphPtr graph, unsigned int layerIndex);
+ void ParseGatherNd(GraphPtr graph, unsigned int layerIndex);
void ParseGreater(GraphPtr graph, unsigned int layerIndex);
void ParseInstanceNormalization(GraphPtr graph, unsigned int layerIndex);
void ParseL2Normalization(GraphPtr graph, unsigned int layerIndex);
diff --git a/src/armnnDeserializer/test/DeserializeGatherNd.cpp b/src/armnnDeserializer/test/DeserializeGatherNd.cpp
new file mode 100644
index 0000000000..684a42ca07
--- /dev/null
+++ b/src/armnnDeserializer/test/DeserializeGatherNd.cpp
@@ -0,0 +1,146 @@
+//
+// Copyright © 2022 Arm Ltd and Contributors. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include "ParserFlatbuffersSerializeFixture.hpp"
+#include <armnnDeserializer/IDeserializer.hpp>
+
+#include <string>
+
+TEST_SUITE("Deserializer_GatherNd")
+{
+struct GatherNdFixture : public ParserFlatbuffersSerializeFixture
+{
+ explicit GatherNdFixture(const std::string& paramsShape,
+ const std::string& indicesShape,
+ const std::string& outputShape,
+ const std::string& indicesData,
+ const std::string dataType,
+ const std::string constDataType)
+ {
+ m_JsonString = R"(
+ {
+ inputIds: [0],
+ 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: [ {
+ index: 0,
+ tensorInfo: {
+ dimensions: )" + paramsShape + R"(,
+ dataType: )" + dataType + R"(
+ }}]
+ }
+ }}},
+ {
+ layer_type: "ConstantLayer",
+ layer: {
+ base: {
+ index:1,
+ layerName: "ConstantLayer",
+ layerType: "Constant",
+ outputSlots: [ {
+ index: 0,
+ tensorInfo: {
+ dimensions: )" + indicesShape + R"(,
+ dataType: "Signed32",
+ },
+ }],
+ },
+ input: {
+ info: {
+ dimensions: )" + indicesShape + R"(,
+ dataType: )" + dataType + R"(
+ },
+ data_type: )" + constDataType + R"(,
+ data: {
+ data: )" + indicesData + R"(,
+ } }
+ },},
+ {
+ layer_type: "GatherNdLayer",
+ layer: {
+ base: {
+ index: 2,
+ layerName: "GatherNdLayer",
+ layerType: "GatherNd",
+ 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 SimpleGatherNdFixtureFloat32 : GatherNdFixture
+{
+ SimpleGatherNdFixtureFloat32() : GatherNdFixture("[ 6, 3 ]", "[ 3, 1 ]", "[ 3, 3 ]",
+ "[ 5, 1, 0 ]", "Float32", "IntData") {}
+};
+
+TEST_CASE_FIXTURE(SimpleGatherNdFixtureFloat32, "GatherNdFloat32")
+{
+ RunTest<4, armnn::DataType::Float32>(0,
+ {{"InputLayer", { 1, 2, 3,
+ 4, 5, 6,
+ 7, 8, 9,
+ 10, 11, 12,
+ 13, 14, 15,
+ 16, 17, 18 }}},
+ {{"OutputLayer", { 16, 17, 18,
+ 4, 5, 6,
+ 1, 2, 3}}});
+}
+
+}
+