ArmNN
 20.08
FlowControl.cpp File Reference
#include <armnn/Descriptors.hpp>
#include <armnn/IRuntime.hpp>
#include <armnn/INetwork.hpp>
#include <boost/test/unit_test.hpp>
#include <set>

Go to the source code of this file.

Functions

 BOOST_AUTO_TEST_CASE (ErrorOnLoadNetwork)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE()

BOOST_AUTO_TEST_CASE ( ErrorOnLoadNetwork  )

Definition at line 16 of file FlowControl.cpp.

References armnn::Boolean, BOOST_AUTO_TEST_SUITE_END(), IOutputSlot::Connect(), armnn::CpuRef, INetwork::Create(), IRuntime::Create(), IConnectableLayer::GetInputSlot(), IConnectableLayer::GetOutputSlot(), armnn::Optimize(), and IOutputSlot::SetTensorInfo().

17 {
18  using namespace armnn;
19 
20  // Create runtime in which test will run
22  IRuntimePtr runtime(IRuntime::Create(options));
23 
24  // build up the structure of the network
25  // It's equivalent to something like
26  // if (0) {} else {}
28 
29  std::vector<uint8_t> falseData = {0};
30  ConstTensor falseTensor(armnn::TensorInfo({1}, armnn::DataType::Boolean), falseData);
31  IConnectableLayer* constLayer = net->AddConstantLayer(falseTensor, "const");
33 
34  IConnectableLayer* input = net->AddInputLayer(0);
36 
37  IConnectableLayer* switchLayer = net->AddSwitchLayer("switch");
40 
41  IConnectableLayer* mergeLayer = net->AddMergeLayer("merge");
43 
44  IConnectableLayer* output = net->AddOutputLayer(0);
45 
46  input->GetOutputSlot(0).Connect(switchLayer->GetInputSlot(0));
47  constLayer->GetOutputSlot(0).Connect(switchLayer->GetInputSlot(1));
48  switchLayer->GetOutputSlot(0).Connect(mergeLayer->GetInputSlot(0));
49  switchLayer->GetOutputSlot(1).Connect(mergeLayer->GetInputSlot(1));
50  mergeLayer->GetOutputSlot(0).Connect(output->GetInputSlot(0));
51 
52  // optimize the network
53  std::vector<BackendId> backends = {Compute::CpuRef};
54  IOptimizedNetworkPtr optNet = Optimize(*net, backends, runtime->GetDeviceSpec());
55  BOOST_CHECK(!optNet); // Should have failed to optimise, as flow control is not yet implemented
56 }
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
CPU Execution: Reference C++ kernels.
std::unique_ptr< IRuntime, void(*)(IRuntime *runtime)> IRuntimePtr
Definition: IRuntime.hpp:25
Copyright (c) 2020 ARM Limited.
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:1014
A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.
Definition: Tensor.hpp:298
std::unique_ptr< IOptimizedNetwork, void(*)(IOptimizedNetwork *network)> IOptimizedNetworkPtr
Definition: INetwork.hpp:593
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:50