blob: 045007b5c9c2081091f4ba58ae0df143b9fbde98 [file] [log] [blame]
Laurent Carlier749294b2020-06-01 09:03:17 +01001//
Jim Flynn6398a982020-05-27 17:05:21 +01002// Copyright © 2017 Arm Ltd and Contributors. All rights reserved.
David Beckecb56cd2018-09-05 12:52:57 +01003// SPDX-License-Identifier: MIT
telsoa014fcda012018-03-09 14:13:49 +00004//
telsoa014fcda012018-03-09 14:13:49 +00005
Aron Virginas-Tarc26ba752018-10-22 13:32:01 +01006#include <armnn/Descriptors.hpp>
7#include <armnn/IRuntime.hpp>
8#include <armnn/INetwork.hpp>
Jim Flynnf7713212020-07-14 09:50:59 +01009#include <Processes.hpp>
Aron Virginas-Tarc9cc8042018-11-01 16:15:57 +000010#include <Runtime.hpp>
Aron Virginas-Tarc26ba752018-10-22 13:32:01 +010011#include <armnn/TypesUtils.hpp>
telsoa014fcda012018-03-09 14:13:49 +000012
Nikhil Raj77fe76b2021-06-09 14:55:32 +010013#include <common/include/LabelsAndEventClasses.hpp>
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +000014#include <test/ProfilingTestUtils.hpp>
15
Aron Virginas-Tarc9cc8042018-11-01 16:15:57 +000016#include <HeapProfiling.hpp>
17#include <LeakChecking.hpp>
telsoa014fcda012018-03-09 14:13:49 +000018
19#ifdef WITH_VALGRIND
Aron Virginas-Tarc26ba752018-10-22 13:32:01 +010020#include <valgrind/memcheck.h>
telsoa014fcda012018-03-09 14:13:49 +000021#endif
22
Sadik Armagan1625efc2021-06-10 18:24:34 +010023#include <doctest/doctest.h>
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +000024#include "RuntimeTests.hpp"
Sadik Armagana097d2a2021-11-24 15:47:28 +000025#include <TestUtils.hpp>
Aron Virginas-Tarc26ba752018-10-22 13:32:01 +010026
telsoa014fcda012018-03-09 14:13:49 +000027namespace armnn
28{
29
Kevin Mayd92a6e42021-02-04 10:27:41 +000030void RuntimeLoadedNetworksReserve(armnn::RuntimeImpl* runtime)
telsoa014fcda012018-03-09 14:13:49 +000031{
32 runtime->m_LoadedNetworks.reserve(1);
33}
34
35}
36
Sadik Armagan1625efc2021-06-10 18:24:34 +010037TEST_SUITE("Runtime")
38{
39TEST_CASE("RuntimeUnloadNetwork")
telsoa014fcda012018-03-09 14:13:49 +000040{
41 // build 2 mock-networks and load them into the runtime
telsoa01c577f2c2018-08-31 09:22:23 +010042 armnn::IRuntime::CreationOptions options;
Keith Davis97da5e22020-03-05 16:25:28 +000043 armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options));
telsoa014fcda012018-03-09 14:13:49 +000044
telsoa01c577f2c2018-08-31 09:22:23 +010045 // Mock network 1.
Keith Davis97da5e22020-03-05 16:25:28 +000046 armnn::NetworkId networkIdentifier1 = 1;
telsoa014fcda012018-03-09 14:13:49 +000047 armnn::INetworkPtr mockNetwork1(armnn::INetwork::Create());
48 mockNetwork1->AddInputLayer(0, "test layer");
Keith Davis97da5e22020-03-05 16:25:28 +000049 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
telsoa01c577f2c2018-08-31 09:22:23 +010050 runtime->LoadNetwork(networkIdentifier1, Optimize(*mockNetwork1, backends, runtime->GetDeviceSpec()));
telsoa014fcda012018-03-09 14:13:49 +000051
telsoa01c577f2c2018-08-31 09:22:23 +010052 // Mock network 2.
Keith Davis97da5e22020-03-05 16:25:28 +000053 armnn::NetworkId networkIdentifier2 = 2;
telsoa014fcda012018-03-09 14:13:49 +000054 armnn::INetworkPtr mockNetwork2(armnn::INetwork::Create());
55 mockNetwork2->AddInputLayer(0, "test layer");
telsoa01c577f2c2018-08-31 09:22:23 +010056 runtime->LoadNetwork(networkIdentifier2, Optimize(*mockNetwork2, backends, runtime->GetDeviceSpec()));
telsoa014fcda012018-03-09 14:13:49 +000057
telsoa01c577f2c2018-08-31 09:22:23 +010058 // Unloads one by its networkID.
Sadik Armagan1625efc2021-06-10 18:24:34 +010059 CHECK(runtime->UnloadNetwork(networkIdentifier1) == armnn::Status::Success);
telsoa014fcda012018-03-09 14:13:49 +000060
Sadik Armagan1625efc2021-06-10 18:24:34 +010061 CHECK(runtime->UnloadNetwork(networkIdentifier1) == armnn::Status::Failure);
telsoa014fcda012018-03-09 14:13:49 +000062}
63
Finn Williamsf37b9702021-09-01 18:06:04 +010064TEST_CASE("RuntimePreImportInputs")
65{
66 armnn::IRuntime::CreationOptions options;
Finn Williams8636bc72021-10-02 15:06:39 +010067 armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options));
68 armnn::NetworkId networkId = 1;
Finn Williamsf37b9702021-09-01 18:06:04 +010069 armnn::INetworkPtr testNetwork(armnn::INetwork::Create());
Finn Williams8636bc72021-10-02 15:06:39 +010070
Finn Williamsf37b9702021-09-01 18:06:04 +010071 auto inputLayer1 = testNetwork->AddInputLayer(0, "input 1 layer");
72 auto inputLayer2 = testNetwork->AddInputLayer(1, "input 2 layer");
73 auto addLayer = testNetwork->AddAdditionLayer("add layer");
74 auto outputLayer = testNetwork->AddOutputLayer(2, "output layer");
75
76 TensorInfo tensorInfo{{4}, armnn::DataType::Signed32};
77
78 inputLayer1->GetOutputSlot(0).Connect(addLayer->GetInputSlot(0));
79 inputLayer1->GetOutputSlot(0).SetTensorInfo(tensorInfo);
Finn Williams8636bc72021-10-02 15:06:39 +010080
Finn Williamsf37b9702021-09-01 18:06:04 +010081 inputLayer2->GetOutputSlot(0).Connect(addLayer->GetInputSlot(1));
82 inputLayer2->GetOutputSlot(0).SetTensorInfo(tensorInfo);
83
84 addLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0));
85 addLayer->GetOutputSlot(0).SetTensorInfo(tensorInfo);
86
Finn Williams8636bc72021-10-02 15:06:39 +010087 std::vector<armnn::BackendId> backends = {armnn::Compute::CpuRef};
Finn Williamsf37b9702021-09-01 18:06:04 +010088
89 std::string er;
90 armnn::INetworkProperties networkProperties(true, MemorySource::Malloc, MemorySource::Undefined);
Finn Williams8636bc72021-10-02 15:06:39 +010091 runtime->LoadNetwork(networkId,
Finn Williamsf37b9702021-09-01 18:06:04 +010092 Optimize(*testNetwork, backends, runtime->GetDeviceSpec()),
93 er,
94 networkProperties);
95
96 std::vector<int> inputData1(4, 10);
97 std::vector<int> inputData2(4, 20);
98 std::vector<int> output(4);
99
Cathal Corbett5b8093c2021-10-22 11:12:07 +0100100 ConstTensor inputTensor1({{4}, armnn::DataType::Signed32, 0.0f, 0, true}, inputData1.data());
101 ConstTensor inputTensor2({{4}, armnn::DataType::Signed32, 0.0f, 0, true}, inputData2.data());
Finn Williamsf37b9702021-09-01 18:06:04 +0100102 Tensor outputTensor({{4}, armnn::DataType::Signed32}, output.data());
103
Finn Williams8636bc72021-10-02 15:06:39 +0100104 auto importedInputVec1 = runtime->ImportInputs(networkId, {{0, inputTensor1}});
Finn Williamsf37b9702021-09-01 18:06:04 +0100105 CHECK(importedInputVec1.size() == 1);
106 CHECK(importedInputVec1[0] == 0);
107
Finn Williams8636bc72021-10-02 15:06:39 +0100108 auto memHandle = runtime->CreateWorkingMemHandle(networkId);
Finn Williamsf37b9702021-09-01 18:06:04 +0100109
110 runtime->Execute(*memHandle.get(), {{1, inputTensor2}}, {{2, outputTensor}}, {0 /* pre-imported id */});
Finn Williams8636bc72021-10-02 15:06:39 +0100111 for (auto val: output) {
Finn Williamsf37b9702021-09-01 18:06:04 +0100112 CHECK(val == 30);
113 }
114
Finn Williams8636bc72021-10-02 15:06:39 +0100115 auto importedInputVec2 = runtime->ImportInputs(networkId, {{1, inputTensor2}});
Finn Williamsf37b9702021-09-01 18:06:04 +0100116 CHECK(importedInputVec2.size() == 1);
117 CHECK(importedInputVec2[0] == 1);
118
119 runtime->Execute(*memHandle.get(), {{0, inputTensor1}}, {{2, outputTensor}}, {1 /* pre-imported id */});
Finn Williams8636bc72021-10-02 15:06:39 +0100120 for (auto val: output) {
Finn Williamsf37b9702021-09-01 18:06:04 +0100121 CHECK(val == 30);
122 }
123
124 runtime->Execute(*memHandle.get(), {}, {{2, outputTensor}}, {0, 1});
Finn Williams8636bc72021-10-02 15:06:39 +0100125 for (auto val: output) {
Finn Williamsf37b9702021-09-01 18:06:04 +0100126 CHECK(val == 30);
127 }
Finn Williamsf37b9702021-09-01 18:06:04 +0100128 // Duplicate ImportedInputId and LayerBindingId
Finn Williams8636bc72021-10-02 15:06:39 +0100129 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), {}, {{2, outputTensor}}, {0, 0});,
130 armnn::InvalidArgumentException);
Finn Williamsf37b9702021-09-01 18:06:04 +0100131 // Duplicate LayerBindingId
Finn Williams8636bc72021-10-02 15:06:39 +0100132 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), {{1, inputTensor2}}, {{2, outputTensor}}, {1});,
133 armnn::InvalidArgumentException);
Finn Williamsf37b9702021-09-01 18:06:04 +0100134 // Incorrect ImportedInputId
Finn Williams8636bc72021-10-02 15:06:39 +0100135 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), {{1, inputTensor2}}, {{2, outputTensor}}, {10});,
136 armnn::InvalidArgumentException);
Finn Williamsf37b9702021-09-01 18:06:04 +0100137 // Incorrect LayerBindingId
Finn Williams8636bc72021-10-02 15:06:39 +0100138 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), {{-2, inputTensor2}}, {{2, outputTensor}}, {1});,
139 armnn::InvalidArgumentException);
Finn Williamsf37b9702021-09-01 18:06:04 +0100140 // Incorrect layer binding id and ImportedInputId
Finn Williams8636bc72021-10-02 15:06:39 +0100141 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), {{-2, inputTensor2}}, {{2, outputTensor}}, {10});,
142 armnn::InvalidArgumentException);
143 auto importedInputVec3 = runtime->ImportInputs(networkId, {{1, inputTensor2}});
Finn Williamsf37b9702021-09-01 18:06:04 +0100144 CHECK(importedInputVec3[0] == 2);
145 // Too many ImportedInputIds
Finn Williams8636bc72021-10-02 15:06:39 +0100146 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), {}, {{2, outputTensor}}, {0, 1, 2});,
147 armnn::InvalidArgumentException);
Finn Williamsf37b9702021-09-01 18:06:04 +0100148 // Too many InputTensors
149 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(),
Finn Williams8636bc72021-10-02 15:06:39 +0100150 {{0, inputTensor2},
151 {1, inputTensor2},
152 {2, inputTensor2}},
153 {{2, outputTensor}});, armnn::InvalidArgumentException);
Finn Williamsf37b9702021-09-01 18:06:04 +0100154 // Too few ImportedInputIds
Finn Williams8636bc72021-10-02 15:06:39 +0100155 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), {}, {{2, outputTensor}}, {0});,
156 armnn::InvalidArgumentException);
157 runtime->ClearImportedInputs(networkId, {1});
158 runtime->Execute(*memHandle.get(), {{1, inputTensor2}}, {{2, outputTensor}}, {0}, {});
159 for (auto val: output) {
160 CHECK(val == 30);
161 }
162 // Using deleted pre-imported input
163 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), {}, {{2, outputTensor}}, {0, 1}, {});,
164 armnn::InvalidArgumentException);
165
166 // Trying to delete deleted pre-imported tensor
167 CHECK_THROWS_AS(runtime->ClearImportedInputs(networkId, {1});, armnn::InvalidArgumentException);
168
169 // Trying to delete unknown pre-imported tensor
170 CHECK_THROWS_AS(runtime->ClearImportedInputs(networkId, {10});, armnn::InvalidArgumentException);
171}
172TEST_CASE("RuntimePreImportOutputs")
173{
174 armnn::IRuntime::CreationOptions options;
175 armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options));
176
177 armnn::NetworkId networkId = 1;
178
179 armnn::INetworkPtr testNetwork(armnn::INetwork::Create());
Cathal Corbett5b8093c2021-10-22 11:12:07 +0100180 TensorInfo tensorInfo{{4}, armnn::DataType::Float32, 0.0f, 0, true};
Finn Williams8636bc72021-10-02 15:06:39 +0100181
182 auto inputLayer1 = testNetwork->AddInputLayer(0, "input 1 layer");
183 inputLayer1->GetOutputSlot(0).SetTensorInfo(tensorInfo);
184
185 ActivationDescriptor activationDescriptor;
186 activationDescriptor.m_Function = ActivationFunction::BoundedReLu;
187 activationDescriptor.m_A = 2.0f;
188 activationDescriptor.m_B = 0.0f;
189 auto activationLayer1 = testNetwork->AddActivationLayer(activationDescriptor, "add layer");
190 auto outputLayer1 = testNetwork->AddOutputLayer(2, "output layer");
191
192 inputLayer1->GetOutputSlot(0).Connect(activationLayer1->GetInputSlot(0));
193
194 activationLayer1->GetOutputSlot(0).Connect(outputLayer1->GetInputSlot(0));
195 activationLayer1->GetOutputSlot(0).SetTensorInfo(tensorInfo);
196
197 auto inputLayer2 = testNetwork->AddInputLayer(1, "input 1 layer");
198
199 activationDescriptor.m_A = 4.0f;
200 activationDescriptor.m_B = 2.0f;
201 auto activationLayer2 = testNetwork->AddActivationLayer(activationDescriptor, "add layer");
202 auto outputLayer2 = testNetwork->AddOutputLayer(3, "output layer");
203
204 inputLayer2->GetOutputSlot(0).Connect(activationLayer2->GetInputSlot(0));
205 inputLayer2->GetOutputSlot(0).SetTensorInfo(tensorInfo);
206
207 activationLayer2->GetOutputSlot(0).Connect(outputLayer2->GetInputSlot(0));
208 activationLayer2->GetOutputSlot(0).SetTensorInfo(tensorInfo);
209
210 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
211
212 std::string er;
213 armnn::INetworkProperties networkProperties(true, MemorySource::Malloc, MemorySource::Malloc);
214 runtime->LoadNetwork(networkId,
215 Optimize(*testNetwork, backends, runtime->GetDeviceSpec()),
216 er,
217 networkProperties);
218
219 std::vector<float> inputData1(4, 1.0f);
220 std::vector<float> inputData2(4, 3.0f);
221
222 std::vector<float> outputData1(4);
223 std::vector<float> outputData2(4);
224
225 ConstTensor inputTensor1(tensorInfo, inputData1.data());
226 ConstTensor inputTensor2(tensorInfo, inputData2.data());
227
228 Tensor outputTensor1{tensorInfo, outputData1.data()};
229 Tensor outputTensor2{tensorInfo, outputData2.data()};
230
231 InputTensors inputTensors = {{0, inputTensor1}, {1, inputTensor2}};
232
233 std::pair<LayerBindingId, class Tensor> output1{2, outputTensor1};
234 std::pair<LayerBindingId, class Tensor> output2{3, outputTensor2};
235
236 auto testOutputs = [&]()
237 {
238 for (auto val : outputData1)
239 {
240 CHECK(val == 1.0f);
241 }
242
243 for (auto val : outputData2)
244 {
245 CHECK(val == 3.0f);
246 }
247 };
248
249 auto memHandle = runtime->CreateWorkingMemHandle(networkId);
250
251 runtime->Execute(*memHandle.get(),inputTensors, {output1, output2});
252 testOutputs();
253
254 auto importedOutputVec = runtime->ImportOutputs(networkId, {output1, output2 });
255 CHECK(importedOutputVec.size() == 2);
256 CHECK(importedOutputVec[0] == 0);
257 CHECK(importedOutputVec[1] == 1);
258
259 runtime->Execute(*memHandle.get(), inputTensors, {}, {}, importedOutputVec);
260 testOutputs();
261
262 runtime->Execute(*memHandle.get(), inputTensors, {output1}, {}, {1});
263 testOutputs();
264
265 runtime->Execute(*memHandle.get(), inputTensors, {output2}, {}, {0});
266 testOutputs();
267
268 auto importedInputVec = runtime->ImportInputs(networkId, inputTensors);
269 CHECK(importedInputVec.size() == 2);
270 CHECK(importedInputVec[0] == 0);
271 CHECK(importedInputVec[1] == 1);
272
273 runtime->Execute(*memHandle.get(), {}, {}, importedInputVec, importedOutputVec);
274 testOutputs();
275
276 runtime->Execute(*memHandle.get(), {{0, inputTensor1}}, {output2}, {1}, {0});
277 testOutputs();
278
279 // Too many ids
280 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), inputTensors, {output1, output2}, {}, {0, 1});,
281 armnn::InvalidArgumentException);
282
283 // Duplicate ids
284 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), inputTensors, {output2}, {}, {1});,
285 armnn::InvalidArgumentException);
286
287 // Duplicate ids
288 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), inputTensors, {output1, output1}, {}, {});,
289 armnn::InvalidArgumentException);
290
291 // Duplicate ids
292 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), inputTensors, {}, {}, {0, 0}),
293 armnn::InvalidArgumentException);
294
295 // Unknown id
296 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), inputTensors, {output1}, {}, {3});,
297 armnn::InvalidArgumentException);
298
299 // Unknown id
300 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), inputTensors, {{4, outputTensor2}}, {}, {1});,
301 armnn::InvalidArgumentException);
302
303 // Input id for output
304 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), inputTensors, {{0, outputTensor2}}, {}, {1});,
305 armnn::InvalidArgumentException);
306
307 // Input id for output
308 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), inputTensors, {{0, outputTensor2}}, {}, {1});,
309 armnn::InvalidArgumentException);
310
311 // Output id for input
312 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), {{2, inputTensor1}}, {{0, outputTensor2}}, {1}, {1, 0});,
313 armnn::InvalidArgumentException);
314
315 runtime->ClearImportedOutputs(networkId, {1});
316
317 runtime->Execute(*memHandle.get(), inputTensors, {output2}, {}, {0});
318 testOutputs();
319
320 // Trying to use deleted pre-imported tensor
321 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), inputTensors, {}, {}, importedOutputVec),
322 armnn::InvalidArgumentException);
323
324 // Trying to delete deleted pre-imported tensor
325 CHECK_THROWS_AS(runtime->ClearImportedOutputs(networkId, {1});, armnn::InvalidArgumentException);
326
327 // Trying to delete unknown pre-imported tensor
328 CHECK_THROWS_AS(runtime->ClearImportedOutputs(networkId, {10});, armnn::InvalidArgumentException);
Finn Williamsf37b9702021-09-01 18:06:04 +0100329}
330
surmeh013537c2c2018-05-18 16:31:43 +0100331// Note: the current builds we don't do valgrind and gperftools based leak checking at the same
telsoa01c577f2c2018-08-31 09:22:23 +0100332// time, so in practice WITH_VALGRIND and ARMNN_LEAK_CHECKING_ENABLED are exclusive. The
333// valgrind tests can stay for x86 builds, but on hikey Valgrind is just way too slow
334// to be integrated into the CI system.
surmeh013537c2c2018-05-18 16:31:43 +0100335
telsoa01c577f2c2018-08-31 09:22:23 +0100336#ifdef ARMNN_LEAK_CHECKING_ENABLED
337
338struct DisableGlobalLeakChecking
339{
340 DisableGlobalLeakChecking()
341 {
342 ARMNN_LOCAL_LEAK_CHECKING_ONLY();
343 }
344};
345
Sadik Armagan1625efc2021-06-10 18:24:34 +0100346TEST_CASE_FIXTURE(DisableGlobalLeakChecking, "RuntimeHeapMemoryUsageSanityChecks")
surmeh013537c2c2018-05-18 16:31:43 +0100347{
Sadik Armagan1625efc2021-06-10 18:24:34 +0100348 CHECK(ARMNN_LEAK_CHECKER_IS_ACTIVE());
surmeh013537c2c2018-05-18 16:31:43 +0100349 {
350 ARMNN_SCOPED_LEAK_CHECKER("Sanity_Check_Outer");
351 {
352 ARMNN_SCOPED_LEAK_CHECKER("Sanity_Check_Inner");
Sadik Armagan1625efc2021-06-10 18:24:34 +0100353 CHECK(ARMNN_NO_LEAKS_IN_SCOPE() == true);
surmeh013537c2c2018-05-18 16:31:43 +0100354 std::unique_ptr<char[]> dummyAllocation(new char[1000]);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100355 // "A leak of 1000 bytes is expected here. "
356 // "Please make sure environment variable: HEAPCHECK=draconian is set!"
357 CHECK((ARMNN_NO_LEAKS_IN_SCOPE() == false));
358 CHECK(ARMNN_BYTES_LEAKED_IN_SCOPE() == 1000);
359 CHECK(ARMNN_OBJECTS_LEAKED_IN_SCOPE() == 1);
surmeh013537c2c2018-05-18 16:31:43 +0100360 }
Sadik Armagan1625efc2021-06-10 18:24:34 +0100361 CHECK(ARMNN_NO_LEAKS_IN_SCOPE());
362 CHECK(ARMNN_BYTES_LEAKED_IN_SCOPE() == 0);
363 CHECK(ARMNN_OBJECTS_LEAKED_IN_SCOPE() == 0);
surmeh013537c2c2018-05-18 16:31:43 +0100364 }
365}
366
surmeh013537c2c2018-05-18 16:31:43 +0100367#endif // ARMNN_LEAK_CHECKING_ENABLED
368
369// Note: this part of the code is due to be removed when we fully trust the gperftools based results.
telsoa014fcda012018-03-09 14:13:49 +0000370#ifdef WITH_VALGRIND
telsoa01c577f2c2018-08-31 09:22:23 +0100371// Run with the following command to get all the amazing output (in the devenv/build folder) :)
telsoa014fcda012018-03-09 14:13:49 +0000372// valgrind --leak-check=full --show-leak-kinds=all --log-file=Valgrind_Memcheck_Leak_Report.txt armnn/test/UnitTests
Sadik Armagan1625efc2021-06-10 18:24:34 +0100373TEST_CASE("RuntimeMemoryLeak")
telsoa014fcda012018-03-09 14:13:49 +0000374{
375 // From documentation:
376
377 // This means that no pointer to the block can be found. The block is classified as "lost",
378 // because the programmer could not possibly have freed it at program exit, since no pointer to it exists.
379 unsigned long leakedBefore = 0;
Keith Davis97da5e22020-03-05 16:25:28 +0000380 unsigned long leakedAfter = 0;
telsoa014fcda012018-03-09 14:13:49 +0000381
382 // A start-pointer or chain of start-pointers to the block is found. Since the block is still pointed at,
383 // the programmer could, at least in principle, have freed it before program exit.
telsoa01c577f2c2018-08-31 09:22:23 +0100384 // We want to test this in case memory is not freed as early as it could have been.
telsoa014fcda012018-03-09 14:13:49 +0000385 unsigned long reachableBefore = 0;
Keith Davis97da5e22020-03-05 16:25:28 +0000386 unsigned long reachableAfter = 0;
telsoa014fcda012018-03-09 14:13:49 +0000387
telsoa01c577f2c2018-08-31 09:22:23 +0100388 // Needed as out params but we don't test them.
Keith Davis97da5e22020-03-05 16:25:28 +0000389 unsigned long dubious = 0;
telsoa014fcda012018-03-09 14:13:49 +0000390 unsigned long suppressed = 0;
391
392 armnn::NetworkId networkIdentifier1 = 1;
393
394 // ensure that runtime is large enough before checking for memory leaks
395 // otherwise when loading the network it will automatically reserve memory that won't be released until destruction
telsoa01c577f2c2018-08-31 09:22:23 +0100396 armnn::IRuntime::CreationOptions options;
Kevin Mayd92a6e42021-02-04 10:27:41 +0000397 armnn::RuntimeImpl runtime(options);
telsoa014fcda012018-03-09 14:13:49 +0000398 armnn::RuntimeLoadedNetworksReserve(&runtime);
399
telsoa014fcda012018-03-09 14:13:49 +0000400 {
Keith Davis97da5e22020-03-05 16:25:28 +0000401 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
telsoa014fcda012018-03-09 14:13:49 +0000402
Francis Murtagh3d2b4b22021-02-15 18:23:17 +0000403 armnn::INetworkPtr mockNetwork1(armnn::INetwork::Create());
telsoa014fcda012018-03-09 14:13:49 +0000404 mockNetwork1->AddInputLayer(0, "test layer");
405
Matteo Martincigh9326aab2018-11-15 10:54:54 +0000406 // Warm-up load/unload pair to put the runtime in a stable state (memory-wise).
telsoa01c577f2c2018-08-31 09:22:23 +0100407 runtime.LoadNetwork(networkIdentifier1, Optimize(*mockNetwork1, backends, runtime.GetDeviceSpec()));
Matteo Martincigh9326aab2018-11-15 10:54:54 +0000408 runtime.UnloadNetwork(networkIdentifier1);
409
410 // Checks for leaks before we load the network and record them so that we can see the delta after unloading.
411 VALGRIND_DO_QUICK_LEAK_CHECK;
412 VALGRIND_COUNT_LEAKS(leakedBefore, dubious, reachableBefore, suppressed);
413
414 // The actual test.
415 runtime.LoadNetwork(networkIdentifier1, Optimize(*mockNetwork1, backends, runtime.GetDeviceSpec()));
416 runtime.UnloadNetwork(networkIdentifier1);
417
418 VALGRIND_DO_ADDED_LEAK_CHECK;
419 VALGRIND_COUNT_LEAKS(leakedAfter, dubious, reachableAfter, suppressed);
telsoa014fcda012018-03-09 14:13:49 +0000420 }
421
telsoa01c577f2c2018-08-31 09:22:23 +0100422 // If we're not running under Valgrind, these vars will have been initialised to 0, so this will always pass.
Sadik Armagan1625efc2021-06-10 18:24:34 +0100423 CHECK(leakedBefore == leakedAfter);
424 CHECK(reachableBefore == reachableAfter);
telsoa014fcda012018-03-09 14:13:49 +0000425
telsoa01c577f2c2018-08-31 09:22:23 +0100426 // These are needed because VALGRIND_COUNT_LEAKS is a macro that assigns to the parameters
427 // so they are assigned to, but still considered unused, causing a warning.
Jan Eilers8eb25602020-03-09 12:13:48 +0000428 IgnoreUnused(dubious);
429 IgnoreUnused(suppressed);
telsoa014fcda012018-03-09 14:13:49 +0000430}
Aron Virginas-Tarc26ba752018-10-22 13:32:01 +0100431#endif // WITH_VALGRIND
telsoa01c577f2c2018-08-31 09:22:23 +0100432
Sadik Armagan1625efc2021-06-10 18:24:34 +0100433TEST_CASE("RuntimeCpuRef")
telsoa01c577f2c2018-08-31 09:22:23 +0100434{
435 using namespace armnn;
436
437 // Create runtime in which test will run
438 armnn::IRuntime::CreationOptions options;
Keith Davis97da5e22020-03-05 16:25:28 +0000439 armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options));
telsoa01c577f2c2018-08-31 09:22:23 +0100440
441 // build up the structure of the network
442 INetworkPtr net(INetwork::Create());
443
444 IConnectableLayer* input = net->AddInputLayer(0);
445
446 // This layer configuration isn't supported by CpuAcc, should be fall back to CpuRef.
447 NormalizationDescriptor descriptor;
448 IConnectableLayer* normalize = net->AddNormalizationLayer(descriptor);
449
450 IConnectableLayer* output = net->AddOutputLayer(0);
451
452 input->GetOutputSlot(0).Connect(normalize->GetInputSlot(0));
453 normalize->GetOutputSlot(0).Connect(output->GetInputSlot(0));
454
455 input->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
456 normalize->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
457
458 // optimize the network
David Beckf0b48452018-10-19 15:20:56 +0100459 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
Keith Davis97da5e22020-03-05 16:25:28 +0000460 IOptimizedNetworkPtr optNet = Optimize(*net, backends, runtime->GetDeviceSpec());
telsoa01c577f2c2018-08-31 09:22:23 +0100461
462 // Load it into the runtime. It should success.
463 armnn::NetworkId netId;
Sadik Armagan1625efc2021-06-10 18:24:34 +0100464 CHECK(runtime->LoadNetwork(netId, std::move(optNet)) == Status::Success);
telsoa01c577f2c2018-08-31 09:22:23 +0100465}
466
Sadik Armagan1625efc2021-06-10 18:24:34 +0100467TEST_CASE("RuntimeFallbackToCpuRef")
telsoa01c577f2c2018-08-31 09:22:23 +0100468{
469 using namespace armnn;
470
471 // Create runtime in which test will run
472 armnn::IRuntime::CreationOptions options;
Keith Davis97da5e22020-03-05 16:25:28 +0000473 armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options));
telsoa01c577f2c2018-08-31 09:22:23 +0100474
475 // build up the structure of the network
476 INetworkPtr net(INetwork::Create());
477
478 IConnectableLayer* input = net->AddInputLayer(0);
479
480 // This layer configuration isn't supported by CpuAcc, should be fall back to CpuRef.
481 NormalizationDescriptor descriptor;
482 IConnectableLayer* normalize = net->AddNormalizationLayer(descriptor);
483
484 IConnectableLayer* output = net->AddOutputLayer(0);
485
486 input->GetOutputSlot(0).Connect(normalize->GetInputSlot(0));
487 normalize->GetOutputSlot(0).Connect(output->GetInputSlot(0));
488
489 input->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
490 normalize->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
491
492 // Allow fallback to CpuRef.
David Beckf0b48452018-10-19 15:20:56 +0100493 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc, armnn::Compute::CpuRef };
telsoa01c577f2c2018-08-31 09:22:23 +0100494 // optimize the network
Keith Davis97da5e22020-03-05 16:25:28 +0000495 IOptimizedNetworkPtr optNet = Optimize(*net, backends, runtime->GetDeviceSpec());
telsoa01c577f2c2018-08-31 09:22:23 +0100496
497 // Load it into the runtime. It should succeed.
498 armnn::NetworkId netId;
Sadik Armagan1625efc2021-06-10 18:24:34 +0100499 CHECK(runtime->LoadNetwork(netId, std::move(optNet)) == Status::Success);
telsoa01c577f2c2018-08-31 09:22:23 +0100500}
501
Sadik Armagan1625efc2021-06-10 18:24:34 +0100502TEST_CASE("IVGCVSW_1929_QuantizedSoftmaxIssue")
jimfly016b0b53d2018-10-08 14:43:01 +0100503{
504 // Test for issue reported by Chris Nix in https://jira.arm.com/browse/IVGCVSW-1929
505 using namespace armnn;
506
507 // Create runtime in which test will run
508 armnn::IRuntime::CreationOptions options;
Keith Davis97da5e22020-03-05 16:25:28 +0000509 armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options));
jimfly016b0b53d2018-10-08 14:43:01 +0100510
511 // build up the structure of the network
512 INetworkPtr net(INetwork::Create());
Keith Davis97da5e22020-03-05 16:25:28 +0000513 armnn::IConnectableLayer* input = net->AddInputLayer(0,"input");
514 armnn::IConnectableLayer* softmax = net->AddSoftmaxLayer(armnn::SoftmaxDescriptor(), "softmax");
515 armnn::IConnectableLayer* output = net->AddOutputLayer(0, "output");
jimfly016b0b53d2018-10-08 14:43:01 +0100516
517 input->GetOutputSlot(0).Connect(softmax->GetInputSlot(0));
518 softmax->GetOutputSlot(0).Connect(output->GetInputSlot(0));
519
Keith Davis97da5e22020-03-05 16:25:28 +0000520 input->GetOutputSlot(0).SetTensorInfo(armnn::TensorInfo(armnn::TensorShape({ 1, 5 }),
521 armnn::DataType::QAsymmU8,
522 1.0f / 255,
523 0));
jimfly016b0b53d2018-10-08 14:43:01 +0100524
Keith Davis97da5e22020-03-05 16:25:28 +0000525 softmax->GetOutputSlot(0).SetTensorInfo(armnn::TensorInfo(armnn::TensorShape({ 1, 5 }),
526 armnn::DataType::QAsymmU8));
jimfly016b0b53d2018-10-08 14:43:01 +0100527
Keith Davis97da5e22020-03-05 16:25:28 +0000528 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
529 std::vector<std::string> errMessages;
Mike Kelly3a613cc2020-09-29 20:50:35 +0100530
531 try
532 {
533 armnn::IOptimizedNetworkPtr optNet = Optimize(*net,
Keith Davis97da5e22020-03-05 16:25:28 +0000534 backends,
535 runtime->GetDeviceSpec(),
536 OptimizerOptions(),
537 errMessages);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100538 FAIL("An exception should have been thrown");
Mike Kelly3a613cc2020-09-29 20:50:35 +0100539 }
Rob Hughesc013bc82021-07-14 09:31:31 +0100540 catch (const InvalidArgumentException&)
Mike Kelly3a613cc2020-09-29 20:50:35 +0100541 {
542 // Different exceptions are thrown on different backends
543 }
Sadik Armagan1625efc2021-06-10 18:24:34 +0100544 CHECK(errMessages.size() > 0);
jimfly016b0b53d2018-10-08 14:43:01 +0100545}
546
Sadik Armagan1625efc2021-06-10 18:24:34 +0100547TEST_CASE("RuntimeBackendOptions")
Derek Lamberti836b27b2019-11-20 10:51:57 +0000548{
549 using namespace armnn;
550
551 IRuntime::CreationOptions creationOptions;
552 auto& backendOptions = creationOptions.m_BackendOptions;
553
554
555 // Define Options on explicit construction
556 BackendOptions options1("FakeBackend1",
Keith Davis97da5e22020-03-05 16:25:28 +0000557 {
558 { "Option1", 1.3f },
559 { "Option2", true }
560 });
Derek Lamberti836b27b2019-11-20 10:51:57 +0000561
562 // Add an option after construction
Keith Davis97da5e22020-03-05 16:25:28 +0000563 options1.AddOption({ "Option3", "some_value" });
Derek Lamberti836b27b2019-11-20 10:51:57 +0000564
565 // Add the options to CreationOptions struct
566 backendOptions.push_back(options1);
567
568 // Add more Options via inplace explicit construction
Keith Davis97da5e22020-03-05 16:25:28 +0000569 backendOptions.emplace_back(BackendOptions{ "FakeBackend1",
570 {{ "Option4", 42 }}
571 });
Derek Lamberti836b27b2019-11-20 10:51:57 +0000572
573
574 // First group
Sadik Armagan1625efc2021-06-10 18:24:34 +0100575 CHECK(backendOptions[0].GetBackendId().Get() == "FakeBackend1");
576 CHECK(backendOptions[0].GetOption(0).GetName() == "Option1");
577 CHECK(backendOptions[0].GetOption(0).GetValue().IsFloat() == true);
578 CHECK(backendOptions[0].GetOption(0).GetValue().AsFloat() == 1.3f);
Derek Lamberti836b27b2019-11-20 10:51:57 +0000579
Sadik Armagan1625efc2021-06-10 18:24:34 +0100580 CHECK(backendOptions[0].GetOption(1).GetName() == "Option2");
581 CHECK(backendOptions[0].GetOption(1).GetValue().IsBool() == true);
582 CHECK(backendOptions[0].GetOption(1).GetValue().AsBool() == true);
Derek Lamberti836b27b2019-11-20 10:51:57 +0000583
Sadik Armagan1625efc2021-06-10 18:24:34 +0100584 CHECK(backendOptions[0].GetOption(2).GetName() == "Option3");
585 CHECK(backendOptions[0].GetOption(2).GetValue().IsString() == true);
586 CHECK(backendOptions[0].GetOption(2).GetValue().AsString() == "some_value");
Derek Lamberti836b27b2019-11-20 10:51:57 +0000587
588 // Second group
Sadik Armagan1625efc2021-06-10 18:24:34 +0100589 CHECK(backendOptions[1].GetBackendId().Get() == "FakeBackend1");
590 CHECK(backendOptions[1].GetOption(0).GetName() == "Option4");
591 CHECK(backendOptions[1].GetOption(0).GetValue().IsInt() == true);
592 CHECK(backendOptions[1].GetOption(0).GetValue().AsInt() == 42);
Derek Lamberti836b27b2019-11-20 10:51:57 +0000593}
594
Sadik Armagan1625efc2021-06-10 18:24:34 +0100595TEST_CASE("ProfilingDisable")
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000596{
597 using namespace armnn;
598
599 // Create runtime in which the test will run
600 armnn::IRuntime::CreationOptions options;
Kevin Mayd92a6e42021-02-04 10:27:41 +0000601 armnn::RuntimeImpl runtime(options);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000602
603 // build up the structure of the network
604 INetworkPtr net(INetwork::Create());
605
606 IConnectableLayer* input = net->AddInputLayer(0);
607
608 // This layer configuration isn't supported by CpuAcc, should fall back to CpuRef.
609 NormalizationDescriptor descriptor;
610 IConnectableLayer* normalize = net->AddNormalizationLayer(descriptor);
611
612 IConnectableLayer* output = net->AddOutputLayer(0);
613
614 input->GetOutputSlot(0).Connect(normalize->GetInputSlot(0));
615 normalize->GetOutputSlot(0).Connect(output->GetInputSlot(0));
616
617 input->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
618 normalize->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
619
620 // optimize the network
621 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
Sadik Armagan3184c902020-03-18 10:57:30 +0000622 IOptimizedNetworkPtr optNet = Optimize(*net, backends, runtime.GetDeviceSpec());
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000623
624 // Load it into the runtime. It should succeed.
625 armnn::NetworkId netId;
Sadik Armagan1625efc2021-06-10 18:24:34 +0100626 CHECK(runtime.LoadNetwork(netId, std::move(optNet)) == Status::Success);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000627
Sadik Armagan3184c902020-03-18 10:57:30 +0000628 profiling::ProfilingServiceRuntimeHelper profilingServiceHelper(GetProfilingService(&runtime));
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000629 profiling::BufferManager& bufferManager = profilingServiceHelper.GetProfilingBufferManager();
630 auto readableBuffer = bufferManager.GetReadableBuffer();
631
632 // Profiling is not enabled, the post-optimisation structure should not be created
Sadik Armagan1625efc2021-06-10 18:24:34 +0100633 CHECK(!readableBuffer);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000634}
635
Sadik Armagan1625efc2021-06-10 18:24:34 +0100636TEST_CASE("ProfilingEnableCpuRef")
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000637{
638 using namespace armnn;
639 using namespace armnn::profiling;
640
641 // Create runtime in which the test will run
642 armnn::IRuntime::CreationOptions options;
643 options.m_ProfilingOptions.m_EnableProfiling = true;
Keith Davis33ed2212020-03-30 10:43:41 +0100644 options.m_ProfilingOptions.m_TimelineEnabled = true;
645
Kevin Mayd92a6e42021-02-04 10:27:41 +0000646 armnn::RuntimeImpl runtime(options);
Keith Davis33ed2212020-03-30 10:43:41 +0100647 GetProfilingService(&runtime).ResetExternalProfilingOptions(options.m_ProfilingOptions, false);
648
649 profiling::ProfilingServiceRuntimeHelper profilingServiceHelper(GetProfilingService(&runtime));
650 profilingServiceHelper.ForceTransitionToState(ProfilingState::NotConnected);
651 profilingServiceHelper.ForceTransitionToState(ProfilingState::WaitingForAck);
652 profilingServiceHelper.ForceTransitionToState(ProfilingState::Active);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000653
654 // build up the structure of the network
655 INetworkPtr net(INetwork::Create());
656
657 IConnectableLayer* input = net->AddInputLayer(0, "input");
658
659 NormalizationDescriptor descriptor;
660 IConnectableLayer* normalize = net->AddNormalizationLayer(descriptor, "normalization");
661
662 IConnectableLayer* output = net->AddOutputLayer(0, "output");
663
664 input->GetOutputSlot(0).Connect(normalize->GetInputSlot(0));
665 normalize->GetOutputSlot(0).Connect(output->GetInputSlot(0));
666
667 input->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
668 normalize->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
669
670 // optimize the network
671 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
Sadik Armagan3184c902020-03-18 10:57:30 +0000672 IOptimizedNetworkPtr optNet = Optimize(*net, backends, runtime.GetDeviceSpec());
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000673
674 ProfilingGuid optNetGuid = optNet->GetGuid();
675
676 // Load it into the runtime. It should succeed.
677 armnn::NetworkId netId;
Sadik Armagan1625efc2021-06-10 18:24:34 +0100678 CHECK(runtime.LoadNetwork(netId, std::move(optNet)) == Status::Success);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000679
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000680 profiling::BufferManager& bufferManager = profilingServiceHelper.GetProfilingBufferManager();
681 auto readableBuffer = bufferManager.GetReadableBuffer();
682
683 // Profiling is enabled, the post-optimisation structure should be created
Sadik Armagan1625efc2021-06-10 18:24:34 +0100684 CHECK(readableBuffer != nullptr);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000685
686 unsigned int size = readableBuffer->GetSize();
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000687
688 const unsigned char* readableData = readableBuffer->GetReadableData();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100689 CHECK(readableData != nullptr);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000690
691 unsigned int offset = 0;
692
Keith Davis97da5e22020-03-05 16:25:28 +0000693 // Verify Header
Jim Flynnf7713212020-07-14 09:50:59 +0100694 VerifyTimelineHeaderBinary(readableData, offset, size - 8);
Keith Davis97da5e22020-03-05 16:25:28 +0000695
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000696 // Post-optimisation network
697 // Network entity
Jim Flynn6398a982020-05-27 17:05:21 +0100698 VerifyTimelineEntityBinaryPacketData(optNetGuid, readableData, offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000699
700 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000701 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
702 EmptyOptional(),
703 optNetGuid,
704 LabelsAndEventClasses::NETWORK_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000705 LabelsAndEventClasses::TYPE_GUID,
706 readableData,
707 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000708
Jim Flynnf7713212020-07-14 09:50:59 +0100709 // Network - START OF LIFE
710 ProfilingGuid networkSolEventGuid = VerifyTimelineEventBinaryPacket(EmptyOptional(),
711 EmptyOptional(),
712 EmptyOptional(),
713 readableData,
714 offset);
Jim Flynnf7713212020-07-14 09:50:59 +0100715
716 // Network - START OF LIFE event relationship
717 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
718 EmptyOptional(),
719 optNetGuid,
720 networkSolEventGuid,
721 LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS,
722 readableData,
723 offset);
Jim Flynnf7713212020-07-14 09:50:59 +0100724
725 // Process ID Label
726 int processID = armnnUtils::Processes::GetCurrentId();
727 std::stringstream ss;
728 ss << processID;
729 std::string processIdLabel = ss.str();
730 VerifyTimelineLabelBinaryPacketData(EmptyOptional(), processIdLabel, readableData, offset);
Jim Flynnf7713212020-07-14 09:50:59 +0100731
732 // Entity - Process ID relationship
733 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
734 EmptyOptional(),
735 optNetGuid,
736 EmptyOptional(),
737 LabelsAndEventClasses::PROCESS_ID_GUID,
738 readableData,
739 offset);
Jim Flynnf7713212020-07-14 09:50:59 +0100740
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000741 // Input layer
742 // Input layer entity
Keith Davis97da5e22020-03-05 16:25:28 +0000743 VerifyTimelineEntityBinaryPacketData(input->GetGuid(), readableData, offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000744
745 // Name Entity
Jim Flynn6398a982020-05-27 17:05:21 +0100746 ProfilingGuid inputLabelGuid = VerifyTimelineLabelBinaryPacketData(EmptyOptional(), "input", readableData, offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000747
748 // Entity - Name relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000749 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
750 EmptyOptional(),
751 input->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100752 inputLabelGuid,
Keith Davis97da5e22020-03-05 16:25:28 +0000753 LabelsAndEventClasses::NAME_GUID,
754 readableData,
755 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000756
757 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000758 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
759 EmptyOptional(),
760 input->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100761 LabelsAndEventClasses::LAYER_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000762 LabelsAndEventClasses::TYPE_GUID,
763 readableData,
764 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000765
766 // Network - Input layer relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000767 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
768 EmptyOptional(),
769 optNetGuid,
770 input->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100771 LabelsAndEventClasses::CHILD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000772 readableData,
773 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000774
775 // Normalization layer
776 // Normalization layer entity
Keith Davis97da5e22020-03-05 16:25:28 +0000777 VerifyTimelineEntityBinaryPacketData(normalize->GetGuid(), readableData, offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000778
779 // Name entity
Jim Flynn6398a982020-05-27 17:05:21 +0100780 ProfilingGuid normalizationLayerNameGuid = VerifyTimelineLabelBinaryPacketData(
781 EmptyOptional(), "normalization", readableData, offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000782
783 // Entity - Name relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000784 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
785 EmptyOptional(),
786 normalize->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100787 normalizationLayerNameGuid,
Keith Davis97da5e22020-03-05 16:25:28 +0000788 LabelsAndEventClasses::NAME_GUID,
789 readableData,
790 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000791
792 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000793 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
794 EmptyOptional(),
795 normalize->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100796 LabelsAndEventClasses::LAYER_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000797 LabelsAndEventClasses::TYPE_GUID,
798 readableData,
799 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000800
801 // Network - Normalize layer relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000802 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
803 EmptyOptional(),
804 optNetGuid,
805 normalize->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100806 LabelsAndEventClasses::CHILD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000807 readableData,
808 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000809
810 // Input layer - Normalize layer relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000811 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
812 EmptyOptional(),
813 input->GetGuid(),
814 normalize->GetGuid(),
Keith Davis97da5e22020-03-05 16:25:28 +0000815 LabelsAndEventClasses::CONNECTION_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000816 readableData,
817 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000818
819 // Normalization workload
820 // Normalization workload entity
Jim Flynn6398a982020-05-27 17:05:21 +0100821 ProfilingGuid normalizationWorkloadGuid = VerifyTimelineEntityBinaryPacketData(
822 EmptyOptional(), readableData, offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000823
824 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000825 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
826 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +0100827 normalizationWorkloadGuid,
828 LabelsAndEventClasses::WORKLOAD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000829 LabelsAndEventClasses::TYPE_GUID,
830 readableData,
831 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000832
833 // BackendId entity
Jim Flynn6398a982020-05-27 17:05:21 +0100834 ProfilingGuid cpuRefLabelGuid = VerifyTimelineLabelBinaryPacketData(
835 EmptyOptional(), "CpuRef", readableData, offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000836
837 // Entity - BackendId relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000838 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
839 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +0100840 normalizationWorkloadGuid,
841 cpuRefLabelGuid,
Keith Davis97da5e22020-03-05 16:25:28 +0000842 LabelsAndEventClasses::BACKENDID_GUID,
843 readableData,
844 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000845
846 // Normalize layer - Normalize workload relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000847 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
848 EmptyOptional(),
849 normalize->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100850 normalizationWorkloadGuid,
851 LabelsAndEventClasses::CHILD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000852 readableData,
853 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000854
855 // Output layer
856 // Output layer entity
Keith Davis97da5e22020-03-05 16:25:28 +0000857 VerifyTimelineEntityBinaryPacketData(output->GetGuid(), readableData, offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000858
859 // Name entity
Jim Flynn6398a982020-05-27 17:05:21 +0100860 ProfilingGuid outputLabelGuid = VerifyTimelineLabelBinaryPacketData(
861 EmptyOptional(), "output", readableData, offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000862
863 // Entity - Name relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000864 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
865 EmptyOptional(),
866 output->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100867 outputLabelGuid,
Keith Davis97da5e22020-03-05 16:25:28 +0000868 LabelsAndEventClasses::NAME_GUID,
869 readableData,
870 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000871
872 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000873 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
874 EmptyOptional(),
875 output->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100876 LabelsAndEventClasses::LAYER_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000877 LabelsAndEventClasses::TYPE_GUID,
878 readableData,
879 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000880
881 // Network - Output layer relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000882 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
883 EmptyOptional(),
884 optNetGuid,
885 output->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100886 LabelsAndEventClasses::CHILD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000887 readableData,
888 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000889
890 // Normalize layer - Output layer relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000891 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
892 EmptyOptional(),
893 normalize->GetGuid(),
894 output->GetGuid(),
Keith Davis97da5e22020-03-05 16:25:28 +0000895 LabelsAndEventClasses::CONNECTION_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000896 readableData,
897 offset);
Derek Lamberti836b27b2019-11-20 10:51:57 +0000898
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000899 bufferManager.MarkRead(readableBuffer);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000900
901 // Creates structures for input & output.
902 std::vector<float> inputData(16);
903 std::vector<float> outputData(16);
904
Cathal Corbett5b8093c2021-10-22 11:12:07 +0100905 TensorInfo inputTensorInfo = runtime.GetInputTensorInfo(netId, 0);
906 inputTensorInfo.SetConstant(true);
Keith Davis97da5e22020-03-05 16:25:28 +0000907 InputTensors inputTensors
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000908 {
Cathal Corbett5b8093c2021-10-22 11:12:07 +0100909 {0, ConstTensor(inputTensorInfo, inputData.data())}
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000910 };
911 OutputTensors outputTensors
912 {
Sadik Armagan3184c902020-03-18 10:57:30 +0000913 {0, Tensor(runtime.GetOutputTensorInfo(netId, 0), outputData.data())}
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000914 };
915
916 // Does the inference.
Sadik Armagan3184c902020-03-18 10:57:30 +0000917 runtime.EnqueueWorkload(netId, inputTensors, outputTensors);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000918
Finn Williamsb6a402f2020-03-24 13:46:22 +0000919 // Get readable buffer for input workload
920 auto inputReadableBuffer = bufferManager.GetReadableBuffer();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100921 CHECK(inputReadableBuffer != nullptr);
David Monahan6198fe02019-12-02 08:35:43 +0000922
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000923 // Get readable buffer for output workload
924 auto outputReadableBuffer = bufferManager.GetReadableBuffer();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100925 CHECK(outputReadableBuffer != nullptr);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000926
Finn Williamsb6a402f2020-03-24 13:46:22 +0000927 // Get readable buffer for inference timeline
928 auto inferenceReadableBuffer = bufferManager.GetReadableBuffer();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100929 CHECK(inferenceReadableBuffer != nullptr);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000930
931 // Validate input workload data
932 size = inputReadableBuffer->GetSize();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100933 CHECK(size == 164);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000934
935 readableData = inputReadableBuffer->GetReadableData();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100936 CHECK(readableData != nullptr);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000937
938 offset = 0;
939
Keith Davis97da5e22020-03-05 16:25:28 +0000940 // Verify Header
Finn Williams0a336dc2020-05-11 15:39:58 +0100941 VerifyTimelineHeaderBinary(readableData, offset, 156);
Keith Davis97da5e22020-03-05 16:25:28 +0000942
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000943 // Input workload
944 // Input workload entity
Jim Flynn6398a982020-05-27 17:05:21 +0100945 ProfilingGuid inputWorkloadGuid = VerifyTimelineEntityBinaryPacketData(EmptyOptional(), readableData, offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000946
947 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000948 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
949 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +0100950 inputWorkloadGuid,
951 LabelsAndEventClasses::WORKLOAD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000952 LabelsAndEventClasses::TYPE_GUID,
953 readableData,
954 offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000955
956 // BackendId entity
Jim Flynn6398a982020-05-27 17:05:21 +0100957 ProfilingGuid CpuRefLabelGuid = VerifyTimelineLabelBinaryPacketData(
958 EmptyOptional(), "CpuRef", readableData, offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000959
960 // Entity - BackendId relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000961 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
962 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +0100963 inputWorkloadGuid,
964 CpuRefLabelGuid,
Keith Davis97da5e22020-03-05 16:25:28 +0000965 LabelsAndEventClasses::BACKENDID_GUID,
966 readableData,
967 offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000968
969 // Input layer - Input workload relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000970 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
971 EmptyOptional(),
972 input->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100973 inputWorkloadGuid,
974 LabelsAndEventClasses::CHILD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000975 readableData,
976 offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000977
978 bufferManager.MarkRead(inputReadableBuffer);
979
980 // Validate output workload data
981 size = outputReadableBuffer->GetSize();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100982 CHECK(size == 164);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000983
984 readableData = outputReadableBuffer->GetReadableData();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100985 CHECK(readableData != nullptr);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000986
987 offset = 0;
988
Keith Davis97da5e22020-03-05 16:25:28 +0000989 // Verify Header
Finn Williams0a336dc2020-05-11 15:39:58 +0100990 VerifyTimelineHeaderBinary(readableData, offset, 156);
Keith Davis97da5e22020-03-05 16:25:28 +0000991
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000992 // Output workload
993 // Output workload entity
Jim Flynn6398a982020-05-27 17:05:21 +0100994 ProfilingGuid outputWorkloadGuid = VerifyTimelineEntityBinaryPacketData(EmptyOptional(), readableData, offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000995
996 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000997 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
998 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +0100999 outputWorkloadGuid,
1000 LabelsAndEventClasses::WORKLOAD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001001 LabelsAndEventClasses::TYPE_GUID,
1002 readableData,
1003 offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +00001004
1005 // BackendId entity
Keith Davis97da5e22020-03-05 16:25:28 +00001006 VerifyTimelineLabelBinaryPacketData(EmptyOptional(), "CpuRef", readableData, offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +00001007
1008 // Entity - BackendId relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001009 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
1010 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001011 outputWorkloadGuid,
1012 CpuRefLabelGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001013 LabelsAndEventClasses::BACKENDID_GUID,
1014 readableData,
1015 offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +00001016
1017 // Output layer - Output workload relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001018 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
1019 EmptyOptional(),
1020 output->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +01001021 outputWorkloadGuid,
1022 LabelsAndEventClasses::CHILD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001023 readableData,
1024 offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +00001025
1026 bufferManager.MarkRead(outputReadableBuffer);
David Monahan6198fe02019-12-02 08:35:43 +00001027
1028 // Validate inference data
1029 size = inferenceReadableBuffer->GetSize();
Sadik Armagan1625efc2021-06-10 18:24:34 +01001030 CHECK(size == 976 + 8 * ThreadIdSize);
David Monahan6198fe02019-12-02 08:35:43 +00001031
1032 readableData = inferenceReadableBuffer->GetReadableData();
Sadik Armagan1625efc2021-06-10 18:24:34 +01001033 CHECK(readableData != nullptr);
David Monahan6198fe02019-12-02 08:35:43 +00001034
1035 offset = 0;
1036
Keith Davis97da5e22020-03-05 16:25:28 +00001037 // Verify Header
Finn Williams0a336dc2020-05-11 15:39:58 +01001038 VerifyTimelineHeaderBinary(readableData, offset, 968 + 8 * ThreadIdSize);
Keith Davis97da5e22020-03-05 16:25:28 +00001039
David Monahan6198fe02019-12-02 08:35:43 +00001040 // Inference timeline trace
1041 // Inference entity
Jim Flynn6398a982020-05-27 17:05:21 +01001042 ProfilingGuid inferenceGuid = VerifyTimelineEntityBinaryPacketData(EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001043
1044 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001045 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
1046 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001047 inferenceGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001048 LabelsAndEventClasses::INFERENCE_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001049 LabelsAndEventClasses::TYPE_GUID,
1050 readableData,
1051 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001052
1053 // Network - Inference relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001054 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
1055 EmptyOptional(),
1056 optNetGuid,
Jim Flynn6398a982020-05-27 17:05:21 +01001057 inferenceGuid,
1058 LabelsAndEventClasses::EXECUTION_OF_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001059 readableData,
1060 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001061
1062 // Start Inference life
1063 // Event packet - timeline, threadId, eventGuid
Jim Flynn6398a982020-05-27 17:05:21 +01001064 ProfilingGuid inferenceEventGuid = VerifyTimelineEventBinaryPacket(
1065 EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001066
1067 // Inference - event relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001068 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
1069 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001070 inferenceGuid,
1071 inferenceEventGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001072 LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS,
1073 readableData,
1074 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001075
1076 // Execution
1077 // Input workload execution
1078 // Input workload execution entity
Jim Flynn6398a982020-05-27 17:05:21 +01001079 ProfilingGuid inputWorkloadExecutionGuid = VerifyTimelineEntityBinaryPacketData(
1080 EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001081
1082 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001083 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
1084 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001085 inputWorkloadExecutionGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001086 LabelsAndEventClasses::WORKLOAD_EXECUTION_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001087 LabelsAndEventClasses::TYPE_GUID,
1088 readableData,
1089 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001090
1091 // Inference - Workload execution relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001092 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
1093 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001094 inferenceGuid,
1095 inputWorkloadExecutionGuid,
1096 LabelsAndEventClasses::CHILD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001097 readableData,
1098 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001099
1100 // Workload - Workload execution relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001101 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
1102 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001103 inputWorkloadGuid,
1104 inputWorkloadExecutionGuid,
1105 LabelsAndEventClasses::EXECUTION_OF_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001106 readableData,
1107 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001108
1109 // Start Input workload execution life
1110 // Event packet - timeline, threadId, eventGuid
Jim Flynn6398a982020-05-27 17:05:21 +01001111 ProfilingGuid inputWorkloadExecutionSOLEventId = VerifyTimelineEventBinaryPacket(
1112 EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001113
1114 // Input workload execution - event relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001115 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
1116 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001117 inputWorkloadExecutionGuid,
1118 inputWorkloadExecutionSOLEventId,
Keith Davis97da5e22020-03-05 16:25:28 +00001119 LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS,
1120 readableData,
1121 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001122
1123 // End of Input workload execution life
1124 // Event packet - timeline, threadId, eventGuid
Jim Flynn6398a982020-05-27 17:05:21 +01001125 ProfilingGuid inputWorkloadExecutionEOLEventId = VerifyTimelineEventBinaryPacket(
1126 EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001127
1128 // Input workload execution - event relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001129 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
1130 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001131 inputWorkloadExecutionGuid,
1132 inputWorkloadExecutionEOLEventId,
Keith Davis97da5e22020-03-05 16:25:28 +00001133 LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS,
1134 readableData,
1135 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001136
1137 // Normalize workload execution
1138 // Normalize workload execution entity
Jim Flynn6398a982020-05-27 17:05:21 +01001139 ProfilingGuid normalizeWorkloadExecutionGuid = VerifyTimelineEntityBinaryPacketData(
1140 EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001141
1142 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001143 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
1144 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001145 normalizeWorkloadExecutionGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001146 LabelsAndEventClasses::WORKLOAD_EXECUTION_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001147 LabelsAndEventClasses::TYPE_GUID,
1148 readableData,
1149 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001150
1151 // Inference - Workload execution relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001152 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
1153 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001154 inferenceGuid,
1155 normalizeWorkloadExecutionGuid,
1156 LabelsAndEventClasses::CHILD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001157 readableData,
1158 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001159
1160 // Workload - Workload execution relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001161 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
1162 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001163 normalizationWorkloadGuid,
1164 normalizeWorkloadExecutionGuid,
1165 LabelsAndEventClasses::EXECUTION_OF_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001166 readableData,
1167 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001168
1169 // Start Normalize workload execution life
1170 // Event packet - timeline, threadId, eventGuid
Jim Flynn6398a982020-05-27 17:05:21 +01001171 ProfilingGuid normalizationWorkloadExecutionSOLEventGuid = VerifyTimelineEventBinaryPacket(
1172 EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001173
1174 // Normalize workload execution - event relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001175 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
1176 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001177 normalizeWorkloadExecutionGuid,
1178 normalizationWorkloadExecutionSOLEventGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001179 LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS,
1180 readableData,
1181 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001182
1183 // End of Normalize workload execution life
1184 // Event packet - timeline, threadId, eventGuid
Jim Flynn6398a982020-05-27 17:05:21 +01001185 ProfilingGuid normalizationWorkloadExecutionEOLEventGuid = VerifyTimelineEventBinaryPacket(
1186 EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001187
1188 // Normalize workload execution - event relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001189 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
1190 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001191 normalizeWorkloadExecutionGuid,
1192 normalizationWorkloadExecutionEOLEventGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001193 LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS,
1194 readableData,
1195 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001196
1197 // Output workload execution
1198 // Output workload execution entity
Jim Flynn6398a982020-05-27 17:05:21 +01001199 ProfilingGuid outputWorkloadExecutionGuid = VerifyTimelineEntityBinaryPacketData(
1200 EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001201
1202 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001203 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
1204 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001205 outputWorkloadExecutionGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001206 LabelsAndEventClasses::WORKLOAD_EXECUTION_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001207 LabelsAndEventClasses::TYPE_GUID,
1208 readableData,
1209 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001210
1211 // Inference - Workload execution relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001212 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
1213 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001214 inferenceGuid,
1215 outputWorkloadExecutionGuid,
1216 LabelsAndEventClasses::CHILD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001217 readableData,
1218 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001219
1220 // Workload - Workload execution relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001221 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
1222 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001223 outputWorkloadGuid,
1224 outputWorkloadExecutionGuid,
1225 LabelsAndEventClasses::EXECUTION_OF_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001226 readableData,
1227 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001228
1229 // Start Output workload execution life
1230 // Event packet - timeline, threadId, eventGuid
Jim Flynn6398a982020-05-27 17:05:21 +01001231 ProfilingGuid outputWorkloadExecutionSOLEventGuid = VerifyTimelineEventBinaryPacket(
1232 EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001233
1234 // Output workload execution - event relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001235 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
1236 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001237 outputWorkloadExecutionGuid,
1238 outputWorkloadExecutionSOLEventGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001239 LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS,
1240 readableData,
1241 offset);
Finn Williams0a336dc2020-05-11 15:39:58 +01001242
David Monahan6198fe02019-12-02 08:35:43 +00001243 // End of Normalize workload execution life
1244 // Event packet - timeline, threadId, eventGuid
Jim Flynn6398a982020-05-27 17:05:21 +01001245 ProfilingGuid outputWorkloadExecutionEOLEventGuid = VerifyTimelineEventBinaryPacket(
1246 EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001247
1248 // Output workload execution - event relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001249 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
1250 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001251 outputWorkloadExecutionGuid,
1252 outputWorkloadExecutionEOLEventGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001253 LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS,
1254 readableData,
1255 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001256
1257 // End of Inference life
1258 // Event packet - timeline, threadId, eventGuid
Jim Flynn6398a982020-05-27 17:05:21 +01001259 ProfilingGuid inferenceEOLEventGuid = VerifyTimelineEventBinaryPacket(
1260 EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001261
1262 // Inference - event relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001263 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
1264 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001265 inferenceGuid,
1266 inferenceEOLEventGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001267 LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS,
1268 readableData,
1269 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001270
1271 bufferManager.MarkRead(inferenceReadableBuffer);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +00001272}
1273
Sadik Armagan1625efc2021-06-10 18:24:34 +01001274TEST_CASE("ProfilingPostOptimisationStructureCpuRef")
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +00001275{
1276 VerifyPostOptimisationStructureTestImpl(armnn::Compute::CpuRef);
1277}
1278
Sadik Armagan1625efc2021-06-10 18:24:34 +01001279}