2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
6 #include <armnn/Descriptors.hpp>
7 #include <armnn/IRuntime.hpp>
8 #include <armnn/INetwork.hpp>
10 #include <armnn/TypesUtils.hpp>
12 #include <LabelsAndEventClasses.hpp>
13 #include <test/ProfilingTestUtils.hpp>
15 #include <HeapProfiling.hpp>
16 #include <LeakChecking.hpp>
19 #include <valgrind/memcheck.h>
22 #include <boost/test/unit_test.hpp>
23 #include "RuntimeTests.hpp"
28 void RuntimeLoadedNetworksReserve(armnn::Runtime* runtime)
30 runtime->m_LoadedNetworks.reserve(1);
33 profiling::ProfilingService& GetProfilingService(armnn::Runtime* runtime)
35 return runtime->m_ProfilingService;
40 BOOST_AUTO_TEST_SUITE(Runtime)
42 BOOST_AUTO_TEST_CASE(RuntimeUnloadNetwork)
44 // build 2 mock-networks and load them into the runtime
45 armnn::IRuntime::CreationOptions options;
46 armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options));
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()));
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()));
61 // Unloads one by its networkID.
62 BOOST_TEST(runtime->UnloadNetwork(networkIdentifier1) == armnn::Status::Success);
64 BOOST_TEST(runtime->UnloadNetwork(networkIdentifier1) == armnn::Status::Failure);
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.
72 #ifdef ARMNN_LEAK_CHECKING_ENABLED
74 struct DisableGlobalLeakChecking
76 DisableGlobalLeakChecking()
78 ARMNN_LOCAL_LEAK_CHECKING_ONLY();
82 BOOST_GLOBAL_FIXTURE(DisableGlobalLeakChecking);
84 BOOST_AUTO_TEST_CASE(RuntimeHeapMemoryUsageSanityChecks)
86 BOOST_TEST(ARMNN_LEAK_CHECKER_IS_ACTIVE());
88 ARMNN_SCOPED_LEAK_CHECKER("Sanity_Check_Outer");
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);
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);
105 #endif // ARMNN_LEAK_CHECKING_ENABLED
107 // Note: this part of the code is due to be removed when we fully trust the gperftools based results.
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)
113 // From documentation:
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;
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;
126 // Needed as out params but we don't test them.
127 unsigned long dubious = 0;
128 unsigned long suppressed = 0;
130 armnn::NetworkId networkIdentifier1 = 1;
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);
139 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
141 std::unique_ptr<armnn::Network> mockNetwork1 = std::make_unique<armnn::Network>();
142 mockNetwork1->AddInputLayer(0, "test layer");
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);
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);
153 runtime.LoadNetwork(networkIdentifier1, Optimize(*mockNetwork1, backends, runtime.GetDeviceSpec()));
154 runtime.UnloadNetwork(networkIdentifier1);
156 VALGRIND_DO_ADDED_LEAK_CHECK;
157 VALGRIND_COUNT_LEAKS(leakedAfter, dubious, reachableAfter, suppressed);
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);
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);
169 #endif // WITH_VALGRIND
171 BOOST_AUTO_TEST_CASE(RuntimeCpuRef)
173 using namespace armnn;
175 // Create runtime in which test will run
176 armnn::IRuntime::CreationOptions options;
177 armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options));
179 // build up the structure of the network
180 INetworkPtr net(INetwork::Create());
182 IConnectableLayer* input = net->AddInputLayer(0);
184 // This layer configuration isn't supported by CpuAcc, should be fall back to CpuRef.
185 NormalizationDescriptor descriptor;
186 IConnectableLayer* normalize = net->AddNormalizationLayer(descriptor);
188 IConnectableLayer* output = net->AddOutputLayer(0);
190 input->GetOutputSlot(0).Connect(normalize->GetInputSlot(0));
191 normalize->GetOutputSlot(0).Connect(output->GetInputSlot(0));
193 input->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
194 normalize->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
196 // optimize the network
197 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
198 IOptimizedNetworkPtr optNet = Optimize(*net, backends, runtime->GetDeviceSpec());
200 // Load it into the runtime. It should success.
201 armnn::NetworkId netId;
202 BOOST_TEST(runtime->LoadNetwork(netId, std::move(optNet)) == Status::Success);
205 BOOST_AUTO_TEST_CASE(RuntimeFallbackToCpuRef)
207 using namespace armnn;
209 // Create runtime in which test will run
210 armnn::IRuntime::CreationOptions options;
211 armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options));
213 // build up the structure of the network
214 INetworkPtr net(INetwork::Create());
216 IConnectableLayer* input = net->AddInputLayer(0);
218 // This layer configuration isn't supported by CpuAcc, should be fall back to CpuRef.
219 NormalizationDescriptor descriptor;
220 IConnectableLayer* normalize = net->AddNormalizationLayer(descriptor);
222 IConnectableLayer* output = net->AddOutputLayer(0);
224 input->GetOutputSlot(0).Connect(normalize->GetInputSlot(0));
225 normalize->GetOutputSlot(0).Connect(output->GetInputSlot(0));
227 input->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
228 normalize->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
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());
235 // Load it into the runtime. It should succeed.
236 armnn::NetworkId netId;
237 BOOST_TEST(runtime->LoadNetwork(netId, std::move(optNet)) == Status::Success);
240 BOOST_AUTO_TEST_CASE(IVGCVSW_1929_QuantizedSoftmaxIssue)
242 // Test for issue reported by Chris Nix in https://jira.arm.com/browse/IVGCVSW-1929
243 using namespace armnn;
245 // Create runtime in which test will run
246 armnn::IRuntime::CreationOptions options;
247 armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options));
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");
255 input->GetOutputSlot(0).Connect(softmax->GetInputSlot(0));
256 softmax->GetOutputSlot(0).Connect(output->GetInputSlot(0));
258 input->GetOutputSlot(0).SetTensorInfo(armnn::TensorInfo(armnn::TensorShape({ 1, 5 }),
259 armnn::DataType::QAsymmU8,
263 softmax->GetOutputSlot(0).SetTensorInfo(armnn::TensorInfo(armnn::TensorShape({ 1, 5 }),
264 armnn::DataType::QAsymmU8));
266 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
267 std::vector<std::string> errMessages;
268 armnn::IOptimizedNetworkPtr optNet = Optimize(*net,
270 runtime->GetDeviceSpec(),
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");
281 BOOST_AUTO_TEST_CASE(RuntimeBackendOptions)
283 using namespace armnn;
285 IRuntime::CreationOptions creationOptions;
286 auto& backendOptions = creationOptions.m_BackendOptions;
289 // Define Options on explicit construction
290 BackendOptions options1("FakeBackend1",
296 // Add an option after construction
297 options1.AddOption({ "Option3", "some_value" });
299 // Add the options to CreationOptions struct
300 backendOptions.push_back(options1);
302 // Add more Options via inplace explicit construction
303 backendOptions.emplace_back(BackendOptions{ "FakeBackend1",
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);
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);
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");
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);
329 BOOST_AUTO_TEST_CASE(ProfilingDisable)
331 using namespace armnn;
333 // Create runtime in which the test will run
334 armnn::IRuntime::CreationOptions options;
335 armnn::Runtime runtime(options);
337 // build up the structure of the network
338 INetworkPtr net(INetwork::Create());
340 IConnectableLayer* input = net->AddInputLayer(0);
342 // This layer configuration isn't supported by CpuAcc, should fall back to CpuRef.
343 NormalizationDescriptor descriptor;
344 IConnectableLayer* normalize = net->AddNormalizationLayer(descriptor);
346 IConnectableLayer* output = net->AddOutputLayer(0);
348 input->GetOutputSlot(0).Connect(normalize->GetInputSlot(0));
349 normalize->GetOutputSlot(0).Connect(output->GetInputSlot(0));
351 input->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
352 normalize->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
354 // optimize the network
355 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
356 IOptimizedNetworkPtr optNet = Optimize(*net, backends, runtime.GetDeviceSpec());
358 // Load it into the runtime. It should succeed.
359 armnn::NetworkId netId;
360 BOOST_TEST(runtime.LoadNetwork(netId, std::move(optNet)) == Status::Success);
362 profiling::ProfilingServiceRuntimeHelper profilingServiceHelper(GetProfilingService(&runtime));
363 profiling::BufferManager& bufferManager = profilingServiceHelper.GetProfilingBufferManager();
364 auto readableBuffer = bufferManager.GetReadableBuffer();
366 // Profiling is not enabled, the post-optimisation structure should not be created
367 BOOST_TEST(!readableBuffer);
370 BOOST_AUTO_TEST_CASE(ProfilingEnableCpuRef)
372 using namespace armnn;
373 using namespace armnn::profiling;
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);
380 // build up the structure of the network
381 INetworkPtr net(INetwork::Create());
383 IConnectableLayer* input = net->AddInputLayer(0, "input");
385 NormalizationDescriptor descriptor;
386 IConnectableLayer* normalize = net->AddNormalizationLayer(descriptor, "normalization");
388 IConnectableLayer* output = net->AddOutputLayer(0, "output");
390 input->GetOutputSlot(0).Connect(normalize->GetInputSlot(0));
391 normalize->GetOutputSlot(0).Connect(output->GetInputSlot(0));
393 input->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
394 normalize->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
396 // optimize the network
397 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
398 IOptimizedNetworkPtr optNet = Optimize(*net, backends, runtime.GetDeviceSpec());
400 ProfilingGuid optNetGuid = optNet->GetGuid();
402 // Load it into the runtime. It should succeed.
403 armnn::NetworkId netId;
404 BOOST_TEST(runtime.LoadNetwork(netId, std::move(optNet)) == Status::Success);
406 profiling::ProfilingServiceRuntimeHelper profilingServiceHelper(GetProfilingService(&runtime));
407 profiling::BufferManager& bufferManager = profilingServiceHelper.GetProfilingBufferManager();
408 auto readableBuffer = bufferManager.GetReadableBuffer();
410 // Profiling is enabled, the post-optimisation structure should be created
411 BOOST_CHECK(readableBuffer != nullptr);
413 unsigned int size = readableBuffer->GetSize();
414 BOOST_CHECK(size == 1068);
416 const unsigned char* readableData = readableBuffer->GetReadableData();
417 BOOST_CHECK(readableData != nullptr);
419 unsigned int offset = 0;
422 VerifyTimelineHeaderBinary(readableData, offset, 1060);
424 // Post-optimisation network
426 VerifyTimelineEntityBinaryPacketData(optNetGuid, readableData, offset
429 // Entity - Type relationship
430 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
433 LabelsAndEventClasses::NETWORK_GUID,
437 // Type label relationship
438 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
441 LabelsAndEventClasses::TYPE_GUID,
446 // Input layer entity
447 VerifyTimelineEntityBinaryPacketData(input->GetGuid(), readableData, offset);
450 VerifyTimelineLabelBinaryPacketData(EmptyOptional(), "input", readableData, offset);
452 // Entity - Name relationship
453 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
460 // Name label relationship
461 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
464 LabelsAndEventClasses::NAME_GUID,
468 // Entity - Type relationship
469 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
476 // Type label relationship
477 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
480 LabelsAndEventClasses::TYPE_GUID,
484 // Network - Input layer relationship
485 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
492 // Normalization layer
493 // Normalization layer entity
494 VerifyTimelineEntityBinaryPacketData(normalize->GetGuid(), readableData, offset);
497 VerifyTimelineLabelBinaryPacketData(EmptyOptional(), "normalization", readableData, offset);
499 // Entity - Name relationship
500 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
502 normalize->GetGuid(),
507 // Name label relationship
508 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
511 LabelsAndEventClasses::NAME_GUID,
515 // Entity - Type relationship
516 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
518 normalize->GetGuid(),
523 // Type label relationship
524 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
527 LabelsAndEventClasses::TYPE_GUID,
531 // Network - Normalize layer relationship
532 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
535 normalize->GetGuid(),
539 // Input layer - Normalize layer relationship
540 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
543 normalize->GetGuid(),
547 // Entity - Type relationship
548 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
551 LabelsAndEventClasses::CONNECTION_GUID,
555 // Type label relationship
556 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
559 LabelsAndEventClasses::TYPE_GUID,
563 // Normalization workload
564 // Normalization workload entity
565 VerifyTimelineEntityBinaryPacketData(EmptyOptional(), readableData, offset);
567 // Entity - Type relationship
568 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
575 // Type label relationship
576 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
579 LabelsAndEventClasses::TYPE_GUID,
584 VerifyTimelineLabelBinaryPacketData(EmptyOptional(), "CpuRef", readableData, offset);
586 // Entity - BackendId relationship
587 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
594 // BackendId label relationship
595 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
598 LabelsAndEventClasses::BACKENDID_GUID,
602 // Normalize layer - Normalize workload relationship
603 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
605 normalize->GetGuid(),
611 // Output layer entity
612 VerifyTimelineEntityBinaryPacketData(output->GetGuid(), readableData, offset);
615 VerifyTimelineLabelBinaryPacketData(EmptyOptional(), "output", readableData, offset);
617 // Entity - Name relationship
618 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
625 // Name label relationship
626 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
629 LabelsAndEventClasses::NAME_GUID,
633 // Entity - Type relationship
634 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
641 // Type label relationship
642 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
645 LabelsAndEventClasses::TYPE_GUID,
649 // Network - Output layer relationship
650 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
657 // Normalize layer - Output layer relationship
658 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
660 normalize->GetGuid(),
665 // Entity - Type relationship
666 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
669 LabelsAndEventClasses::CONNECTION_GUID,
673 // Type label relationship
674 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
677 LabelsAndEventClasses::TYPE_GUID,
681 bufferManager.MarkRead(readableBuffer);
683 // Creates structures for input & output.
684 std::vector<float> inputData(16);
685 std::vector<float> outputData(16);
687 InputTensors inputTensors
689 {0, ConstTensor(runtime.GetInputTensorInfo(netId, 0), inputData.data())}
691 OutputTensors outputTensors
693 {0, Tensor(runtime.GetOutputTensorInfo(netId, 0), outputData.data())}
696 // Does the inference.
697 runtime.EnqueueWorkload(netId, inputTensors, outputTensors);
699 // Get readable buffer for inference timeline
700 auto inferenceReadableBuffer = bufferManager.GetReadableBuffer();
701 BOOST_CHECK(inferenceReadableBuffer != nullptr);
703 // Get readable buffer for output workload
704 auto outputReadableBuffer = bufferManager.GetReadableBuffer();
705 BOOST_CHECK(outputReadableBuffer != nullptr);
707 // Get readable buffer for input workload
708 auto inputReadableBuffer = bufferManager.GetReadableBuffer();
709 BOOST_CHECK(inputReadableBuffer != nullptr);
711 // Validate input workload data
712 size = inputReadableBuffer->GetSize();
713 BOOST_CHECK(size == 204);
715 readableData = inputReadableBuffer->GetReadableData();
716 BOOST_CHECK(readableData != nullptr);
721 VerifyTimelineHeaderBinary(readableData, offset, 196);
724 // Input workload entity
725 VerifyTimelineEntityBinaryPacketData(EmptyOptional(), readableData, offset);
727 // Entity - Type relationship
728 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
735 // Type label relationship
736 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
739 LabelsAndEventClasses::TYPE_GUID,
744 VerifyTimelineLabelBinaryPacketData(EmptyOptional(), "CpuRef", readableData, offset);
746 // Entity - BackendId relationship
747 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
754 // BackendId label relationship
755 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
758 LabelsAndEventClasses::BACKENDID_GUID,
762 // Input layer - Input workload relationship
763 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
770 bufferManager.MarkRead(inputReadableBuffer);
772 // Validate output workload data
773 size = outputReadableBuffer->GetSize();
774 BOOST_CHECK(size == 204);
776 readableData = outputReadableBuffer->GetReadableData();
777 BOOST_CHECK(readableData != nullptr);
782 VerifyTimelineHeaderBinary(readableData, offset, 196);
785 // Output workload entity
786 VerifyTimelineEntityBinaryPacketData(EmptyOptional(), readableData, offset);
788 // Entity - Type relationship
789 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
796 // Type label relationship
797 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
800 LabelsAndEventClasses::TYPE_GUID,
805 VerifyTimelineLabelBinaryPacketData(EmptyOptional(), "CpuRef", readableData, offset);
807 // Entity - BackendId relationship
808 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
815 // BackendId label relationship
816 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
819 LabelsAndEventClasses::BACKENDID_GUID,
823 // Output layer - Output workload relationship
824 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
831 bufferManager.MarkRead(outputReadableBuffer);
833 // Validate inference data
834 size = inferenceReadableBuffer->GetSize();
835 BOOST_CHECK(size == 1272);
837 readableData = inferenceReadableBuffer->GetReadableData();
838 BOOST_CHECK(readableData != nullptr);
843 VerifyTimelineHeaderBinary(readableData, offset, 1264);
845 // Inference timeline trace
847 VerifyTimelineEntityBinaryPacketData(EmptyOptional(), readableData, offset);
849 // Entity - Type relationship
850 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
853 LabelsAndEventClasses::INFERENCE_GUID,
857 // Type label relationship
858 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
861 LabelsAndEventClasses::TYPE_GUID,
865 // Network - Inference relationship
866 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
873 // Start Inference life
874 // Event packet - timeline, threadId, eventGuid
875 VerifyTimelineEventBinaryPacket(EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
877 // Inference - event relationship
878 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
885 // Event - event class relationship
886 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::DataLink,
889 LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS,
894 // Input workload execution
895 // Input workload execution entity
896 VerifyTimelineEntityBinaryPacketData(EmptyOptional(), readableData, offset);
898 // Entity - Type relationship
899 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
902 LabelsAndEventClasses::WORKLOAD_EXECUTION_GUID,
906 // Type label relationship
907 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
910 LabelsAndEventClasses::TYPE_GUID,
914 // Inference - Workload execution relationship
915 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
922 // Workload - Workload execution relationship
923 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
930 // Start Input workload execution life
931 // Event packet - timeline, threadId, eventGuid
932 VerifyTimelineEventBinaryPacket(EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
934 // Input workload execution - event relationship
935 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
942 // Event - event class relationship
943 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::DataLink,
946 LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS,
950 // End of Input workload execution life
951 // Event packet - timeline, threadId, eventGuid
952 VerifyTimelineEventBinaryPacket(EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
954 // Input workload execution - event relationship
955 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
962 // Event - event class relationship
963 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::DataLink,
966 LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS,
970 // Normalize workload execution
971 // Normalize workload execution entity
972 VerifyTimelineEntityBinaryPacketData(EmptyOptional(), readableData, offset);
974 // Entity - Type relationship
975 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
978 LabelsAndEventClasses::WORKLOAD_EXECUTION_GUID,
982 // Type label relationship
983 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
986 LabelsAndEventClasses::TYPE_GUID,
990 // Inference - Workload execution relationship
991 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
998 // Workload - Workload execution relationship
999 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
1006 // Start Normalize workload execution life
1007 // Event packet - timeline, threadId, eventGuid
1008 VerifyTimelineEventBinaryPacket(EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
1010 // Normalize workload execution - event relationship
1011 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
1018 // Event - event class relationship
1019 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::DataLink,
1022 LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS,
1026 // End of Normalize workload execution life
1027 // Event packet - timeline, threadId, eventGuid
1028 VerifyTimelineEventBinaryPacket(EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
1030 // Normalize workload execution - event relationship
1031 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
1038 // Event - event class relationship
1039 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::DataLink,
1042 LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS,
1046 // Output workload execution
1047 // Output workload execution entity
1048 VerifyTimelineEntityBinaryPacketData(EmptyOptional(), readableData, offset);
1050 // Entity - Type relationship
1051 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
1054 LabelsAndEventClasses::WORKLOAD_EXECUTION_GUID,
1058 // Type label relationship
1059 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
1062 LabelsAndEventClasses::TYPE_GUID,
1066 // Inference - Workload execution relationship
1067 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
1074 // Workload - Workload execution relationship
1075 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
1082 // Start Output workload execution life
1083 // Event packet - timeline, threadId, eventGuid
1084 VerifyTimelineEventBinaryPacket(EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
1086 // Output workload execution - event relationship
1087 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
1094 // Event - event class relationship
1095 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::DataLink,
1098 LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS,
1102 // End of Normalize workload execution life
1103 // Event packet - timeline, threadId, eventGuid
1104 VerifyTimelineEventBinaryPacket(EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
1106 // Output workload execution - event relationship
1107 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
1114 // Event - event class relationship
1115 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::DataLink,
1118 LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS,
1122 // End of Inference life
1123 // Event packet - timeline, threadId, eventGuid
1124 VerifyTimelineEventBinaryPacket(EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
1126 // Inference - event relationship
1127 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
1134 // Event - event class relationship
1135 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::DataLink,
1138 LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS,
1142 bufferManager.MarkRead(inferenceReadableBuffer);
1145 BOOST_AUTO_TEST_CASE(ProfilingPostOptimisationStructureCpuRef)
1147 VerifyPostOptimisationStructureTestImpl(armnn::Compute::CpuRef);
1150 BOOST_AUTO_TEST_SUITE_END()