ArmNN
 20.11
NeonOptimizedNetworkTests.cpp File Reference
#include "NeonWorkloadFactoryHelper.hpp"
#include <Graph.hpp>
#include <Network.hpp>
#include <neon/NeonWorkloadFactory.hpp>
#include <boost/test/unit_test.hpp>

Go to the source code of this file.

Functions

 BOOST_AUTO_TEST_CASE (OptimizeValidateCpuAccDeviceSupportLayerNoFallback)
 
 BOOST_AUTO_TEST_CASE (OptimizeValidateDeviceNonSupportLayerNoFallback)
 
 BOOST_AUTO_TEST_CASE (FastMathEnabledTestOnCpuAcc)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/3]

BOOST_AUTO_TEST_CASE ( OptimizeValidateCpuAccDeviceSupportLayerNoFallback  )

Definition at line 17 of file NeonOptimizedNetworkTests.cpp.

References IOutputSlot::Connect(), armnn::CpuAcc, INetwork::Create(), IRuntime::Create(), armnn::Float32, IConnectableLayer::GetInputSlot(), IConnectableLayer::GetOutputSlot(), armnn::Optimize(), and IOutputSlot::SetTensorInfo().

18 {
19  // build up the structure of the network
21 
22  armnn::IConnectableLayer* input = net->AddInputLayer(0);
23  armnn::IConnectableLayer* output = net->AddOutputLayer(0);
24 
25  input->GetOutputSlot(0).Connect(output->GetInputSlot(0));
27 
30 
31  std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc };
32  armnn::IOptimizedNetworkPtr optNet = armnn::Optimize(*net, backends, runtime->GetDeviceSpec());
33  BOOST_CHECK(optNet);
34  // validate workloads
36  NeonWorkloadFactoryHelper::GetFactory(NeonWorkloadFactoryHelper::GetMemoryManager());
37 
38  for (auto&& layer : static_cast<armnn::OptimizedNetwork*>(optNet.get())->GetGraph())
39  {
40  BOOST_CHECK(layer->GetBackendId() == armnn::Compute::CpuAcc);
41  BOOST_CHECK_NO_THROW(
42  layer->CreateWorkload(fact));
43  }
44 }
static IRuntimePtr Create(const CreationOptions &options)
Definition: Runtime.cpp:32
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
Definition: INetwork.hpp:61
std::unique_ptr< IRuntime, void(*)(IRuntime *runtime)> IRuntimePtr
Definition: IRuntime.hpp:25
virtual void SetTensorInfo(const TensorInfo &tensorInfo)=0
IOptimizedNetworkPtr Optimize(const INetwork &network, const std::vector< BackendId > &backendPreferences, const IDeviceSpec &deviceSpec, const OptimizerOptions &options=OptimizerOptions(), Optional< std::vector< std::string > &> messages=EmptyOptional())
Create an optimized version of the network.
Definition: Network.cpp:1011
std::unique_ptr< IOptimizedNetwork, void(*)(IOptimizedNetwork *network)> IOptimizedNetworkPtr
Definition: INetwork.hpp:600
CPU Execution: NEON: ArmCompute.
virtual const IInputSlot & GetInputSlot(unsigned int index) const =0
Get a const input slot handle by slot index.
virtual const IOutputSlot & GetOutputSlot(unsigned int index) const =0
Get the const output slot handle by slot index.
std::unique_ptr< INetwork, void(*)(INetwork *network)> INetworkPtr
Definition: INetwork.hpp:101
virtual int Connect(IInputSlot &destination)=0
static INetworkPtr Create(NetworkOptions networkOptions={})
Definition: Network.cpp:46

◆ BOOST_AUTO_TEST_CASE() [2/3]

BOOST_AUTO_TEST_CASE ( OptimizeValidateDeviceNonSupportLayerNoFallback  )

Definition at line 46 of file NeonOptimizedNetworkTests.cpp.

References IOutputSlot::Connect(), armnn::CpuAcc, INetwork::Create(), IRuntime::Create(), armnn::Float32, IConnectableLayer::GetInputSlot(), IConnectableLayer::GetOutputSlot(), armnn::Optimize(), and IOutputSlot::SetTensorInfo().

