aboutsummaryrefslogtreecommitdiff
path: root/src/armnnDeserializer
diff options
context:
space:
mode:
authorMatthew Sloyan <matthew.sloyan@arm.com>2021-09-08 13:05:51 +0100
committerMatthew Sloyan <matthew.sloyan@arm.com>2021-10-01 15:27:01 +0100
commitb63a31170aee1d28267d83a4bc67b57708fb6b05 (patch)
tree16cea0a872939be749b72f45ad125964439bc40e /src/armnnDeserializer
parenteb852bb9e45b1db42a26001ece11ec7cc1f2bbfe (diff)
downloadarmnn-b63a31170aee1d28267d83a4bc67b57708fb6b05.tar.gz
IVGCVSW-6163 Add Conv3d FrontEnd and Ref Implementation
* Added front-end * Added Reference workload * Added Serializer & Deserializer support * Added unit tests * Added NDHWC DataLayout Signed-off-by: Matthew Sloyan <matthew.sloyan@arm.com> Change-Id: Iec4d39e7433b5334d52fa44cf8efc6bcd39319d8
Diffstat (limited to 'src/armnnDeserializer')
-rw-r--r--src/armnnDeserializer/Deserializer.cpp55
-rw-r--r--src/armnnDeserializer/Deserializer.hpp1
-rw-r--r--src/armnnDeserializer/test/DeserializeConvolution3d.cpp223
3 files changed, 279 insertions, 0 deletions
diff --git a/src/armnnDeserializer/Deserializer.cpp b/src/armnnDeserializer/Deserializer.cpp
index 13415814a2..eaeab780e4 100644
--- a/src/armnnDeserializer/Deserializer.cpp
+++ b/src/armnnDeserializer/Deserializer.cpp
@@ -221,6 +221,7 @@ m_ParserFunctions(Layer_MAX+1, &IDeserializer::DeserializerImpl::ParseUnsupporte
m_ParserFunctions[Layer_ConcatLayer] = &DeserializerImpl::ParseConcat;
m_ParserFunctions[Layer_ConstantLayer] = &DeserializerImpl::ParseConstant;
m_ParserFunctions[Layer_Convolution2dLayer] = &DeserializerImpl::ParseConvolution2d;
+ m_ParserFunctions[Layer_Convolution3dLayer] = &DeserializerImpl::ParseConvolution3d;
m_ParserFunctions[Layer_DepthToSpaceLayer] = &DeserializerImpl::ParseDepthToSpace;
m_ParserFunctions[Layer_DepthwiseConvolution2dLayer] = &DeserializerImpl::ParseDepthwiseConvolution2d;
m_ParserFunctions[Layer_DequantizeLayer] = &DeserializerImpl::ParseDequantize;
@@ -304,6 +305,8 @@ LayerBaseRawPtr IDeserializer::DeserializerImpl::GetBaseLayer(const GraphPtr& gr
return graphPtr->layers()->Get(layerIndex)->layer_as_ConstantLayer()->base();
case Layer::Layer_Convolution2dLayer:
return graphPtr->layers()->Get(layerIndex)->layer_as_Convolution2dLayer()->base();
+ case Layer::Layer_Convolution3dLayer:
+ return graphPtr->layers()->Get(layerIndex)->layer_as_Convolution3dLayer()->base();
case Layer::Layer_DepthToSpaceLayer:
return graphPtr->layers()->Get(layerIndex)->layer_as_DepthToSpaceLayer()->base();
case Layer::Layer_DepthwiseConvolution2dLayer:
@@ -444,6 +447,8 @@ armnn::DataLayout ToDataLayout(armnnSerializer::DataLayout dataLayout)
{
case armnnSerializer::DataLayout::DataLayout_NHWC:
return armnn::DataLayout::NHWC;
+ case armnnSerializer::DataLayout::DataLayout_NDHWC:
+ return armnn::DataLayout::NDHWC;
case armnnSerializer::DataLayout::DataLayout_NCHW:
default:
return armnn::DataLayout::NCHW;
@@ -1392,6 +1397,56 @@ void IDeserializer::DeserializerImpl::ParseConvolution2d(GraphPtr graph, unsigne
RegisterOutputSlots(graph, layerIndex, layer);
}
+void IDeserializer::DeserializerImpl::ParseConvolution3d(GraphPtr graph, unsigned int layerIndex)
+{
+ CHECK_LAYERS(graph, 0, layerIndex);
+ auto inputs = GetInputs(graph, layerIndex);
+ CHECK_LOCATION();
+ CHECK_VALID_SIZE(inputs.size(), 1);
+
+ auto outputs = GetOutputs(graph, layerIndex);
+ CHECK_VALID_SIZE(outputs.size(), 1);
+
+ auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_Convolution3dLayer();
+ auto layerName = GetLayerName(graph, layerIndex);
+ auto serializerDescriptor = serializerLayer->descriptor();
+
+ armnn::Convolution3dDescriptor descriptor;
+ descriptor.m_PadLeft = serializerDescriptor->padLeft();
+ descriptor.m_PadRight = serializerDescriptor->padRight();
+ descriptor.m_PadTop = serializerDescriptor->padTop();
+ descriptor.m_PadBottom = serializerDescriptor->padBottom();
+ descriptor.m_PadFront = serializerDescriptor->padFront();
+ descriptor.m_PadBack = serializerDescriptor->padBack();
+ descriptor.m_StrideX = serializerDescriptor->strideX();
+ descriptor.m_StrideY = serializerDescriptor->strideY();
+ descriptor.m_StrideZ = serializerDescriptor->strideZ();
+ descriptor.m_DilationX = serializerDescriptor->dilationX();
+ descriptor.m_DilationY = serializerDescriptor->dilationY();
+ descriptor.m_DilationZ = serializerDescriptor->dilationZ();
+ descriptor.m_BiasEnabled = serializerDescriptor->biasEnabled();;
+ descriptor.m_DataLayout = ToDataLayout(serializerDescriptor->dataLayout());
+
+ armnn::ConstTensor weights = ToConstTensor(serializerLayer->weights());
+ armnn::ConstTensor biases;
+
+ armnn::Optional<armnn::ConstTensor> optionalBiases = armnn::EmptyOptional();
+ if (descriptor.m_BiasEnabled)
+ {
+ biases = ToConstTensor(serializerLayer->biases());
+ optionalBiases = armnn::Optional<armnn::ConstTensor>(biases);
+ }
+ IConnectableLayer* layer = m_Network->AddConvolution3dLayer(descriptor,
+ weights,
+ optionalBiases,
+ 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::ParseDepthToSpace(GraphPtr graph, unsigned int layerIndex)
{
CHECK_LAYERS(graph, 0, layerIndex);
diff --git a/src/armnnDeserializer/Deserializer.hpp b/src/armnnDeserializer/Deserializer.hpp
index a07e41ff76..d2291c07a7 100644
--- a/src/armnnDeserializer/Deserializer.hpp
+++ b/src/armnnDeserializer/Deserializer.hpp
@@ -93,6 +93,7 @@ private:
void ParseConcat(GraphPtr graph, unsigned int layerIndex);
void ParseConstant(GraphPtr graph, unsigned int layerIndex);
void ParseConvolution2d(GraphPtr graph, unsigned int layerIndex);
+ void ParseConvolution3d(GraphPtr graph, unsigned int layerIndex);
void ParseDepthToSpace(GraphPtr graph, unsigned int layerIndex);
void ParseDepthwiseConvolution2d(GraphPtr graph, unsigned int layerIndex);
void ParseDequantize(GraphPtr graph, unsigned int layerIndex);
diff --git a/src/armnnDeserializer/test/DeserializeConvolution3d.cpp b/src/armnnDeserializer/test/DeserializeConvolution3d.cpp
new file mode 100644
index 0000000000..057ab6fbda
--- /dev/null
+++ b/src/armnnDeserializer/test/DeserializeConvolution3d.cpp
@@ -0,0 +1,223 @@
+//
+// Copyright © 2021 Arm Ltd and Contributors. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include "ParserFlatbuffersSerializeFixture.hpp"
+#include <armnnDeserializer/IDeserializer.hpp>
+
+#include <string>
+
+TEST_SUITE("Deserializer_Convolution3d")
+{
+struct Convolution3dFixture : public ParserFlatbuffersSerializeFixture
+{
+ explicit Convolution3dFixture(const std::string& inputShape,
+ const std::string& outputShape,
+ const std::string& weightsShape,
+ const std::string& dataType)
+ {
+ m_JsonString = R"(
+ {
+ inputIds: [0],
+ outputIds: [2],
+ layers: [
+ {
+ layer_type: "InputLayer",
+ layer: {
+ base: {
+ layerBindingId: 0,
+ base: {
+ layerName: "InputLayer",
+ layerType: "Input",
+ inputSlots: [{
+ index: 0,
+ connection: {sourceLayerIndex:0, outputSlotIndex:0 },
+ }],
+ outputSlots: [
+ {
+ index: 0,
+ tensorInfo: {
+ dimensions: )" + inputShape + R"(,
+ dataType: )" + dataType + R"(,
+ quantizationScale: 0.1,
+ dimensionSpecificity: [
+ true,
+ true,
+ true,
+ true,
+ true
+ ]
+ }
+ }
+ ]
+ }
+ }
+ }
+ },
+ {
+ layer_type: "Convolution3dLayer",
+ layer: {
+ base: {
+ index: 1,
+ layerName: "convolution3d",
+ layerType: "Convolution2d",
+ inputSlots: [
+ {
+ index: 0,
+ connection: {
+ sourceLayerIndex: 0,
+ outputSlotIndex: 0
+ }
+ }
+ ],
+ outputSlots: [
+ {
+ index: 0,
+ tensorInfo: {
+ dimensions: )" + outputShape + R"(,
+ dataType: )" + dataType + R"(,
+ quantizationScale: 0.1,
+ dimensionSpecificity: [
+ true,
+ true,
+ true,
+ true,
+ true
+ ]
+ }
+ }
+ ]
+ },
+ descriptor: {
+ strideX: 2,
+ strideY: 2,
+ strideZ: 2
+ },
+ weights: {
+ info: {
+ dimensions: )" + weightsShape + R"(,
+ dataType: )" + dataType + R"(,
+ quantizationScale: 0.1,
+ dimensionSpecificity: [
+ true,
+ true,
+ true,
+ true,
+ true
+ ]
+ },
+ data_type: "ByteData",
+ data: {
+ data: [
+ 1, 1, 1,
+ 1, 1, 1,
+ 1, 1, 1,
+
+ 0, 0, 0,
+ 0, 0, 0,
+ 0, 0, 0,
+
+ 0, 0, 0,
+ 0, 0, 0,
+ 0, 0, 0
+ ]
+ }
+ }
+ }
+ },
+ {
+ layer_type: "OutputLayer",
+ layer: {
+ base: {
+ layerBindingId: 2,
+ base: {
+ index: 2,
+ layerName: "OutputLayer",
+ layerType: "Output",
+ inputSlots: [
+ {
+ connection: {
+ sourceLayerIndex: 1,
+ outputSlotIndex: 0
+ }
+ }
+ ],
+ outputSlots: [{
+ index: 0,
+ tensorInfo: {
+ dimensions: )" + outputShape + R"(,
+ dataType: )" + dataType + R"(
+ },
+ }]
+ }
+ }
+ }
+ }
+ ],
+ featureVersions: {
+ bindingIdsScheme: 1,
+ weightsLayoutScheme: 1,
+ constantTensorsAsInputs: 1
+ }
+ }
+ )";
+ Setup();
+ }
+
+
+};
+
+struct SimpleConvolution3dFixture : Convolution3dFixture
+{
+ SimpleConvolution3dFixture() : Convolution3dFixture(
+ "[ 1, 5, 5, 5, 1 ]",
+ "[ 1, 2, 2, 2, 1 ]",
+ "[ 3, 3, 3, 1, 1 ]",
+ "QAsymmS8") {}
+};
+
+TEST_CASE_FIXTURE(SimpleConvolution3dFixture, "Convolution3dInt8")
+{
+ RunTest<5, armnn::DataType::QAsymmS8>(
+ 0,
+ {{"InputLayer", { 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,
+ 25, 26, 27, 28, 29,
+ 30, 31, 32, 33, 34,
+ 35, 36, 37, 38, 39,
+ 40, 41, 42, 43, 44,
+
+ 45, 46, 47, 48, 49,
+ 50, 51, 52, 53, 54,
+ 55, 56, 57, 58, 59,
+ 60, 61, 62, 63, 64,
+ 65, 66, 67, 68, 69,
+
+ 70, 71, 72, 73, 74,
+ 75, 76, 77, 78, 79,
+ 80, 81, 82, 83, 84,
+ 85, 86, 87, 88, 89,
+ 90, 91, 92, 93, 94,
+ 95, 96, 97, 98, 99,
+
+ 100, 101, 102, 103, 104,
+ 105, 106, 107, 108, 109,
+ 110, 111, 112, 113, 114,
+ 115, 116, 117, 118, 119,
+ 120, 121, 122, 123, 124
+ }}},
+ {{"OutputLayer", {5, 7,
+
+ 14, 16,
+
+ 50, 52,
+
+ 59, 61}}});
+}
+
+}