ArmNN
 22.02
FlowControl.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include <armnn/Descriptors.hpp>
7 #include <armnn/IRuntime.hpp>
8 #include <armnn/INetwork.hpp>
9 
10 #include <doctest/doctest.h>
11 
12 #include <set>
13 
14 TEST_SUITE("FlowControl")
15 {
16 TEST_CASE("ErrorOnLoadNetwork")
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, 0.0f, 0, true), 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  std::vector<std::string> errMessages;
55 
56  try
57  {
58  Optimize(*net, backends, runtime->GetDeviceSpec(), OptimizerOptions(), errMessages);
59  FAIL("Should have thrown an exception.");
60  }
61  catch (const InvalidArgumentException&)
62  {
63  // Different exceptions are thrown on different backends
64  }
65  CHECK(errMessages.size() > 0);
66 }
67 
68 }
static IRuntimePtr Create(const CreationOptions &options)
Definition: Runtime.cpp:40
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
Definition: INetwork.hpp:66
CPU Execution: Reference C++ kernels.
TEST_SUITE("FlowControl")
Definition: FlowControl.cpp:14
std::unique_ptr< IRuntime, void(*)(IRuntime *runtime)> IRuntimePtr
Definition: IRuntime.hpp:31
Copyright (c) 2021 ARM Limited and Contributors.
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:1680
A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.
Definition: Tensor.hpp:327
ArmNN performs an optimization on each model/network before it gets loaded for execution.
Definition: INetwork.hpp:137
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:241
virtual int Connect(IInputSlot &destination)=0
static INetworkPtr Create(NetworkOptions networkOptions={})
Definition: Network.cpp:492