ArmNN
 21.08
armnn::experimental Namespace Reference

Classes

class  AsyncCallbackManager
 
class  AsyncExecutionCallback
 
class  IAsyncExecutionCallback
 
class  IWorkingMemHandle
 
class  Threadpool
 
struct  WorkingMemDescriptor
 
class  WorkingMemHandle
 

Typedefs

using IAsyncExecutionCallbackPtr = std::shared_ptr< IAsyncExecutionCallback >
 
using InferenceId = uint64_t
 

Functions

template<DataType ArmnnIType, DataType ArmnnOType, typename TInput = ResolveType <ArmnnIType>, typename TOutput = ResolveType <ArmnnOType>>
void AsyncThreadedEndToEndTestImpl (INetworkPtr network, const std::vector< std::map< int, std::vector< TInput >>> &inputTensorData, const std::vector< std::map< int, std::vector< TOutput >>> &expectedOutputData, std::vector< BackendId > backends, const size_t numberOfInferences, float tolerance=0.000001f)
 
template<DataType ArmnnIType, DataType ArmnnOType, typename TInput = ResolveType<ArmnnIType>, typename TOutput = ResolveType<ArmnnOType>>
void AsyncEndToEndTestImpl (INetworkPtr network, const std::map< int, std::vector< TInput >> &inputTensorData, const std::map< int, std::vector< TOutput >> &expectedOutputData, std::vector< BackendId > backends, float tolerance=0.000001f, size_t numThreads=1)
 
template<typename armnn::DataType DataType>
INetworkPtr CreateStridedSliceNetwork (const TensorShape &inputShape, const TensorShape &outputShape, const std::vector< int > &beginData, const std::vector< int > &endData, const std::vector< int > &stridesData, int beginMask=0, int endMask=0, int shrinkAxisMask=0, int ellipsisMask=0, int newAxisMask=0, const float qScale=1.0f, const int32_t qOffset=0)
 
template<armnn::DataType ArmnnType>
void StridedSlicedEndToEndTest (const std::vector< BackendId > &backends, size_t numThreads)
 
template<armnn::DataType ArmnnType>
void StridedSlicedMultiThreadedEndToEndTest (const std::vector< BackendId > &backends)
 

Typedef Documentation

◆ IAsyncExecutionCallbackPtr

Definition at line 17 of file IAsyncExecutionCallback.hpp.

◆ InferenceId

using InferenceId = uint64_t

Definition at line 24 of file AsyncExecutionCallback.hpp.

Function Documentation

◆ AsyncEndToEndTestImpl()

void armnn::experimental::AsyncEndToEndTestImpl ( INetworkPtr  network,
const std::map< int, std::vector< TInput >> &  inputTensorData,
const std::map< int, std::vector< TOutput >> &  expectedOutputData,
std::vector< BackendId backends,
float  tolerance = 0.000001f,
size_t  numThreads = 1 
)

Definition at line 122 of file StridedSliceAsyncEndToEndTest.hpp.

References IRuntime::Create(), AsyncCallbackManager::GetNotifiedCallback(), armnn::Optimize(), armnn::Success, and armnn::Undefined.

