From 0690265d83e5aa79bd174544a7b35330781619dd Mon Sep 17 00:00:00 2001 From: Cathal Corbett Date: Thu, 14 Apr 2022 17:55:11 +0100 Subject: IVGCVSW-6127 ConstTensorsAsInput: DepthwiseConvolution2d !android-nn-driver:7418 * Update Front-end and Tools. * Updated Serializer, Deserializer and unit tests to reflect this. * Updated TfLiteDelegate, TfLiteParser and OnnxParser. * Change NNDriver to new API. * Updated Ref. * Neon and Cl backend partially completed (Backend.cpp files). * Added dynamic or constant input EndToEnd tests. * Added ConstantTensorAsInputMemeberVariableRedirect Optimization. Signed-off-by: Cathal Corbett Change-Id: Ib18b6c10a093042e165e25237dc04a4c67ba82da --- src/armnnDeserializer/test/DeserializeConstant.cpp | 5 +- .../test/DeserializeDepthwiseConv2d.cpp | 280 ++++++++++++++++++++- src/armnnDeserializer/test/DeserializeGather.cpp | 5 +- src/armnnDeserializer/test/DeserializeGatherNd.cpp | 5 +- 4 files changed, 283 insertions(+), 12 deletions(-) (limited to 'src/armnnDeserializer/test') diff --git a/src/armnnDeserializer/test/DeserializeConstant.cpp b/src/armnnDeserializer/test/DeserializeConstant.cpp index 682e8a157d..b5a2151268 100644 --- a/src/armnnDeserializer/test/DeserializeConstant.cpp +++ b/src/armnnDeserializer/test/DeserializeConstant.cpp @@ -121,7 +121,10 @@ struct ConstantAddFixture : public ParserFlatbuffersSerializeFixture }, }], }}}, - }] + }], + featureVersions: { + weightsLayoutScheme: 1, + } } )"; SetupSingleInputSingleOutput("InputLayer1", "OutputLayer"); diff --git a/src/armnnDeserializer/test/DeserializeDepthwiseConv2d.cpp b/src/armnnDeserializer/test/DeserializeDepthwiseConv2d.cpp index 1920c1cc79..d5f3c6396f 100644 --- a/src/armnnDeserializer/test/DeserializeDepthwiseConv2d.cpp +++ b/src/armnnDeserializer/test/DeserializeDepthwiseConv2d.cpp @@ -13,9 +13,9 @@ TEST_SUITE("Deserializer_DepthwiseConv2d") { -struct DepthwiseConv2dFlatbufferVersion1Fixture : public ParserFlatbuffersSerializeFixture +struct DepthwiseConv2dFlatbufferVersion1FixtureOld : public ParserFlatbuffersSerializeFixture { - explicit DepthwiseConv2dFlatbufferVersion1Fixture() + explicit DepthwiseConv2dFlatbufferVersion1FixtureOld() { m_JsonString = R"( { @@ -214,20 +214,282 @@ struct DepthwiseConv2dFlatbufferVersion1Fixture : public ParserFlatbuffersSerial } }; +struct DepthwiseConv2dFlatbufferVersion1Fixture : public ParserFlatbuffersSerializeFixture +{ + explicit DepthwiseConv2dFlatbufferVersion1Fixture() + { + m_JsonString = R"( + { + "layers": [ + { + "layer_type": "InputLayer", + "layer": { + "base": { + "base": { + "index": 0, + "layerName": "InputLayer", + "layerType": "Input", + "inputSlots": [ + ], + "outputSlots": [ + { + "index": 0, + "tensorInfo": { + "dimensions": [ + 1, + 3, + 3, + 3 + ], + "dataType": "QAsymmS8", + "quantizationScale": 1.0, + "quantizationOffset": 0, + "quantizationDim": 0, + "dimensionality": 1, + "dimensionSpecificity": [ + true, + true, + true, + true + ] + } + } + ] + }, + "layerBindingId": 0 + } + } + }, + { + "layer_type": "DepthwiseConvolution2dLayer", + "layer": { + "base": { + "index": 1, + "layerName": "depthwiseConvolution2dWithPerAxis", + "layerType": "DepthwiseConvolution2d", + "inputSlots": [ + { + "index": 0, + "connection": { + "sourceLayerIndex": 0, + "outputSlotIndex": 0 + } + }, + { + "index": 1, + "connection": { + "sourceLayerIndex": 2, + "outputSlotIndex": 0 + } + } + ], + "outputSlots": [ + { + "index": 0, + "tensorInfo": { + "dimensions": [ + 1, + 3, + 3, + 3 + ], + "dataType": "QAsymmS8", + "quantizationScale": 1.0, + "quantizationOffset": 0, + "quantizationDim": 0, + "dimensionality": 1, + "dimensionSpecificity": [ + true, + true, + true, + true + ] + } + } + ] + }, + "descriptor": { + "padLeft": 1, + "padRight": 1, + "padTop": 1, + "padBottom": 1, + "strideX": 1, + "strideY": 1, + "dilationX": 1, + "dilationY": 1, + "biasEnabled": false, + "dataLayout": "NHWC" + } + } + }, + { + "layer_type": "ConstantLayer", + "layer": { + "base": { + "index": 2, + "layerName": "Weights", + "layerType": "Constant", + "inputSlots": [ + ], + "outputSlots": [ + { + "index": 0, + "tensorInfo": { + "dimensions": [ + 1, + 3, + 3, + 3 + ], + "dataType": "QSymmS8", + "quantizationScale": 0.25, + "quantizationOffset": 0, + "quantizationDim": 0, + "dimensionality": 1, + "dimensionSpecificity": [ + true, + true, + true, + true + ], + quantizationScales: [ + 0.25, + 0.2, + 0.1 + ], + "isConstant": true, + } + } + ] + }, + "input": { + "info": { + "dimensions": [ + 1, + 3, + 3, + 3 + ], + "dataType": "QSymmS8", + "quantizationScale": 0.25, + "quantizationOffset": 0, + "quantizationDim": 0, + "dimensionality": 1, + "dimensionSpecificity": [ + true, + true, + true, + true + ], + quantizationScales: [ + 0.25, + 0.2, + 0.1 + ] + }, + "data_type": "ByteData", + "data": { + "data": [ + 4, + 20, + 0, + 8, + 20, + 30, + 4, + 0, + 10, + 12, + 0, + 40, + 0, + 5, + 30, + 16, + 10, + 40, + 12, + 0, + 30, + 16, + 20, + 0, + 12, + 20, + 20 + ] + } + } + } + }, + { + "layer_type": "OutputLayer", + "layer": { + "base": { + "base": { + "index": 3, + "layerName": "OutputLayer", + "layerType": "Output", + "inputSlots": [ + { + "index": 0, + "connection": { + "sourceLayerIndex": 1, + "outputSlotIndex": 0 + } + } + ], + "outputSlots": [ + ] + }, + "layerBindingId": 0 + } + } + } + ], + "inputIds": [ + 0 + ], + "outputIds": [ + 0 + ], + "featureVersions": { + "bindingIdsScheme": 1, + "constantTensorsAsInputs": 1 + } + } + )"; + Setup(); + } +}; + // This test uses a model that was created before weights layout scheme version was added to our flatbuffers // file. It ensures older models can still be read and executed // featureVersion weights layout scheme 1 indicates a change in the depthwise weights layout within // armm from [M,I,H,W] --> [1,H,W,I*M] -TEST_CASE_FIXTURE(DepthwiseConv2dFlatbufferVersion1Fixture, "DepthwiseConv2d_FlatbufferVersion1") +TEST_CASE_FIXTURE(DepthwiseConv2dFlatbufferVersion1FixtureOld, "DepthwiseConv2d_FlatbufferVersion1Old") +{ + RunTest<4, armnn::DataType::QAsymmS8>( + 0, + { 3,2,0,0,4,3,0,1,2, + 0,1,3,0,4,2,2,2,3, + 2,4,3,2,0,4,3,4,0}, + { 15,60,10,11,37,20, 0,18,17, + 20,65,28,28,74,26,12,20,18, + 25,36,12,37,42,25,29,14, 9}); +} + +TEST_CASE_FIXTURE(DepthwiseConv2dFlatbufferVersion1Fixture, + "DepthwiseConv2d_FlatbufferVersion1_WeightsAndBiasesAsConstantLayers") { RunTest<4, armnn::DataType::QAsymmS8>( 0, - { 3,2,0,0,4,3,0,1,2, - 0,1,3,0,4,2,2,2,3, - 2,4,3,2,0,4,3,4,0}, - { 15,60,10,11,37,20, 0,18,17, - 20,65,28,28,74,26,12,20,18, - 25,36,12,37,42,25,29,14, 9}); + {{"InputLayer", { 3,2,0,0,4,3,0,1,2, + 0,1,3,0,4,2,2,2,3, + 2,4,3,2,0,4,3,4,0}}}, + {{"OutputLayer", { 15,60,10,11,37,20, 0,18,17, + 20,65,28,28,74,26,12,20,18, + 25,36,12,37,42,25,29,14, 9}}}); } } \ No newline at end of file diff --git a/src/armnnDeserializer/test/DeserializeGather.cpp b/src/armnnDeserializer/test/DeserializeGather.cpp index 47919c4481..0d12d71c9d 100644 --- a/src/armnnDeserializer/test/DeserializeGather.cpp +++ b/src/armnnDeserializer/test/DeserializeGather.cpp @@ -119,7 +119,10 @@ struct GatherFixture : public ParserFlatbuffersSerializeFixture }, }], }}}, - }] + }], + featureVersions: { + weightsLayoutScheme: 1, + } } )"; Setup(); diff --git a/src/armnnDeserializer/test/DeserializeGatherNd.cpp b/src/armnnDeserializer/test/DeserializeGatherNd.cpp index 684a42ca07..f0341e24ee 100644 --- a/src/armnnDeserializer/test/DeserializeGatherNd.cpp +++ b/src/armnnDeserializer/test/DeserializeGatherNd.cpp @@ -115,7 +115,10 @@ struct GatherNdFixture : public ParserFlatbuffersSerializeFixture }, }], }}}, - }] + }], + featureVersions: { + weightsLayoutScheme: 1, + } } )"; Setup(); -- cgit v1.2.1