aboutsummaryrefslogtreecommitdiff
path: root/src/armnnDeserializer
diff options
context:
space:
mode:
Diffstat (limited to 'src/armnnDeserializer')
-rw-r--r--src/armnnDeserializer/Deserializer.cpp29
-rw-r--r--src/armnnDeserializer/Deserializer.hpp1
-rw-r--r--src/armnnDeserializer/DeserializerSupport.md1
-rw-r--r--src/armnnDeserializer/test/DeserializePermute.cpp137
4 files changed, 167 insertions, 1 deletions
diff --git a/src/armnnDeserializer/Deserializer.cpp b/src/armnnDeserializer/Deserializer.cpp
index 2462061190..ead4fc5453 100644
--- a/src/armnnDeserializer/Deserializer.cpp
+++ b/src/armnnDeserializer/Deserializer.cpp
@@ -175,6 +175,7 @@ m_ParserFunctions(Layer_MAX+1, &Deserializer::ParseUnsupportedLayer)
m_ParserFunctions[Layer_Convolution2dLayer] = &Deserializer::ParseConvolution2d;
m_ParserFunctions[Layer_DepthwiseConvolution2dLayer] = &Deserializer::ParseDepthwiseConvolution2d;
m_ParserFunctions[Layer_MultiplicationLayer] = &Deserializer::ParseMultiplication;
+ m_ParserFunctions[Layer_PermuteLayer] = &Deserializer::ParsePermute;
m_ParserFunctions[Layer_Pooling2dLayer] = &Deserializer::ParsePooling2d;
m_ParserFunctions[Layer_ReshapeLayer] = &Deserializer::ParseReshape;
m_ParserFunctions[Layer_SoftmaxLayer] = &Deserializer::ParseSoftmax;
@@ -200,6 +201,8 @@ Deserializer::LayerBaseRawPtr Deserializer::GetBaseLayer(const GraphPtr& graphPt
return graphPtr->layers()->Get(layerIndex)->layer_as_MultiplicationLayer()->base();
case Layer::Layer_OutputLayer:
return graphPtr->layers()->Get(layerIndex)->layer_as_OutputLayer()->base()->base();
+ case Layer::Layer_PermuteLayer:
+ return graphPtr->layers()->Get(layerIndex)->layer_as_PermuteLayer()->base();
case Layer::Layer_Pooling2dLayer:
return graphPtr->layers()->Get(layerIndex)->layer_as_Pooling2dLayer()->base();
case Layer::Layer_ReshapeLayer:
@@ -831,8 +834,32 @@ void Deserializer::ParseMultiplication(unsigned int layerIndex)
RegisterOutputSlots(layerIndex, layer);
}
+void Deserializer::ParsePermute(unsigned int layerIndex)
+{
+ CHECK_LAYERS(m_Graph, 0, layerIndex);
+
+ auto dimsMapping =
+ m_Graph->layers()->Get(layerIndex)->layer_as_PermuteLayer()->descriptor()->dimMappings();
+
+ auto inputs = GetInputs(m_Graph, layerIndex);
+ CHECK_VALID_SIZE(inputs.size(), 1);
+
+ auto outputs = GetOutputs(m_Graph, layerIndex);
+ CHECK_VALID_SIZE(outputs.size(), 1);
+ auto outputInfo = ToTensorInfo(outputs[0]);
+
+ m_layerName = boost::str(boost::format("Permute:%1%") % layerIndex);
+ const armnn::PermuteDescriptor descriptor(armnn::PermutationVector(dimsMapping->data(), dimsMapping->Length()));
+
+ IConnectableLayer* layer = m_Network->AddPermuteLayer(descriptor, m_layerName.c_str());
+ layer->GetOutputSlot(0).SetTensorInfo(outputInfo);
+
+ RegisterInputSlots(layerIndex, layer);
+ RegisterOutputSlots(layerIndex, layer);
+}
+
armnn::Pooling2dDescriptor Deserializer::GetPoolingDescriptor(Deserializer::PoolingDescriptor pooling2dDesc,
- unsigned int layerIndex)
+ unsigned int layerIndex)
{
armnn::Pooling2dDescriptor desc;
diff --git a/src/armnnDeserializer/Deserializer.hpp b/src/armnnDeserializer/Deserializer.hpp
index bf78e10f40..6af1afb776 100644
--- a/src/armnnDeserializer/Deserializer.hpp
+++ b/src/armnnDeserializer/Deserializer.hpp
@@ -73,6 +73,7 @@ private:
void ParseConvolution2d(unsigned int layerIndex);
void ParseDepthwiseConvolution2d(unsigned int layerIndex);
void ParseMultiplication(unsigned int layerIndex);
+ void ParsePermute(unsigned int layerIndex);
void ParsePooling2d(unsigned int layerIndex);
void ParseReshape(unsigned int layerIndex);
void ParseSoftmax(unsigned int layerIndex);
diff --git a/src/armnnDeserializer/DeserializerSupport.md b/src/armnnDeserializer/DeserializerSupport.md
index 86d3d02415..14c720ac81 100644
--- a/src/armnnDeserializer/DeserializerSupport.md
+++ b/src/armnnDeserializer/DeserializerSupport.md
@@ -11,6 +11,7 @@ The Arm NN SDK Deserialize parser currently supports the following layers:
* DepthwiseConvolution2d
* FullyConnected
* Multiplication
+* Permute
* Pooling2d
* Reshape
* Softmax
diff --git a/src/armnnDeserializer/test/DeserializePermute.cpp b/src/armnnDeserializer/test/DeserializePermute.cpp
new file mode 100644
index 0000000000..6d08b5fee9
--- /dev/null
+++ b/src/armnnDeserializer/test/DeserializePermute.cpp
@@ -0,0 +1,137 @@
+//
+// 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>
+
+BOOST_AUTO_TEST_SUITE(Deserializer)
+
+struct PermuteFixture : public ParserFlatbuffersSerializeFixture
+{
+ explicit PermuteFixture(const std::string &inputShape,
+ const std::string &dimMappings,
+ 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: "PermuteLayer",
+ layer: {
+ base: {
+ index: 1,
+ layerName: "PermuteLayer",
+ layerType: "Permute",
+ inputSlots: [{
+ index: 0,
+ connection: {sourceLayerIndex:0, outputSlotIndex:0 },
+ }],
+ outputSlots: [{
+ index: 0,
+ tensorInfo: {
+ dimensions: )" + outputShape + R"(,
+ dataType: )" + dataType + R"(
+ }
+ }]
+ },
+ descriptor: {
+ dimMappings: )" + dimMappings + R"(,
+ }
+ }
+ },
+ {
+ 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"(
+ },
+ }],
+ }
+ }
+ },
+ }
+ ]
+ }
+ )";
+ SetupSingleInputSingleOutput("InputLayer", "OutputLayer");
+ }
+};
+
+struct SimplePermute2DFixture : PermuteFixture
+{
+ SimplePermute2DFixture() : PermuteFixture("[ 2, 3 ]",
+ "[ 1, 0 ]",
+ "[ 3, 2 ]",
+ "QuantisedAsymm8") {}
+};
+
+BOOST_FIXTURE_TEST_CASE(SimplePermute2DQuantisedAsymm8, SimplePermute2DFixture)
+{
+ RunTest<2, armnn::DataType::QuantisedAsymm8>(0,
+ { 1, 2, 3, 4, 5, 6 },
+ { 1, 4, 2, 5, 3, 6 });
+}
+
+struct SimplePermute4DFixture : PermuteFixture
+{
+ SimplePermute4DFixture() : PermuteFixture("[ 1, 2, 3, 4 ]",
+ "[ 3, 2, 1, 0 ]",
+ "[ 4, 3, 2, 1 ]",
+ "QuantisedAsymm8") {}
+};
+
+BOOST_FIXTURE_TEST_CASE(SimplePermute4DQuantisedAsymm8, SimplePermute4DFixture)
+{
+ RunTest<4, armnn::DataType::QuantisedAsymm8>(0,
+ { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
+ 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24 },
+ { 1, 13, 5, 17, 9, 21, 2, 14, 6, 18, 10, 22,
+ 3, 15, 7, 19, 11, 23, 4, 16, 8, 20, 12, 24 });
+}
+
+BOOST_AUTO_TEST_SUITE_END()