aboutsummaryrefslogtreecommitdiff
path: root/src/armnnDeserializer
diff options
context:
space:
mode:
Diffstat (limited to 'src/armnnDeserializer')
-rw-r--r--src/armnnDeserializer/Deserializer.cpp53
-rw-r--r--src/armnnDeserializer/Deserializer.hpp3
-rw-r--r--src/armnnDeserializer/test/DeserializeScatterNd.cpp179
3 files changed, 233 insertions, 2 deletions
diff --git a/src/armnnDeserializer/Deserializer.cpp b/src/armnnDeserializer/Deserializer.cpp
index f27489f339..b77eb0efc0 100644
--- a/src/armnnDeserializer/Deserializer.cpp
+++ b/src/armnnDeserializer/Deserializer.cpp
@@ -1,5 +1,5 @@
//
-// Copyright © 2017,2019-2023 Arm Ltd and Contributors. All rights reserved.
+// Copyright © 2017,2019-2024 Arm Ltd and Contributors. All rights reserved.
// SPDX-License-Identifier: MIT
//
@@ -265,6 +265,7 @@ m_ParserFunctions(Layer_MAX+1, &IDeserializer::DeserializerImpl::ParseUnsupporte
m_ParserFunctions[Layer_ResizeLayer] = &DeserializerImpl::ParseResize;
m_ParserFunctions[Layer_ReverseV2Layer] = &DeserializerImpl::ParseReverseV2;
m_ParserFunctions[Layer_RsqrtLayer] = &DeserializerImpl::ParseRsqrt;
+ m_ParserFunctions[Layer_ScatterNdLayer] = &DeserializerImpl::ParseScatterNd;
m_ParserFunctions[Layer_ShapeLayer] = &DeserializerImpl::ParseShape;
m_ParserFunctions[Layer_SliceLayer] = &DeserializerImpl::ParseSlice;
m_ParserFunctions[Layer_SoftmaxLayer] = &DeserializerImpl::ParseSoftmax;
@@ -402,6 +403,8 @@ LayerBaseRawPtr IDeserializer::DeserializerImpl::GetBaseLayer(const GraphPtr& gr
return graphPtr->layers()->Get(layerIndex)->layer_as_ReverseV2Layer()->base();
case Layer::Layer_RsqrtLayer:
return graphPtr->layers()->Get(layerIndex)->layer_as_RsqrtLayer()->base();
+ case Layer::Layer_ScatterNdLayer:
+ return graphPtr->layers()->Get(layerIndex)->layer_as_ScatterNdLayer()->base();
case Layer::Layer_ShapeLayer:
return graphPtr->layers()->Get(layerIndex)->layer_as_ShapeLayer()->base();
case Layer::Layer_SliceLayer:
@@ -521,6 +524,25 @@ armnn::ArgMinMaxFunction ToArgMinMaxFunction(armnnSerializer::ArgMinMaxFunction
}
}
+armnn::ScatterNdFunction ToScatterNdFunction(armnnSerializer::ScatterNdFunction function)
+{
+ switch (function)
+ {
+ case armnnSerializer::ScatterNdFunction_Update:
+ return armnn::ScatterNdFunction::Update;
+ case armnnSerializer::ScatterNdFunction_Add:
+ return armnn::ScatterNdFunction::Add;
+ case armnnSerializer::ScatterNdFunction_Sub:
+ return armnn::ScatterNdFunction::Sub;
+ case armnnSerializer::ScatterNdFunction_Max:
+ return armnn::ScatterNdFunction::Max;
+ case armnnSerializer::ScatterNdFunction_Min:
+ return armnn::ScatterNdFunction::Min;
+ default:
+ return armnn::ScatterNdFunction::Update;
+ }
+}
+
armnn::ComparisonOperation ToComparisonOperation(armnnSerializer::ComparisonOperation operation)
{
switch (operation)
@@ -4008,4 +4030,33 @@ void IDeserializer::DeserializerImpl::ParseUnidirectionalSequenceLstm(GraphPtr g
RegisterOutputSlots(graph, layerIndex, layer);
}
+void IDeserializer::DeserializerImpl::ParseScatterNd(GraphPtr graph, unsigned int layerIndex)
+{
+ CHECK_LAYERS(graph, 0, layerIndex);
+ auto inputs = GetInputs(graph, layerIndex);
+ CHECK_LOCATION();
+ CHECK_VALID_SIZE(inputs.size(), 3);
+
+ auto outputs = GetOutputs(graph, layerIndex);
+ CHECK_VALID_SIZE(outputs.size(), 1);
+
+ auto ScatterNdLayer = graph->layers()->Get(layerIndex)->layer_as_ScatterNdLayer();
+ auto layerName = GetLayerName(graph, layerIndex);
+ auto flatBufferDescriptor = ScatterNdLayer->descriptor();
+
+ armnn::ScatterNdDescriptor scatterNdDescriptor;
+ scatterNdDescriptor.m_Function = ToScatterNdFunction(flatBufferDescriptor->m_Function());
+ scatterNdDescriptor.m_InputEnabled = flatBufferDescriptor->m_InputEnabled();
+ scatterNdDescriptor.m_Axis = flatBufferDescriptor->m_Axis();
+ scatterNdDescriptor.m_AxisEnabled = flatBufferDescriptor->m_AxisEnabled();
+
+ IConnectableLayer* layer = m_Network->AddScatterNdLayer(scatterNdDescriptor, layerName.c_str());
+
+ armnn::TensorInfo output0TensorInfo = ToTensorInfo(outputs[0]);
+ layer->GetOutputSlot(0).SetTensorInfo(output0TensorInfo);
+
+ RegisterInputSlots(graph, layerIndex, layer);
+ RegisterOutputSlots(graph, layerIndex, layer);
+}
+
} // namespace armnnDeserializer
diff --git a/src/armnnDeserializer/Deserializer.hpp b/src/armnnDeserializer/Deserializer.hpp
index 7e427d6dfa..4b29a70752 100644
--- a/src/armnnDeserializer/Deserializer.hpp
+++ b/src/armnnDeserializer/Deserializer.hpp
@@ -1,5 +1,5 @@
//
-// Copyright © 2017,2019-2023 Arm Ltd and Contributors. All rights reserved.
+// Copyright © 2017,2019-2024 Arm Ltd and Contributors. All rights reserved.
// SPDX-License-Identifier: MIT
//
@@ -138,6 +138,7 @@ private:
void ParseResizeBilinear(GraphPtr graph, unsigned int layerIndex);
void ParseReverseV2(GraphPtr graph, unsigned int layerIndex);
void ParseRsqrt(GraphPtr graph, unsigned int layerIndex);
+ void ParseScatterNd(GraphPtr graph, unsigned int layerIndex);
void ParseShape(GraphPtr graph, unsigned int layerIndex);
void ParseSlice(GraphPtr graph, unsigned int layerIndex);
void ParseSoftmax(GraphPtr graph, unsigned int layerIndex);
diff --git a/src/armnnDeserializer/test/DeserializeScatterNd.cpp b/src/armnnDeserializer/test/DeserializeScatterNd.cpp
new file mode 100644
index 0000000000..3e88310c8e
--- /dev/null
+++ b/src/armnnDeserializer/test/DeserializeScatterNd.cpp
@@ -0,0 +1,179 @@
+//
+// Copyright © 2024 Arm Ltd and Contributors. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include "ParserFlatbuffersSerializeFixture.hpp"
+#include <armnnDeserializer/IDeserializer.hpp>
+
+#include <string>
+
+TEST_SUITE("Deserializer_ScatterNd")
+{
+struct ScatterNdFixture : public ParserFlatbuffersSerializeFixture
+{
+ explicit ScatterNdFixture(const std::string& inputShape,
+ const std::string& indicesShape,
+ const std::string& updatesShape,
+ const std::string& outputShape,
+ const std::string& indicesData,
+ const std::string& updatesData,
+ const std::string dataType,
+ const std::string constDataType)
+ {
+ m_JsonString = R"(
+ {
+ inputIds: [0],
+ outputIds: [4],
+ 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: "ConstantLayer",
+ layer: {
+ base: {
+ index:1,
+ layerName: "ConstantLayer",
+ layerType: "Constant",
+ outputSlots: [ {
+ index: 0,
+ tensorInfo: {
+ dimensions: )" + indicesShape + R"(,
+ dataType: "Signed32",
+ },
+ }],
+ },
+ input: {
+ info: {
+ dimensions: )" + indicesShape + R"(,
+ dataType: "Signed32",
+ },
+ data_type: )" + constDataType + R"(,
+ data: {
+ data: )" + indicesData + R"(,
+ } }
+ },},
+ {
+ layer_type: "ConstantLayer",
+ layer: {
+ base: {
+ index:2,
+ layerName: "ConstantLayer",
+ layerType: "Constant",
+ outputSlots: [ {
+ index: 0,
+ tensorInfo: {
+ dimensions: )" + updatesShape + R"(,
+ dataType: )" + dataType + R"(
+ },
+ }],
+ },
+ input: {
+ info: {
+ dimensions: )" + updatesShape + R"(,
+ dataType: )" + dataType + R"(
+ },
+ data_type: )" + constDataType + R"(,
+ data: {
+ data: )" + updatesData + R"(,
+ } }
+ },},
+ {
+ layer_type: "ScatterNdLayer",
+ layer: {
+ base: {
+ index: 3,
+ layerName: "ScatterNdLayer",
+ layerType: "ScatterNd",
+ inputSlots: [
+ {
+ index: 0,
+ connection: {sourceLayerIndex:0, outputSlotIndex:0 },
+ },
+ {
+ index: 1,
+ connection: {sourceLayerIndex:1, outputSlotIndex:0 },
+ },
+ {
+ index: 2,
+ connection: {sourceLayerIndex:2, outputSlotIndex:0 },
+ }],
+ outputSlots: [ {
+ index: 0,
+ tensorInfo: {
+ dimensions: )" + outputShape + R"(,
+ dataType: )" + dataType + R"(
+
+ }}]},
+ descriptor: {
+ m_Function: Update,
+ m_InputEnabled: true,
+ m_Axis: 0,
+ m_AxisEnabled: false
+ },
+ }},
+ {
+ layer_type: "OutputLayer",
+ layer: {
+ base:{
+ layerBindingId: 0,
+ base: {
+ index: 4,
+ layerName: "OutputLayer",
+ layerType: "Output",
+ inputSlots: [{
+ index: 0,
+ connection: {sourceLayerIndex:3, outputSlotIndex:0 },
+ }],
+ outputSlots: [ {
+ index: 0,
+ tensorInfo: {
+ dimensions: )" + outputShape + R"(,
+ dataType: )" + dataType + R"(
+ },
+ }],
+ }}},
+ }],
+ featureVersions: {
+ weightsLayoutScheme: 1,
+ }
+ } )";
+
+ Setup();
+ }
+};
+
+struct SimpleScatterNdFixtureSigned32 : ScatterNdFixture
+{
+ SimpleScatterNdFixtureSigned32() : ScatterNdFixture("[ 5 ]", "[ 3, 1 ]", "[ 3 ]", "[ 5 ]",
+ "[ 0, 1, 2 ]", "[ 1, 2, 3 ]", "Signed32", "IntData") {}
+};
+
+TEST_CASE_FIXTURE(SimpleScatterNdFixtureSigned32, "ScatterNdSigned32")
+{
+ RunTest<1, armnn::DataType::Signed32>(0,
+ {{"InputLayer", { 0, 0, 0, 0, 0 }}},
+ {{"OutputLayer", { 1, 2, 3, 0, 0 }}});
+}
+
+}
+