128 {
129  // Create Runtime in which test will run
131  IRuntimePtr runtime(IRuntime::Create(options));
132 
133  // Optimize the Network
134  IOptimizedNetworkPtr optNet = Optimize(*network, backends, runtime->GetDeviceSpec());
135 
136  // Creates AsyncNetwork
137  NetworkId networkId = 0;
138 
139  std::string errorMessage;
140 
141  const INetworkProperties networkProperties(true, MemorySource::Undefined, MemorySource::Undefined);
142 
143  runtime->LoadNetwork(networkId, std::move(optNet), errorMessage, networkProperties);
144 
145  InputTensors inputTensors;
146  inputTensors.reserve(inputTensorData.size());
147  for (auto&& it : inputTensorData)
148  {
149  inputTensors.push_back({it.first,
150  ConstTensor(runtime->GetInputTensorInfo(networkId, it.first), it.second.data())});
151  }
152 
153  OutputTensors outputTensors;
154  outputTensors.reserve(expectedOutputData.size());
155  std::map<int, std::vector<TOutput>> outputStorage;
156  for (auto&& it : expectedOutputData)
157  {
158  std::vector<TOutput> out(it.second.size());
159  outputStorage.emplace(it.first, out);
160  outputTensors.push_back({it.first,
161  Tensor(runtime->GetOutputTensorInfo(networkId, it.first),
162  outputStorage.at(it.first).data())});
163  }
164 
165  if (numThreads <= 1)
166  {
167  // Create WorkingMemHandle for this async network
168  std::unique_ptr<IWorkingMemHandle> workingMemHandle = runtime->CreateWorkingMemHandle(networkId);
169  IWorkingMemHandle& workingMemHandleRef = *workingMemHandle.get();
170 
171  // Run the async network
172  runtime->Execute(workingMemHandleRef, inputTensors, outputTensors);
173  }
174  else
175  {
176  std::vector<std::shared_ptr<IWorkingMemHandle>> memHandles;
177 
178  for (size_t i = 0; i < numThreads; ++i)
179  {
180  memHandles.emplace_back(runtime->CreateWorkingMemHandle(networkId));
181  }
182 
183  Threadpool threadpool(numThreads, runtime.get(), memHandles);
184  AsyncCallbackManager callbackManager;
185 
186  // For the asyncronous execution, we are adding a pool of working memory handles (1 per thread) in the
187  // LoadedNetwork with a each scheduled inference having a spefic priority
188  for (size_t i = 0; i < 1000; ++i)
189  {
190  threadpool.Schedule(networkId,
191  inputTensors,
192  outputTensors,
193  static_cast<QosExecPriority>(rand()%3),
194  callbackManager.GetNewCallback());
195  }
196 
197  // Wait until the execution signals a notify
198  for (size_t i = 0; i < 1000; ++i)
199  {
200  auto cb = callbackManager.GetNotifiedCallback();
201 
202  // Checks the results.
203  CHECK(cb->GetStatus() == Status::Success);
204  }
205  }
206 
207  for (auto&& it : expectedOutputData)
208  {
209  std::vector<TOutput> out = outputStorage.at(it.first);
210 
211  for (unsigned int i = 0; i < out.size(); ++i)
212  {
213  CHECK(Compare<ArmnnOType>(it.second[i], out[i], tolerance) == true);
214  }
215  }
216 }
std::unique_ptr< IRuntime, void(*)(IRuntime *runtime)> IRuntimePtr
Definition: IRuntime.hpp:30
std::vector< std::pair< LayerBindingId, class ConstTensor > > InputTensors
Definition: Tensor.hpp:360
A tensor defined by a TensorInfo (shape and data type) and a mutable backing store.
Definition: Tensor.hpp:319
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:1613
int NetworkId
Definition: IRuntime.hpp:24
A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.
Definition: Tensor.hpp:327
std::vector< std::pair< LayerBindingId, class Tensor > > OutputTensors
Definition: Tensor.hpp:361
std::unique_ptr< IOptimizedNetwork, void(*)(IOptimizedNetwork *network)> IOptimizedNetworkPtr
Definition: INetwork.hpp:173

◆ AsyncThreadedEndToEndTestImpl()

void armnn::experimental::AsyncThreadedEndToEndTestImpl ( INetworkPtr  network,
const std::vector< std::map< int, std::vector< TInput >>> &  inputTensorData,
const std::vector< std::map< int, std::vector< TOutput >>> &  expectedOutputData,
std::vector< BackendId backends,
const size_t  numberOfInferences,
float  tolerance = 0.000001f 
)

Definition at line 30 of file StridedSliceAsyncEndToEndTest.hpp.

References IRuntime::Create(), armnn::Optimize(), and armnn::Undefined.

