9ced7e907c7f22f6b9ff01a60436e0df1f06c79a
[platform/upstream/armnn.git] / src / armnn / test / RuntimeTests.cpp
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 #include <Runtime.hpp>
10 #include <armnn/TypesUtils.hpp>
11
12 #include <LabelsAndEventClasses.hpp>
13 #include <test/ProfilingTestUtils.hpp>
14
15 #include <HeapProfiling.hpp>
16 #include <LeakChecking.hpp>
17
18 #ifdef WITH_VALGRIND
19 #include <valgrind/memcheck.h>
20 #endif
21
22 #include <boost/test/unit_test.hpp>
23 #include "RuntimeTests.hpp"
24
25 namespace armnn
26 {
27
28 void RuntimeLoadedNetworksReserve(armnn::Runtime* runtime)
29 {
30     runtime->m_LoadedNetworks.reserve(1);
31 }
32
33 profiling::ProfilingService& GetProfilingService(armnn::Runtime* runtime)
34 {
35     return runtime->m_ProfilingService;
36 }
37
38 }
39
40 BOOST_AUTO_TEST_SUITE(Runtime)
41
42 BOOST_AUTO_TEST_CASE(RuntimeUnloadNetwork)
43 {
44     // build 2 mock-networks and load them into the runtime
45     armnn::IRuntime::CreationOptions options;
46     armnn::IRuntimePtr               runtime(armnn::IRuntime::Create(options));
47
48     // Mock network 1.
49     armnn::NetworkId   networkIdentifier1 = 1;
50     armnn::INetworkPtr mockNetwork1(armnn::INetwork::Create());
51     mockNetwork1->AddInputLayer(0, "test layer");
52     std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
53     runtime->LoadNetwork(networkIdentifier1, Optimize(*mockNetwork1, backends, runtime->GetDeviceSpec()));
54
55     // Mock network 2.
56     armnn::NetworkId   networkIdentifier2 = 2;
57     armnn::INetworkPtr mockNetwork2(armnn::INetwork::Create());
58     mockNetwork2->AddInputLayer(0, "test layer");
59     runtime->LoadNetwork(networkIdentifier2, Optimize(*mockNetwork2, backends, runtime->GetDeviceSpec()));
60
61     // Unloads one by its networkID.
62     BOOST_TEST(runtime->UnloadNetwork(networkIdentifier1) == armnn::Status::Success);
63
64     BOOST_TEST(runtime->UnloadNetwork(networkIdentifier1) == armnn::Status::Failure);
65 }
66
67 // Note: the current builds we don't do valgrind and gperftools based leak checking at the same
68 //       time, so in practice WITH_VALGRIND and ARMNN_LEAK_CHECKING_ENABLED are exclusive. The
69 //       valgrind tests can stay for x86 builds, but on hikey Valgrind is just way too slow
70 //       to be integrated into the CI system.
71
72 #ifdef ARMNN_LEAK_CHECKING_ENABLED
73
74 struct DisableGlobalLeakChecking
75 {
76     DisableGlobalLeakChecking()
77     {
78         ARMNN_LOCAL_LEAK_CHECKING_ONLY();
79     }
80 };
81
82 BOOST_GLOBAL_FIXTURE(DisableGlobalLeakChecking);
83
84 BOOST_AUTO_TEST_CASE(RuntimeHeapMemoryUsageSanityChecks)
85 {
86     BOOST_TEST(ARMNN_LEAK_CHECKER_IS_ACTIVE());
87     {
88         ARMNN_SCOPED_LEAK_CHECKER("Sanity_Check_Outer");
89         {
90             ARMNN_SCOPED_LEAK_CHECKER("Sanity_Check_Inner");
91             BOOST_TEST(ARMNN_NO_LEAKS_IN_SCOPE() == true);
92             std::unique_ptr<char[]> dummyAllocation(new char[1000]);
93             BOOST_CHECK_MESSAGE(ARMNN_NO_LEAKS_IN_SCOPE() == false,
94                 "A leak of 1000 bytes is expected here. "
95                 "Please make sure environment variable: HEAPCHECK=draconian is set!");
96             BOOST_TEST(ARMNN_BYTES_LEAKED_IN_SCOPE() == 1000);
97             BOOST_TEST(ARMNN_OBJECTS_LEAKED_IN_SCOPE() == 1);
98         }
99         BOOST_TEST(ARMNN_NO_LEAKS_IN_SCOPE());
100         BOOST_TEST(ARMNN_BYTES_LEAKED_IN_SCOPE() == 0);
101         BOOST_TEST(ARMNN_OBJECTS_LEAKED_IN_SCOPE() == 0);
102     }
103 }
104
105 #endif // ARMNN_LEAK_CHECKING_ENABLED
106
107 // Note: this part of the code is due to be removed when we fully trust the gperftools based results.
108 #ifdef WITH_VALGRIND
109 // Run with the following command to get all the amazing output (in the devenv/build folder) :)
110 // valgrind --leak-check=full --show-leak-kinds=all --log-file=Valgrind_Memcheck_Leak_Report.txt armnn/test/UnitTests
111 BOOST_AUTO_TEST_CASE(RuntimeMemoryLeak)
112 {
113     // From documentation:
114
115     // This means that no pointer to the block can be found. The block is classified as "lost",
116     // because the programmer could not possibly have freed it at program exit, since no pointer to it exists.
117     unsigned long leakedBefore = 0;
118     unsigned long leakedAfter  = 0;
119
120     // A start-pointer or chain of start-pointers to the block is found. Since the block is still pointed at,
121     // the programmer could, at least in principle, have freed it before program exit.
122     // We want to test this in case memory is not freed as early as it could have been.
123     unsigned long reachableBefore = 0;
124     unsigned long reachableAfter  = 0;
125
126     // Needed as out params but we don't test them.
127     unsigned long dubious    = 0;
128     unsigned long suppressed = 0;
129
130     armnn::NetworkId networkIdentifier1 = 1;
131
132     // ensure that runtime is large enough before checking for memory leaks
133     // otherwise when loading the network it will automatically reserve memory that won't be released until destruction
134     armnn::IRuntime::CreationOptions options;
135     armnn::Runtime                   runtime(options);
136     armnn::RuntimeLoadedNetworksReserve(&runtime);
137
138     {
139         std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
140
141         std::unique_ptr<armnn::Network> mockNetwork1 = std::make_unique<armnn::Network>();
142         mockNetwork1->AddInputLayer(0, "test layer");
143
144         // Warm-up load/unload pair to put the runtime in a stable state (memory-wise).
145         runtime.LoadNetwork(networkIdentifier1, Optimize(*mockNetwork1, backends, runtime.GetDeviceSpec()));
146         runtime.UnloadNetwork(networkIdentifier1);
147
148         // Checks for leaks before we load the network and record them so that we can see the delta after unloading.
149         VALGRIND_DO_QUICK_LEAK_CHECK;
150         VALGRIND_COUNT_LEAKS(leakedBefore, dubious, reachableBefore, suppressed);
151
152         // The actual test.
153         runtime.LoadNetwork(networkIdentifier1, Optimize(*mockNetwork1, backends, runtime.GetDeviceSpec()));
154         runtime.UnloadNetwork(networkIdentifier1);
155
156         VALGRIND_DO_ADDED_LEAK_CHECK;
157         VALGRIND_COUNT_LEAKS(leakedAfter, dubious, reachableAfter, suppressed);
158     }
159
160     // If we're not running under Valgrind, these vars will have been initialised to 0, so this will always pass.
161     BOOST_TEST(leakedBefore == leakedAfter);
162     BOOST_TEST(reachableBefore == reachableAfter);
163
164     // These are needed because VALGRIND_COUNT_LEAKS is a macro that assigns to the parameters
165     // so they are assigned to, but still considered unused, causing a warning.
166     IgnoreUnused(dubious);
167     IgnoreUnused(suppressed);
168 }
169 #endif // WITH_VALGRIND
170
171 BOOST_AUTO_TEST_CASE(RuntimeCpuRef)
172 {
173     using namespace armnn;
174
175     // Create runtime in which test will run
176     armnn::IRuntime::CreationOptions options;
177     armnn::IRuntimePtr               runtime(armnn::IRuntime::Create(options));
178
179     // build up the structure of the network
180     INetworkPtr net(INetwork::Create());
181
182     IConnectableLayer* input = net->AddInputLayer(0);
183
184     // This layer configuration isn't supported by CpuAcc, should be fall back to CpuRef.
185     NormalizationDescriptor descriptor;
186     IConnectableLayer* normalize = net->AddNormalizationLayer(descriptor);
187
188     IConnectableLayer* output = net->AddOutputLayer(0);
189
190     input->GetOutputSlot(0).Connect(normalize->GetInputSlot(0));
191     normalize->GetOutputSlot(0).Connect(output->GetInputSlot(0));
192
193     input->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
194     normalize->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
195
196     // optimize the network
197     std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
198     IOptimizedNetworkPtr          optNet   = Optimize(*net, backends, runtime->GetDeviceSpec());
199
200     // Load it into the runtime. It should success.
201     armnn::NetworkId netId;
202     BOOST_TEST(runtime->LoadNetwork(netId, std::move(optNet)) == Status::Success);
203 }
204
205 BOOST_AUTO_TEST_CASE(RuntimeFallbackToCpuRef)
206 {
207     using namespace armnn;
208
209     // Create runtime in which test will run
210     armnn::IRuntime::CreationOptions options;
211     armnn::IRuntimePtr               runtime(armnn::IRuntime::Create(options));
212
213     // build up the structure of the network
214     INetworkPtr net(INetwork::Create());
215
216     IConnectableLayer* input = net->AddInputLayer(0);
217
218     // This layer configuration isn't supported by CpuAcc, should be fall back to CpuRef.
219     NormalizationDescriptor descriptor;
220     IConnectableLayer* normalize = net->AddNormalizationLayer(descriptor);
221
222     IConnectableLayer* output = net->AddOutputLayer(0);
223
224     input->GetOutputSlot(0).Connect(normalize->GetInputSlot(0));
225     normalize->GetOutputSlot(0).Connect(output->GetInputSlot(0));
226
227     input->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
228     normalize->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
229
230     // Allow fallback to CpuRef.
231     std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc, armnn::Compute::CpuRef };
232     // optimize the network
233     IOptimizedNetworkPtr          optNet   = Optimize(*net, backends, runtime->GetDeviceSpec());
234
235     // Load it into the runtime. It should succeed.
236     armnn::NetworkId netId;
237     BOOST_TEST(runtime->LoadNetwork(netId, std::move(optNet)) == Status::Success);
238 }
239
240 BOOST_AUTO_TEST_CASE(IVGCVSW_1929_QuantizedSoftmaxIssue)
241 {
242     // Test for issue reported by Chris Nix in https://jira.arm.com/browse/IVGCVSW-1929
243     using namespace armnn;
244
245     // Create runtime in which test will run
246     armnn::IRuntime::CreationOptions options;
247     armnn::IRuntimePtr               runtime(armnn::IRuntime::Create(options));
248
249     // build up the structure of the network
250     INetworkPtr net(INetwork::Create());
251     armnn::IConnectableLayer* input   = net->AddInputLayer(0,"input");
252     armnn::IConnectableLayer* softmax = net->AddSoftmaxLayer(armnn::SoftmaxDescriptor(), "softmax");
253     armnn::IConnectableLayer* output  = net->AddOutputLayer(0, "output");
254
255     input->GetOutputSlot(0).Connect(softmax->GetInputSlot(0));
256     softmax->GetOutputSlot(0).Connect(output->GetInputSlot(0));
257
258     input->GetOutputSlot(0).SetTensorInfo(armnn::TensorInfo(armnn::TensorShape({ 1, 5 }),
259                                                             armnn::DataType::QAsymmU8,
260                                                             1.0f / 255,
261                                                             0));
262
263     softmax->GetOutputSlot(0).SetTensorInfo(armnn::TensorInfo(armnn::TensorShape({ 1, 5 }),
264                                                               armnn::DataType::QAsymmU8));
265
266     std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
267     std::vector<std::string>      errMessages;
268     armnn::IOptimizedNetworkPtr   optNet   = Optimize(*net,
269                                                       backends,
270                                                       runtime->GetDeviceSpec(),
271                                                       OptimizerOptions(),
272                                                       errMessages);
273
274     BOOST_TEST(errMessages.size() == 1);
275     BOOST_TEST(errMessages[0] ==
276         "ERROR: output 0 of layer Softmax (softmax) is of type "
277         "Quantized 8 bit but its scale parameter has not been set");
278     BOOST_TEST(!optNet);
279 }
280
281 BOOST_AUTO_TEST_CASE(RuntimeBackendOptions)
282 {
283     using namespace armnn;
284
285     IRuntime::CreationOptions creationOptions;
286     auto& backendOptions = creationOptions.m_BackendOptions;
287
288
289     // Define Options on explicit construction
290     BackendOptions options1("FakeBackend1",
291                             {
292                                 { "Option1", 1.3f },
293                                 { "Option2", true }
294                             });
295
296     // Add an option after construction
297     options1.AddOption({ "Option3", "some_value" });
298
299     // Add the options to CreationOptions struct
300     backendOptions.push_back(options1);
301
302     // Add more Options via inplace explicit construction
303     backendOptions.emplace_back(BackendOptions{ "FakeBackend1",
304                                                 {{ "Option4", 42 }}
305     });
306
307
308     // First group
309     BOOST_TEST(backendOptions[0].GetBackendId().Get() == "FakeBackend1");
310     BOOST_TEST(backendOptions[0].GetOption(0).GetName() == "Option1");
311     BOOST_TEST(backendOptions[0].GetOption(0).GetValue().IsFloat() == true);
312     BOOST_TEST(backendOptions[0].GetOption(0).GetValue().AsFloat() == 1.3f);
313
314     BOOST_TEST(backendOptions[0].GetOption(1).GetName() == "Option2");
315     BOOST_TEST(backendOptions[0].GetOption(1).GetValue().IsBool() == true);
316     BOOST_TEST(backendOptions[0].GetOption(1).GetValue().AsBool() == true);
317
318     BOOST_TEST(backendOptions[0].GetOption(2).GetName() == "Option3");
319     BOOST_TEST(backendOptions[0].GetOption(2).GetValue().IsString() == true);
320     BOOST_TEST(backendOptions[0].GetOption(2).GetValue().AsString() == "some_value");
321
322     // Second group
323     BOOST_TEST(backendOptions[1].GetBackendId().Get() == "FakeBackend1");
324     BOOST_TEST(backendOptions[1].GetOption(0).GetName() == "Option4");
325     BOOST_TEST(backendOptions[1].GetOption(0).GetValue().IsInt() == true);
326     BOOST_TEST(backendOptions[1].GetOption(0).GetValue().AsInt() == 42);
327 }
328
329 BOOST_AUTO_TEST_CASE(ProfilingDisable)
330 {
331     using namespace armnn;
332
333     // Create runtime in which the test will run
334     armnn::IRuntime::CreationOptions options;
335     armnn::Runtime runtime(options);
336
337     // build up the structure of the network
338     INetworkPtr net(INetwork::Create());
339
340     IConnectableLayer* input = net->AddInputLayer(0);
341
342     // This layer configuration isn't supported by CpuAcc, should fall back to CpuRef.
343     NormalizationDescriptor descriptor;
344     IConnectableLayer* normalize = net->AddNormalizationLayer(descriptor);
345
346     IConnectableLayer* output = net->AddOutputLayer(0);
347
348     input->GetOutputSlot(0).Connect(normalize->GetInputSlot(0));
349     normalize->GetOutputSlot(0).Connect(output->GetInputSlot(0));
350
351     input->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
352     normalize->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
353
354     // optimize the network
355     std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
356     IOptimizedNetworkPtr optNet = Optimize(*net, backends, runtime.GetDeviceSpec());
357
358     // Load it into the runtime. It should succeed.
359     armnn::NetworkId netId;
360     BOOST_TEST(runtime.LoadNetwork(netId, std::move(optNet)) == Status::Success);
361
362     profiling::ProfilingServiceRuntimeHelper profilingServiceHelper(GetProfilingService(&runtime));
363     profiling::BufferManager& bufferManager = profilingServiceHelper.GetProfilingBufferManager();
364     auto readableBuffer = bufferManager.GetReadableBuffer();
365
366     // Profiling is not enabled, the post-optimisation structure should not be created
367     BOOST_TEST(!readableBuffer);
368 }
369
370 BOOST_AUTO_TEST_CASE(ProfilingEnableCpuRef)
371 {
372     using namespace armnn;
373     using namespace armnn::profiling;
374
375     // Create runtime in which the test will run
376     armnn::IRuntime::CreationOptions options;
377     options.m_ProfilingOptions.m_EnableProfiling = true;
378     armnn::Runtime runtime(options);
379
380     // build up the structure of the network
381     INetworkPtr net(INetwork::Create());
382
383     IConnectableLayer* input = net->AddInputLayer(0, "input");
384
385     NormalizationDescriptor descriptor;
386     IConnectableLayer* normalize = net->AddNormalizationLayer(descriptor, "normalization");
387
388     IConnectableLayer* output = net->AddOutputLayer(0, "output");
389
390     input->GetOutputSlot(0).Connect(normalize->GetInputSlot(0));
391     normalize->GetOutputSlot(0).Connect(output->GetInputSlot(0));
392
393     input->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
394     normalize->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
395
396     // optimize the network
397     std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
398     IOptimizedNetworkPtr optNet = Optimize(*net, backends, runtime.GetDeviceSpec());
399
400     ProfilingGuid optNetGuid = optNet->GetGuid();
401
402     // Load it into the runtime. It should succeed.
403     armnn::NetworkId netId;
404     BOOST_TEST(runtime.LoadNetwork(netId, std::move(optNet)) == Status::Success);
405
406     profiling::ProfilingServiceRuntimeHelper profilingServiceHelper(GetProfilingService(&runtime));
407     profiling::BufferManager& bufferManager = profilingServiceHelper.GetProfilingBufferManager();
408     auto readableBuffer = bufferManager.GetReadableBuffer();
409
410     // Profiling is enabled, the post-optimisation structure should be created
411     BOOST_CHECK(readableBuffer != nullptr);
412
413     unsigned int size = readableBuffer->GetSize();
414     BOOST_CHECK(size == 1068);
415
416     const unsigned char* readableData = readableBuffer->GetReadableData();
417     BOOST_CHECK(readableData != nullptr);
418
419     unsigned int offset = 0;
420
421     // Verify Header
422     VerifyTimelineHeaderBinary(readableData, offset, 1060);
423
424     // Post-optimisation network
425     // Network entity
426     VerifyTimelineEntityBinaryPacketData(optNetGuid, readableData, offset
427                                         );
428
429     // Entity - Type relationship
430     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
431                                                EmptyOptional(),
432                                                optNetGuid,
433                                                LabelsAndEventClasses::NETWORK_GUID,
434                                                readableData,
435                                                offset);
436
437     // Type label relationship
438     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
439                                                EmptyOptional(),
440                                                EmptyOptional(),
441                                                LabelsAndEventClasses::TYPE_GUID,
442                                                readableData,
443                                                offset);
444
445     // Input layer
446     // Input layer entity
447     VerifyTimelineEntityBinaryPacketData(input->GetGuid(), readableData, offset);
448
449     // Name Entity
450     VerifyTimelineLabelBinaryPacketData(EmptyOptional(), "input", readableData, offset);
451
452     // Entity - Name relationship
453     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
454                                                EmptyOptional(),
455                                                input->GetGuid(),
456                                                EmptyOptional(),
457                                                readableData,
458                                                offset);
459
460     // Name label relationship
461     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
462                                                EmptyOptional(),
463                                                EmptyOptional(),
464                                                LabelsAndEventClasses::NAME_GUID,
465                                                readableData,
466                                                offset);
467
468     // Entity - Type relationship
469     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
470                                                EmptyOptional(),
471                                                input->GetGuid(),
472                                                EmptyOptional(),
473                                                readableData,
474                                                offset);
475
476     // Type label relationship
477     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
478                                                EmptyOptional(),
479                                                EmptyOptional(),
480                                                LabelsAndEventClasses::TYPE_GUID,
481                                                readableData,
482                                                offset);
483
484     // Network - Input layer relationship
485     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
486                                                EmptyOptional(),
487                                                optNetGuid,
488                                                input->GetGuid(),
489                                                readableData,
490                                                offset);
491
492     // Normalization layer
493     // Normalization layer entity
494     VerifyTimelineEntityBinaryPacketData(normalize->GetGuid(), readableData, offset);
495
496     // Name entity
497     VerifyTimelineLabelBinaryPacketData(EmptyOptional(), "normalization", readableData, offset);
498
499     // Entity - Name relationship
500     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
501                                                EmptyOptional(),
502                                                normalize->GetGuid(),
503                                                EmptyOptional(),
504                                                readableData,
505                                                offset);
506
507     // Name label relationship
508     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
509                                                EmptyOptional(),
510                                                EmptyOptional(),
511                                                LabelsAndEventClasses::NAME_GUID,
512                                                readableData,
513                                                offset);
514
515     // Entity - Type relationship
516     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
517                                                EmptyOptional(),
518                                                normalize->GetGuid(),
519                                                EmptyOptional(),
520                                                readableData,
521                                                offset);
522
523     // Type label relationship
524     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
525                                                EmptyOptional(),
526                                                EmptyOptional(),
527                                                LabelsAndEventClasses::TYPE_GUID,
528                                                readableData,
529                                                offset);
530
531     // Network - Normalize layer relationship
532     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
533                                                EmptyOptional(),
534                                                optNetGuid,
535                                                normalize->GetGuid(),
536                                                readableData,
537                                                offset);
538
539     // Input layer - Normalize layer relationship
540     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
541                                                EmptyOptional(),
542                                                input->GetGuid(),
543                                                normalize->GetGuid(),
544                                                readableData,
545                                                offset);
546
547     // Entity - Type relationship
548     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
549                                                EmptyOptional(),
550                                                EmptyOptional(),
551                                                LabelsAndEventClasses::CONNECTION_GUID,
552                                                readableData,
553                                                offset);
554
555     // Type label relationship
556     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
557                                                EmptyOptional(),
558                                                EmptyOptional(),
559                                                LabelsAndEventClasses::TYPE_GUID,
560                                                readableData,
561                                                offset);
562
563     // Normalization workload
564     // Normalization workload entity
565     VerifyTimelineEntityBinaryPacketData(EmptyOptional(), readableData, offset);
566
567     // Entity - Type relationship
568     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
569                                                EmptyOptional(),
570                                                EmptyOptional(),
571                                                EmptyOptional(),
572                                                readableData,
573                                                offset);
574
575     // Type label relationship
576     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
577                                                EmptyOptional(),
578                                                EmptyOptional(),
579                                                LabelsAndEventClasses::TYPE_GUID,
580                                                readableData,
581                                                offset);
582
583     // BackendId entity
584     VerifyTimelineLabelBinaryPacketData(EmptyOptional(), "CpuRef", readableData, offset);
585
586     // Entity - BackendId relationship
587     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
588                                                EmptyOptional(),
589                                                EmptyOptional(),
590                                                EmptyOptional(),
591                                                readableData,
592                                                offset);
593
594     // BackendId label relationship
595     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
596                                                EmptyOptional(),
597                                                EmptyOptional(),
598                                                LabelsAndEventClasses::BACKENDID_GUID,
599                                                readableData,
600                                                offset);
601
602     // Normalize layer - Normalize workload relationship
603     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
604                                                EmptyOptional(),
605                                                normalize->GetGuid(),
606                                                EmptyOptional(),
607                                                readableData,
608                                                offset);
609
610     // Output layer
611     // Output layer entity
612     VerifyTimelineEntityBinaryPacketData(output->GetGuid(), readableData, offset);
613
614     // Name entity
615     VerifyTimelineLabelBinaryPacketData(EmptyOptional(), "output", readableData, offset);
616
617     // Entity - Name relationship
618     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
619                                                EmptyOptional(),
620                                                output->GetGuid(),
621                                                EmptyOptional(),
622                                                readableData,
623                                                offset);
624
625     // Name label relationship
626     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
627                                                EmptyOptional(),
628                                                EmptyOptional(),
629                                                LabelsAndEventClasses::NAME_GUID,
630                                                readableData,
631                                                offset);
632
633     // Entity - Type relationship
634     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
635                                                EmptyOptional(),
636                                                output->GetGuid(),
637                                                EmptyOptional(),
638                                                readableData,
639                                                offset);
640
641     // Type label relationship
642     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
643                                                EmptyOptional(),
644                                                EmptyOptional(),
645                                                LabelsAndEventClasses::TYPE_GUID,
646                                                readableData,
647                                                offset);
648
649     // Network - Output layer relationship
650     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
651                                                EmptyOptional(),
652                                                optNetGuid,
653                                                output->GetGuid(),
654                                                readableData,
655                                                offset);
656
657     // Normalize layer - Output layer relationship
658     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
659                                                EmptyOptional(),
660                                                normalize->GetGuid(),
661                                                output->GetGuid(),
662                                                readableData,
663                                                offset);
664
665     // Entity - Type relationship
666     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
667                                                EmptyOptional(),
668                                                EmptyOptional(),
669                                                LabelsAndEventClasses::CONNECTION_GUID,
670                                                readableData,
671                                                offset);
672
673     // Type label relationship
674     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
675                                                EmptyOptional(),
676                                                EmptyOptional(),
677                                                LabelsAndEventClasses::TYPE_GUID,
678                                                readableData,
679                                                offset);
680
681     bufferManager.MarkRead(readableBuffer);
682
683     // Creates structures for input & output.
684     std::vector<float> inputData(16);
685     std::vector<float> outputData(16);
686
687     InputTensors  inputTensors
688     {
689         {0, ConstTensor(runtime.GetInputTensorInfo(netId, 0), inputData.data())}
690     };
691     OutputTensors outputTensors
692     {
693         {0, Tensor(runtime.GetOutputTensorInfo(netId, 0), outputData.data())}
694     };
695
696     // Does the inference.
697     runtime.EnqueueWorkload(netId, inputTensors, outputTensors);
698
699     // Get readable buffer for inference timeline
700     auto inferenceReadableBuffer = bufferManager.GetReadableBuffer();
701     BOOST_CHECK(inferenceReadableBuffer != nullptr);
702
703     // Get readable buffer for output workload
704     auto outputReadableBuffer = bufferManager.GetReadableBuffer();
705     BOOST_CHECK(outputReadableBuffer != nullptr);
706
707     // Get readable buffer for input workload
708     auto inputReadableBuffer = bufferManager.GetReadableBuffer();
709     BOOST_CHECK(inputReadableBuffer != nullptr);
710
711     // Validate input workload data
712     size = inputReadableBuffer->GetSize();
713     BOOST_CHECK(size == 204);
714
715     readableData = inputReadableBuffer->GetReadableData();
716     BOOST_CHECK(readableData != nullptr);
717
718     offset = 0;
719
720     // Verify Header
721     VerifyTimelineHeaderBinary(readableData, offset, 196);
722
723     // Input workload
724     // Input workload entity
725     VerifyTimelineEntityBinaryPacketData(EmptyOptional(), readableData, offset);
726
727     // Entity - Type relationship
728     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
729                                                EmptyOptional(),
730                                                EmptyOptional(),
731                                                EmptyOptional(),
732                                                readableData,
733                                                offset);
734
735     // Type label relationship
736     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
737                                                EmptyOptional(),
738                                                EmptyOptional(),
739                                                LabelsAndEventClasses::TYPE_GUID,
740                                                readableData,
741                                                offset);
742
743     // BackendId entity
744     VerifyTimelineLabelBinaryPacketData(EmptyOptional(), "CpuRef", readableData, offset);
745
746     // Entity - BackendId relationship
747     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
748                                                EmptyOptional(),
749                                                EmptyOptional(),
750                                                EmptyOptional(),
751                                                readableData,
752                                                offset);
753
754     // BackendId label relationship
755     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
756                                                EmptyOptional(),
757                                                EmptyOptional(),
758                                                LabelsAndEventClasses::BACKENDID_GUID,
759                                                readableData,
760                                                offset);
761
762     // Input layer - Input workload relationship
763     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
764                                                EmptyOptional(),
765                                                input->GetGuid(),
766                                                EmptyOptional(),
767                                                readableData,
768                                                offset);
769
770     bufferManager.MarkRead(inputReadableBuffer);
771
772     // Validate output workload data
773     size = outputReadableBuffer->GetSize();
774     BOOST_CHECK(size == 204);
775
776     readableData = outputReadableBuffer->GetReadableData();
777     BOOST_CHECK(readableData != nullptr);
778
779     offset = 0;
780
781     // Verify Header
782     VerifyTimelineHeaderBinary(readableData, offset, 196);
783
784     // Output workload
785     // Output workload entity
786     VerifyTimelineEntityBinaryPacketData(EmptyOptional(), readableData, offset);
787
788     // Entity - Type relationship
789     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
790                                                EmptyOptional(),
791                                                EmptyOptional(),
792                                                EmptyOptional(),
793                                                readableData,
794                                                offset);
795
796     // Type label relationship
797     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
798                                                EmptyOptional(),
799                                                EmptyOptional(),
800                                                LabelsAndEventClasses::TYPE_GUID,
801                                                readableData,
802                                                offset);
803
804     // BackendId entity
805     VerifyTimelineLabelBinaryPacketData(EmptyOptional(), "CpuRef", readableData, offset);
806
807     // Entity - BackendId relationship
808     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
809                                                EmptyOptional(),
810                                                EmptyOptional(),
811                                                EmptyOptional(),
812                                                readableData,
813                                                offset);
814
815     // BackendId label relationship
816     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
817                                                EmptyOptional(),
818                                                EmptyOptional(),
819                                                LabelsAndEventClasses::BACKENDID_GUID,
820                                                readableData,
821                                                offset);
822
823     // Output layer - Output workload relationship
824     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
825                                                EmptyOptional(),
826                                                output->GetGuid(),
827                                                EmptyOptional(),
828                                                readableData,
829                                                offset);
830
831     bufferManager.MarkRead(outputReadableBuffer);
832
833     // Validate inference data
834     size = inferenceReadableBuffer->GetSize();
835     BOOST_CHECK(size == 1272);
836
837     readableData = inferenceReadableBuffer->GetReadableData();
838     BOOST_CHECK(readableData != nullptr);
839
840     offset = 0;
841
842     // Verify Header
843     VerifyTimelineHeaderBinary(readableData, offset, 1264);
844
845     // Inference timeline trace
846     // Inference entity
847     VerifyTimelineEntityBinaryPacketData(EmptyOptional(), readableData, offset);
848
849     // Entity - Type relationship
850     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
851                                                EmptyOptional(),
852                                                EmptyOptional(),
853                                                LabelsAndEventClasses::INFERENCE_GUID,
854                                                readableData,
855                                                offset);
856
857     // Type label relationship
858     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
859                                                EmptyOptional(),
860                                                EmptyOptional(),
861                                                LabelsAndEventClasses::TYPE_GUID,
862                                                readableData,
863                                                offset);
864
865     // Network - Inference relationship
866     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
867                                                EmptyOptional(),
868                                                optNetGuid,
869                                                EmptyOptional(),
870                                                readableData,
871                                                offset);
872
873     // Start Inference life
874     // Event packet - timeline, threadId, eventGuid
875     VerifyTimelineEventBinaryPacket(EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
876
877     // Inference - event relationship
878     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
879                                                EmptyOptional(),
880                                                EmptyOptional(),
881                                                EmptyOptional(),
882                                                readableData,
883                                                offset);
884
885     // Event - event class relationship
886     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::DataLink,
887                                                EmptyOptional(),
888                                                EmptyOptional(),
889                                                LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS,
890                                                readableData,
891                                                offset);
892
893     // Execution
894     // Input workload execution
895     // Input workload execution entity
896     VerifyTimelineEntityBinaryPacketData(EmptyOptional(), readableData, offset);
897
898     // Entity - Type relationship
899     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
900                                                EmptyOptional(),
901                                                EmptyOptional(),
902                                                LabelsAndEventClasses::WORKLOAD_EXECUTION_GUID,
903                                                readableData,
904                                                offset);
905
906     // Type label relationship
907     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
908                                                EmptyOptional(),
909                                                EmptyOptional(),
910                                                LabelsAndEventClasses::TYPE_GUID,
911                                                readableData,
912                                                offset);
913
914     // Inference - Workload execution relationship
915     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
916                                                EmptyOptional(),
917                                                EmptyOptional(),
918                                                EmptyOptional(),
919                                                readableData,
920                                                offset);
921
922     // Workload - Workload execution relationship
923     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
924                                                EmptyOptional(),
925                                                EmptyOptional(),
926                                                EmptyOptional(),
927                                                readableData,
928                                                offset);
929
930     // Start Input workload execution life
931     // Event packet - timeline, threadId, eventGuid
932     VerifyTimelineEventBinaryPacket(EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
933
934     // Input workload execution - event relationship
935     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
936                                                EmptyOptional(),
937                                                EmptyOptional(),
938                                                EmptyOptional(),
939                                                readableData,
940                                                offset);
941
942     // Event - event class relationship
943     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::DataLink,
944                                                EmptyOptional(),
945                                                EmptyOptional(),
946                                                LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS,
947                                                readableData,
948                                                offset);
949
950     // End of Input workload execution life
951     // Event packet - timeline, threadId, eventGuid
952     VerifyTimelineEventBinaryPacket(EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
953
954     // Input workload execution - event relationship
955     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
956                                                EmptyOptional(),
957                                                EmptyOptional(),
958                                                EmptyOptional(),
959                                                readableData,
960                                                offset);
961
962     // Event - event class relationship
963     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::DataLink,
964                                                EmptyOptional(),
965                                                EmptyOptional(),
966                                                LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS,
967                                                readableData,
968                                                offset);
969
970     // Normalize workload execution
971     // Normalize workload execution entity
972     VerifyTimelineEntityBinaryPacketData(EmptyOptional(), readableData, offset);
973
974     // Entity - Type relationship
975     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
976                                                EmptyOptional(),
977                                                EmptyOptional(),
978                                                LabelsAndEventClasses::WORKLOAD_EXECUTION_GUID,
979                                                readableData,
980                                                offset);
981
982     // Type label relationship
983     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
984                                                EmptyOptional(),
985                                                EmptyOptional(),
986                                                LabelsAndEventClasses::TYPE_GUID,
987                                                readableData,
988                                                offset);
989
990     // Inference - Workload execution relationship
991     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
992                                                EmptyOptional(),
993                                                EmptyOptional(),
994                                                EmptyOptional(),
995                                                readableData,
996                                                offset);
997
998     // Workload - Workload execution relationship
999     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
1000                                                EmptyOptional(),
1001                                                EmptyOptional(),
1002                                                EmptyOptional(),
1003                                                readableData,
1004                                                offset);
1005
1006     // Start Normalize workload execution life
1007     // Event packet - timeline, threadId, eventGuid
1008     VerifyTimelineEventBinaryPacket(EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
1009
1010     // Normalize workload execution - event relationship
1011     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
1012                                                EmptyOptional(),
1013                                                EmptyOptional(),
1014                                                EmptyOptional(),
1015                                                readableData,
1016                                                offset);
1017
1018     // Event - event class relationship
1019     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::DataLink,
1020                                                EmptyOptional(),
1021                                                EmptyOptional(),
1022                                                LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS,
1023                                                readableData,
1024                                                offset);
1025
1026     // End of Normalize workload execution life
1027     // Event packet - timeline, threadId, eventGuid
1028     VerifyTimelineEventBinaryPacket(EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
1029
1030     // Normalize workload execution - event relationship
1031     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
1032                                                EmptyOptional(),
1033                                                EmptyOptional(),
1034                                                EmptyOptional(),
1035                                                readableData,
1036                                                offset);
1037
1038     // Event - event class relationship
1039     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::DataLink,
1040                                                EmptyOptional(),
1041                                                EmptyOptional(),
1042                                                LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS,
1043                                                readableData,
1044                                                offset);
1045
1046     // Output workload execution
1047     // Output workload execution entity
1048     VerifyTimelineEntityBinaryPacketData(EmptyOptional(), readableData, offset);
1049
1050     // Entity - Type relationship
1051     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
1052                                                EmptyOptional(),
1053                                                EmptyOptional(),
1054                                                LabelsAndEventClasses::WORKLOAD_EXECUTION_GUID,
1055                                                readableData,
1056                                                offset);
1057
1058     // Type label relationship
1059     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
1060                                                EmptyOptional(),
1061                                                EmptyOptional(),
1062                                                LabelsAndEventClasses::TYPE_GUID,
1063                                                readableData,
1064                                                offset);
1065
1066     // Inference - Workload execution relationship
1067     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
1068                                                EmptyOptional(),
1069                                                EmptyOptional(),
1070                                                EmptyOptional(),
1071                                                readableData,
1072                                                offset);
1073
1074     // Workload - Workload execution relationship
1075     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
1076                                                EmptyOptional(),
1077                                                EmptyOptional(),
1078                                                EmptyOptional(),
1079                                                readableData,
1080                                                offset);
1081
1082     // Start Output workload execution life
1083     // Event packet - timeline, threadId, eventGuid
1084     VerifyTimelineEventBinaryPacket(EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
1085
1086     // Output workload execution - event relationship
1087     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
1088                                                EmptyOptional(),
1089                                                EmptyOptional(),
1090                                                EmptyOptional(),
1091                                                readableData,
1092                                                offset);
1093
1094     // Event - event class relationship
1095     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::DataLink,
1096                                                EmptyOptional(),
1097                                                EmptyOptional(),
1098                                                LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS,
1099                                                readableData,
1100                                                offset);
1101
1102     // End of Normalize workload execution life
1103     // Event packet - timeline, threadId, eventGuid
1104     VerifyTimelineEventBinaryPacket(EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
1105
1106     // Output workload execution - event relationship
1107     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
1108                                                EmptyOptional(),
1109                                                EmptyOptional(),
1110                                                EmptyOptional(),
1111                                                readableData,
1112                                                offset);
1113
1114     // Event - event class relationship
1115     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::DataLink,
1116                                                EmptyOptional(),
1117                                                EmptyOptional(),
1118                                                LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS,
1119                                                readableData,
1120                                                offset);
1121
1122     // End of Inference life
1123     // Event packet - timeline, threadId, eventGuid
1124     VerifyTimelineEventBinaryPacket(EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
1125
1126     // Inference - event relationship
1127     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
1128                                                EmptyOptional(),
1129                                                EmptyOptional(),
1130                                                EmptyOptional(),
1131                                                readableData,
1132                                                offset);
1133
1134     // Event - event class relationship
1135     VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::DataLink,
1136                                                EmptyOptional(),
1137                                                EmptyOptional(),
1138                                                LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS,
1139                                                readableData,
1140                                                offset);
1141
1142     bufferManager.MarkRead(inferenceReadableBuffer);
1143 }
1144
1145 BOOST_AUTO_TEST_CASE(ProfilingPostOptimisationStructureCpuRef)
1146 {
1147     VerifyPostOptimisationStructureTestImpl(armnn::Compute::CpuRef);
1148 }
1149
1150 BOOST_AUTO_TEST_SUITE_END()