47 {
48  // build up the structure of the network
50 
51  armnn::IConnectableLayer* input = net->AddInputLayer(0);
52 
53  // This layer configuration isn't supported by CpuAcc and isn't allowed to fall back, so Optimize will return null.
55  armnn::IConnectableLayer* normalize = net->AddNormalizationLayer(descriptor);
56 
57  armnn::IConnectableLayer* output = net->AddOutputLayer(0);
58 
59  input->GetOutputSlot(0).Connect(normalize->GetInputSlot(0));
60  normalize->GetOutputSlot(0).Connect(output->GetInputSlot(0));
61 
64 
67 
68  std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc };
69  std::vector<std::string> errMessages;
70 
71  try
72  {
73  Optimize(*net, backends, runtime->GetDeviceSpec(), armnn::OptimizerOptions(), errMessages);
74  BOOST_FAIL("Should have thrown an exception.");
75  }
76  catch (const armnn::InvalidArgumentException& e)
77  {
78  // Different exceptions are thrown on different backends
79  }
80  BOOST_CHECK(errMessages.size() > 0);
81 }
static IRuntimePtr Create(const CreationOptions &options)
Definition: Runtime.cpp:32
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
Definition: INetwork.hpp:61
std::unique_ptr< IRuntime, void(*)(IRuntime *runtime)> IRuntimePtr
Definition: IRuntime.hpp:25
virtual void SetTensorInfo(const TensorInfo &tensorInfo)=0
IOptimizedNetworkPtr Optimize(const INetwork &network, const std::vector< BackendId > &backendPreferences, const IDeviceSpec &deviceSpec, const OptimizerOptions &options=OptimizerOptions(), Optional< std::vector< std::string > &> messages=EmptyOptional())
Create an optimized version of the network.
Definition: Network.cpp:1011
CPU Execution: NEON: ArmCompute.
virtual const IInputSlot & GetInputSlot(unsigned int index) const =0
Get a const input slot handle by slot index.
virtual const IOutputSlot & GetOutputSlot(unsigned int index) const =0
Get the const output slot handle by slot index.
std::unique_ptr< INetwork, void(*)(INetwork *network)> INetworkPtr
Definition: INetwork.hpp:101
virtual int Connect(IInputSlot &destination)=0
A NormalizationDescriptor for the NormalizationLayer.
static INetworkPtr Create(NetworkOptions networkOptions={})
Definition: Network.cpp:46

◆ BOOST_AUTO_TEST_CASE() [3/3]

BOOST_AUTO_TEST_CASE ( FastMathEnabledTestOnCpuAcc  )

Definition at line 83 of file NeonOptimizedNetworkTests.cpp.

References BOOST_AUTO_TEST_SUITE_END(), IOutputSlot::Connect(), armnn::CpuAcc, INetwork::Create(), IRuntime::Create(), armnn::Float32, IConnectableLayer::GetInputSlot(), IConnectableLayer::GetOutputSlot(), OptimizerOptions::m_ModelOptions, armnn::Optimize(), and IOutputSlot::SetTensorInfo().

84 {
86 
87  armnn::IConnectableLayer* input = net->AddInputLayer(0);
88  armnn::IConnectableLayer* output = net->AddOutputLayer(0);
89 
90  input->GetOutputSlot(0).Connect(output->GetInputSlot(0));
92 
95 
96  std::vector<armnn::BackendId> backends = {armnn::Compute::CpuAcc};
97  armnn::OptimizerOptions optimizerOptions;
98  armnn::BackendOptions modelOptions("CpuAcc", {{"FastMathEnabled", true}});
99  optimizerOptions.m_ModelOptions.push_back(modelOptions);
100 
102  *net, backends, runtime->GetDeviceSpec(), optimizerOptions);
103 
104  BOOST_CHECK(optimizedNet);
105 
106  auto modelOptionsOut = static_cast<armnn::OptimizedNetwork*>(optimizedNet.get())->GetModelOptions();
107 
108  BOOST_TEST(modelOptionsOut.size() == 1);
109  BOOST_TEST(modelOptionsOut[0].GetOption(0).GetName() == "FastMathEnabled");
110  BOOST_TEST(modelOptionsOut[0].GetOption(0).GetValue().AsBool() == true);
111 }
ModelOptions m_ModelOptions
Definition: INetwork.hpp:674
static IRuntimePtr Create(const CreationOptions &options)
Definition: Runtime.cpp:32
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
Definition: INetwork.hpp:61
std::unique_ptr< IRuntime, void(*)(IRuntime *runtime)> IRuntimePtr
Definition: IRuntime.hpp:25
virtual void SetTensorInfo(const TensorInfo &tensorInfo)=0
IOptimizedNetworkPtr Optimize(const INetwork &network, const std::vector< BackendId > &backendPreferences, const IDeviceSpec &deviceSpec, const OptimizerOptions &options=OptimizerOptions(), Optional< std::vector< std::string > &> messages=EmptyOptional())
Create an optimized version of the network.
Definition: Network.cpp:1011
std::unique_ptr< IOptimizedNetwork, void(*)(IOptimizedNetwork *network)> IOptimizedNetworkPtr
Definition: INetwork.hpp:600
Struct for the users to pass backend specific options.
CPU Execution: NEON: ArmCompute.
virtual const IInputSlot & GetInputSlot(unsigned int index) const =0
Get a const input slot handle by slot index.
virtual const IOutputSlot & GetOutputSlot(unsigned int index) const =0
Get the const output slot handle by slot index.
std::unique_ptr< INetwork, void(*)(INetwork *network)> INetworkPtr
Definition: INetwork.hpp:101
virtual int Connect(IInputSlot &destination)=0
static INetworkPtr Create(NetworkOptions networkOptions={})
Definition: Network.cpp:46