36 {
37  // Create Runtime in which test will run
39  IRuntimePtr runtime(IRuntime::Create(options));
40 
41  // Optimize the Network
42  IOptimizedNetworkPtr optNet = Optimize(*network, backends, runtime->GetDeviceSpec());
43 
44 
45  // Creates AsyncNetwork
46  NetworkId networkId = 0;
47  std::string errorMessage;
48  const INetworkProperties networkProperties(true, MemorySource::Undefined, MemorySource::Undefined);
49  runtime->LoadNetwork(networkId, std::move(optNet), errorMessage, networkProperties);
50 
51  std::vector<InputTensors> inputTensorsVec;
52  std::vector<OutputTensors> outputTensorsVec;
53  std::vector<std::map<int, std::vector<TOutput>>> outputStorageVec;
54  std::vector<std::unique_ptr<IWorkingMemHandle>> workingMemHandles;
55 
56  for (unsigned int i = 0; i < numberOfInferences; ++i)
57  {
58  InputTensors inputTensors;
59  OutputTensors outputTensors;
60  outputStorageVec.emplace_back(std::map<int, std::vector<TOutput>>());
61 
62  inputTensors.reserve(inputTensorData.size());
63  for (auto&& it : inputTensorData[i])
64  {
65  inputTensors.push_back({it.first,
66  ConstTensor(runtime->GetInputTensorInfo(networkId, it.first), it.second.data())});
67  }
68 
69  outputTensors.reserve(expectedOutputData.size());
70  for (auto&& it : expectedOutputData[i])
71  {
72  std::vector<TOutput> out(it.second.size());
73  outputStorageVec[i].emplace(it.first, out);
74  outputTensors.push_back({it.first,
75  Tensor(runtime->GetOutputTensorInfo(networkId, it.first),
76  outputStorageVec[i].at(it.first).data())});
77  }
78 
79  inputTensorsVec.push_back(inputTensors);
80  outputTensorsVec.push_back(outputTensors);
81 
82  workingMemHandles.push_back(runtime->CreateWorkingMemHandle(networkId));
83  }
84 
85  std::vector<std::thread> threads;
86  for (unsigned int i = 0; i < numberOfInferences; ++i)
87  {
88  // Access the vectors before we do anything multi-threaded
89  InputTensors& inputTensors = inputTensorsVec[i];
90  OutputTensors& outputTensors = outputTensorsVec[i];
91  IWorkingMemHandle& workingMemHandle = *workingMemHandles[i].get();
92 
93  threads.emplace_back([&]()
94  {
95  // Run the async network
96  runtime->Execute(workingMemHandle, inputTensors, outputTensors);
97  });
98  }
99 
100  for (unsigned int i = 0; i < numberOfInferences; ++i)
101  {
102  threads[i].join();
103  }
104 
105  // Checks the results.
106  for (unsigned int i = 0; i < numberOfInferences; ++i)
107  {
108  for (auto &&it : expectedOutputData[i])
109  {
110  std::vector<TOutput> out = outputStorageVec[i].at(it.first);
111  for (unsigned int j = 0; j < out.size(); ++j)
112  {
113  CHECK(Compare<ArmnnOType>(it.second[j], out[j], tolerance) == true);
114  }
115  }
116  }
117 
118 }
std::unique_ptr< IRuntime, void(*)(IRuntime *runtime)> IRuntimePtr
Definition: IRuntime.hpp:30
std::vector< std::pair< LayerBindingId, class ConstTensor > > InputTensors
Definition: Tensor.hpp:360
A tensor defined by a TensorInfo (shape and data type) and a mutable backing store.
Definition: Tensor.hpp:319
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:1613
int NetworkId
Definition: IRuntime.hpp:24
A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.
Definition: Tensor.hpp:327
std::vector< std::pair< LayerBindingId, class Tensor > > OutputTensors
Definition: Tensor.hpp:361
std::unique_ptr< IOptimizedNetwork, void(*)(IOptimizedNetwork *network)> IOptimizedNetworkPtr
Definition: INetwork.hpp:173

◆ CreateStridedSliceNetwork()

INetworkPtr armnn::experimental::CreateStridedSliceNetwork ( const TensorShape inputShape,
const TensorShape outputShape,
const std::vector< int > &  beginData,
const std::vector< int > &  endData,
const std::vector< int > &  stridesData,
int  beginMask = 0,
int  endMask = 0,
int  shrinkAxisMask = 0,
int  ellipsisMask = 0,
int  newAxisMask = 0,
const float  qScale = 1.0f,
const int32_t  qOffset = 0 
)

Definition at line 219 of file StridedSliceAsyncEndToEndTest.hpp.

References Connect(), INetwork::Create(), StridedSliceDescriptor::m_Begin, StridedSliceDescriptor::m_BeginMask, StridedSliceDescriptor::m_EllipsisMask, StridedSliceDescriptor::m_End, StridedSliceDescriptor::m_EndMask, StridedSliceDescriptor::m_NewAxisMask, StridedSliceDescriptor::m_ShrinkAxisMask, and StridedSliceDescriptor::m_Stride.

