From 70104000ddcf3bc1a1d21f16d1468456ca17b80a Mon Sep 17 00:00:00 2001 From: Aron Virginas-Tar Date: Wed, 24 Oct 2018 15:33:28 +0100 Subject: IVGCVSW-2073: Move remaining backend-specific tests from armnn to backends Change-Id: I45fd5b6dd32c435b78a54dc377a623e60978ce13 --- src/armnn/test/NetworkTests.cpp | 640 +--------------------------------------- 1 file changed, 4 insertions(+), 636 deletions(-) (limited to 'src/armnn/test/NetworkTests.cpp') diff --git a/src/armnn/test/NetworkTests.cpp b/src/armnn/test/NetworkTests.cpp index 4f8dd7ea7b..91ff7fa983 100644 --- a/src/armnn/test/NetworkTests.cpp +++ b/src/armnn/test/NetworkTests.cpp @@ -2,16 +2,13 @@ // Copyright © 2017 Arm Ltd. All rights reserved. // SPDX-License-Identifier: MIT // -#include + +#include "GraphUtils.hpp" #include -#include -#include -#include -#include -#include +#include -#include "GraphUtils.hpp" +#include namespace { @@ -43,54 +40,6 @@ BOOST_AUTO_TEST_CASE(LayerGuids) BOOST_TEST(inputId != outputId); } -BOOST_AUTO_TEST_CASE(SerializeToDot) -{ - armnn::Network net; - - //Defines layers. - auto input = net.AddInputLayer(0); - auto add = net.AddAdditionLayer(); - auto output = net.AddOutputLayer(0); - - // Connects layers. - input->GetOutputSlot(0).Connect(add->GetInputSlot(0)); - input->GetOutputSlot(0).Connect(add->GetInputSlot(1)); - add->GetOutputSlot(0).Connect(output->GetInputSlot(0)); - - armnn::TensorShape shape({4}); - armnn::TensorInfo info(shape, armnn::DataType::Float32); - input->GetOutputSlot(0).SetTensorInfo(info); - add->GetOutputSlot(0).SetTensorInfo(info); - - armnn::IRuntime::CreationOptions options; - armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options)); - - std::vector backends = {armnn::Compute::CpuRef}; - armnn::IOptimizedNetworkPtr optimizedNet = armnn::Optimize(net, backends, runtime->GetDeviceSpec()); - - std::ostringstream ss; - optimizedNet->SerializeToDot(ss); - - auto inputId = input->GetGuid(); - auto addId = add->GetGuid(); - auto outputId = output->GetGuid(); - - std::stringstream expected; - expected << - "digraph Optimized {\n" - " node [shape=\"record\"];\n" - " edge [fontsize=8 fontcolor=\"blue\" fontname=\"arial-bold\"];\n" - " " << inputId << " [label=\"{Input}\"];\n" - " " << addId << " [label=\"{Addition}\"];\n" - " " << outputId << " [label=\"{Output}\"];\n" - " " << inputId << " -> " << addId << " [label=< [4] >];\n" - " " << inputId << " -> " << addId << " [label=< [4] >];\n" - " " << addId << " -> " << outputId << " [label=< [4] >];\n" - "}\n"; - - BOOST_TEST(ss.str() == expected.str()); -} - BOOST_AUTO_TEST_CASE(NetworkBasic) { armnn::Network net; @@ -417,585 +366,4 @@ BOOST_AUTO_TEST_CASE(NetworkModification_SplitterMultiplication) prevLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(0)); } -BOOST_AUTO_TEST_CASE(OptimizeValidateCpuRefWorkloads) -{ - const armnn::TensorInfo desc({3, 5}, armnn::DataType::Float32); - - armnn::Network net; - - armnn::NormalizationDescriptor nmDesc; - armnn::ActivationDescriptor acDesc; - - // in - // | - // nm - // / | - // ac | - // \ | - // ml - // | - // sm - // | - // ot - armnn::IConnectableLayer* layer = net.AddInputLayer(0, "in"); - layer->GetOutputSlot(0).SetTensorInfo(desc); - - armnn::IConnectableLayer* const normLayer = net.AddNormalizationLayer(nmDesc, "nm"); - - layer->GetOutputSlot(0).Connect(normLayer->GetInputSlot(0)); - normLayer->GetOutputSlot(0).SetTensorInfo(desc); - - layer = net.AddActivationLayer(acDesc, "ac"); - - normLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(0)); - layer->GetOutputSlot(0).SetTensorInfo(desc); - - armnn::IConnectableLayer* prevLayer = layer; - layer = net.AddMultiplicationLayer("ml"); - - prevLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(0)); - normLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(1)); - layer->GetOutputSlot(0).SetTensorInfo(desc); - - prevLayer = layer; - armnn::SoftmaxDescriptor softmaxDescriptor; - layer = net.AddSoftmaxLayer(softmaxDescriptor, "sm"); - - prevLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(0)); - layer->GetOutputSlot(0).SetTensorInfo(desc); - - prevLayer = layer; - layer = net.AddOutputLayer(0, "ot"); - - prevLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(0)); - - armnn::IRuntime::CreationOptions options; - armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options)); - - std::vector backends = { armnn::Compute::CpuRef }; - armnn::IOptimizedNetworkPtr optNet = armnn::Optimize(net, backends, runtime->GetDeviceSpec()); - static_cast(optNet.get())->GetGraph().AllocateDynamicBuffers(); - BOOST_CHECK(optNet); - - // Validates workloads. - armnn::RefWorkloadFactory fact; - for (auto&& layer : static_cast(optNet.get())->GetGraph()) - { - BOOST_CHECK_NO_THROW( - layer->CreateWorkload(static_cast(optNet.get())->GetGraph(), fact)); - } -} - -#if ARMCOMPUTENEON_ENABLED -BOOST_AUTO_TEST_CASE(OptimizeValidateCpuAccDeviceSupportLayerNoFallback) -{ - // build up the structure of the network - armnn::INetworkPtr net(armnn::INetwork::Create()); - - armnn::IConnectableLayer* input = net->AddInputLayer(0); - - armnn::IConnectableLayer* output = net->AddOutputLayer(0); - - input->GetOutputSlot(0).Connect(output->GetInputSlot(0)); - - input->GetOutputSlot(0).SetTensorInfo(armnn::TensorInfo({ 1, 1, 4, 4 }, armnn::DataType::Float32)); - - armnn::IRuntime::CreationOptions options; - armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options)); - - std::vector backends = { armnn::Compute::CpuAcc }; - armnn::IOptimizedNetworkPtr optNet = armnn::Optimize(*net, backends, runtime->GetDeviceSpec()); - BOOST_CHECK(optNet); - // validate workloads - armnn::NeonWorkloadFactory fact; - for (auto&& layer : static_cast(optNet.get())->GetGraph()) - { - BOOST_CHECK(layer->GetBackendId() == armnn::Compute::CpuAcc); - BOOST_CHECK_NO_THROW( - layer->CreateWorkload(static_cast(optNet.get())->GetGraph(), fact)); - } -} -#endif // ARMCOMPUTENEON_ENABLED - -#if ARMCOMPUTECL_ENABLED -BOOST_AUTO_TEST_CASE(OptimizeValidateGpuDeviceSupportLayerNoFallback) -{ - // build up the structure of the network - armnn::INetworkPtr net(armnn::INetwork::Create()); - - armnn::IConnectableLayer* input = net->AddInputLayer(0); - - armnn::IConnectableLayer* output = net->AddOutputLayer(0); - - input->GetOutputSlot(0).Connect(output->GetInputSlot(0)); - - input->GetOutputSlot(0).SetTensorInfo(armnn::TensorInfo({ 1, 1, 4, 4 }, armnn::DataType::Float32)); - - armnn::IRuntime::CreationOptions options; - armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options)); - - std::vector backends = { armnn::Compute::GpuAcc }; - armnn::IOptimizedNetworkPtr optNet = armnn::Optimize(*net, backends, runtime->GetDeviceSpec()); - BOOST_CHECK(optNet); - // validate workloads - armnn::ClWorkloadFactory fact; - for (auto&& layer : static_cast(optNet.get())->GetGraph()) - { - BOOST_CHECK(layer->GetBackendId() == armnn::Compute::GpuAcc); - BOOST_CHECK_NO_THROW( - layer->CreateWorkload(static_cast(optNet.get())->GetGraph(), fact)); - } -} -#endif // ARMCOMPUTECL_ENABLED - -BOOST_AUTO_TEST_CASE(OptimizeValidateDeviceNonSupportLayerNoFallback) -{ - // build up the structure of the network - armnn::INetworkPtr net(armnn::INetwork::Create()); - - armnn::IConnectableLayer* input = net->AddInputLayer(0); - - // This layer configuration isn't supported by CpuAcc and isn't allowed to fall back, so Optimize will return null. - armnn::NormalizationDescriptor descriptor; - armnn::IConnectableLayer* normalize = net->AddNormalizationLayer(descriptor); - - armnn::IConnectableLayer* output = net->AddOutputLayer(0); - - input->GetOutputSlot(0).Connect(normalize->GetInputSlot(0)); - normalize->GetOutputSlot(0).Connect(output->GetInputSlot(0)); - - input->GetOutputSlot(0).SetTensorInfo(armnn::TensorInfo({ 1, 1, 4, 4 }, armnn::DataType::Float32)); - normalize->GetOutputSlot(0).SetTensorInfo(armnn::TensorInfo({ 1, 1, 4, 4 }, armnn::DataType::Float32)); - - armnn::IRuntime::CreationOptions options; - armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options)); - - std::vector backends = { armnn::Compute::CpuAcc }; - armnn::IOptimizedNetworkPtr optNet = armnn::Optimize(*net, backends, runtime->GetDeviceSpec()); - BOOST_CHECK(!optNet); -} - -BOOST_AUTO_TEST_CASE(OptimizeValidateDeviceNonSupportLayerWithFallback) -{ - // build up the structure of the network - armnn::INetworkPtr net(armnn::INetwork::Create()); - - armnn::IConnectableLayer* input = net->AddInputLayer(0); - - // This layer configuration isn't supported by CpuAcc but it allows to fallback to CpuRef. - armnn::NormalizationDescriptor descriptor; - armnn::IConnectableLayer* normalize = net->AddNormalizationLayer(descriptor); - - armnn::IConnectableLayer* output = net->AddOutputLayer(0); - - input->GetOutputSlot(0).Connect(normalize->GetInputSlot(0)); - normalize->GetOutputSlot(0).Connect(output->GetInputSlot(0)); - - input->GetOutputSlot(0).SetTensorInfo(armnn::TensorInfo({ 1, 1, 4, 4 }, armnn::DataType::Float32)); - normalize->GetOutputSlot(0).SetTensorInfo(armnn::TensorInfo({ 1, 1, 4, 4 }, armnn::DataType::Float32)); - - armnn::IRuntime::CreationOptions options; - armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options)); - - std::vector backends = { armnn::Compute::CpuAcc, armnn::Compute::CpuRef }; - armnn::IOptimizedNetworkPtr optNet = armnn::Optimize(*net, backends, runtime->GetDeviceSpec()); - BOOST_REQUIRE(optNet); - - for (auto&& layer : static_cast(optNet.get())->GetGraph()) - { - // If NEON is enabled, Input and Output layers are supported by CpuAcc, - // the other layers are supported by CpuRef. - // If NEON is not enabled, all layers are supported by CpuRef. -#if ARMCOMPUTENEON_ENABLED - if (layer->GetType() == armnn::LayerType::Input || layer->GetType() == armnn::LayerType::Output) - { - BOOST_CHECK(layer->GetBackendId() == armnn::Compute::CpuAcc); - } - else if (layer->GetType() == armnn::LayerType::Normalization) - { - BOOST_CHECK(layer->GetBackendId() == armnn::Compute::CpuRef); - } -#else - BOOST_CHECK(layer->GetBackendId() == armnn::Compute::CpuRef); -#endif - } -} - -BOOST_AUTO_TEST_CASE(OptimizeValidateWorkloadsUndefinedComputeDevice) -{ - const armnn::TensorInfo desc({3, 5}, armnn::DataType::Float32); - - armnn::Network net; - - armnn::NormalizationDescriptor nmDesc; - armnn::ActivationDescriptor acDesc; - - // in - // | - // nm - // / | - // ac | - // \ | - // ml - // | - // sm - // | - // ot - armnn::IConnectableLayer* layer = net.AddInputLayer(0, "in"); - layer->GetOutputSlot(0).SetTensorInfo(desc); - - armnn::IConnectableLayer* const normLayer = net.AddNormalizationLayer(nmDesc, "nm"); - - layer->GetOutputSlot(0).Connect(normLayer->GetInputSlot(0)); - normLayer->GetOutputSlot(0).SetTensorInfo(desc); - - layer = net.AddActivationLayer(acDesc, "ac"); - - normLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(0)); - layer->GetOutputSlot(0).SetTensorInfo(desc); - - armnn::IConnectableLayer* prevLayer = layer; - layer = net.AddMultiplicationLayer("ml"); - - prevLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(0)); - normLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(1)); - layer->GetOutputSlot(0).SetTensorInfo(desc); - - prevLayer = layer; - armnn::SoftmaxDescriptor softmaxDescriptor; - layer = net.AddSoftmaxLayer(softmaxDescriptor, "sm"); - - prevLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(0)); - layer->GetOutputSlot(0).SetTensorInfo(desc); - - prevLayer = layer; - layer = net.AddOutputLayer(0, "ot"); - - prevLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(0)); - - armnn::IRuntime::CreationOptions options; - armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options)); - - std::vector backends = { armnn::Compute::Undefined }; - - armnn::IOptimizedNetworkPtr optNet = armnn::Optimize(net, backends, runtime->GetDeviceSpec()); - BOOST_CHECK(!optNet); - -} - -BOOST_AUTO_TEST_CASE(OptimizeValidateWorkloadsUndefinedComputeDeviceWithFallback) -{ - const armnn::TensorInfo desc({3, 5}, armnn::DataType::Float32); - - armnn::Network net; - - armnn::NormalizationDescriptor nmDesc; - armnn::ActivationDescriptor acDesc; - - // in - // | - // nm - // / | - // ac | - // \ | - // ml - // | - // sm - // | - // ot - armnn::IConnectableLayer* layer = net.AddInputLayer(0, "in"); - layer->GetOutputSlot(0).SetTensorInfo(desc); - - armnn::IConnectableLayer* const normLayer = net.AddNormalizationLayer(nmDesc, "nm"); - - layer->GetOutputSlot(0).Connect(normLayer->GetInputSlot(0)); - normLayer->GetOutputSlot(0).SetTensorInfo(desc); - - layer = net.AddActivationLayer(acDesc, "ac"); - - normLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(0)); - layer->GetOutputSlot(0).SetTensorInfo(desc); - - armnn::IConnectableLayer* prevLayer = layer; - layer = net.AddMultiplicationLayer("ml"); - - prevLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(0)); - normLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(1)); - layer->GetOutputSlot(0).SetTensorInfo(desc); - - prevLayer = layer; - armnn::SoftmaxDescriptor softmaxDescriptor; - layer = net.AddSoftmaxLayer(softmaxDescriptor, "sm"); - - prevLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(0)); - layer->GetOutputSlot(0).SetTensorInfo(desc); - - prevLayer = layer; - layer = net.AddOutputLayer(0, "ot"); - - prevLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(0)); - - armnn::IRuntime::CreationOptions options; - armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options)); - - std::vector backends = { armnn::Compute::Undefined, armnn::Compute::CpuRef }; - - armnn::IOptimizedNetworkPtr optNet = armnn::Optimize(net, backends, runtime->GetDeviceSpec()); - BOOST_CHECK(optNet); - - // validate workloads - armnn::RefWorkloadFactory fact; - for (auto&& layer : static_cast(optNet.get())->GetGraph()) - { - BOOST_CHECK(layer->GetBackendId() == armnn::Compute::CpuRef); - BOOST_CHECK_NO_THROW( - layer->CreateWorkload(static_cast(optNet.get())->GetGraph(), fact)); - } -} -BOOST_AUTO_TEST_CASE(OptimizeValidateWorkloadsDuplicateComputeDeviceWithFallback) -{ - // build up the structure of the network - armnn::INetworkPtr net(armnn::INetwork::Create()); - - armnn::IConnectableLayer* input = net->AddInputLayer(0); - - // This layer configuration isn't supported by CpuAcc but it allows to fallback to CpuRef. - armnn::NormalizationDescriptor descriptor; - armnn::IConnectableLayer* normalize = net->AddNormalizationLayer(descriptor); - - armnn::IConnectableLayer* output = net->AddOutputLayer(0); - - input->GetOutputSlot(0).Connect(normalize->GetInputSlot(0)); - normalize->GetOutputSlot(0).Connect(output->GetInputSlot(0)); - - input->GetOutputSlot(0).SetTensorInfo(armnn::TensorInfo({ 1, 1, 4, 4 }, armnn::DataType::Float32)); - normalize->GetOutputSlot(0).SetTensorInfo(armnn::TensorInfo({ 1, 1, 4, 4 }, armnn::DataType::Float32)); - - armnn::IRuntime::CreationOptions options; - armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options)); - - std::vector backends = { armnn::Compute::CpuAcc, - armnn::Compute::GpuAcc, - armnn::Compute::CpuRef }; - - armnn::IOptimizedNetworkPtr optNet = armnn::Optimize(*net, backends, runtime->GetDeviceSpec()); - BOOST_REQUIRE(optNet); - - for (auto&& layer : static_cast(optNet.get())->GetGraph()) - { - // If NEON is enabled, Input and Output layers are supported by CpuAcc, - // the other layers are supported by CpuRef. - // If only CL is enabled, Input and Output layers are supported by GpuAcc, - // the other layers are supported by CpuRef. - // If neither NEON, nor CL is enabled, all layers are supported by CpuRef. -#if ARMCOMPUTENEON_ENABLED - if (layer->GetType() == armnn::LayerType::Input || layer->GetType() == armnn::LayerType::Output) - { - BOOST_CHECK(layer->GetBackendId() == armnn::Compute::CpuAcc); - } - else if (layer->GetType() == armnn::LayerType::Normalization) - { - BOOST_CHECK(layer->GetBackendId() == armnn::Compute::CpuRef); - } -#elif ARMCOMPUTECL_ENABLED - if (layer->GetType() == armnn::LayerType::Input || layer->GetType() == armnn::LayerType::Output) - { - BOOST_CHECK(layer->GetBackendId() == armnn::Compute::GpuAcc); - } - else if (layer->GetType() == armnn::LayerType::Normalization) - { - BOOST_CHECK(layer->GetBackendId() == armnn::Compute::CpuRef); - } -#else - BOOST_CHECK(layer->GetBackendId() == armnn::Compute::CpuRef); -#endif - } -} - -BOOST_AUTO_TEST_CASE(OptimizeValidateWorkloadsCpuRefPermuteLayer) -{ - // Create runtime in which test will run - armnn::IRuntime::CreationOptions options; - armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options)); - - std::vector backends = {armnn::Compute::CpuRef}; - - // build up the structure of the network - armnn::INetworkPtr net(armnn::INetwork::Create()); - - armnn::IConnectableLayer* input = net->AddInputLayer(0); - - armnn::PermuteDescriptor descriptor({0, 2, 3, 1}); - armnn::IConnectableLayer* permute = net->AddPermuteLayer(descriptor); - - armnn::IConnectableLayer* output = net->AddOutputLayer(0); - - input->GetOutputSlot(0).Connect(permute->GetInputSlot(0)); - permute->GetOutputSlot(0).Connect(output->GetInputSlot(0)); - - input->GetOutputSlot(0).SetTensorInfo(armnn::TensorInfo({ 1, 1, 4, 4 }, armnn::DataType::Float32)); - permute->GetOutputSlot(0).SetTensorInfo(armnn::TensorInfo({ 1, 4, 1, 4 }, armnn::DataType::Float32)); - - // optimize the network - armnn::IOptimizedNetworkPtr optNet = armnn::Optimize(*net, backends, runtime->GetDeviceSpec()); - - for (auto&& layer : static_cast(optNet.get())->GetGraph()) - { - BOOST_CHECK(layer->GetBackendId() == armnn::Compute::CpuRef); - } -} - -BOOST_AUTO_TEST_CASE(OptimizeValidateWorkloadsCpuRefMeanLayer) -{ - // Create runtime in which test will run - armnn::IRuntime::CreationOptions options; - armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options)); - - std::vector backends = {armnn::Compute::CpuRef}; - - // build up the structure of the network - armnn::INetworkPtr net(armnn::INetwork::Create()); - - armnn::IConnectableLayer* input = net->AddInputLayer(0); - - armnn::MeanDescriptor descriptor({ 0, 1 }, false); - armnn::IConnectableLayer* meanLayer = net->AddMeanLayer(descriptor); - - armnn::IConnectableLayer* output = net->AddOutputLayer(0); - - input->GetOutputSlot(0).Connect(meanLayer->GetInputSlot(0)); - meanLayer->GetOutputSlot(0).Connect(output->GetInputSlot(0)); - - input->GetOutputSlot(0).SetTensorInfo(armnn::TensorInfo({ 4, 3, 2 }, armnn::DataType::Float32)); - meanLayer->GetOutputSlot(0).SetTensorInfo(armnn::TensorInfo({ 2 }, armnn::DataType::Float32)); - - // optimize the network - armnn::IOptimizedNetworkPtr optNet = armnn::Optimize(*net, backends, runtime->GetDeviceSpec()); - - for (auto&& layer : static_cast(optNet.get())->GetGraph()) - { - BOOST_CHECK(layer->GetBackendId() == armnn::Compute::CpuRef); - } -} - -BOOST_AUTO_TEST_CASE(FP16TurboModeTestOnCpuRef) -{ - // Test to check when FP16 Turbo mode set - // it converts the FP32 network to FP16 Network - // add FP32ToFP16 conversion layer after the InputLayer - // add FP16ToFP32 conversion layer after the OutputLayer - // checks the other layers if they are supported in FP16 - // if they are not put the conversion layers before and after - // if they are not supported in FP16 use FP32 instead - // if there are inverse conversion layers remove them with optimization - // at the moment FloorLayer is not supported in FP16 so it rolls back to FP32 - // and inverse conversion layers are removed by the optimizer - armnn::Network net; - - // Defines layers. - auto input = net.AddInputLayer(0); - auto floor = net.AddFloorLayer(); - auto output = net.AddOutputLayer(0); - - // Connects layers. - input->GetOutputSlot(0).Connect(floor->GetInputSlot(0)); - floor->GetOutputSlot(0).Connect(output->GetInputSlot(0)); - - armnn::TensorShape shape({4}); - armnn::TensorInfo info(shape, armnn::DataType::Float32); - input->GetOutputSlot(0).SetTensorInfo(info); - floor->GetOutputSlot(0).SetTensorInfo(info); - - armnn::IRuntime::CreationOptions options; - armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options)); - - std::vector backends = {armnn::Compute::CpuRef}; - - armnn::OptimizerOptions optimizerOptions; - optimizerOptions.m_ReduceFp32ToFp16 = true; - - armnn::IOptimizedNetworkPtr optimizedNet = armnn::Optimize(net, backends, runtime->GetDeviceSpec(), - optimizerOptions); - - std::ostringstream ss; - optimizedNet->SerializeToDot(ss); - - auto inputId = input->GetGuid(); - auto floorId = floor->GetGuid(); - auto outputId = output->GetGuid(); - - std::stringstream expected; - expected << - "digraph Optimized {\n" - " node [shape=\"record\"];\n" - " edge [fontsize=8 fontcolor=\"blue\" fontname=\"arial-bold\"];\n" - " " << inputId << " [label=\"{Input}\"];\n" - " " << floorId << " [label=\"{Floor}\"];\n" - " " << outputId << " [label=\"{Output}\"];\n" - " " << inputId << " -> " << floorId << " [label=< [4] >];\n" - " " << floorId << " -> " << outputId << " [label=< [4] >];\n" - "}\n"; - - BOOST_TEST(ss.str() == expected.str()); -} - -#if ARMCOMPUTECL_ENABLED -BOOST_AUTO_TEST_CASE(FP16TurboModeTestOnGpuAcc) -{ - // Test to check when Fp16 Turbo mode set - // it converts the Fp32 network to Fp16 Network - // add Fp32ToFp16 conversion layer after the InputLayer - // add Fp16ToFp32 conversion layer after the OutputLayer - // checks the other layers if they are supported in Fp16 - // if they are not put the conversion layers before and after - // if they are not supported in Fp16 use Fp32 instead - // if there are inverse conversion layers remove them with optimization - // at the moment FloorLayer is not supported in Fp16 so it rolls back to Fp32 - // and inverse conversion layers are removed by the optimizer - armnn::Network net; - - // Defines layers. - auto input = net.AddInputLayer(0, "input layer"); - // ReLu1 - armnn::ActivationDescriptor activation1Descriptor; - activation1Descriptor.m_Function = armnn::ActivationFunction::BoundedReLu; - activation1Descriptor.m_A = 1.f; - activation1Descriptor.m_B = -1.f; - auto activation = net.AddActivationLayer(activation1Descriptor, "activation layer"); - auto output = net.AddOutputLayer(0, "output layer"); - - // Connects layers. - input->GetOutputSlot(0).Connect(activation->GetInputSlot(0)); - activation->GetOutputSlot(0).Connect(output->GetInputSlot(0)); - - armnn::TensorShape shape({4}); - armnn::TensorInfo info(shape, armnn::DataType::Float32); - input->GetOutputSlot(0).SetTensorInfo(info); - activation->GetOutputSlot(0).SetTensorInfo(info); - - armnn::IRuntime::CreationOptions options; - armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options)); - - std::vector backends = {armnn::Compute::GpuAcc}; - - armnn::OptimizerOptions optimizerOptions; - optimizerOptions.m_ReduceFp32ToFp16 = true; - - armnn::IOptimizedNetworkPtr optimizedNet = armnn::Optimize( - net, backends, runtime->GetDeviceSpec(), optimizerOptions); - - const armnn::Graph& graph = static_cast(optimizedNet.get())->GetGraph(); - - // Tests that all layers are present in the graph. - BOOST_TEST(graph.GetNumLayers() == 5); - - // Tests that the vertices exist and have correct names. - BOOST_TEST(GraphHasNamedLayer(graph, "input layer")); - BOOST_TEST(GraphHasNamedLayer(graph, "convert_fp32_to_fp16-0-input layer")); - BOOST_TEST(GraphHasNamedLayer(graph, "activation layer")); - BOOST_TEST(GraphHasNamedLayer(graph, "convert_fp16_to_fp32-0-output layer")); - BOOST_TEST(GraphHasNamedLayer(graph, "output layer")); -} -#endif - BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.1