59 TEST_CASE(
"CheckCommandHandlerKeyComparisons")
61 arm::pipe::CommandHandlerKey testKey1_0(1, 1, 1);
62 arm::pipe::CommandHandlerKey testKey1_1(1, 1, 1);
63 arm::pipe::CommandHandlerKey testKey1_2(1, 2, 1);
65 arm::pipe::CommandHandlerKey testKey0(0, 1, 1);
66 arm::pipe::CommandHandlerKey testKey1(0, 1, 1);
67 arm::pipe::CommandHandlerKey testKey2(0, 1, 1);
68 arm::pipe::CommandHandlerKey testKey3(0, 0, 0);
69 arm::pipe::CommandHandlerKey testKey4(0, 2, 2);
70 arm::pipe::CommandHandlerKey testKey5(0, 0, 2);
72 CHECK(testKey1_0 > testKey0);
73 CHECK(testKey1_0 == testKey1_1);
74 CHECK(testKey1_0 < testKey1_2);
76 CHECK(testKey1 < testKey4);
77 CHECK(testKey1 > testKey3);
78 CHECK(testKey1 <= testKey4);
79 CHECK(testKey1 >= testKey3);
80 CHECK(testKey1 <= testKey2);
81 CHECK(testKey1 >= testKey2);
82 CHECK(testKey1 == testKey2);
83 CHECK(testKey1 == testKey1);
85 CHECK(!(testKey1 == testKey5));
86 CHECK(!(testKey1 != testKey1));
87 CHECK(testKey1 != testKey5);
89 CHECK((testKey1 == testKey2 && testKey2 == testKey1));
90 CHECK((testKey0 == testKey1 && testKey1 == testKey2 && testKey0 == testKey2));
92 CHECK(testKey1.GetPacketId() == 1);
93 CHECK(testKey1.GetVersion() == 1);
95 std::vector<arm::pipe::CommandHandlerKey> vect = {
96 arm::pipe::CommandHandlerKey(0, 0, 1), arm::pipe::CommandHandlerKey(0, 2, 0),
97 arm::pipe::CommandHandlerKey(0, 1, 0), arm::pipe::CommandHandlerKey(0, 2, 1),
98 arm::pipe::CommandHandlerKey(0, 1, 1), arm::pipe::CommandHandlerKey(0, 0, 1),
99 arm::pipe::CommandHandlerKey(0, 2, 0), arm::pipe::CommandHandlerKey(0, 0, 0) };
101 std::sort(vect.begin(), vect.end());
103 std::vector<arm::pipe::CommandHandlerKey> expectedVect = {
104 arm::pipe::CommandHandlerKey(0, 0, 0), arm::pipe::CommandHandlerKey(0, 0, 1),
105 arm::pipe::CommandHandlerKey(0, 0, 1), arm::pipe::CommandHandlerKey(0, 1, 0),
106 arm::pipe::CommandHandlerKey(0, 1, 1), arm::pipe::CommandHandlerKey(0, 2, 0),
107 arm::pipe::CommandHandlerKey(0, 2, 0), arm::pipe::CommandHandlerKey(0, 2, 1) };
109 CHECK(vect == expectedVect);
112 TEST_CASE(
"CheckPacketKeyComparisons")
114 arm::pipe::PacketKey key0(0, 0);
115 arm::pipe::PacketKey key1(0, 0);
116 arm::pipe::PacketKey key2(0, 1);
117 arm::pipe::PacketKey key3(0, 2);
118 arm::pipe::PacketKey key4(1, 0);
119 arm::pipe::PacketKey key5(1, 0);
120 arm::pipe::PacketKey key6(1, 1);
122 CHECK(!(key0 < key1));
123 CHECK(!(key0 > key1));
137 TEST_CASE(
"CheckCommandHandler")
139 arm::pipe::PacketVersionResolver packetVersionResolver;
148 SendThread sendThread(profilingStateMachine, mockBuffer, sendCounterPacket);
153 sendCounterPacket, sendTimelinePacket,
154 profilingStateMachine,
155 mockProfilingServiceStatus);
156 arm::pipe::CommandHandlerRegistry commandHandlerRegistry;
158 commandHandlerRegistry.RegisterFunctor(&connectionAcknowledgedCommandHandler);
163 CommandHandler commandHandler0(1,
true, commandHandlerRegistry, packetVersionResolver);
167 commandHandler0.Start(testProfilingConnectionBase);
169 commandHandler0.Start(testProfilingConnectionBase);
172 for (
int i = 0; i < 10; i++)
178 std::this_thread::sleep_for(std::chrono::milliseconds(2));
181 CHECK(profilingStateMachine.
GetCurrentState() == ProfilingState::Active);
184 commandHandler0.Stop();
191 CommandHandler commandHandler1(1,
true, commandHandlerRegistry, packetVersionResolver);
193 commandHandler1.Start(testProfilingConnectionTimeOutError);
195 for (
int i = 0; i < 10; i++)
201 std::this_thread::sleep_for(std::chrono::milliseconds(2));
206 uint32_t timeout = 50;
207 uint32_t timeSlept = 0;
208 while (commandHandler1.IsRunning())
210 if (timeSlept >= timeout)
212 FAIL(
"Timeout: The command handler loop did not stop after the timeout");
214 std::this_thread::sleep_for(std::chrono::milliseconds(1));
218 commandHandler1.Stop();
220 CHECK(profilingStateMachine.
GetCurrentState() == ProfilingState::WaitingForAck);
224 commandHandler1.Start(testProfilingConnectionBadAckPacket);
225 commandHandler1.Stop();
227 CHECK(profilingStateMachine.
GetCurrentState() == ProfilingState::WaitingForAck);
230 commandHandler1.SetStopAfterTimeout(
false);
232 commandHandler1.Start(testProfilingConnectionTimeOutError);
235 for (
int i = 0; i < 10; i++)
241 std::this_thread::sleep_for(std::chrono::milliseconds(2));
243 commandHandler1.Stop();
246 CHECK(profilingStateMachine.
GetCurrentState() == ProfilingState::Active);
249 CommandHandler commandHandler2(1,
false, commandHandlerRegistry, packetVersionResolver);
251 commandHandler2.Start(testProfilingConnectionArmnnError);
254 for (
int i = 0; i < 10; i++)
260 std::this_thread::sleep_for(std::chrono::milliseconds(2));
263 CHECK(commandHandler2.IsRunning());
264 commandHandler2.Stop();
267 TEST_CASE(
"CheckEncodeVersion")
269 arm::pipe::Version version1(12);
271 CHECK(version1.GetMajor() == 0);
272 CHECK(version1.GetMinor() == 0);
273 CHECK(version1.GetPatch() == 12);
275 arm::pipe::Version version2(4108);
277 CHECK(version2.GetMajor() == 0);
278 CHECK(version2.GetMinor() == 1);
279 CHECK(version2.GetPatch() == 12);
281 arm::pipe::Version version3(4198412);
283 CHECK(version3.GetMajor() == 1);
284 CHECK(version3.GetMinor() == 1);
285 CHECK(version3.GetPatch() == 12);
287 arm::pipe::Version version4(0);
289 CHECK(version4.GetMajor() == 0);
290 CHECK(version4.GetMinor() == 0);
291 CHECK(version4.GetPatch() == 0);
293 arm::pipe::Version version5(1, 0, 0);
294 CHECK(version5.GetEncodedValue() == 4194304);
297 TEST_CASE(
"CheckPacketClass")
300 std::unique_ptr<unsigned char[]> packetData0 = std::make_unique<unsigned char[]>(length);
301 std::unique_ptr<unsigned char[]> packetData1 = std::make_unique<unsigned char[]>(0);
302 std::unique_ptr<unsigned char[]> nullPacketData;
304 arm::pipe::Packet packetTest0(472580096, length, packetData0);
306 CHECK(packetTest0.GetHeader() == 472580096);
307 CHECK(packetTest0.GetPacketFamily() == 7);
308 CHECK(packetTest0.GetPacketId() == 43);
309 CHECK(packetTest0.GetLength() == length);
310 CHECK(packetTest0.GetPacketType() == 3);
311 CHECK(packetTest0.GetPacketClass() == 5);
313 CHECK_THROWS_AS(arm::pipe::Packet packetTest1(472580096, 0, packetData1), arm::pipe::InvalidArgumentException);
314 CHECK_NOTHROW(arm::pipe::Packet packetTest2(472580096, 0, nullPacketData));
316 arm::pipe::Packet packetTest3(472580096, 0, nullPacketData);
317 CHECK(packetTest3.GetLength() == 0);
318 CHECK(packetTest3.GetData() ==
nullptr);
320 const unsigned char* packetTest0Data = packetTest0.GetData();
321 arm::pipe::Packet packetTest4(std::move(packetTest0));
323 CHECK(packetTest0.GetData() ==
nullptr);
324 CHECK(packetTest4.GetData() == packetTest0Data);
326 CHECK(packetTest4.GetHeader() == 472580096);
327 CHECK(packetTest4.GetPacketFamily() == 7);
328 CHECK(packetTest4.GetPacketId() == 43);
329 CHECK(packetTest4.GetLength() == length);
330 CHECK(packetTest4.GetPacketType() == 3);
331 CHECK(packetTest4.GetPacketClass() == 5);
334 TEST_CASE(
"CheckCommandHandlerFunctor")
337 uint32_t version = 1;
343 arm::pipe::CommandHandlerKey keyA(
344 testFunctorA.GetFamilyId(), testFunctorA.GetPacketId(), testFunctorA.GetVersion());
345 arm::pipe::CommandHandlerKey keyB(
346 testFunctorB.GetFamilyId(), testFunctorB.GetPacketId(), testFunctorB.GetVersion());
347 arm::pipe::CommandHandlerKey keyC(
348 testFunctorC.GetFamilyId(), testFunctorC.GetPacketId(), testFunctorC.GetVersion());
351 std::map<arm::pipe::CommandHandlerKey, arm::pipe::CommandHandlerFunctor*> registry;
353 registry.insert(std::make_pair(keyB, &testFunctorB));
354 registry.insert(std::make_pair(keyA, &testFunctorA));
355 registry.insert(std::make_pair(keyC, &testFunctorC));
358 auto it = registry.begin();
359 CHECK(it->first == keyC);
361 CHECK(it->first == keyA);
363 CHECK(it->first == keyB);
365 std::unique_ptr<unsigned char[]> packetDataA;
366 std::unique_ptr<unsigned char[]> packetDataB;
367 std::unique_ptr<unsigned char[]> packetDataC;
369 arm::pipe::Packet packetA(500000000, 0, packetDataA);
370 arm::pipe::Packet packetB(600000000, 0, packetDataB);
371 arm::pipe::Packet packetC(400000000, 0, packetDataC);
374 registry.at(arm::pipe::CommandHandlerKey(
375 packetA.GetPacketFamily(), packetA.GetPacketId(), version))->operator()(packetA);
376 CHECK(testFunctorA.GetCount() == 1);
377 CHECK(testFunctorB.GetCount() == 0);
378 CHECK(testFunctorC.GetCount() == 0);
380 registry.at(arm::pipe::CommandHandlerKey(
381 packetB.GetPacketFamily(), packetB.GetPacketId(), version))->operator()(packetB);
382 CHECK(testFunctorA.GetCount() == 1);
383 CHECK(testFunctorB.GetCount() == 1);
384 CHECK(testFunctorC.GetCount() == 0);
386 registry.at(arm::pipe::CommandHandlerKey(
387 packetC.GetPacketFamily(), packetC.GetPacketId(), version))->operator()(packetC);
388 CHECK(testFunctorA.GetCount() == 1);
389 CHECK(testFunctorB.GetCount() == 1);
390 CHECK(testFunctorC.GetCount() == 1);
393 TEST_CASE(
"CheckCommandHandlerRegistry")
396 uint32_t version = 1;
403 arm::pipe::CommandHandlerRegistry registry;
406 registry.RegisterFunctor(&testFunctorA);
407 registry.RegisterFunctor(&testFunctorB);
408 registry.RegisterFunctor(&testFunctorC);
410 std::unique_ptr<unsigned char[]> packetDataA;
411 std::unique_ptr<unsigned char[]> packetDataB;
412 std::unique_ptr<unsigned char[]> packetDataC;
414 arm::pipe::Packet packetA(500000000, 0, packetDataA);
415 arm::pipe::Packet packetB(600000000, 0, packetDataB);
416 arm::pipe::Packet packetC(400000000, 0, packetDataC);
419 registry.GetFunctor(packetA.GetPacketFamily(), packetA.GetPacketId(), version)->
operator()(packetA);
420 CHECK(testFunctorA.GetCount() == 1);
421 CHECK(testFunctorB.GetCount() == 0);
422 CHECK(testFunctorC.GetCount() == 0);
424 registry.GetFunctor(packetB.GetPacketFamily(), packetB.GetPacketId(), version)->
operator()(packetB);
425 CHECK(testFunctorA.GetCount() == 1);
426 CHECK(testFunctorB.GetCount() == 1);
427 CHECK(testFunctorC.GetCount() == 0);
429 registry.GetFunctor(packetC.GetPacketFamily(), packetC.GetPacketId(), version)->
operator()(packetC);
430 CHECK(testFunctorA.GetCount() == 1);
431 CHECK(testFunctorB.GetCount() == 1);
432 CHECK(testFunctorC.GetCount() == 1);
435 registry.RegisterFunctor(&testFunctorC, testFunctorA.GetFamilyId(), testFunctorA.GetPacketId(), version);
436 registry.GetFunctor(packetA.GetPacketFamily(), packetA.GetPacketId(), version)->
operator()(packetC);
437 CHECK(testFunctorA.GetCount() == 1);
438 CHECK(testFunctorB.GetCount() == 1);
439 CHECK(testFunctorC.GetCount() == 2);
442 CHECK_THROWS_AS(registry.GetFunctor(0, 0, 0), arm::pipe::ProfilingException);
445 TEST_CASE(
"CheckPacketVersionResolver")
448 std::random_device device;
449 std::mt19937 generator(device());
450 std::uniform_int_distribution<uint32_t> distribution(std::numeric_limits<uint32_t>::min(),
451 std::numeric_limits<uint32_t>::max());
454 const arm::pipe::Version expectedVersion(1, 0, 0);
456 arm::pipe::PacketVersionResolver packetVersionResolver;
458 constexpr
unsigned int numTests = 10u;
460 for (
unsigned int i = 0u; i < numTests; ++i)
462 const uint32_t familyId = distribution(generator);
463 const uint32_t packetId = distribution(generator);
464 arm::pipe::Version resolvedVersion = packetVersionResolver.ResolvePacketVersion(familyId, packetId);
466 CHECK(resolvedVersion == expectedVersion);
477 TEST_CASE(
"CheckProfilingStateMachine")
480 profilingState1.TransitionToState(ProfilingState::Uninitialised);
481 CHECK(profilingState1.GetCurrentState() == ProfilingState::Uninitialised);
484 profilingState2.TransitionToState(ProfilingState::NotConnected);
485 CHECK(profilingState2.GetCurrentState() == ProfilingState::NotConnected);
488 profilingState3.TransitionToState(ProfilingState::NotConnected);
489 CHECK(profilingState3.GetCurrentState() == ProfilingState::NotConnected);
492 profilingState4.TransitionToState(ProfilingState::WaitingForAck);
493 CHECK(profilingState4.GetCurrentState() == ProfilingState::WaitingForAck);
496 profilingState5.TransitionToState(ProfilingState::WaitingForAck);
497 CHECK(profilingState5.GetCurrentState() == ProfilingState::WaitingForAck);
500 profilingState6.TransitionToState(ProfilingState::Active);
501 CHECK(profilingState6.GetCurrentState() == ProfilingState::Active);
504 profilingState7.TransitionToState(ProfilingState::NotConnected);
505 CHECK(profilingState7.GetCurrentState() == ProfilingState::NotConnected);
508 profilingState8.TransitionToState(ProfilingState::Active);
509 CHECK(profilingState8.GetCurrentState() == ProfilingState::Active);
512 CHECK_THROWS_AS(profilingState9.TransitionToState(ProfilingState::WaitingForAck),
armnn::Exception);
515 CHECK_THROWS_AS(profilingState10.TransitionToState(ProfilingState::Active),
armnn::Exception);
518 CHECK_THROWS_AS(profilingState11.TransitionToState(ProfilingState::Uninitialised),
armnn::Exception);
521 CHECK_THROWS_AS(profilingState12.TransitionToState(ProfilingState::Active),
armnn::Exception);
524 CHECK_THROWS_AS(profilingState13.TransitionToState(ProfilingState::Uninitialised),
armnn::Exception);
527 profilingState14.TransitionToState(ProfilingState::NotConnected);
528 CHECK(profilingState14.GetCurrentState() == ProfilingState::NotConnected);
531 CHECK_THROWS_AS(profilingState15.TransitionToState(ProfilingState::Uninitialised),
armnn::Exception);
534 CHECK_THROWS_AS(profilingState16.TransitionToState(ProfilingState::WaitingForAck),
armnn::Exception);
538 std::vector<std::thread> threads;
539 for (
unsigned int i = 0; i < 5; ++i)
541 threads.push_back(std::thread(ProfilingCurrentStateThreadImpl, std::ref(profilingState17)));
543 std::for_each(threads.begin(), threads.end(), [](std::thread& theThread)
548 CHECK((profilingState17.GetCurrentState() == ProfilingState::NotConnected));
551 void CaptureDataWriteThreadImpl(
Holder& holder, uint32_t capturePeriod,
const std::vector<uint16_t>& counterIds)
561 TEST_CASE(
"CheckCaptureDataHolder")
563 std::map<uint32_t, std::vector<uint16_t>> periodIdMap;
564 std::vector<uint16_t> counterIds;
565 uint32_t numThreads = 10;
566 for (uint32_t i = 0; i < numThreads; ++i)
568 counterIds.emplace_back(i);
569 periodIdMap.insert(std::make_pair(i, counterIds));
579 std::thread thread1(CaptureDataWriteThreadImpl, std::ref(holder), 2, std::ref(periodIdMap[2]));
582 CHECK((holder.
GetCaptureData()).GetCounterIds() == periodIdMap[2]);
590 std::thread thread2(CaptureDataReadThreadImpl, std::ref(holder), std::ref(captureData));
592 CHECK(captureData.GetCapturePeriod() == 2);
593 CHECK(captureData.GetCounterIds() == periodIdMap[2]);
595 std::map<uint32_t, CaptureData> captureDataIdMap;
596 for (uint32_t i = 0; i < numThreads; ++i)
599 captureDataIdMap.insert(std::make_pair(i, perThreadCaptureData));
602 std::vector<std::thread> threadsVect;
603 std::vector<std::thread> readThreadsVect;
604 for (uint32_t i = 0; i < numThreads; ++i)
606 threadsVect.emplace_back(
607 std::thread(CaptureDataWriteThreadImpl, std::ref(holder), i, std::ref(periodIdMap[i])));
610 CHECK(captureDataIdMap.at(i).GetCapturePeriod() == 0);
611 CHECK(captureDataIdMap.at(i).GetCounterIds().empty());
612 readThreadsVect.emplace_back(
613 std::thread(CaptureDataReadThreadImpl, std::ref(holder), std::ref(captureDataIdMap.at(i))));
616 for (uint32_t i = 0; i < numThreads; ++i)
618 threadsVect[i].join();
619 readThreadsVect[i].join();
624 for (uint32_t i = 0; i < numThreads; ++i)
626 CaptureData perThreadCaptureData = captureDataIdMap.at(i);
631 TEST_CASE(
"CaptureDataMethods")
634 std::vector<uint16_t> counterIds = { 42, 29, 13 };
646 secondCaptureData = captureData;
647 CHECK(secondCaptureData.GetCapturePeriod() == 150);
648 CHECK(secondCaptureData.GetCounterIds() == counterIds);
651 CaptureData copyConstructedCaptureData(captureData);
653 CHECK(copyConstructedCaptureData.GetCapturePeriod() == 150);
654 CHECK(copyConstructedCaptureData.GetCounterIds() == counterIds);
657 TEST_CASE(
"CheckProfilingServiceDisabled")
662 CHECK(profilingService.
GetCurrentState() == ProfilingState::Uninitialised);
663 profilingService.
Update();
664 CHECK(profilingService.
GetCurrentState() == ProfilingState::Uninitialised);
667 TEST_CASE(
"CheckProfilingServiceCounterDirectory")
675 profilingService.
Update();
683 profilingService.
Update();
690 TEST_CASE(
"CheckProfilingServiceCounterValues")
697 profilingService.
Update();
700 CHECK(!counters.empty());
702 std::vector<std::thread> writers;
704 CHECK(!counters.empty());
705 uint16_t inferencesRun = armnn::profiling::INFERENCES_RUN;
708 for (
int i = 0; i < 4; ++i)
711 writers.push_back(std::thread([&profilingService, inferencesRun]()
713 for (
int i = 0; i < 250; ++i)
719 writers.push_back(std::thread([&profilingService, inferencesRun]()
721 for (
int i = 0; i < 200; ++i)
727 writers.push_back(std::thread([&profilingService, inferencesRun]()
729 for (
int i = 0; i < 200; ++i)
735 std::for_each(writers.begin(), writers.end(), mem_fn(&std::thread::join));
737 uint32_t absoluteCounterValue = 0;
740 CHECK(absoluteCounterValue == 5000);
745 CHECK(absoluteCounterValue == 0);
749 uint32_t deltaCounterValue = 0;
751 std::thread reader([&profilingService, inferencesRun](uint32_t& deltaCounterValue)
753 for (
int i = 0; i < 300; ++i)
757 }, std::ref(deltaCounterValue));
759 for (
int i = 0; i < 4; ++i)
762 writers.push_back(std::thread([&profilingService, inferencesRun]()
764 for (
int i = 0; i < 250; ++i)
770 writers.push_back(std::thread([&profilingService, inferencesRun]()
772 for (
int i = 0; i < 200; ++i)
778 writers.push_back(std::thread([&profilingService, inferencesRun]()
780 for (
int i = 0; i < 200; ++i)
787 std::for_each(writers.begin(), writers.end(), mem_fn(&std::thread::join));
792 CHECK(deltaCounterValue == 5000);
799 TEST_CASE(
"CheckProfilingObjectUids")
805 uint16_t nextUid = 0;
807 CHECK(nextUid > uid);
809 std::vector<uint16_t> counterUids;
811 CHECK(counterUids.size() == 1);
813 std::vector<uint16_t> nextCounterUids;
815 CHECK(nextCounterUids.size() == 2);
816 CHECK(nextCounterUids[0] > counterUids[0]);
818 std::vector<uint16_t> counterUidsMultiCore;
819 uint16_t thirdUid = nextCounterUids[0];
820 uint16_t numberOfCores = 13;
822 CHECK(counterUidsMultiCore.size() == numberOfCores);
823 CHECK(counterUidsMultiCore.front() >= nextCounterUids[0]);
824 for (
size_t i = 1; i < numberOfCores; i++)
826 CHECK(counterUidsMultiCore[i] == counterUidsMultiCore[i - 1] + 1);
828 CHECK(counterUidsMultiCore.back() == counterUidsMultiCore.front() + numberOfCores - 1);
831 TEST_CASE(
"CheckCounterDirectoryRegisterCategory")
840 const Category* noCategory =
nullptr;
846 CHECK_THROWS_AS(noCategory = counterDirectory.
RegisterCategory(
"invalid category"),
852 const std::string categoryName =
"some_category";
857 CHECK(category->
m_Name == categoryName);
863 CHECK(registeredCategory);
864 CHECK(registeredCategory == category);
867 const Category* notRegisteredCategory = counterDirectory.
GetCategory(
"not_registered_category");
869 CHECK(!notRegisteredCategory);
872 const Category* anotherCategory =
nullptr;
873 CHECK_THROWS_AS(anotherCategory = counterDirectory.
RegisterCategory(categoryName),
876 CHECK(!anotherCategory);
879 const std::string deviceName =
"some_device";
880 const Device* device =
nullptr;
881 CHECK_NOTHROW(device = counterDirectory.
RegisterDevice(deviceName));
884 CHECK(device->
m_Uid >= 1);
885 CHECK(device->
m_Name == deviceName);
889 const std::string categoryWoDeviceName =
"some_category_without_device";
890 const Category* categoryWoDevice =
nullptr;
891 CHECK_NOTHROW(categoryWoDevice = counterDirectory.
RegisterCategory(categoryWoDeviceName));
893 CHECK(categoryWoDevice);
894 CHECK(categoryWoDevice->
m_Name == categoryWoDeviceName);
898 const Category* categoryInvalidDeviceName =
nullptr;
899 CHECK_THROWS_AS(categoryInvalidDeviceName =
903 CHECK(!categoryInvalidDeviceName);
906 const std::string categoryWValidDeviceName =
"some_category_with_valid_device";
907 const Category* categoryWValidDevice =
nullptr;
908 CHECK_NOTHROW(categoryWValidDevice =
911 CHECK(categoryWValidDevice);
912 CHECK(categoryWValidDevice != category);
913 CHECK(categoryWValidDevice->
m_Name == categoryWValidDeviceName);
916 const std::string counterSetName =
"some_counter_set";
921 CHECK(counterSet->
m_Uid >= 1);
922 CHECK(counterSet->
m_Name == counterSetName);
923 CHECK(counterSet->
m_Count == 0);
926 const std::string categoryWoCounterSetName =
"some_category_without_counter_set";
927 const Category* categoryWoCounterSet =
nullptr;
928 CHECK_NOTHROW(categoryWoCounterSet =
931 CHECK(categoryWoCounterSet);
932 CHECK(categoryWoCounterSet->
m_Name == categoryWoCounterSetName);
935 const std::string categoryWValidCounterSetName =
"some_category_with_valid_counter_set";
936 const Category* categoryWValidCounterSet =
nullptr;
937 CHECK_NOTHROW(categoryWValidCounterSet = counterDirectory.
RegisterCategory(categoryWValidCounterSetName));
939 CHECK(categoryWValidCounterSet);
940 CHECK(categoryWValidCounterSet != category);
941 CHECK(categoryWValidCounterSet->
m_Name == categoryWValidCounterSetName);
944 const std::string categoryWValidDeviceAndValidCounterSetName =
"some_category_with_valid_device_and_counter_set";
945 const Category* categoryWValidDeviceAndValidCounterSet =
nullptr;
946 CHECK_NOTHROW(categoryWValidDeviceAndValidCounterSet = counterDirectory.
RegisterCategory(
947 categoryWValidDeviceAndValidCounterSetName));
949 CHECK(categoryWValidDeviceAndValidCounterSet);
950 CHECK(categoryWValidDeviceAndValidCounterSet != category);
951 CHECK(categoryWValidDeviceAndValidCounterSet->
m_Name == categoryWValidDeviceAndValidCounterSetName);
954 TEST_CASE(
"CheckCounterDirectoryRegisterDevice")
963 const Device* noDevice =
nullptr;
974 const std::string deviceName =
"some_device";
975 const Device* device =
nullptr;
976 CHECK_NOTHROW(device = counterDirectory.
RegisterDevice(deviceName));
979 CHECK(device->
m_Name == deviceName);
980 CHECK(device->
m_Uid >= 1);
985 CHECK(!unregisteredDevice);
990 CHECK(registeredDevice);
991 CHECK(registeredDevice == device);
994 const Device* deviceSameName =
nullptr;
997 CHECK(!deviceSameName);
1000 const std::string deviceWCoresName =
"some_device_with_cores";
1001 const Device* deviceWCores =
nullptr;
1002 CHECK_NOTHROW(deviceWCores = counterDirectory.
RegisterDevice(deviceWCoresName, 2));
1004 CHECK(deviceWCores);
1005 CHECK(deviceWCores->
m_Name == deviceWCoresName);
1006 CHECK(deviceWCores->
m_Uid >= 1);
1008 CHECK(deviceWCores->
m_Cores == 2);
1013 CHECK(registeredDeviceWCores);
1014 CHECK(registeredDeviceWCores == deviceWCores);
1015 CHECK(registeredDeviceWCores != device);
1018 const std::string deviceWCoresWInvalidParentCategoryName =
"some_device_with_cores_with_invalid_parent_category";
1019 const Device* deviceWCoresWInvalidParentCategory =
nullptr;
1020 CHECK_THROWS_AS(deviceWCoresWInvalidParentCategory =
1021 counterDirectory.
RegisterDevice(deviceWCoresWInvalidParentCategoryName, 3, std::string(
"")),
1024 CHECK(!deviceWCoresWInvalidParentCategory);
1027 const std::string deviceWCoresWInvalidParentCategoryName2 =
"some_device_with_cores_with_invalid_parent_category2";
1028 const Device* deviceWCoresWInvalidParentCategory2 =
nullptr;
1029 CHECK_THROWS_AS(deviceWCoresWInvalidParentCategory2 = counterDirectory.
RegisterDevice(
1030 deviceWCoresWInvalidParentCategoryName2, 3, std::string(
"invalid_parent_category")),
1033 CHECK(!deviceWCoresWInvalidParentCategory2);
1036 const std::string categoryName =
"some_category";
1037 const Category* category =
nullptr;
1041 CHECK(category->
m_Name == categoryName);
1045 const std::string deviceWCoresWValidParentCategoryName =
"some_device_with_cores_with_valid_parent_category";
1046 const Device* deviceWCoresWValidParentCategory =
nullptr;
1047 CHECK_NOTHROW(deviceWCoresWValidParentCategory =
1048 counterDirectory.
RegisterDevice(deviceWCoresWValidParentCategoryName, 4, categoryName));
1050 CHECK(deviceWCoresWValidParentCategory);
1051 CHECK(deviceWCoresWValidParentCategory->
m_Name == deviceWCoresWValidParentCategoryName);
1052 CHECK(deviceWCoresWValidParentCategory->
m_Uid >= 1);
1053 CHECK(deviceWCoresWValidParentCategory->
m_Uid > device->
m_Uid);
1054 CHECK(deviceWCoresWValidParentCategory->
m_Uid > deviceWCores->
m_Uid);
1055 CHECK(deviceWCoresWValidParentCategory->
m_Cores == 4);
1058 TEST_CASE(
"CheckCounterDirectoryRegisterCounterSet")
1070 CHECK(!noCounterSet);
1076 CHECK(!noCounterSet);
1079 const std::string counterSetName =
"some_counter_set";
1084 CHECK(counterSet->
m_Name == counterSetName);
1085 CHECK(counterSet->
m_Uid >= 1);
1086 CHECK(counterSet->
m_Count == 0);
1090 CHECK(!unregisteredCounterSet);
1095 CHECK(registeredCounterSet);
1096 CHECK(registeredCounterSet == counterSet);
1099 const CounterSet* counterSetSameName =
nullptr;
1100 CHECK_THROWS_AS(counterSetSameName = counterDirectory.
RegisterCounterSet(counterSetName),
1103 CHECK(!counterSetSameName);
1106 const std::string counterSetWCountName =
"some_counter_set_with_count";
1107 const CounterSet* counterSetWCount =
nullptr;
1108 CHECK_NOTHROW(counterSetWCount = counterDirectory.
RegisterCounterSet(counterSetWCountName, 37));
1110 CHECK(counterSetWCount);
1111 CHECK(counterSetWCount->
m_Name == counterSetWCountName);
1112 CHECK(counterSetWCount->
m_Uid >= 1);
1113 CHECK(counterSetWCount->
m_Uid > counterSet->
m_Uid);
1114 CHECK(counterSetWCount->
m_Count == 37);
1119 CHECK(registeredCounterSetWCount);
1120 CHECK(registeredCounterSetWCount == counterSetWCount);
1121 CHECK(registeredCounterSetWCount != counterSet);
1124 const std::string counterSetWCountWInvalidParentCategoryName =
"some_counter_set_with_count_" 1125 "with_invalid_parent_category";
1126 const CounterSet* counterSetWCountWInvalidParentCategory =
nullptr;
1127 CHECK_THROWS_AS(counterSetWCountWInvalidParentCategory = counterDirectory.
RegisterCounterSet(
1128 counterSetWCountWInvalidParentCategoryName, 42, std::string(
"")),
1131 CHECK(!counterSetWCountWInvalidParentCategory);
1134 const std::string counterSetWCountWInvalidParentCategoryName2 =
"some_counter_set_with_count_" 1135 "with_invalid_parent_category2";
1136 const CounterSet* counterSetWCountWInvalidParentCategory2 =
nullptr;
1137 CHECK_THROWS_AS(counterSetWCountWInvalidParentCategory2 = counterDirectory.
RegisterCounterSet(
1138 counterSetWCountWInvalidParentCategoryName2, 42, std::string(
"invalid_parent_category")),
1141 CHECK(!counterSetWCountWInvalidParentCategory2);
1144 const std::string categoryName =
"some_category";
1145 const Category* category =
nullptr;
1149 CHECK(category->
m_Name == categoryName);
1153 const std::string counterSetWCountWValidParentCategoryName =
"some_counter_set_with_count_" 1154 "with_valid_parent_category";
1155 const CounterSet* counterSetWCountWValidParentCategory =
nullptr;
1156 CHECK_NOTHROW(counterSetWCountWValidParentCategory = counterDirectory.
RegisterCounterSet(
1157 counterSetWCountWValidParentCategoryName, 42, categoryName));
1159 CHECK(counterSetWCountWValidParentCategory);
1160 CHECK(counterSetWCountWValidParentCategory->
m_Name == counterSetWCountWValidParentCategoryName);
1161 CHECK(counterSetWCountWValidParentCategory->
m_Uid >= 1);
1162 CHECK(counterSetWCountWValidParentCategory->
m_Uid > counterSet->
m_Uid);
1163 CHECK(counterSetWCountWValidParentCategory->
m_Uid > counterSetWCount->
m_Uid);
1164 CHECK(counterSetWCountWValidParentCategory->
m_Count == 42);
1167 const std::string counterSetSameCategoryName =
"some_counter_set_with_invalid_parent_category";
1168 const std::string invalidCategoryName =
"";
1169 const CounterSet* counterSetSameCategory =
nullptr;
1170 CHECK_THROWS_AS(counterSetSameCategory =
1171 counterDirectory.
RegisterCounterSet(counterSetSameCategoryName, 0, invalidCategoryName),
1174 CHECK(!counterSetSameCategory);
1177 TEST_CASE(
"CheckCounterDirectoryRegisterCounter")
1186 const Counter* noCounter =
nullptr;
1187 CHECK_THROWS_AS(noCounter =
1201 CHECK_THROWS_AS(noCounter = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1203 "invalid parent category",
1208 "valid description"),
1214 CHECK_THROWS_AS(noCounter = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1216 "valid_parent_category",
1222 "valid description"),
1228 CHECK_THROWS_AS(noCounter = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1230 "valid_parent_category",
1236 "valid description"),
1242 CHECK_THROWS_AS(noCounter = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1244 "valid_parent_category",
1250 "valid description"),
1257 noCounter = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1259 "valid_parent_category",
1264 "valid description"),
1270 CHECK_THROWS_AS(noCounter = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1272 "valid_parent_category",
1277 "valid description"),
1283 CHECK_THROWS_AS(noCounter =
1286 "valid_parent_category",
1297 CHECK_THROWS_AS(noCounter = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1299 "valid_parent_category",
1305 "inv@lid description"),
1311 CHECK_THROWS_AS(noCounter = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1313 "valid_parent_category",
1318 "valid description",
1319 std::string(
"Mb/s2")),
1325 CHECK_THROWS_AS(noCounter = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1327 "invalid_parent_category",
1332 "valid description"),
1339 CHECK(!unregisteredCounter);
1342 const std::string categoryName =
"some_category";
1343 const Category* category =
nullptr;
1347 CHECK(category->
m_Name == categoryName);
1351 const Counter* counter =
nullptr;
1353 counter = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1360 "valid description"));
1363 CHECK(counter->m_MaxCounterUid == counter->m_Uid);
1364 CHECK(counter->m_Class == 0);
1365 CHECK(counter->m_Interpolation == 1);
1366 CHECK(counter->m_Multiplier == 123.45f);
1367 CHECK(counter->m_Name ==
"valid name");
1368 CHECK(counter->m_Description ==
"valid description");
1369 CHECK(counter->m_Units ==
"");
1370 CHECK(counter->m_DeviceUid == 0);
1371 CHECK(counter->m_CounterSetUid == 0);
1373 CHECK(category->
m_Counters.back() == counter->m_Uid);
1376 const Counter* counterSameName =
nullptr;
1377 CHECK_THROWS_AS(counterSameName =
1385 "valid description",
1386 std::string(
"description")),
1389 CHECK(!counterSameName);
1392 const Counter* counterWUnits =
nullptr;
1393 CHECK_NOTHROW(counterWUnits = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1400 "valid description",
1401 std::string(
"Mnnsq2")));
1403 CHECK(counterWUnits);
1404 CHECK(counterWUnits->
m_Uid > counter->m_Uid);
1406 CHECK(counterWUnits->
m_Class == 0);
1409 CHECK(counterWUnits->
m_Name ==
"valid name 2");
1411 CHECK(counterWUnits->
m_Units ==
"Mnnsq2");
1418 const Counter* counterWoDevice =
nullptr;
1419 CHECK_NOTHROW(counterWoDevice = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1426 "valid description",
1431 CHECK(counterWoDevice);
1432 CHECK(counterWoDevice->m_Uid > counter->m_Uid);
1433 CHECK(counterWoDevice->m_MaxCounterUid == counterWoDevice->m_Uid);
1434 CHECK(counterWoDevice->m_Class == 0);
1435 CHECK(counterWoDevice->m_Interpolation == 1);
1436 CHECK(counterWoDevice->m_Multiplier == 123.45f);
1437 CHECK(counterWoDevice->m_Name ==
"valid name 3");
1438 CHECK(counterWoDevice->m_Description ==
"valid description");
1439 CHECK(counterWoDevice->m_Units ==
"");
1440 CHECK(counterWoDevice->m_DeviceUid == 0);
1441 CHECK(counterWoDevice->m_CounterSetUid == 0);
1443 CHECK(category->
m_Counters.back() == counterWoDevice->m_Uid);
1446 CHECK_THROWS_AS(noCounter = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1453 "valid description",
1462 const std::string deviceName =
"some_device";
1463 const Device* device =
nullptr;
1464 CHECK_NOTHROW(device = counterDirectory.
RegisterDevice(deviceName));
1467 CHECK(device->
m_Name == deviceName);
1468 CHECK(device->
m_Uid >= 1);
1472 const Counter* counterWDevice =
nullptr;
1473 CHECK_NOTHROW(counterWDevice = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1480 std::string(
"valid description"),
1485 CHECK(counterWDevice);
1486 CHECK(counterWDevice->
m_Uid > counter->m_Uid);
1488 CHECK(counterWDevice->
m_Class == 0);
1491 CHECK(counterWDevice->
m_Name ==
"valid name 5");
1492 CHECK(counterWDevice->
m_Description ==
"valid description");
1493 CHECK(counterWDevice->
m_Units ==
"");
1500 const Counter* counterWoCounterSet =
nullptr;
1501 CHECK_NOTHROW(counterWoCounterSet = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1508 "valid description",
1514 CHECK(counterWoCounterSet);
1515 CHECK(counterWoCounterSet->m_Uid > counter->m_Uid);
1516 CHECK(counterWoCounterSet->m_MaxCounterUid == counterWoCounterSet->m_Uid);
1517 CHECK(counterWoCounterSet->m_Class == 0);
1518 CHECK(counterWoCounterSet->m_Interpolation == 1);
1519 CHECK(counterWoCounterSet->m_Multiplier == 123.45f);
1520 CHECK(counterWoCounterSet->m_Name ==
"valid name 6");
1521 CHECK(counterWoCounterSet->m_Description ==
"valid description");
1522 CHECK(counterWoCounterSet->m_Units ==
"");
1523 CHECK(counterWoCounterSet->m_DeviceUid == 0);
1524 CHECK(counterWoCounterSet->m_CounterSetUid == 0);
1526 CHECK(category->
m_Counters.back() == counterWoCounterSet->m_Uid);
1529 CHECK_THROWS_AS(noCounter = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1537 std::string(
"valid description"),
1546 const Counter* counterWNumberOfCores =
nullptr;
1547 uint16_t numberOfCores = 15;
1548 CHECK_NOTHROW(counterWNumberOfCores = counterDirectory.
RegisterCounter(
1549 armnn::profiling::BACKEND_ID, 50,
1550 categoryName, 0, 1, 123.45f,
"valid name 8",
"valid description",
1556 CHECK(counterWNumberOfCores);
1557 CHECK(counterWNumberOfCores->
m_Uid > counter->m_Uid);
1558 CHECK(counterWNumberOfCores->
m_MaxCounterUid == counterWNumberOfCores->
m_Uid + numberOfCores - 1);
1559 CHECK(counterWNumberOfCores->
m_Class == 0);
1562 CHECK(counterWNumberOfCores->
m_Name ==
"valid name 8");
1563 CHECK(counterWNumberOfCores->
m_Description ==
"valid description");
1564 CHECK(counterWNumberOfCores->
m_Units ==
"");
1568 for (
size_t i = 0; i < numberOfCores; i++)
1571 counterWNumberOfCores->
m_Uid + i);
1575 const std::string multiCoreDeviceName =
"some_multi_core_device";
1576 const Device* multiCoreDevice =
nullptr;
1577 CHECK_NOTHROW(multiCoreDevice = counterDirectory.
RegisterDevice(multiCoreDeviceName, 4));
1579 CHECK(multiCoreDevice);
1580 CHECK(multiCoreDevice->
m_Name == multiCoreDeviceName);
1581 CHECK(multiCoreDevice->
m_Uid >= 1);
1582 CHECK(multiCoreDevice->
m_Cores == 4);
1585 const Counter* counterWMultiCoreDevice =
nullptr;
1586 CHECK_NOTHROW(counterWMultiCoreDevice = counterDirectory.
RegisterCounter(
1587 armnn::profiling::BACKEND_ID, 19, categoryName, 0, 1,
1588 123.45f,
"valid name 9",
"valid description",
1591 multiCoreDevice->
m_Uid,
1594 CHECK(counterWMultiCoreDevice);
1595 CHECK(counterWMultiCoreDevice->
m_Uid > counter->m_Uid);
1597 counterWMultiCoreDevice->
m_Uid + multiCoreDevice->
m_Cores - 1);
1598 CHECK(counterWMultiCoreDevice->
m_Class == 0);
1600 CHECK(counterWMultiCoreDevice->
m_Multiplier == 123.45f);
1601 CHECK(counterWMultiCoreDevice->
m_Name ==
"valid name 9");
1602 CHECK(counterWMultiCoreDevice->
m_Description ==
"valid description");
1603 CHECK(counterWMultiCoreDevice->
m_Units ==
"");
1607 for (
size_t i = 0; i < 4; i++)
1613 const std::string multiCoreDeviceNameWParentCategory =
"some_multi_core_device_with_parent_category";
1614 const Device* multiCoreDeviceWParentCategory =
nullptr;
1615 CHECK_NOTHROW(multiCoreDeviceWParentCategory =
1616 counterDirectory.
RegisterDevice(multiCoreDeviceNameWParentCategory, 2, categoryName));
1618 CHECK(multiCoreDeviceWParentCategory);
1619 CHECK(multiCoreDeviceWParentCategory->
m_Name == multiCoreDeviceNameWParentCategory);
1620 CHECK(multiCoreDeviceWParentCategory->
m_Uid >= 1);
1621 CHECK(multiCoreDeviceWParentCategory->
m_Cores == 2);
1625 const Counter* counterWMultiCoreDeviceWParentCategory =
nullptr;
1626 uint16_t numberOfCourse = multiCoreDeviceWParentCategory->
m_Cores;
1627 CHECK_NOTHROW(counterWMultiCoreDeviceWParentCategory =
1629 armnn::profiling::BACKEND_ID,
1636 "valid description",
1642 CHECK(counterWMultiCoreDeviceWParentCategory);
1643 CHECK(counterWMultiCoreDeviceWParentCategory->
m_Uid > counter->m_Uid);
1645 counterWMultiCoreDeviceWParentCategory->
m_Uid + multiCoreDeviceWParentCategory->
m_Cores - 1);
1646 CHECK(counterWMultiCoreDeviceWParentCategory->
m_Class == 0);
1648 CHECK(counterWMultiCoreDeviceWParentCategory->
m_Multiplier == 123.45f);
1649 CHECK(counterWMultiCoreDeviceWParentCategory->
m_Name ==
"valid name 10");
1650 CHECK(counterWMultiCoreDeviceWParentCategory->
m_Description ==
"valid description");
1651 CHECK(counterWMultiCoreDeviceWParentCategory->
m_Units ==
"");
1653 for (
size_t i = 0; i < 2; i++)
1656 counterWMultiCoreDeviceWParentCategory->
m_Uid + i);
1660 const std::string counterSetName =
"some_counter_set";
1665 CHECK(counterSet->
m_Name == counterSetName);
1666 CHECK(counterSet->
m_Uid >= 1);
1667 CHECK(counterSet->
m_Count == 0);
1670 const Counter* counterWCounterSet =
nullptr;
1672 armnn::profiling::BACKEND_ID, 300,
1673 categoryName, 0, 1, 123.45f,
"valid name 11",
"valid description",
1677 counterSet->
m_Uid));
1679 CHECK(counterWCounterSet);
1680 CHECK(counterWCounterSet->
m_Uid > counter->m_Uid);
1682 CHECK(counterWCounterSet->
m_Class == 0);
1685 CHECK(counterWCounterSet->
m_Name ==
"valid name 11");
1686 CHECK(counterWCounterSet->
m_Description ==
"valid description");
1687 CHECK(counterWCounterSet->
m_Units ==
"");
1694 const Counter* counterWDeviceWCounterSet =
nullptr;
1695 CHECK_NOTHROW(counterWDeviceWCounterSet = counterDirectory.
RegisterCounter(
1696 armnn::profiling::BACKEND_ID, 23,
1697 categoryName, 0, 1, 123.45f,
"valid name 12",
"valid description",
1701 counterSet->
m_Uid));
1703 CHECK(counterWDeviceWCounterSet);
1704 CHECK(counterWDeviceWCounterSet->m_Uid > counter->m_Uid);
1705 CHECK(counterWDeviceWCounterSet->m_MaxCounterUid == counterWDeviceWCounterSet->m_Uid);
1706 CHECK(counterWDeviceWCounterSet->m_Class == 0);
1707 CHECK(counterWDeviceWCounterSet->m_Interpolation == 1);
1708 CHECK(counterWDeviceWCounterSet->m_Multiplier == 123.45f);
1709 CHECK(counterWDeviceWCounterSet->m_Name ==
"valid name 12");
1710 CHECK(counterWDeviceWCounterSet->m_Description ==
"valid description");
1711 CHECK(counterWDeviceWCounterSet->m_Units ==
"");
1712 CHECK(counterWDeviceWCounterSet->m_DeviceUid == device->
m_Uid);
1713 CHECK(counterWDeviceWCounterSet->m_CounterSetUid == counterSet->
m_Uid);
1715 CHECK(category->
m_Counters.back() == counterWDeviceWCounterSet->m_Uid);
1718 const std::string anotherCategoryName =
"some_other_category";
1719 const Category* anotherCategory =
nullptr;
1720 CHECK_NOTHROW(anotherCategory = counterDirectory.
RegisterCategory(anotherCategoryName));
1722 CHECK(anotherCategory);
1723 CHECK(anotherCategory != category);
1724 CHECK(anotherCategory->
m_Name == anotherCategoryName);
1728 const Counter* anotherCounter =
nullptr;
1729 CHECK_NOTHROW(anotherCounter = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID, 24,
1730 anotherCategoryName, 1, 0, .00043f,
1731 "valid name",
"valid description",
1735 counterSet->
m_Uid));
1737 CHECK(anotherCounter);
1738 CHECK(anotherCounter->m_MaxCounterUid == anotherCounter->m_Uid);
1739 CHECK(anotherCounter->m_Class == 1);
1740 CHECK(anotherCounter->m_Interpolation == 0);
1741 CHECK(anotherCounter->m_Multiplier == .00043f);
1742 CHECK(anotherCounter->m_Name ==
"valid name");
1743 CHECK(anotherCounter->m_Description ==
"valid description");
1744 CHECK(anotherCounter->m_Units ==
"");
1745 CHECK(anotherCounter->m_DeviceUid == device->
m_Uid);
1746 CHECK(anotherCounter->m_CounterSetUid == counterSet->
m_Uid);
1747 CHECK(anotherCategory->
m_Counters.size() == 1);
1748 CHECK(anotherCategory->
m_Counters.back() == anotherCounter->m_Uid);
1751 TEST_CASE(
"CounterSelectionCommandHandlerParseData")
1757 void Start()
override 1759 void Stop()
override 1765 bool IsCounterRegistered(uint16_t counterUid)
const override 1770 uint16_t GetCounterCount()
const override 1774 uint32_t GetAbsoluteCounterValue(uint16_t counterUid)
const override 1779 uint32_t GetDeltaCounterValue(uint16_t counterUid)
override 1785 const uint32_t familyId = 0;
1786 const uint32_t packetId = 0x40000;
1788 uint32_t version = 1;
1790 std::shared_ptr<armnn::profiling::IBackendProfilingContext>> backendProfilingContext;
1793 TestCaptureThread captureThread;
1794 TestReadCounterValues readCounterValues;
1797 SendThread sendThread(profilingStateMachine, mockBuffer, sendCounterPacket);
1804 uint32_t dataLength1 = 8;
1805 uint32_t offset = 0;
1807 std::unique_ptr<unsigned char[]> uniqueData1 = std::make_unique<unsigned char[]>(dataLength1);
1808 unsigned char* data1 =
reinterpret_cast<unsigned char*
>(uniqueData1.get());
1811 offset += sizeOfUint32;
1813 offset += sizeOfUint16;
1816 arm::pipe::Packet packetA(packetId, dataLength1, uniqueData1);
1819 counterIdMap, holder, 10000u, captureThread,
1820 readCounterValues, sendCounterPacket, profilingStateMachine);
1829 CHECK_NOTHROW(commandHandler(packetA));
1834 CHECK(counterIdsA.size() == 2);
1835 CHECK(counterIdsA[0] == 4000);
1836 CHECK(counterIdsA[1] == 5000);
1838 auto readBuffer = mockBuffer.GetReadableBuffer();
1842 uint32_t headerWord0 =
ReadUint32(readBuffer, offset);
1843 offset += sizeOfUint32;
1844 uint32_t headerWord1 =
ReadUint32(readBuffer, offset);
1845 offset += sizeOfUint32;
1846 uint32_t period =
ReadUint32(readBuffer, offset);
1848 CHECK(((headerWord0 >> 26) & 0x3F) == 0);
1849 CHECK(((headerWord0 >> 16) & 0x3FF) == 4);
1850 CHECK(headerWord1 == 8);
1853 uint16_t counterId = 0;
1854 offset += sizeOfUint32;
1856 CHECK(counterId == 4000);
1857 offset += sizeOfUint16;
1859 CHECK(counterId == 5000);
1861 mockBuffer.MarkRead(readBuffer);
1864 uint32_t period2 = 9000;
1865 uint32_t dataLength2 = 4;
1867 std::unique_ptr<unsigned char[]> uniqueData2 = std::make_unique<unsigned char[]>(dataLength2);
1869 WriteUint32(reinterpret_cast<unsigned char*>(uniqueData2.get()), 0, period2);
1871 arm::pipe::Packet packetB(packetId, dataLength2, uniqueData2);
1873 commandHandler(packetB);
1879 CHECK(counterIdsB.size() == 0);
1881 readBuffer = mockBuffer.GetReadableBuffer();
1885 headerWord0 =
ReadUint32(readBuffer, offset);
1886 offset += sizeOfUint32;
1887 headerWord1 =
ReadUint32(readBuffer, offset);
1888 offset += sizeOfUint32;
1891 CHECK(((headerWord0 >> 26) & 0x3F) == 0);
1892 CHECK(((headerWord0 >> 16) & 0x3FF) == 4);
1893 CHECK(headerWord1 == 4);
1897 TEST_CASE(
"CheckTimelineActivationAndDeactivation")
1902 virtual void ReportStructure()
override 1904 m_ReportStructureCalled =
true;
1907 bool m_ReportStructureCalled =
false;
1913 TestNotifyBackends() : m_timelineReporting(false) {}
1914 virtual void NotifyBackendsForTimelineReporting()
override 1916 m_TestNotifyBackendsCalled = m_timelineReporting.load();
1919 bool m_TestNotifyBackendsCalled =
false;
1920 std::atomic<bool> m_timelineReporting;
1923 arm::pipe::PacketVersionResolver packetVersionResolver;
1928 TestReportStructure testReportStructure;
1929 TestNotifyBackends testNotifyBackends;
1933 packetVersionResolver.ResolvePacketVersion(0, 6)
1937 testReportStructure,
1938 testNotifyBackends.m_timelineReporting,
1939 testNotifyBackends);
1943 const uint32_t packetFamily1 = 0;
1944 const uint32_t packetId1 = 6;
1948 arm::pipe::Packet ActivateTimelineReportingPacket(packetHeader1);
1951 activateTimelineReportingCommandHandler.operator()(ActivateTimelineReportingPacket),
armnn::Exception);
1953 stateMachine.TransitionToState(ProfilingState::NotConnected);
1955 activateTimelineReportingCommandHandler.operator()(ActivateTimelineReportingPacket),
armnn::Exception);
1957 stateMachine.TransitionToState(ProfilingState::WaitingForAck);
1959 activateTimelineReportingCommandHandler.operator()(ActivateTimelineReportingPacket),
armnn::Exception);
1961 stateMachine.TransitionToState(ProfilingState::Active);
1962 activateTimelineReportingCommandHandler.operator()(ActivateTimelineReportingPacket);
1964 CHECK(testReportStructure.m_ReportStructureCalled);
1965 CHECK(testNotifyBackends.m_TestNotifyBackendsCalled);
1966 CHECK(testNotifyBackends.m_timelineReporting.load());
1970 packetVersionResolver.ResolvePacketVersion(0, 7).GetEncodedValue(),
1971 testNotifyBackends.m_timelineReporting,
1973 testNotifyBackends);
1975 const uint32_t packetFamily2 = 0;
1976 const uint32_t packetId2 = 7;
1980 arm::pipe::Packet deactivateTimelineReportingPacket(packetHeader2);
1982 stateMachine.Reset();
1984 deactivateTimelineReportingCommandHandler.operator()(deactivateTimelineReportingPacket),
armnn::Exception);
1986 stateMachine.TransitionToState(ProfilingState::NotConnected);
1988 deactivateTimelineReportingCommandHandler.operator()(deactivateTimelineReportingPacket),
armnn::Exception);
1990 stateMachine.TransitionToState(ProfilingState::WaitingForAck);
1992 deactivateTimelineReportingCommandHandler.operator()(deactivateTimelineReportingPacket),
armnn::Exception);
1994 stateMachine.TransitionToState(ProfilingState::Active);
1995 deactivateTimelineReportingCommandHandler.operator()(deactivateTimelineReportingPacket);
1997 CHECK(!testNotifyBackends.m_TestNotifyBackendsCalled);
1998 CHECK(!testNotifyBackends.m_timelineReporting.load());
2001 TEST_CASE(
"CheckProfilingServiceNotActive")
2003 using namespace armnn;
2012 profilingServiceHelper.ForceTransitionToState(ProfilingState::NotConnected);
2013 profilingServiceHelper.ForceTransitionToState(ProfilingState::WaitingForAck);
2014 profilingServiceHelper.ForceTransitionToState(ProfilingState::Active);
2020 CHECK(readableBuffer ==
nullptr);
2023 TEST_CASE(
"CheckConnectionAcknowledged")
2025 const uint32_t packetFamilyId = 0;
2026 const uint32_t connectionPacketId = 0x10000;
2027 const uint32_t version = 1;
2033 uint32_t period1 = 10;
2034 uint32_t dataLength1 = 8;
2035 uint32_t offset = 0;
2037 std::unique_ptr<unsigned char[]> uniqueData1 = std::make_unique<unsigned char[]>(dataLength1);
2038 unsigned char* data1 =
reinterpret_cast<unsigned char*
>(uniqueData1.get());
2041 offset += sizeOfUint32;
2043 offset += sizeOfUint16;
2046 arm::pipe::Packet packetA(connectionPacketId, dataLength1, uniqueData1);
2049 CHECK(profilingState.GetCurrentState() == ProfilingState::Uninitialised);
2053 SendThread sendThread(profilingState, mockBuffer, sendCounterPacket);
2064 mockProfilingServiceStatus);
2069 profilingState.TransitionToState(ProfilingState::NotConnected);
2070 CHECK(profilingState.GetCurrentState() == ProfilingState::NotConnected);
2074 profilingState.TransitionToState(ProfilingState::WaitingForAck);
2075 CHECK(profilingState.GetCurrentState() == ProfilingState::WaitingForAck);
2077 CHECK_NOTHROW(commandHandler(packetA));
2078 CHECK(profilingState.GetCurrentState() == ProfilingState::Active);
2081 CHECK_NOTHROW(commandHandler(packetA));
2082 CHECK(profilingState.GetCurrentState() == ProfilingState::Active);
2085 const uint32_t differentPacketId = 0x40000;
2086 arm::pipe::Packet packetB(differentPacketId, dataLength1, uniqueData1);
2087 profilingState.TransitionToState(ProfilingState::NotConnected);
2088 profilingState.TransitionToState(ProfilingState::WaitingForAck);
2096 mockProfilingServiceStatus);
2100 TEST_CASE(
"CheckSocketConnectionException")
2106 TEST_CASE(
"CheckSocketConnectionException2")
2112 catch (
const arm::pipe::SocketConnectionException& ex)
2114 CHECK(ex.GetSocketFd() == 0);
2115 CHECK(ex.GetErrorNo() == ECONNREFUSED);
2117 == std::string(
"SocketProfilingConnection: Cannot connect to stream socket: Connection refused"));
2121 TEST_CASE(
"SwTraceIsValidCharTest")
2124 for (
unsigned char c = 0; c < 128; c++)
2126 CHECK(arm::pipe::SwTraceCharPolicy::IsValidChar(c));
2130 for (
unsigned char c = 255; c >= 128; c++)
2132 CHECK(!arm::pipe::SwTraceCharPolicy::IsValidChar(c));
2136 TEST_CASE(
"SwTraceIsValidNameCharTest")
2139 const unsigned char validChars[] =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_";
2140 for (
unsigned char i = 0; i <
sizeof(validChars) /
sizeof(validChars[0]) - 1; i++)
2142 CHECK(arm::pipe::SwTraceNameCharPolicy::IsValidChar(validChars[i]));
2146 for (
unsigned char c = 0; c < 48; c++)
2148 CHECK(!arm::pipe::SwTraceNameCharPolicy::IsValidChar(c));
2150 for (
unsigned char c = 58; c < 65; c++)
2152 CHECK(!arm::pipe::SwTraceNameCharPolicy::IsValidChar(c));
2154 for (
unsigned char c = 91; c < 95; c++)
2156 CHECK(!arm::pipe::SwTraceNameCharPolicy::IsValidChar(c));
2158 for (
unsigned char c = 96; c < 97; c++)
2160 CHECK(!arm::pipe::SwTraceNameCharPolicy::IsValidChar(c));
2162 for (
unsigned char c = 123; c < 128; c++)
2164 CHECK(!arm::pipe::SwTraceNameCharPolicy::IsValidChar(c));
2168 for (
unsigned char c = 255; c >= 128; c++)
2170 CHECK(!arm::pipe::SwTraceNameCharPolicy::IsValidChar(c));
2174 TEST_CASE(
"IsValidSwTraceStringTest")
2177 CHECK(arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceCharPolicy>(
""));
2178 CHECK(arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceCharPolicy>(
"_"));
2179 CHECK(arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceCharPolicy>(
"0123"));
2180 CHECK(arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceCharPolicy>(
"valid_string"));
2181 CHECK(arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceCharPolicy>(
"VALID_string_456"));
2182 CHECK(arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceCharPolicy>(
" "));
2183 CHECK(arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceCharPolicy>(
"valid string"));
2184 CHECK(arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceCharPolicy>(
"!$%"));
2185 CHECK(arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceCharPolicy>(
"valid|\\~string#123"));
2188 CHECK(!arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceCharPolicy>(
"€£"));
2189 CHECK(!arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceCharPolicy>(
"invalid‡string"));
2190 CHECK(!arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceCharPolicy>(
"12Ž34"));
2193 TEST_CASE(
"IsValidSwTraceNameStringTest")
2196 CHECK(arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
""));
2197 CHECK(arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
"_"));
2198 CHECK(arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
"0123"));
2199 CHECK(arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
"valid_string"));
2200 CHECK(arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
"VALID_string_456"));
2203 CHECK(!arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
" "));
2204 CHECK(!arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
"invalid string"));
2205 CHECK(!arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
"!$%"));
2206 CHECK(!arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
"invalid|\\~string#123"));
2207 CHECK(!arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
"€£"));
2208 CHECK(!arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
"invalid‡string"));
2209 CHECK(!arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
"12Ž34"));
2212 template <
typename SwTracePolicy>
2213 void StringToSwTraceStringTestHelper(
const std::string& testString, std::vector<uint32_t> buffer,
size_t expectedSize)
2216 CHECK(arm::pipe::StringToSwTraceString<SwTracePolicy>(testString, buffer));
2219 CHECK(!buffer.empty());
2222 CHECK(buffer.size() == expectedSize);
2225 CHECK(buffer[0] == testString.size() + 1);
2228 CHECK(std::memcmp(testString.data(), buffer.data() + 1, testString.size()) == 0);
2231 size_t nullTerminatorIndex =
sizeof(uint32_t) + testString.size();
2232 CHECK(reinterpret_cast<unsigned char*>(buffer.data())[nullTerminatorIndex] ==
'\0');
2235 TEST_CASE(
"StringToSwTraceStringTest")
2237 std::vector<uint32_t> buffer;
2240 StringToSwTraceStringTestHelper<arm::pipe::SwTraceCharPolicy>(
"", buffer, 2);
2241 StringToSwTraceStringTestHelper<arm::pipe::SwTraceCharPolicy>(
"_", buffer, 2);
2242 StringToSwTraceStringTestHelper<arm::pipe::SwTraceCharPolicy>(
"0123", buffer, 3);
2243 StringToSwTraceStringTestHelper<arm::pipe::SwTraceCharPolicy>(
"valid_string", buffer, 5);
2244 StringToSwTraceStringTestHelper<arm::pipe::SwTraceCharPolicy>(
"VALID_string_456", buffer, 6);
2245 StringToSwTraceStringTestHelper<arm::pipe::SwTraceCharPolicy>(
" ", buffer, 2);
2246 StringToSwTraceStringTestHelper<arm::pipe::SwTraceCharPolicy>(
"valid string", buffer, 5);
2247 StringToSwTraceStringTestHelper<arm::pipe::SwTraceCharPolicy>(
"!$%", buffer, 2);
2248 StringToSwTraceStringTestHelper<arm::pipe::SwTraceCharPolicy>(
"valid|\\~string#123", buffer, 6);
2251 CHECK(!arm::pipe::StringToSwTraceString<arm::pipe::SwTraceCharPolicy>(
"€£", buffer));
2252 CHECK(buffer.empty());
2253 CHECK(!arm::pipe::StringToSwTraceString<arm::pipe::SwTraceCharPolicy>(
"invalid‡string", buffer));
2254 CHECK(buffer.empty());
2255 CHECK(!arm::pipe::StringToSwTraceString<arm::pipe::SwTraceCharPolicy>(
"12Ž34", buffer));
2256 CHECK(buffer.empty());
2259 TEST_CASE(
"StringToSwTraceNameStringTest")
2261 std::vector<uint32_t> buffer;
2264 StringToSwTraceStringTestHelper<arm::pipe::SwTraceNameCharPolicy>(
"", buffer, 2);
2265 StringToSwTraceStringTestHelper<arm::pipe::SwTraceNameCharPolicy>(
"_", buffer, 2);
2266 StringToSwTraceStringTestHelper<arm::pipe::SwTraceNameCharPolicy>(
"0123", buffer, 3);
2267 StringToSwTraceStringTestHelper<arm::pipe::SwTraceNameCharPolicy>(
"valid_string", buffer, 5);
2268 StringToSwTraceStringTestHelper<arm::pipe::SwTraceNameCharPolicy>(
"VALID_string_456", buffer, 6);
2271 CHECK(!arm::pipe::StringToSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
" ", buffer));
2272 CHECK(buffer.empty());
2273 CHECK(!arm::pipe::StringToSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
"invalid string", buffer));
2274 CHECK(buffer.empty());
2275 CHECK(!arm::pipe::StringToSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
"!$%", buffer));
2276 CHECK(buffer.empty());
2277 CHECK(!arm::pipe::StringToSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
"invalid|\\~string#123", buffer));
2278 CHECK(buffer.empty());
2279 CHECK(!arm::pipe::StringToSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
"€£", buffer));
2280 CHECK(buffer.empty());
2281 CHECK(!arm::pipe::StringToSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
"invalid‡string", buffer));
2282 CHECK(buffer.empty());
2283 CHECK(!arm::pipe::StringToSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
"12Ž34", buffer));
2284 CHECK(buffer.empty());
2287 TEST_CASE(
"CheckPeriodicCounterCaptureThread")
2292 CaptureReader(uint16_t counterSize)
2294 for (uint16_t i = 0; i < counterSize; ++i)
2298 m_CounterSize = counterSize;
2301 bool IsCounterRegistered(uint16_t counterUid)
const override 2307 uint16_t GetCounterCount()
const override 2309 return m_CounterSize;
2312 uint32_t GetAbsoluteCounterValue(uint16_t counterUid)
const override 2314 if (counterUid > m_CounterSize)
2316 FAIL(
"Invalid counter Uid");
2318 return m_Data.at(counterUid).load();
2321 uint32_t GetDeltaCounterValue(uint16_t counterUid)
override 2323 if (counterUid > m_CounterSize)
2325 FAIL(
"Invalid counter Uid");
2327 return m_Data.at(counterUid).load();
2330 void SetCounterValue(uint16_t counterUid, uint32_t value)
2332 if (counterUid > m_CounterSize)
2334 FAIL(
"Invalid counter Uid");
2336 m_Data.at(counterUid).store(value);
2340 std::unordered_map<uint16_t, std::atomic<uint32_t>> m_Data;
2341 uint16_t m_CounterSize;
2347 std::shared_ptr<armnn::profiling::IBackendProfilingContext>> backendProfilingContext;
2350 std::vector<uint16_t> captureIds1 = { 0, 1 };
2351 std::vector<uint16_t> captureIds2;
2355 SendThread sendThread(profilingStateMachine, mockBuffer, sendCounterPacket);
2357 std::vector<uint16_t> counterIds;
2358 CaptureReader captureReader(2);
2360 unsigned int valueA = 10;
2361 unsigned int valueB = 15;
2362 unsigned int numSteps = 5;
2364 PeriodicCounterCapture periodicCounterCapture(std::ref(data), std::ref(sendCounterPacket), captureReader,
2365 counterIdMap, backendProfilingContext);
2367 for (
unsigned int i = 0; i < numSteps; ++i)
2370 captureReader.SetCounterValue(0, valueA * (i + 1));
2371 captureReader.SetCounterValue(1, valueB * (i + 1));
2373 periodicCounterCapture.Start();
2374 periodicCounterCapture.Stop();
2377 auto buffer = mockBuffer.GetReadableBuffer();
2379 uint32_t headerWord0 =
ReadUint32(buffer, 0);
2380 uint32_t headerWord1 =
ReadUint32(buffer, 4);
2382 CHECK(((headerWord0 >> 26) & 0x0000003F) == 3);
2383 CHECK(((headerWord0 >> 19) & 0x0000007F) == 0);
2384 CHECK(((headerWord0 >> 16) & 0x00000007) == 0);
2385 CHECK(headerWord1 == 20);
2387 uint32_t offset = 16;
2388 uint16_t readIndex =
ReadUint16(buffer, offset);
2389 CHECK(0 == readIndex);
2392 uint32_t readValue =
ReadUint32(buffer, offset);
2393 CHECK((valueA * numSteps) == readValue);
2397 CHECK(1 == readIndex);
2401 CHECK((valueB * numSteps) == readValue);
2404 TEST_CASE(
"RequestCounterDirectoryCommandHandlerTest1")
2406 const uint32_t familyId = 0;
2407 const uint32_t packetId = 3;
2408 const uint32_t version = 1;
2413 SendThread sendThread(profilingStateMachine, mockBuffer1, sendCounterPacket);
2417 sendCounterPacket, sendTimelinePacket, profilingStateMachine);
2419 const uint32_t wrongPacketId = 47;
2420 const uint32_t wrongHeader = (wrongPacketId & 0x000003FF) << 16;
2422 arm::pipe::Packet wrongPacket(wrongHeader);
2433 const uint32_t rightHeader = (packetId & 0x000003FF) << 16;
2435 arm::pipe::Packet rightPacket(rightHeader);
2437 CHECK_NOTHROW(commandHandler(rightPacket));
2439 auto readBuffer1 = mockBuffer1.GetReadableBuffer();
2441 uint32_t header1Word0 =
ReadUint32(readBuffer1, 0);
2442 uint32_t header1Word1 =
ReadUint32(readBuffer1, 4);
2445 CHECK(((header1Word0 >> 26) & 0x0000003F) == 0);
2446 CHECK(((header1Word0 >> 16) & 0x000003FF) == 2);
2447 CHECK(header1Word1 == 24);
2449 uint32_t bodyHeader1Word0 =
ReadUint32(readBuffer1, 8);
2451 CHECK(deviceRecordCount == 0);
2453 auto readBuffer2 = mockBuffer2.GetReadableBuffer();
2455 uint32_t header2Word0 =
ReadUint32(readBuffer2, 0);
2456 uint32_t header2Word1 =
ReadUint32(readBuffer2, 4);
2459 CHECK(((header2Word0 >> 26) & 0x0000003F) == 1);
2460 CHECK(((header2Word0 >> 16) & 0x000003FF) == 0);
2461 CHECK(header2Word1 == 443);
2464 TEST_CASE(
"RequestCounterDirectoryCommandHandlerTest2")
2466 const uint32_t familyId = 0;
2467 const uint32_t packetId = 3;
2468 const uint32_t version = 1;
2473 SendThread sendThread(profilingStateMachine, mockBuffer1, sendCounterPacket);
2477 sendCounterPacket, sendTimelinePacket, profilingStateMachine);
2478 const uint32_t header = (packetId & 0x000003FF) << 16;
2479 const arm::pipe::Packet packet(header);
2482 CHECK(device !=
nullptr);
2484 CHECK(counterSet !=
nullptr);
2487 "categoryA", 0, 1, 2.0f,
"counterA",
"descA");
2489 "categoryA", 1, 1, 3.0f,
"counterB",
"descB");
2498 CHECK_NOTHROW(commandHandler(packet));
2500 auto readBuffer1 = mockBuffer1.GetReadableBuffer();
2502 const uint32_t header1Word0 =
ReadUint32(readBuffer1, 0);
2503 const uint32_t header1Word1 =
ReadUint32(readBuffer1, 4);
2505 CHECK(((header1Word0 >> 26) & 0x0000003F) == 0);
2506 CHECK(((header1Word0 >> 16) & 0x000003FF) == 2);
2507 CHECK(header1Word1 == 236);
2509 const uint32_t bodyHeaderSizeBytes = bodyHeaderSize *
sizeof(uint32_t);
2511 const uint32_t bodyHeader1Word0 =
ReadUint32(readBuffer1, 8);
2512 const uint32_t bodyHeader1Word1 =
ReadUint32(readBuffer1, 12);
2513 const uint32_t bodyHeader1Word2 =
ReadUint32(readBuffer1, 16);
2514 const uint32_t bodyHeader1Word3 =
ReadUint32(readBuffer1, 20);
2515 const uint32_t bodyHeader1Word4 =
ReadUint32(readBuffer1, 24);
2516 const uint32_t bodyHeader1Word5 =
ReadUint32(readBuffer1, 28);
2518 const uint16_t counterSetRecordCount =
armnn::numeric_cast<uint16_t>(bodyHeader1Word2 >> 16);
2519 const uint16_t categoryRecordCount =
armnn::numeric_cast<uint16_t>(bodyHeader1Word4 >> 16);
2520 CHECK(deviceRecordCount == 1);
2521 CHECK(bodyHeader1Word1 == 0 + bodyHeaderSizeBytes);
2522 CHECK(counterSetRecordCount == 1);
2523 CHECK(bodyHeader1Word3 == 4 + bodyHeaderSizeBytes);
2524 CHECK(categoryRecordCount == 1);
2525 CHECK(bodyHeader1Word5 == 8 + bodyHeaderSizeBytes);
2527 const uint32_t deviceRecordOffset =
ReadUint32(readBuffer1, 32);
2528 CHECK(deviceRecordOffset == 12);
2530 const uint32_t counterSetRecordOffset =
ReadUint32(readBuffer1, 36);
2531 CHECK(counterSetRecordOffset == 28);
2533 const uint32_t categoryRecordOffset =
ReadUint32(readBuffer1, 40);
2534 CHECK(categoryRecordOffset == 48);
2536 auto readBuffer2 = mockBuffer2.GetReadableBuffer();
2538 const uint32_t header2Word0 =
ReadUint32(readBuffer2, 0);
2539 const uint32_t header2Word1 =
ReadUint32(readBuffer2, 4);
2542 CHECK(((header2Word0 >> 26) & 0x0000003F) == 1);
2543 CHECK(((header2Word0 >> 16) & 0x000003FF) == 0);
2544 CHECK(header2Word1 == 443);
2547 TEST_CASE(
"CheckProfilingServiceGoodConnectionAcknowledgedPacket")
2561 CHECK(profilingService.
GetCurrentState() == ProfilingState::Uninitialised);
2562 profilingService.
Update();
2563 CHECK(profilingService.
GetCurrentState() == ProfilingState::NotConnected);
2564 profilingService.
Update();
2568 CHECK(mockProfilingConnection);
2571 mockProfilingConnection->
Clear();
2573 CHECK(profilingService.
GetCurrentState() == ProfilingState::WaitingForAck);
2574 profilingService.
Update();
2577 CHECK(helper.WaitForPacketsSent(
2578 mockProfilingConnection, PacketType::StreamMetaData, streamMetadataPacketsize) >= 1);
2588 uint32_t packetFamily = 0;
2589 uint32_t packetId = 1;
2590 uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
2593 arm::pipe::Packet connectionAcknowledgedPacket(header);
2596 mockProfilingConnection->
WritePacket(std::move(connectionAcknowledgedPacket));
2599 CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::CounterDirectory) == 1);
2609 TEST_CASE(
"CheckProfilingServiceGoodRequestCounterDirectoryPacket")
2621 CHECK(profilingService.
GetCurrentState() == ProfilingState::Uninitialised);
2622 profilingService.
Update();
2623 CHECK(profilingService.
GetCurrentState() == ProfilingState::NotConnected);
2624 profilingService.
Update();
2625 CHECK(profilingService.
GetCurrentState() == ProfilingState::WaitingForAck);
2626 profilingService.
Update();
2630 CHECK(mockProfilingConnection);
2633 helper.ForceTransitionToState(ProfilingState::Active);
2644 uint32_t packetFamily = 0;
2645 uint32_t packetId = 3;
2646 uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
2649 arm::pipe::Packet requestCounterDirectoryPacket(header);
2652 mockProfilingConnection->
WritePacket(std::move(requestCounterDirectoryPacket));
2656 CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::CounterDirectory, 652) == 1);
2657 CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::TimelineMessageDirectory, 451) == 1);
2667 TEST_CASE(
"CheckProfilingServiceBadPeriodicCounterSelectionPacketInvalidCounterUid")
2679 CHECK(profilingService.
GetCurrentState() == ProfilingState::Uninitialised);
2680 profilingService.
Update();
2681 CHECK(profilingService.
GetCurrentState() == ProfilingState::NotConnected);
2682 profilingService.
Update();
2683 CHECK(profilingService.
GetCurrentState() == ProfilingState::WaitingForAck);
2684 profilingService.
Update();
2688 CHECK(mockProfilingConnection);
2691 helper.ForceTransitionToState(ProfilingState::Active);
2695 mockProfilingConnection->
Clear();
2705 uint32_t packetFamily = 0;
2706 uint32_t packetId = 4;
2707 uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
2709 uint32_t capturePeriod = 123456;
2714 CHECK(counters.size() > 1);
2715 uint16_t counterUidA = counters.begin()->first;
2716 uint16_t counterUidB = 9999;
2718 uint32_t length = 8;
2720 auto data = std::make_unique<unsigned char[]>(length);
2727 arm::pipe::Packet periodicCounterSelectionPacket(header, length, data);
2731 mockProfilingConnection->
WritePacket(std::move(periodicCounterSelectionPacket));
2735 CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::PeriodicCounterSelection, 14) == 1);
2736 CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::PeriodicCounterCapture, 22) >= 1);
2746 TEST_CASE(
"CheckProfilingServiceGoodPeriodicCounterSelectionPacketNoCounters")
2758 CHECK(profilingService.
GetCurrentState() == ProfilingState::Uninitialised);
2759 profilingService.
Update();
2760 CHECK(profilingService.
GetCurrentState() == ProfilingState::NotConnected);
2761 profilingService.
Update();
2762 CHECK(profilingService.
GetCurrentState() == ProfilingState::WaitingForAck);
2763 profilingService.
Update();
2767 CHECK(mockProfilingConnection);
2771 helper.WaitForPacketsSent(mockProfilingConnection, PacketType::StreamMetaData);
2774 helper.ForceTransitionToState(ProfilingState::Active);
2785 uint32_t packetFamily = 0;
2786 uint32_t packetId = 4;
2787 uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
2791 arm::pipe::Packet periodicCounterSelectionPacket(header);
2794 mockProfilingConnection->
WritePacket(std::move(periodicCounterSelectionPacket));
2798 CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::PeriodicCounterSelection, 12) == 1);
2804 CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::PeriodicCounterCapture, 0, 0) == 0);
2811 TEST_CASE(
"CheckProfilingServiceGoodPeriodicCounterSelectionPacketSingleCounter")
2823 CHECK(profilingService.
GetCurrentState() == ProfilingState::Uninitialised);
2824 profilingService.
Update();
2825 CHECK(profilingService.
GetCurrentState() == ProfilingState::NotConnected);
2826 profilingService.
Update();
2827 CHECK(profilingService.
GetCurrentState() == ProfilingState::WaitingForAck);
2828 profilingService.
Update();
2832 CHECK(mockProfilingConnection);
2836 helper.WaitForPacketsSent(mockProfilingConnection, PacketType::StreamMetaData);
2839 helper.ForceTransitionToState(ProfilingState::Active);
2850 uint32_t packetFamily = 0;
2851 uint32_t packetId = 4;
2852 uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
2854 uint32_t capturePeriod = 123456;
2859 CHECK(!counters.empty());
2860 uint16_t counterUid = counters.begin()->first;
2862 uint32_t length = 6;
2864 auto data = std::make_unique<unsigned char[]>(length);
2870 arm::pipe::Packet periodicCounterSelectionPacket(header, length, data);
2873 mockProfilingConnection->
WritePacket(std::move(periodicCounterSelectionPacket));
2877 CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::PeriodicCounterSelection, 14) == 1);
2878 CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::PeriodicCounterCapture, 22) >= 1);
2888 TEST_CASE(
"CheckProfilingServiceGoodPeriodicCounterSelectionPacketMultipleCounters")
2900 CHECK(profilingService.
GetCurrentState() == ProfilingState::Uninitialised);
2901 profilingService.
Update();
2902 CHECK(profilingService.
GetCurrentState() == ProfilingState::NotConnected);
2903 profilingService.
Update();
2904 CHECK(profilingService.
GetCurrentState() == ProfilingState::WaitingForAck);
2905 profilingService.
Update();
2909 CHECK(mockProfilingConnection);
2913 helper.WaitForPacketsSent(mockProfilingConnection, PacketType::StreamMetaData);
2916 helper.ForceTransitionToState(ProfilingState::Active);
2927 uint32_t packetFamily = 0;
2928 uint32_t packetId = 4;
2929 uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
2931 uint32_t capturePeriod = 123456;
2936 CHECK(counters.size() > 1);
2937 uint16_t counterUidA = counters.begin()->first;
2938 uint16_t counterUidB = (counters.begin()++)->first;
2940 uint32_t length = 8;
2942 auto data = std::make_unique<unsigned char[]>(length);
2949 arm::pipe::Packet periodicCounterSelectionPacket(header, length, data);
2952 mockProfilingConnection->
WritePacket(std::move(periodicCounterSelectionPacket));
2956 CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::PeriodicCounterSelection, 16) == 1);
2957 CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::PeriodicCounterCapture, 28) >= 1);
2967 TEST_CASE(
"CheckProfilingServiceDisconnect")
2979 CHECK(profilingService.
GetCurrentState() == ProfilingState::Uninitialised);
2981 CHECK(profilingService.
GetCurrentState() == ProfilingState::Uninitialised);
2984 profilingService.
Update();
2985 CHECK(profilingService.
GetCurrentState() == ProfilingState::NotConnected);
2987 CHECK(profilingService.
GetCurrentState() == ProfilingState::NotConnected);
2990 profilingService.
Update();
2991 CHECK(profilingService.
GetCurrentState() == ProfilingState::WaitingForAck);
2993 CHECK(profilingService.
GetCurrentState() == ProfilingState::WaitingForAck);
2996 profilingService.
Update();
3000 CHECK(mockProfilingConnection);
3004 helper.WaitForPacketsSent(mockProfilingConnection, PacketType::StreamMetaData);
3007 helper.ForceTransitionToState(ProfilingState::Active);
3011 CHECK(mockProfilingConnection->
IsOpen());
3014 CHECK(profilingService.
GetCurrentState() == ProfilingState::NotConnected);
3017 mockProfilingConnection = helper.GetMockProfilingConnection();
3018 CHECK(mockProfilingConnection ==
nullptr);
3025 TEST_CASE(
"CheckProfilingServiceGoodPerJobCounterSelectionPacket")
3037 CHECK(profilingService.
GetCurrentState() == ProfilingState::Uninitialised);
3038 profilingService.
Update();
3039 CHECK(profilingService.
GetCurrentState() == ProfilingState::NotConnected);
3040 profilingService.
Update();
3041 CHECK(profilingService.
GetCurrentState() == ProfilingState::WaitingForAck);
3042 profilingService.
Update();
3046 CHECK(mockProfilingConnection);
3050 helper.WaitForPacketsSent(mockProfilingConnection, PacketType::StreamMetaData);
3053 helper.ForceTransitionToState(ProfilingState::Active);
3064 uint32_t packetFamily = 0;
3065 uint32_t packetId = 5;
3066 uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
3070 arm::pipe::Packet periodicCounterSelectionPacket(header);
3073 mockProfilingConnection->
WritePacket(std::move(periodicCounterSelectionPacket));
3077 std::this_thread::sleep_for(std::chrono::milliseconds(5));
3084 const auto StreamMetaDataSize =
static_cast<unsigned long>(
3085 helper.WaitForPacketsSent(mockProfilingConnection, PacketType::StreamMetaData, 0, 0));
3093 TEST_CASE(
"CheckConfigureProfilingServiceOn")
3098 CHECK(profilingService.
GetCurrentState() == ProfilingState::Uninitialised);
3101 CHECK(profilingService.
GetCurrentState() == ProfilingState::NotConnected);
3107 TEST_CASE(
"CheckConfigureProfilingServiceOff")
3111 CHECK(profilingService.
GetCurrentState() == ProfilingState::Uninitialised);
3114 CHECK(profilingService.
GetCurrentState() == ProfilingState::Uninitialised);
3120 TEST_CASE(
"CheckProfilingServiceEnabled")
3128 CHECK(profilingService.
GetCurrentState() == ProfilingState::Uninitialised);
3129 profilingService.
Update();
3130 CHECK(profilingService.
GetCurrentState() == ProfilingState::NotConnected);
3133 std::stringstream ss;
3135 profilingService.
Update();
3141 streamRedirector.CancelRedirect();
3144 if (ss.str().find(
"Cannot connect to stream socket: Connection refused") == std::string::npos)
3146 std::cout << ss.str();
3147 FAIL(
"Expected string not found.");
3151 TEST_CASE(
"CheckProfilingServiceEnabledRuntime")
3158 CHECK(profilingService.
GetCurrentState() == ProfilingState::Uninitialised);
3159 profilingService.
Update();
3160 CHECK(profilingService.
GetCurrentState() == ProfilingState::Uninitialised);
3163 CHECK(profilingService.
GetCurrentState() == ProfilingState::Uninitialised);
3164 profilingService.
Update();
3165 CHECK(profilingService.
GetCurrentState() == ProfilingState::NotConnected);
3168 std::stringstream ss;
3170 profilingService.
Update();
3176 streamRedirector.CancelRedirect();
3179 if (ss.str().find(
"Cannot connect to stream socket: Connection refused") == std::string::npos)
3181 std::cout << ss.str();
3182 FAIL(
"Expected string not found.");
3186 TEST_CASE(
"CheckProfilingServiceBadConnectionAcknowledgedPacket")
3193 std::stringstream ss;
3206 CHECK(profilingService.
GetCurrentState() == ProfilingState::Uninitialised);
3207 profilingService.
Update();
3208 CHECK(profilingService.
GetCurrentState() == ProfilingState::NotConnected);
3209 profilingService.
Update();
3213 CHECK(mockProfilingConnection);
3215 CHECK(profilingService.
GetCurrentState() == ProfilingState::WaitingForAck);
3222 uint32_t packetFamily = 0;
3223 uint32_t packetId = 37;
3224 uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
3227 arm::pipe::Packet connectionAcknowledgedPacket(header);
3230 mockProfilingConnection->
WritePacket(std::move(connectionAcknowledgedPacket));
3233 profilingService.
Update();
3236 options.m_EnableProfiling =
false;
3239 streamRedirector.CancelRedirect();
3242 if (ss.str().find(
"Functor with requested PacketId=37 and Version=4194304 does not exist") == std::string::npos)
3244 std::cout << ss.str();
3245 FAIL(
"Expected string not found.");
3249 TEST_CASE(
"CheckProfilingServiceBadRequestCounterDirectoryPacket")
3255 std::stringstream ss;
3268 CHECK(profilingService.
GetCurrentState() == ProfilingState::Uninitialised);
3269 helper.ForceTransitionToState(ProfilingState::NotConnected);
3270 CHECK(profilingService.
GetCurrentState() == ProfilingState::NotConnected);
3271 profilingService.
Update();
3272 CHECK(profilingService.
GetCurrentState() == ProfilingState::WaitingForAck);
3276 CHECK(mockProfilingConnection);
3286 uint32_t packetFamily = 0;
3287 uint32_t packetId = 123;
3288 uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
3291 arm::pipe::Packet requestCounterDirectoryPacket(header);
3294 mockProfilingConnection->WritePacket(std::move(requestCounterDirectoryPacket));
3297 profilingService.
Update();
3300 options.m_EnableProfiling =
false;
3303 streamRedirector.CancelRedirect();
3306 if (ss.str().find(
"Functor with requested PacketId=123 and Version=4194304 does not exist") == std::string::npos)
3308 std::cout << ss.str();
3309 FAIL(
"Expected string not found.");
3313 TEST_CASE(
"CheckProfilingServiceBadPeriodicCounterSelectionPacket")
3319 std::stringstream ss;
3332 CHECK(profilingService.
GetCurrentState() == ProfilingState::Uninitialised);
3333 profilingService.
Update();
3334 CHECK(profilingService.
GetCurrentState() == ProfilingState::NotConnected);
3335 profilingService.
Update();
3336 CHECK(profilingService.
GetCurrentState() == ProfilingState::WaitingForAck);
3337 profilingService.
Update();
3341 CHECK(mockProfilingConnection);
3351 uint32_t packetFamily = 0;
3352 uint32_t packetId = 999;
3353 uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
3357 arm::pipe::Packet periodicCounterSelectionPacket(header);
3360 mockProfilingConnection->
WritePacket(std::move(periodicCounterSelectionPacket));
3361 profilingService.
Update();
3364 options.m_EnableProfiling =
false;
3368 streamRedirector.CancelRedirect();
3371 if (ss.str().find(
"Functor with requested PacketId=999 and Version=4194304 does not exist") == std::string::npos)
3373 std::cout << ss.str();
3374 FAIL(
"Expected string not found.");
3378 TEST_CASE(
"CheckCounterIdMap")
3384 uint16_t globalCounterIds = 0;
3389 std::vector<uint16_t> cpuRefCounters = {0, 1, 2, 3};
3390 std::vector<uint16_t> cpuAccCounters = {0, 1};
3392 for (uint16_t backendCounterId : cpuRefCounters)
3394 counterIdMap.
RegisterMapping(globalCounterIds, backendCounterId, cpuRefId);
3397 for (uint16_t backendCounterId : cpuAccCounters)
3399 counterIdMap.
RegisterMapping(globalCounterIds, backendCounterId, cpuAccId);
3403 CHECK(counterIdMap.
GetBackendId(0) == (std::pair<uint16_t, armnn::BackendId>(0, cpuRefId)));
3404 CHECK(counterIdMap.
GetBackendId(1) == (std::pair<uint16_t, armnn::BackendId>(1, cpuRefId)));
3405 CHECK(counterIdMap.
GetBackendId(2) == (std::pair<uint16_t, armnn::BackendId>(2, cpuRefId)));
3406 CHECK(counterIdMap.
GetBackendId(3) == (std::pair<uint16_t, armnn::BackendId>(3, cpuRefId)));
3407 CHECK(counterIdMap.
GetBackendId(4) == (std::pair<uint16_t, armnn::BackendId>(0, cpuAccId)));
3408 CHECK(counterIdMap.
GetBackendId(5) == (std::pair<uint16_t, armnn::BackendId>(1, cpuAccId)));
3410 CHECK(counterIdMap.
GetGlobalId(0, cpuRefId) == 0);
3411 CHECK(counterIdMap.
GetGlobalId(1, cpuRefId) == 1);
3412 CHECK(counterIdMap.
GetGlobalId(2, cpuRefId) == 2);
3413 CHECK(counterIdMap.
GetGlobalId(3, cpuRefId) == 3);
3414 CHECK(counterIdMap.
GetGlobalId(0, cpuAccId) == 4);
3415 CHECK(counterIdMap.
GetGlobalId(1, cpuAccId) == 5);
3418 TEST_CASE(
"CheckRegisterBackendCounters")
3420 uint16_t globalCounterIds = armnn::profiling::INFERENCES_RUN;
3434 registerBackendCounters.RegisterCategory(
"categoryOne");
3436 CHECK(categoryOnePtr);
3439 globalCounterIds = registerBackendCounters.RegisterDevice(
"deviceOne");
3441 CHECK(deviceOnePtr);
3442 CHECK(deviceOnePtr->m_Name ==
"deviceOne");
3445 globalCounterIds = registerBackendCounters.RegisterCounterSet(
"counterSetOne");
3447 CHECK(counterSetOnePtr);
3448 CHECK(counterSetOnePtr->m_Name ==
"counterSetOne");
3450 uint16_t newGlobalCounterId = registerBackendCounters.RegisterCounter(0,
3456 "first test counter");
3457 CHECK((newGlobalCounterId = armnn::profiling::INFERENCES_RUN + 1));
3459 CHECK(mappedGlobalId == newGlobalCounterId);
3461 CHECK(backendMapping.first == 0);
3462 CHECK(backendMapping.second == cpuRefId);
3469 TEST_CASE(
"CheckCounterStatusQuery")
3482 BackendProfiling backendProfilingCpuRef(options, profilingService, cpuRefId);
3483 BackendProfiling backendProfilingCpuAcc(options, profilingService, cpuAccId);
3485 uint16_t initialNumGlobalCounterIds = armnn::profiling::INFERENCES_RUN;
3488 RegisterBackendCounters registerBackendCountersCpuRef(initialNumGlobalCounterIds, cpuRefId, profilingService);
3492 registerBackendCountersCpuRef.RegisterCategory(
"testCategory");
3494 CHECK(categoryOnePtr);
3502 std::vector<uint16_t> cpuRefCounters = {0, 1};
3503 std::vector<uint16_t> cpuAccCounters = {0};
3506 uint16_t currentNumGlobalCounterIds = registerBackendCountersCpuRef.RegisterCounter(
3507 0,
"testCategory", 0, 0, 1.f,
"CpuRefCounter0",
"Zeroth CpuRef Counter");
3508 CHECK(currentNumGlobalCounterIds == initialNumGlobalCounterIds + 1);
3510 CHECK(mappedGlobalId == currentNumGlobalCounterIds);
3512 CHECK(backendMapping.first == 0);
3513 CHECK(backendMapping.second == cpuRefId);
3515 currentNumGlobalCounterIds = registerBackendCountersCpuRef.RegisterCounter(
3516 1,
"testCategory", 0, 0, 1.f,
"CpuRefCounter1",
"First CpuRef Counter");
3517 CHECK(currentNumGlobalCounterIds == initialNumGlobalCounterIds + 2);
3519 CHECK(mappedGlobalId == currentNumGlobalCounterIds);
3521 CHECK(backendMapping.first == 1);
3522 CHECK(backendMapping.second == cpuRefId);
3525 RegisterBackendCounters registerBackendCountersCpuAcc(currentNumGlobalCounterIds, cpuAccId, profilingService);
3528 currentNumGlobalCounterIds = registerBackendCountersCpuAcc.RegisterCounter(
3529 0,
"testCategory", 0, 0, 1.f,
"CpuAccCounter0",
"Zeroth CpuAcc Counter");
3530 CHECK(currentNumGlobalCounterIds == initialNumGlobalCounterIds + 3);
3532 CHECK(mappedGlobalId == currentNumGlobalCounterIds);
3534 CHECK(backendMapping.first == 0);
3535 CHECK(backendMapping.second == cpuAccId);
3538 const std::vector<uint16_t> activeGlobalCounterIds = {5};
3539 const std::vector<uint16_t> newActiveGlobalCounterIds = {6, 7};
3541 const uint32_t capturePeriod = 200;
3542 const uint32_t newCapturePeriod = 100;
3545 profilingService.
SetCaptureData(capturePeriod, activeGlobalCounterIds, {});
3548 std::vector<CounterStatus> cpuRefCounterStatus = backendProfilingCpuRef.GetActiveCounters();
3549 std::vector<CounterStatus> cpuAccCounterStatus = backendProfilingCpuAcc.GetActiveCounters();
3550 CHECK_EQ(cpuRefCounterStatus.size(), 1);
3551 CHECK_EQ(cpuAccCounterStatus.size(), 0);
3554 CHECK_EQ(cpuRefCounterStatus[0].m_GlobalCounterId, activeGlobalCounterIds[0]);
3555 CHECK_EQ(cpuRefCounterStatus[0].m_BackendCounterId, cpuRefCounters[0]);
3556 CHECK_EQ(cpuRefCounterStatus[0].m_SamplingRateInMicroseconds, capturePeriod);
3557 CHECK_EQ(cpuRefCounterStatus[0].m_Enabled,
true);
3560 CounterStatus inactiveCpuRefCounter = backendProfilingCpuRef.GetCounterStatus(cpuRefCounters[1]);
3564 CHECK_EQ(inactiveCpuRefCounter.
m_Enabled,
false);
3567 CounterStatus inactiveCpuAccCounter = backendProfilingCpuAcc.GetCounterStatus(cpuAccCounters[0]);
3571 CHECK_EQ(inactiveCpuAccCounter.
m_Enabled,
false);
3574 profilingService.
SetCaptureData(newCapturePeriod, newActiveGlobalCounterIds, {});
3577 cpuRefCounterStatus = backendProfilingCpuRef.GetActiveCounters();
3578 cpuAccCounterStatus = backendProfilingCpuAcc.GetActiveCounters();
3579 CHECK_EQ(cpuRefCounterStatus.size(), 1);
3580 CHECK_EQ(cpuAccCounterStatus.size(), 1);
3583 CHECK_EQ(cpuRefCounterStatus[0].m_GlobalCounterId, newActiveGlobalCounterIds[0]);
3584 CHECK_EQ(cpuRefCounterStatus[0].m_BackendCounterId, cpuRefCounters[1]);
3585 CHECK_EQ(cpuRefCounterStatus[0].m_SamplingRateInMicroseconds, newCapturePeriod);
3586 CHECK_EQ(cpuRefCounterStatus[0].m_Enabled,
true);
3589 CHECK_EQ(cpuAccCounterStatus[0].m_GlobalCounterId, newActiveGlobalCounterIds[1]);
3590 CHECK_EQ(cpuAccCounterStatus[0].m_BackendCounterId, cpuAccCounters[0]);
3591 CHECK_EQ(cpuAccCounterStatus[0].m_SamplingRateInMicroseconds, newCapturePeriod);
3592 CHECK_EQ(cpuAccCounterStatus[0].m_Enabled,
true);
3595 inactiveCpuRefCounter = backendProfilingCpuRef.GetCounterStatus(cpuRefCounters[0]);
3599 CHECK_EQ(inactiveCpuRefCounter.
m_Enabled,
false);
3606 TEST_CASE(
"CheckRegisterCounters")
3616 mockProfilingService.RegisterMapping(6, 0, cpuRefId);
3617 mockProfilingService.RegisterMapping(7, 1, cpuRefId);
3618 mockProfilingService.RegisterMapping(8, 2, cpuRefId);
3621 mockProfilingService,
3628 std::vector<armnn::profiling::Timestamp> timestamps;
3629 timestamps.push_back(timestamp);
3630 backendProfiling.ReportCounters(timestamps);
3632 auto readBuffer = mockBuffer.GetReadableBuffer();
3634 uint32_t headerWord0 =
ReadUint32(readBuffer, 0);
3635 uint32_t headerWord1 =
ReadUint32(readBuffer, 4);
3636 uint64_t readTimestamp =
ReadUint64(readBuffer, 8);
3638 CHECK(((headerWord0 >> 26) & 0x0000003F) == 3);
3639 CHECK(((headerWord0 >> 19) & 0x0000007F) == 0);
3640 CHECK(((headerWord0 >> 16) & 0x00000007) == 0);
3641 CHECK(headerWord1 == 20);
3642 CHECK(1000998 == readTimestamp);
3644 uint32_t offset = 16;
3646 uint16_t readIndex =
ReadUint16(readBuffer, offset);
3647 CHECK(6 == readIndex);
3651 uint32_t readValue =
ReadUint32(readBuffer, offset);
3652 CHECK(700 == readValue);
3657 CHECK(8 == readIndex);
3662 CHECK(93 == readValue);
3665 TEST_CASE(
"CheckFileFormat") {
3681 profilingService.
Update();
3682 CHECK(profilingService.
GetCurrentState()==ProfilingState::NotConnected);
3685 std::stringstream ss;
3690 profilingService.
Update();
3692 streamRedirector.CancelRedirect();
3695 if (ss.str().find(
"Unsupported profiling file format, only binary is supported") == std::string::npos)
3697 std::cout << ss.str();
3698 FAIL(
"Expected string not found.");
profiling::ProfilingService & GetProfilingService(armnn::RuntimeImpl *runtime)
ProfilingState GetCurrentState() const
const Category * RegisterCategory(const std::string &categoryName) override
const Counter * RegisterCounter(const BackendId &backendId, const uint16_t uid, const std::string &parentCategoryName, uint16_t counterClass, uint16_t interpolation, double multiplier, const std::string &name, const std::string &description, const Optional< std::string > &units=EmptyOptional(), const Optional< uint16_t > &numberOfCores=EmptyOptional(), const Optional< uint16_t > &deviceUid=EmptyOptional(), const Optional< uint16_t > &counterSetUid=EmptyOptional()) override
uint32_t GetAbsoluteCounterValue(uint16_t counterUid) const override
uint16_t GetGlobalId(uint16_t backendCounterId, const armnn::BackendId &backendId) const override
CPU Execution: Reference C++ kernels.
ProfilingState GetCurrentState() const
void WriteUint16(const IPacketBufferPtr &packetBuffer, unsigned int offset, uint16_t value)
const std::vector< uint16_t > & GetCounterIds() const
void WriteUint32(const IPacketBufferPtr &packetBuffer, unsigned int offset, uint32_t value)
uint64_t ReadUint64(const IPacketBufferPtr &packetBuffer, unsigned int offset)
uint32_t m_SamplingRateInMicroseconds
std::unordered_map< uint16_t, CounterPtr > Counters
virtual const Category * GetCategory(const std::string &name) const =0
uint32_t GetStreamMetaDataPacketSize()
const Device * GetDevice(uint16_t uid) const override
virtual uint16_t GetCounterCount() const =0
uint16_t ReadUint16(const IPacketBufferPtr &packetBuffer, unsigned int offset)
uint16_t GetCounterSetCount() const override
virtual const Device * GetDevice(uint16_t uid) const =0
unsigned long GetWrittenDataSize()
Copyright (c) 2021 ARM Limited and Contributors.
void IgnoreUnused(Ts &&...)
virtual const CounterSets & GetCounterSets() const =0
void RegisterMapping(uint16_t globalCounterId, uint16_t backendCounterId, const armnn::BackendId &backendId) override
uint32_t IncrementCounterValue(uint16_t counterUid) override
virtual const Categories & GetCategories() const =0
uint16_t GetNextUid(bool peekOnly)
uint16_t GetDeviceCount() const override
uint32_t GetDeltaCounterValue(uint16_t counterUid) override
uint32_t SubtractCounterValue(uint16_t counterUid, uint32_t value) override
virtual const Devices & GetDevices() const =0
void SetCapturePeriod(uint32_t capturePeriod)
uint32_t GetCapturePeriod() const
virtual const CounterSet * GetCounterSet(uint16_t uid) const =0
CaptureData GetCaptureData() const
void SetCaptureData(uint32_t capturePeriod, const std::vector< uint16_t > &counterIds, const std::set< BackendId > &activeBackends)
void SetCaptureData(uint32_t capturePeriod, const std::vector< uint16_t > &counterIds, const std::set< armnn::BackendId > &activeBackends)
std::vector< uint16_t > GetNextCounterUids(uint16_t firstUid, uint16_t cores)
const std::pair< uint16_t, armnn::BackendId > & GetBackendId(uint16_t globalCounterId) const override
const ICounterMappings & GetCounterMappings() const override
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
uint32_t ConstructHeader(uint32_t packetFamily, uint32_t packetId)
uint32_t AddCounterValue(uint16_t counterUid, uint32_t value) override
uint16_t GetCategoryCount() const override
constexpr unsigned int LOWEST_CAPTURE_PERIOD
The lowest performance data capture interval we support is 10 miliseconds.
std::vector< CounterValue > counterValues
IPacketBufferPtr GetReadableBuffer() override
uint16_t m_GlobalCounterId
uint32_t ReadUint32(const IPacketBufferPtr &packetBuffer, unsigned int offset)
std::vector< uint16_t > m_Counters
void SetCounterValue(uint16_t counterUid, uint32_t value) override
const Counter * GetCounter(uint16_t uid) const override
const Category * GetCategory(const std::string &name) const override
EmptyOptional is used to initialize the Optional class in case we want to have default value for an O...
std::string m_Description
const Device * RegisterDevice(const std::string &deviceName, uint16_t cores=0, const Optional< std::string > &parentCategoryName=EmptyOptional()) override
Base class for all ArmNN exceptions so that users can filter to just those.
CPU Execution: NEON: ArmCompute.
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
void SetCounterIds(const std::vector< uint16_t > &counterIds)
bool WritePacket(const unsigned char *buffer, uint32_t length) override
uint16_t GetCounterCount() const override
void TransitionToState(ProfilingState newState)
virtual const Counters & GetCounters() const =0
const CounterSet * RegisterCounterSet(const std::string &counterSetName, uint16_t count=0, const Optional< std::string > &parentCategoryName=EmptyOptional()) override
bool IsOpen() const override
virtual const std::pair< uint16_t, armnn::BackendId > & GetBackendId(uint16_t globalCounterId) const =0
const CounterSet * GetCounterSet(uint16_t uid) const override
ExternalProfilingOptions m_ProfilingOptions
const ICounterDirectory & GetCounterDirectory() const
ProfilingState ConfigureProfilingService(const ExternalProfilingOptions &options, bool resetProfilingService=false)
uint16_t m_BackendCounterId
virtual uint16_t GetGlobalId(uint16_t backendCounterId, const armnn::BackendId &backendId) const =0