231 {
232  using namespace armnn;
233  // Builds up the structure of the network.
235 
236  TensorInfo inputTensorInfo(inputShape, DataType, qScale, qOffset);
237  TensorInfo outputTensorInfo(outputShape, DataType, qScale, qOffset);
238 
239  armnn::StridedSliceDescriptor stridedSliceDescriptor;
240  stridedSliceDescriptor.m_Begin = beginData;
241  stridedSliceDescriptor.m_End = endData;
242  stridedSliceDescriptor.m_Stride = stridesData;
243  stridedSliceDescriptor.m_BeginMask = beginMask;
244  stridedSliceDescriptor.m_EndMask = endMask;
245  stridedSliceDescriptor.m_ShrinkAxisMask = shrinkAxisMask;
246  stridedSliceDescriptor.m_EllipsisMask = ellipsisMask;
247  stridedSliceDescriptor.m_NewAxisMask = newAxisMask;
248 
249  IConnectableLayer* input = net->AddInputLayer(0, "Input_Layer");
250  IConnectableLayer* stridedSlice = net->AddStridedSliceLayer(stridedSliceDescriptor, "splitter");
251  IConnectableLayer* output = net->AddOutputLayer(0);
252 
253  Connect(input, stridedSlice, inputTensorInfo, 0, 0);
254  Connect(stridedSlice, output, outputTensorInfo, 0, 0);
255 
256  return net;
257 }
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
Definition: INetwork.hpp:61
int32_t m_ShrinkAxisMask
Shrink axis mask value. If set, the nth specification shrinks the dimensionality by 1...
std::vector< int > m_Begin
Begin values for the input that will be sliced.
Copyright (c) 2021 ARM Limited and Contributors.
int32_t m_BeginMask
Begin mask value.
int32_t m_EndMask
End mask value.
DataType
Definition: Types.hpp:35
int32_t m_NewAxisMask
New axis mask value.
int32_t m_EllipsisMask
Ellipsis mask value.
std::vector< int > m_Stride
Stride values for the input that will be sliced.
std::vector< int > m_End
End values for the input that will be sliced.
A StridedSliceDescriptor for the StridedSliceLayer.
void Connect(armnn::IConnectableLayer *from, armnn::IConnectableLayer *to, const armnn::TensorInfo &tensorInfo, unsigned int fromIndex, unsigned int toIndex)
Definition: TestUtils.cpp:12
std::unique_ptr< INetwork, void(*)(INetwork *network)> INetworkPtr
Definition: INetwork.hpp:172
static INetworkPtr Create(NetworkOptions networkOptions={})
Definition: Network.cpp:530

◆ StridedSlicedEndToEndTest()

void armnn::experimental::StridedSlicedEndToEndTest ( const std::vector< BackendId > &  backends,
size_t  numThreads 
)

Definition at line 260 of file StridedSliceAsyncEndToEndTest.hpp.

261 {
262  using namespace armnn;
263  using T = ResolveType<ArmnnType>;
264 
265  const TensorShape& inputShape = {3, 2, 3, 1};
266  const TensorShape& outputShape = {1, 2, 3, 1};
267  const std::vector<int>& beginData = {1, 0, 0, 0};
268  const std::vector<int>& endData = {2, 2, 3, 1};
269  const std::vector<int>& stridesData = {1, 1, 1, 1};
270  int beginMask = 0;
271  int endMask = 0;
272  int shrinkAxisMask = 0;
273  int ellipsisMask = 0;
274  int newAxisMask = 0;
275 
276  // Builds up the structure of the network
277  INetworkPtr net = CreateStridedSliceNetwork<ArmnnType>(inputShape,
278  outputShape,
279  beginData,
280  endData,
281  stridesData,
282  beginMask,
283  endMask,
284  shrinkAxisMask,
285  ellipsisMask,
286  newAxisMask);
287 
288  CHECK(net);
289  // Creates structures for input & output.
290  std::vector<T> inputData{
291  1.0f, 1.0f, 1.0f, 2.0f, 2.0f, 2.0f,
292 
293  3.0f, 3.0f, 3.0f, 4.0f, 4.0f, 4.0f,
294 
295  5.0f, 5.0f, 5.0f, 6.0f, 6.0f, 6.0f
296  };
297 
298  std::vector<T> outputExpected{
299  3.0f, 3.0f, 3.0f, 4.0f, 4.0f, 4.0f
300  };
301 
302  std::map<int, std::vector<T>> inputTensorData = {{0, inputData}};
303  std::map<int, std::vector<T>> expectedOutputData = {{0, outputExpected}};
304 
305  AsyncEndToEndTestImpl<ArmnnType, ArmnnType>(move(net),
306  inputTensorData,
307  expectedOutputData,
308  backends,
309  0.000001f,
310  numThreads);
311 }
typename ResolveTypeImpl< DT >::Type ResolveType
Definition: ResolveType.hpp:79
Copyright (c) 2021 ARM Limited and Contributors.
std::unique_ptr< INetwork, void(*)(INetwork *network)> INetworkPtr
Definition: INetwork.hpp:172

