aboutsummaryrefslogtreecommitdiff
path: root/src/armnnDeserializer
diff options
context:
space:
mode:
authorKeith Davis <keith.davis@arm.com>2021-05-21 16:33:48 +0100
committerKeith Davis <keith.davis@arm.com>2021-06-16 17:27:59 +0100
commit3ae3f978cf9ce3174609b7152af87acb410b0fe0 (patch)
tree9c71ea6aafbacfeba6938b5e0e29cdc97a784b70 /src/armnnDeserializer
parent50de4fa4e7e0dd02a442ba350a1b40f293cb5a01 (diff)
downloadarmnn-3ae3f978cf9ce3174609b7152af87acb410b0fe0.tar.gz
MLCE-510 Add CpuRef Shape Operator to ArmNN
* Add front end * Add reference workload * Serialization/Deserialization * Add unit tests * Update ArmNN Versioning Signed-off-by: Keith Davis <keith.davis@arm.com> Change-Id: I6fcb1fa341d6f08dea4003b13544e6e9f53fefd3
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/DeserializeShape.cpp131
3 files changed, 155 insertions, 0 deletions
diff --git a/src/armnnDeserializer/Deserializer.cpp b/src/armnnDeserializer/Deserializer.cpp
index b5bf9daef0..af6ff842a7 100644
--- a/src/armnnDeserializer/Deserializer.cpp
+++ b/src/armnnDeserializer/Deserializer.cpp
@@ -257,6 +257,7 @@ m_ParserFunctions(Layer_MAX+1, &IDeserializer::DeserializerImpl::ParseUnsupporte
m_ParserFunctions[Layer_ResizeBilinearLayer] = &DeserializerImpl::ParseResizeBilinear;
m_ParserFunctions[Layer_ResizeLayer] = &DeserializerImpl::ParseResize;
m_ParserFunctions[Layer_RsqrtLayer] = &DeserializerImpl::ParseRsqrt;
+ m_ParserFunctions[Layer_ShapeLayer] = &DeserializerImpl::ParseShape;
m_ParserFunctions[Layer_SliceLayer] = &DeserializerImpl::ParseSlice;
m_ParserFunctions[Layer_SoftmaxLayer] = &DeserializerImpl::ParseSoftmax;
m_ParserFunctions[Layer_SpaceToBatchNdLayer] = &DeserializerImpl::ParseSpaceToBatchNd;
@@ -377,6 +378,8 @@ LayerBaseRawPtr IDeserializer::DeserializerImpl::GetBaseLayer(const GraphPtr& gr
return graphPtr->layers()->Get(layerIndex)->layer_as_ResizeLayer()->base();
case Layer::Layer_RsqrtLayer:
return graphPtr->layers()->Get(layerIndex)->layer_as_RsqrtLayer()->base();
+ case Layer::Layer_ShapeLayer:
+ return graphPtr->layers()->Get(layerIndex)->layer_as_ShapeLayer()->base();
case Layer::Layer_SliceLayer:
return graphPtr->layers()->Get(layerIndex)->layer_as_SliceLayer()->base();
case Layer::Layer_SoftmaxLayer:
@@ -2338,6 +2341,26 @@ void IDeserializer::DeserializerImpl::ParseResizeBilinear(GraphPtr graph, unsign
RegisterOutputSlots(graph, layerIndex, layer);
}
+void IDeserializer::DeserializerImpl::ParseShape(GraphPtr graph, unsigned int layerIndex)
+{
+ CHECK_LAYERS(graph, 0, layerIndex);
+
+ TensorRawPtrVector inputs = GetInputs(graph, layerIndex);
+ CHECK_VALID_SIZE(inputs.size(), 1);
+
+ TensorRawPtrVector outputs = GetOutputs(graph, layerIndex);
+ CHECK_VALID_SIZE(outputs.size(), 1);
+
+ auto layerName = GetLayerName(graph, layerIndex);
+ IConnectableLayer* layer = m_Network->AddShapeLayer( 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::ParseSoftmax(GraphPtr graph, unsigned int layerIndex)
{
CHECK_LAYERS(graph, 0, layerIndex);
diff --git a/src/armnnDeserializer/Deserializer.hpp b/src/armnnDeserializer/Deserializer.hpp
index 8f38058ae5..0b05e16849 100644
--- a/src/armnnDeserializer/Deserializer.hpp
+++ b/src/armnnDeserializer/Deserializer.hpp
@@ -125,6 +125,7 @@ private:
void ParseResize(GraphPtr graph, unsigned int layerIndex);
void ParseResizeBilinear(GraphPtr graph, unsigned int layerIndex);
void ParseRsqrt(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);
void ParseSpaceToBatchNd(GraphPtr graph, unsigned int layerIndex);
diff --git a/src/armnnDeserializer/test/DeserializeShape.cpp b/src/armnnDeserializer/test/DeserializeShape.cpp
new file mode 100644
index 0000000000..a20fb59699
--- /dev/null
+++ b/src/armnnDeserializer/test/DeserializeShape.cpp
@@ -0,0 +1,131 @@
+//
+// Copyright © 2021 Arm Ltd and Contributors. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include <boost/test/unit_test.hpp>
+#include "ParserFlatbuffersSerializeFixture.hpp"
+#include <armnnDeserializer/IDeserializer.hpp>
+
+#include <string>
+
+BOOST_AUTO_TEST_SUITE(Deserializer)
+
+struct ShapeFixture : public ParserFlatbuffersSerializeFixture
+{
+ explicit ShapeFixture()
+ {
+ m_JsonString = R"(
+ {
+ layers: [
+ {
+ layer_type: "InputLayer",
+ layer: {
+ base: {
+ base: {
+ layerName: "InputLayer",
+ layerType: "Input",
+ inputSlots: [
+
+ ],
+ outputSlots: [
+ {
+ tensorInfo: {
+ dimensions: [
+ 1,
+ 3,
+ 3,
+ 1
+ ],
+ dataType: "Signed32",
+ quantizationScale: 0.0
+ }
+ }
+ ]
+ }
+ }
+ }
+ },
+ {
+ layer_type: "ShapeLayer",
+ layer: {
+ base: {
+ index: 1,
+ layerName: "shape",
+ layerType: "Shape",
+ inputSlots: [
+ {
+ connection: {
+ sourceLayerIndex: 0,
+ outputSlotIndex: 0
+ }
+ }
+ ],
+ outputSlots: [
+ {
+ tensorInfo: {
+ dimensions: [
+ 4
+ ],
+ dataType: "Signed32",
+ quantizationScale: 0.0
+ }
+ }
+ ]
+ }
+ }
+ },
+ {
+ layer_type: "OutputLayer",
+ layer: {
+ base: {
+ base: {
+ index: 2,
+ layerName: "OutputLayer",
+ layerType: "Output",
+ inputSlots: [
+ {
+ connection: {
+ sourceLayerIndex: 1,
+ outputSlotIndex: 0
+ }
+ }
+ ],
+ outputSlots: [
+
+ ]
+ }
+ }
+ }
+ }
+ ],
+ inputIds: [
+ 0
+ ],
+ outputIds: [
+ 0
+ ],
+ featureVersions: {
+ bindingIdsScheme: 1
+ }
+ }
+ )";
+ Setup();
+ }
+};
+
+
+struct SimpleShapeFixture : ShapeFixture
+{
+ SimpleShapeFixture() : ShapeFixture() {}
+};
+
+BOOST_FIXTURE_TEST_CASE(DeserializeShape, SimpleShapeFixture)
+{
+ RunTest<1, armnn::DataType::Signed32>(
+ 0,
+ {{"InputLayer", { 1, 1, 1, 1, 1, 1, 1, 1, 1 }}},
+ {{"OutputLayer",{ 1, 3, 3, 1 }}});
+}
+
+BOOST_AUTO_TEST_SUITE_END()