From 4a3c61091037e7e86e8b03bb060d8c1ab82731a9 Mon Sep 17 00:00:00 2001 From: josh minor Date: Mon, 6 Jan 2020 16:40:46 -0600 Subject: IVGCVSW-4259 Add frontend and reference workload for UnaryOperationLayer * Added new layer named ElementwiseUnary * Deprecated existing Abs/Rsqrt layer functions * Updated existing Abs/Rsqrt test infrastructure to use new layer * Added boilerplate for new Exp,Neg,Sqrt elemwise op layers * AbsQuantize test removed pending future commit * Serialization support added !android-nn-driver:2550 Change-Id: Ic595c645925e17b45db568187fd05646daf2e87f Signed-off-by: josh minor --- src/armnn/test/CreateWorkload.hpp | 37 ++------------- src/armnn/test/QuantizerTest.cpp | 55 ---------------------- .../test/TestNameAndDescriptorLayerVisitor.cpp | 7 +++ .../test/TestNameAndDescriptorLayerVisitor.hpp | 1 + src/armnn/test/TestNameOnlyLayerVisitor.cpp | 2 - src/armnn/test/TestNameOnlyLayerVisitor.hpp | 2 - 6 files changed, 13 insertions(+), 91 deletions(-) (limited to 'src/armnn/test') diff --git a/src/armnn/test/CreateWorkload.hpp b/src/armnn/test/CreateWorkload.hpp index 02ce12a304..4782c432a2 100644 --- a/src/armnn/test/CreateWorkload.hpp +++ b/src/armnn/test/CreateWorkload.hpp @@ -131,14 +131,15 @@ std::unique_ptr CreateElementwiseWorkloadTest(armnn::IWorkloadFact return workload; } -template std::unique_ptr CreateElementwiseUnaryWorkloadTest(armnn::IWorkloadFactory & factory, - armnn::Graph & graph) + armnn::Graph & graph, + armnn::UnaryOperation op) { - Layer* const layer = graph.AddLayer("layer"); + ElementwiseUnaryDescriptor desc = ElementwiseUnaryDescriptor(op); + Layer* const layer = graph.AddLayer(desc, "layer"); Layer* const input = graph.AddLayer(0, "input"); Layer* const output = graph.AddLayer(0, "output"); @@ -1059,34 +1060,6 @@ std::unique_ptr CreateResizeBilinearWorkloadTest(armnn::IWorkloa return workload; } -template -std::unique_ptr CreateRsqrtWorkloadTest(armnn::IWorkloadFactory& factory, - armnn::Graph& graph) -{ - Layer* const layer = graph.AddLayer("rsqrt"); - - // Creates extra layers. - Layer* const input = graph.AddLayer(0, "input"); - Layer* const output = graph.AddLayer(0, "output"); - - // Connects up. - armnn::TensorInfo tensorInfo({1, 1}, DataType); - - Connect(input, layer, tensorInfo); - Connect(layer, output, tensorInfo); - - CreateTensorHandles(graph, factory); - - // Makes the workload and checks it. - auto workload = MakeAndCheckWorkload(*layer, factory); - - RsqrtQueueDescriptor queueDescriptor = workload->GetData(); - BOOST_TEST(queueDescriptor.m_Inputs.size() == 1); - BOOST_TEST(queueDescriptor.m_Outputs.size() == 1); - - return workload; -} - template std::unique_ptr CreateBatchToSpaceNdWorkloadTest(armnn::IWorkloadFactory& factory, armnn::Graph& graph) diff --git a/src/armnn/test/QuantizerTest.cpp b/src/armnn/test/QuantizerTest.cpp index 52beb630f9..d568b2cbc0 100644 --- a/src/armnn/test/QuantizerTest.cpp +++ b/src/armnn/test/QuantizerTest.cpp @@ -1672,61 +1672,6 @@ BOOST_AUTO_TEST_CASE(QuantizeConstant) VisitLayersTopologically(quantizedNetworkQSymm16.get(), validatorQSymm16); } -BOOST_AUTO_TEST_CASE(QuantizeAbs) -{ - class TestAbsQuantization : public TestLeakyReLuActivationQuantization - { - public: - TestAbsQuantization(const TensorShape& inputShape, const TensorShape& outputShape) : - TestLeakyReLuActivationQuantization(inputShape, outputShape) - {} - - TestAbsQuantization(const QuantizerOptions& options, - const TensorShape& inputShape, - const TensorShape& outputShape) : - TestLeakyReLuActivationQuantization(options, inputShape, outputShape) - {} - - void VisitAbsLayer(const IConnectableLayer *layer, - const char *name = nullptr) override - { - boost::ignore_unused(name); - TensorInfo outputInfo = layer->GetOutputSlot(0).GetTensorInfo(); - - TestQuantizationParams(outputInfo, - { 30.0f / g_Asymm8QuantizationBase, 128 }, - { 15.0f / g_Symm8QuantizationBase, 0}, - { 15.0f / g_Symm16QuantizationBase, 0 }); - } - }; - - INetworkPtr network = INetwork::Create(); - - //Add the layer being tested - IConnectableLayer* absLayer = network->AddAbsLayer(); - - const TensorShape shape{1U}; - TensorInfo info(shape, DataType::Float32); - - IConnectableLayer* activation = CreateStartOfLeakyReluNetwork(network.get(), info); - - CompleteLeakyReluNetwork(network.get(), activation, absLayer, info); - - INetworkPtr quantizedNetworkQAsymm8 = INetworkQuantizer::Create(network.get())->ExportNetwork(); - TestAbsQuantization validatorQAsymm8(shape, shape); - VisitLayersTopologically(quantizedNetworkQAsymm8.get(), validatorQAsymm8); - - const QuantizerOptions qSymm8Options(DataType::QSymmS8); - INetworkPtr quantizedNetworkQSymm8 = INetworkQuantizer::Create(network.get(), qSymm8Options)->ExportNetwork(); - TestAbsQuantization validatorQSymm8(qSymm8Options, shape, shape); - VisitLayersTopologically(quantizedNetworkQSymm8.get(), validatorQSymm8); - - const QuantizerOptions qSymm16options(DataType::QSymmS16); - INetworkPtr quantizedNetworkQSymm16 = INetworkQuantizer::Create(network.get(), qSymm16options)->ExportNetwork(); - TestAbsQuantization validatorQSymm16(qSymm16options, shape, shape); - VisitLayersTopologically(quantizedNetworkQSymm16.get(), validatorQSymm16); -} - BOOST_AUTO_TEST_CASE(QuantizeArgMinMax) { class TestArgMinMaxQuantization : public TestQuantization diff --git a/src/armnn/test/TestNameAndDescriptorLayerVisitor.cpp b/src/armnn/test/TestNameAndDescriptorLayerVisitor.cpp index 36bbd36792..efe50a5b58 100644 --- a/src/armnn/test/TestNameAndDescriptorLayerVisitor.cpp +++ b/src/armnn/test/TestNameAndDescriptorLayerVisitor.cpp @@ -85,6 +85,12 @@ armnn::ConcatDescriptor GetDescriptor() return descriptor; } +template<> +armnn::ElementwiseUnaryDescriptor GetDescriptor() +{ + return armnn::ElementwiseUnaryDescriptor(armnn::UnaryOperation::Abs); +} + template<> armnn::InstanceNormalizationDescriptor GetDescriptor() { @@ -251,6 +257,7 @@ TEST_SUITE_NAME_AND_DESCRIPTOR_LAYER_VISITOR(DepthToSpace) TEST_SUITE_NAME_AND_DESCRIPTOR_LAYER_VISITOR(BatchToSpaceNd) TEST_SUITE_NAME_AND_DESCRIPTOR_LAYER_VISITOR(Comparison) TEST_SUITE_NAME_AND_DESCRIPTOR_LAYER_VISITOR(Concat) +TEST_SUITE_NAME_AND_DESCRIPTOR_LAYER_VISITOR(ElementwiseUnary) TEST_SUITE_NAME_AND_DESCRIPTOR_LAYER_VISITOR(InstanceNormalization) TEST_SUITE_NAME_AND_DESCRIPTOR_LAYER_VISITOR(L2Normalization) TEST_SUITE_NAME_AND_DESCRIPTOR_LAYER_VISITOR(LogSoftmax) diff --git a/src/armnn/test/TestNameAndDescriptorLayerVisitor.hpp b/src/armnn/test/TestNameAndDescriptorLayerVisitor.hpp index 221057cbdc..f792bc3554 100644 --- a/src/armnn/test/TestNameAndDescriptorLayerVisitor.hpp +++ b/src/armnn/test/TestNameAndDescriptorLayerVisitor.hpp @@ -48,6 +48,7 @@ DECLARE_TEST_NAME_AND_DESCRIPTOR_LAYER_VISITOR_CLASS(BatchToSpaceNd) DECLARE_TEST_NAME_AND_DESCRIPTOR_LAYER_VISITOR_CLASS(Comparison) DECLARE_TEST_NAME_AND_DESCRIPTOR_LAYER_VISITOR_CLASS(Concat) DECLARE_TEST_NAME_AND_DESCRIPTOR_LAYER_VISITOR_CLASS(DepthToSpace) +DECLARE_TEST_NAME_AND_DESCRIPTOR_LAYER_VISITOR_CLASS(ElementwiseUnary) DECLARE_TEST_NAME_AND_DESCRIPTOR_LAYER_VISITOR_CLASS(InstanceNormalization) DECLARE_TEST_NAME_AND_DESCRIPTOR_LAYER_VISITOR_CLASS(L2Normalization) DECLARE_TEST_NAME_AND_DESCRIPTOR_LAYER_VISITOR_CLASS(LogSoftmax) diff --git a/src/armnn/test/TestNameOnlyLayerVisitor.cpp b/src/armnn/test/TestNameOnlyLayerVisitor.cpp index 32de94e7ef..0653b39e58 100644 --- a/src/armnn/test/TestNameOnlyLayerVisitor.cpp +++ b/src/armnn/test/TestNameOnlyLayerVisitor.cpp @@ -38,7 +38,6 @@ TEST_CASE_CHECK_LAYER_VISITOR_NAME_NULLPTR(name) BOOST_AUTO_TEST_SUITE(TestNameOnlyLayerVisitor) -TEST_SUITE_NAME_ONLY_LAYER_VISITOR(Abs) TEST_SUITE_NAME_ONLY_LAYER_VISITOR(Addition) TEST_SUITE_NAME_ONLY_LAYER_VISITOR(Dequantize) TEST_SUITE_NAME_ONLY_LAYER_VISITOR(Division) @@ -50,7 +49,6 @@ TEST_SUITE_NAME_ONLY_LAYER_VISITOR(Minimum) TEST_SUITE_NAME_ONLY_LAYER_VISITOR(Multiplication) TEST_SUITE_NAME_ONLY_LAYER_VISITOR(Prelu) TEST_SUITE_NAME_ONLY_LAYER_VISITOR(Quantize) -TEST_SUITE_NAME_ONLY_LAYER_VISITOR(Rsqrt) TEST_SUITE_NAME_ONLY_LAYER_VISITOR(Subtraction) TEST_SUITE_NAME_ONLY_LAYER_VISITOR(Switch) diff --git a/src/armnn/test/TestNameOnlyLayerVisitor.hpp b/src/armnn/test/TestNameOnlyLayerVisitor.hpp index c770b5e9e0..84dfdd6539 100644 --- a/src/armnn/test/TestNameOnlyLayerVisitor.hpp +++ b/src/armnn/test/TestNameOnlyLayerVisitor.hpp @@ -25,7 +25,6 @@ public: \ } // anonymous namespace -DECLARE_TEST_NAME_ONLY_LAYER_VISITOR_CLASS(Abs) DECLARE_TEST_NAME_ONLY_LAYER_VISITOR_CLASS(Addition) DECLARE_TEST_NAME_ONLY_LAYER_VISITOR_CLASS(Dequantize) DECLARE_TEST_NAME_ONLY_LAYER_VISITOR_CLASS(Division) @@ -37,6 +36,5 @@ DECLARE_TEST_NAME_ONLY_LAYER_VISITOR_CLASS(Minimum) DECLARE_TEST_NAME_ONLY_LAYER_VISITOR_CLASS(Multiplication) DECLARE_TEST_NAME_ONLY_LAYER_VISITOR_CLASS(Prelu) DECLARE_TEST_NAME_ONLY_LAYER_VISITOR_CLASS(Quantize) -DECLARE_TEST_NAME_ONLY_LAYER_VISITOR_CLASS(Rsqrt) DECLARE_TEST_NAME_ONLY_LAYER_VISITOR_CLASS(Subtraction) DECLARE_TEST_NAME_ONLY_LAYER_VISITOR_CLASS(Switch) -- cgit v1.2.1