◆ StridedSlicedMultiThreadedEndToEndTest()

void armnn::experimental::StridedSlicedMultiThreadedEndToEndTest ( const std::vector< BackendId > &  backends)

Definition at line 314 of file StridedSliceAsyncEndToEndTest.hpp.

315 {
316  using namespace armnn;
317  using T = ResolveType<ArmnnType>;
318 
319  const TensorShape& inputShape = {3, 2, 3, 1};
320  const TensorShape& outputShape = {1, 2, 3, 1};
321  const std::vector<int>& beginData = {1, 0, 0, 0};
322  const std::vector<int>& endData = {2, 2, 3, 1};
323  const std::vector<int>& stridesData = {1, 1, 1, 1};
324  int beginMask = 0;
325  int endMask = 0;
326  int shrinkAxisMask = 0;
327  int ellipsisMask = 0;
328  int newAxisMask = 0;
329 
330  // Builds up the structure of the network
331  INetworkPtr net = CreateStridedSliceNetwork<ArmnnType>(inputShape,
332  outputShape,
333  beginData,
334  endData,
335  stridesData,
336  beginMask,
337  endMask,
338  shrinkAxisMask,
339  ellipsisMask,
340  newAxisMask);
341 
342  CHECK(net);
343 
344  // Creates structures for input & output.
345  std::vector<T> inputData1{
346  1.0f, 1.0f, 1.0f, 2.0f, 2.0f, 2.0f,
347 
348  3.0f, 3.0f, 3.0f, 4.0f, 4.0f, 4.0f,
349 
350  5.0f, 5.0f, 5.0f, 6.0f, 6.0f, 6.0f
351  };
352 
353  std::vector<T> outputExpected1{ 3.0f, 3.0f, 3.0f, 4.0f, 4.0f, 4.0f };
354 
355  // Creates structures for input & output.
356  std::vector<T> inputData2{
357  1.0f, 1.0f, 1.0f, 2.0f, 2.0f, 2.0f,
358 
359  8.0f, 8.0f, 8.0f, 7.0f, 7.0f, 7.0f,
360 
361  5.0f, 5.0f, 5.0f, 6.0f, 6.0f, 6.0f
362  };
363 
364  std::vector<T> outputExpected2{ 8.0f, 8.0f, 8.0f, 7.0f, 7.0f, 7.0f };
365 
366  std::vector<std::map<int, std::vector<T>>> inputTensors;
367  std::vector<std::map<int, std::vector<T>>> outputTensors;
368 
369  inputTensors.push_back(std::map<int, std::vector<T>> {{0, inputData1}});
370  inputTensors.push_back(std::map<int, std::vector<T>> {{0, inputData2}});
371  outputTensors.push_back(std::map<int, std::vector<T>> {{0, outputExpected1}});
372  outputTensors.push_back(std::map<int, std::vector<T>> {{0, outputExpected2}});
373 
374  AsyncThreadedEndToEndTestImpl<ArmnnType, ArmnnType>(move(net), inputTensors, outputTensors, backends, 2);
375 }
typename ResolveTypeImpl< DT >::Type ResolveType
Definition: ResolveType.hpp:79
Copyright (c) 2021 ARM Limited and Contributors.
std::unique_ptr< INetwork, void(*)(INetwork *network)> INetworkPtr
Definition: INetwork.hpp:172