10 #include <common/include/EncodeVersion.hpp> 11 #include <common/include/PacketVersionResolver.hpp> 12 #include <common/include/SwTrace.hpp> 15 #include <CounterDirectory.hpp> 37 #include <common/include/CommandHandlerKey.hpp> 38 #include <common/include/CommandHandlerRegistry.hpp> 39 #include <common/include/SocketConnectionException.hpp> 40 #include <common/include/Packet.hpp> 42 #include <boost/numeric/conversion/cast.hpp> 59 arm::pipe::CommandHandlerKey testKey1_0(1, 1, 1);
60 arm::pipe::CommandHandlerKey testKey1_1(1, 1, 1);
61 arm::pipe::CommandHandlerKey testKey1_2(1, 2, 1);
63 arm::pipe::CommandHandlerKey testKey0(0, 1, 1);
64 arm::pipe::CommandHandlerKey testKey1(0, 1, 1);
65 arm::pipe::CommandHandlerKey testKey2(0, 1, 1);
66 arm::pipe::CommandHandlerKey testKey3(0, 0, 0);
67 arm::pipe::CommandHandlerKey testKey4(0, 2, 2);
68 arm::pipe::CommandHandlerKey testKey5(0, 0, 2);
70 BOOST_CHECK(testKey1_0 > testKey0);
71 BOOST_CHECK(testKey1_0 == testKey1_1);
72 BOOST_CHECK(testKey1_0 < testKey1_2);
74 BOOST_CHECK(testKey1 < testKey4);
75 BOOST_CHECK(testKey1 > testKey3);
76 BOOST_CHECK(testKey1 <= testKey4);
77 BOOST_CHECK(testKey1 >= testKey3);
78 BOOST_CHECK(testKey1 <= testKey2);
79 BOOST_CHECK(testKey1 >= testKey2);
80 BOOST_CHECK(testKey1 == testKey2);
81 BOOST_CHECK(testKey1 == testKey1);
83 BOOST_CHECK(!(testKey1 == testKey5));
84 BOOST_CHECK(!(testKey1 != testKey1));
85 BOOST_CHECK(testKey1 != testKey5);
87 BOOST_CHECK(testKey1 == testKey2 && testKey2 == testKey1);
88 BOOST_CHECK(testKey0 == testKey1 && testKey1 == testKey2 && testKey0 == testKey2);
90 BOOST_CHECK(testKey1.GetPacketId() == 1);
91 BOOST_CHECK(testKey1.GetVersion() == 1);
93 std::vector<arm::pipe::CommandHandlerKey> vect = {
94 arm::pipe::CommandHandlerKey(0, 0, 1), arm::pipe::CommandHandlerKey(0, 2, 0),
95 arm::pipe::CommandHandlerKey(0, 1, 0), arm::pipe::CommandHandlerKey(0, 2, 1),
96 arm::pipe::CommandHandlerKey(0, 1, 1), arm::pipe::CommandHandlerKey(0, 0, 1),
97 arm::pipe::CommandHandlerKey(0, 2, 0), arm::pipe::CommandHandlerKey(0, 0, 0) };
99 std::sort(vect.begin(), vect.end());
101 std::vector<arm::pipe::CommandHandlerKey> expectedVect = {
102 arm::pipe::CommandHandlerKey(0, 0, 0), arm::pipe::CommandHandlerKey(0, 0, 1),
103 arm::pipe::CommandHandlerKey(0, 0, 1), arm::pipe::CommandHandlerKey(0, 1, 0),
104 arm::pipe::CommandHandlerKey(0, 1, 1), arm::pipe::CommandHandlerKey(0, 2, 0),
105 arm::pipe::CommandHandlerKey(0, 2, 0), arm::pipe::CommandHandlerKey(0, 2, 1) };
107 BOOST_CHECK(vect == expectedVect);
112 arm::pipe::PacketKey key0(0, 0);
113 arm::pipe::PacketKey key1(0, 0);
114 arm::pipe::PacketKey key2(0, 1);
115 arm::pipe::PacketKey key3(0, 2);
116 arm::pipe::PacketKey key4(1, 0);
117 arm::pipe::PacketKey key5(1, 0);
118 arm::pipe::PacketKey key6(1, 1);
120 BOOST_CHECK(!(key0 < key1));
121 BOOST_CHECK(!(key0 > key1));
122 BOOST_CHECK(key0 <= key1);
123 BOOST_CHECK(key0 >= key1);
124 BOOST_CHECK(key0 == key1);
125 BOOST_CHECK(key0 < key2);
126 BOOST_CHECK(key2 < key3);
127 BOOST_CHECK(key3 > key0);
128 BOOST_CHECK(key4 == key5);
129 BOOST_CHECK(key4 > key0);
130 BOOST_CHECK(key5 < key6);
131 BOOST_CHECK(key5 <= key6);
132 BOOST_CHECK(key5 != key6);
137 arm::pipe::PacketVersionResolver packetVersionResolver;
146 SendThread sendThread(profilingStateMachine, mockBuffer, sendCounterPacket);
151 sendCounterPacket, sendTimelinePacket,
152 profilingStateMachine,
153 mockProfilingServiceStatus);
154 arm::pipe::CommandHandlerRegistry commandHandlerRegistry;
156 commandHandlerRegistry.RegisterFunctor(&connectionAcknowledgedCommandHandler);
161 CommandHandler commandHandler0(1,
true, commandHandlerRegistry, packetVersionResolver);
165 commandHandler0.
Start(testProfilingConnectionBase);
167 commandHandler0.
Start(testProfilingConnectionBase);
170 for (
int i = 0; i < 10; i++)
176 std::this_thread::sleep_for(std::chrono::milliseconds(2));
182 commandHandler0.
Stop();
189 CommandHandler commandHandler1(1,
true, commandHandlerRegistry, packetVersionResolver);
191 commandHandler1.
Start(testProfilingConnectionTimeOutError);
193 for (
int i = 0; i < 10; i++)
199 std::this_thread::sleep_for(std::chrono::milliseconds(2));
204 uint32_t timeout = 50;
205 uint32_t timeSlept = 0;
208 if (timeSlept >= timeout)
210 BOOST_FAIL(
"Timeout: The command handler loop did not stop after the timeout");
212 std::this_thread::sleep_for(std::chrono::milliseconds(1));
216 commandHandler1.
Stop();
222 commandHandler1.
Start(testProfilingConnectionBadAckPacket);
223 commandHandler1.
Stop();
230 commandHandler1.
Start(testProfilingConnectionTimeOutError);
233 for (
int i = 0; i < 10; i++)
239 std::this_thread::sleep_for(std::chrono::milliseconds(2));
241 commandHandler1.
Stop();
247 CommandHandler commandHandler2(1,
false, commandHandlerRegistry, packetVersionResolver);
249 commandHandler2.Start(testProfilingConnectionArmnnError);
252 for (
int i = 0; i < 10; i++)
258 std::this_thread::sleep_for(std::chrono::milliseconds(2));
261 BOOST_CHECK(commandHandler2.IsRunning());
262 commandHandler2.Stop();
267 arm::pipe::Version version1(12);
269 BOOST_CHECK(version1.GetMajor() == 0);
270 BOOST_CHECK(version1.GetMinor() == 0);
271 BOOST_CHECK(version1.GetPatch() == 12);
273 arm::pipe::Version version2(4108);
275 BOOST_CHECK(version2.GetMajor() == 0);
276 BOOST_CHECK(version2.GetMinor() == 1);
277 BOOST_CHECK(version2.GetPatch() == 12);
279 arm::pipe::Version version3(4198412);
281 BOOST_CHECK(version3.GetMajor() == 1);
282 BOOST_CHECK(version3.GetMinor() == 1);
283 BOOST_CHECK(version3.GetPatch() == 12);
285 arm::pipe::Version version4(0);
287 BOOST_CHECK(version4.GetMajor() == 0);
288 BOOST_CHECK(version4.GetMinor() == 0);
289 BOOST_CHECK(version4.GetPatch() == 0);
291 arm::pipe::Version version5(1, 0, 0);
292 BOOST_CHECK(version5.GetEncodedValue() == 4194304);
298 std::unique_ptr<unsigned char[]> packetData0 = std::make_unique<unsigned char[]>(length);
299 std::unique_ptr<unsigned char[]> packetData1 = std::make_unique<unsigned char[]>(0);
300 std::unique_ptr<unsigned char[]> nullPacketData;
302 arm::pipe::Packet packetTest0(472580096, length, packetData0);
304 BOOST_CHECK(packetTest0.GetHeader() == 472580096);
305 BOOST_CHECK(packetTest0.GetPacketFamily() == 7);
306 BOOST_CHECK(packetTest0.GetPacketId() == 43);
307 BOOST_CHECK(packetTest0.GetLength() == length);
308 BOOST_CHECK(packetTest0.GetPacketType() == 3);
309 BOOST_CHECK(packetTest0.GetPacketClass() == 5);
311 BOOST_CHECK_THROW(arm::pipe::Packet packetTest1(472580096, 0, packetData1), arm::pipe::InvalidArgumentException);
312 BOOST_CHECK_NO_THROW(arm::pipe::Packet packetTest2(472580096, 0, nullPacketData));
314 arm::pipe::Packet packetTest3(472580096, 0, nullPacketData);
315 BOOST_CHECK(packetTest3.GetLength() == 0);
316 BOOST_CHECK(packetTest3.GetData() ==
nullptr);
318 const unsigned char* packetTest0Data = packetTest0.GetData();
319 arm::pipe::Packet packetTest4(std::move(packetTest0));
321 BOOST_CHECK(packetTest0.GetData() ==
nullptr);
322 BOOST_CHECK(packetTest4.GetData() == packetTest0Data);
324 BOOST_CHECK(packetTest4.GetHeader() == 472580096);
325 BOOST_CHECK(packetTest4.GetPacketFamily() == 7);
326 BOOST_CHECK(packetTest4.GetPacketId() == 43);
327 BOOST_CHECK(packetTest4.GetLength() == length);
328 BOOST_CHECK(packetTest4.GetPacketType() == 3);
329 BOOST_CHECK(packetTest4.GetPacketClass() == 5);
335 uint32_t version = 1;
341 arm::pipe::CommandHandlerKey keyA(
342 testFunctorA.GetFamilyId(), testFunctorA.GetPacketId(), testFunctorA.GetVersion());
343 arm::pipe::CommandHandlerKey keyB(
344 testFunctorB.GetFamilyId(), testFunctorB.GetPacketId(), testFunctorB.GetVersion());
345 arm::pipe::CommandHandlerKey keyC(
346 testFunctorC.GetFamilyId(), testFunctorC.GetPacketId(), testFunctorC.GetVersion());
349 std::map<arm::pipe::CommandHandlerKey, arm::pipe::CommandHandlerFunctor*> registry;
351 registry.insert(std::make_pair(keyB, &testFunctorB));
352 registry.insert(std::make_pair(keyA, &testFunctorA));
353 registry.insert(std::make_pair(keyC, &testFunctorC));
356 auto it = registry.begin();
357 BOOST_CHECK(it->first == keyC);
359 BOOST_CHECK(it->first == keyA);
361 BOOST_CHECK(it->first == keyB);
363 std::unique_ptr<unsigned char[]> packetDataA;
364 std::unique_ptr<unsigned char[]> packetDataB;
365 std::unique_ptr<unsigned char[]> packetDataC;
367 arm::pipe::Packet packetA(500000000, 0, packetDataA);
368 arm::pipe::Packet packetB(600000000, 0, packetDataB);
369 arm::pipe::Packet packetC(400000000, 0, packetDataC);
372 registry.at(arm::pipe::CommandHandlerKey(
373 packetA.GetPacketFamily(), packetA.GetPacketId(), version))->operator()(packetA);
374 BOOST_CHECK(testFunctorA.
GetCount() == 1);
375 BOOST_CHECK(testFunctorB.
GetCount() == 0);
376 BOOST_CHECK(testFunctorC.
GetCount() == 0);
378 registry.at(arm::pipe::CommandHandlerKey(
379 packetB.GetPacketFamily(), packetB.GetPacketId(), version))->operator()(packetB);
380 BOOST_CHECK(testFunctorA.
GetCount() == 1);
381 BOOST_CHECK(testFunctorB.
GetCount() == 1);
382 BOOST_CHECK(testFunctorC.
GetCount() == 0);
384 registry.at(arm::pipe::CommandHandlerKey(
385 packetC.GetPacketFamily(), packetC.GetPacketId(), version))->operator()(packetC);
386 BOOST_CHECK(testFunctorA.
GetCount() == 1);
387 BOOST_CHECK(testFunctorB.
GetCount() == 1);
388 BOOST_CHECK(testFunctorC.
GetCount() == 1);
394 uint32_t version = 1;
401 arm::pipe::CommandHandlerRegistry registry;
404 registry.RegisterFunctor(&testFunctorA);
405 registry.RegisterFunctor(&testFunctorB);
406 registry.RegisterFunctor(&testFunctorC);
408 std::unique_ptr<unsigned char[]> packetDataA;
409 std::unique_ptr<unsigned char[]> packetDataB;
410 std::unique_ptr<unsigned char[]> packetDataC;
412 arm::pipe::Packet packetA(500000000, 0, packetDataA);
413 arm::pipe::Packet packetB(600000000, 0, packetDataB);
414 arm::pipe::Packet packetC(400000000, 0, packetDataC);
417 registry.GetFunctor(packetA.GetPacketFamily(), packetA.GetPacketId(), version)->
operator()(packetA);
418 BOOST_CHECK(testFunctorA.
GetCount() == 1);
419 BOOST_CHECK(testFunctorB.
GetCount() == 0);
420 BOOST_CHECK(testFunctorC.
GetCount() == 0);
422 registry.GetFunctor(packetB.GetPacketFamily(), packetB.GetPacketId(), version)->
operator()(packetB);
423 BOOST_CHECK(testFunctorA.
GetCount() == 1);
424 BOOST_CHECK(testFunctorB.
GetCount() == 1);
425 BOOST_CHECK(testFunctorC.
GetCount() == 0);
427 registry.GetFunctor(packetC.GetPacketFamily(), packetC.GetPacketId(), version)->
operator()(packetC);
428 BOOST_CHECK(testFunctorA.
GetCount() == 1);
429 BOOST_CHECK(testFunctorB.
GetCount() == 1);
430 BOOST_CHECK(testFunctorC.
GetCount() == 1);
433 registry.RegisterFunctor(&testFunctorC, testFunctorA.GetFamilyId(), testFunctorA.GetPacketId(), version);
434 registry.GetFunctor(packetA.GetPacketFamily(), packetA.GetPacketId(), version)->
operator()(packetC);
435 BOOST_CHECK(testFunctorA.
GetCount() == 1);
436 BOOST_CHECK(testFunctorB.
GetCount() == 1);
437 BOOST_CHECK(testFunctorC.
GetCount() == 2);
440 BOOST_CHECK_THROW(registry.GetFunctor(0, 0, 0), arm::pipe::ProfilingException);
446 std::random_device device;
447 std::mt19937 generator(device());
448 std::uniform_int_distribution<uint32_t> distribution(std::numeric_limits<uint32_t>::min(),
449 std::numeric_limits<uint32_t>::max());
452 const arm::pipe::Version expectedVersion(1, 0, 0);
454 arm::pipe::PacketVersionResolver packetVersionResolver;
456 constexpr
unsigned int numTests = 10u;
458 for (
unsigned int i = 0u; i < numTests; ++i)
460 const uint32_t familyId = distribution(generator);
461 const uint32_t packetId = distribution(generator);
462 arm::pipe::Version resolvedVersion = packetVersionResolver.ResolvePacketVersion(familyId, packetId);
464 BOOST_TEST(resolvedVersion == expectedVersion);
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));
582 BOOST_CHECK((holder.
GetCaptureData()).GetCounterIds() == periodIdMap[2]);
592 BOOST_CHECK(captureData.GetCapturePeriod() == 2);
593 BOOST_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(
610 BOOST_CHECK(captureDataIdMap.at(i).GetCapturePeriod() == 0);
611 BOOST_CHECK(captureDataIdMap.at(i).GetCounterIds().empty());
612 readThreadsVect.emplace_back(
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);
634 std::vector<uint16_t> counterIds = { 42, 29, 13 };
646 secondCaptureData = captureData;
647 BOOST_CHECK(secondCaptureData.GetCapturePeriod() == 150);
648 BOOST_CHECK(secondCaptureData.GetCounterIds() == counterIds);
651 CaptureData copyConstructedCaptureData(captureData);
653 BOOST_CHECK(copyConstructedCaptureData.GetCapturePeriod() == 150);
654 BOOST_CHECK(copyConstructedCaptureData.GetCounterIds() == counterIds);
659 armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
663 profilingService.
Update();
669 armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
675 profilingService.
Update();
678 options.m_EnableProfiling =
true;
683 profilingService.
Update();
686 options.m_EnableProfiling =
false;
692 armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
693 options.m_EnableProfiling =
true;
697 profilingService.
Update();
700 BOOST_CHECK(!counters.empty());
702 std::vector<std::thread> writers;
704 BOOST_CHECK(!counters.empty());
707 for (
int i = 0; i < 4; ++i)
710 writers.push_back(std::thread([&profilingService]()
712 for (
int i = 0; i < 250; ++i)
718 writers.push_back(std::thread([&profilingService]()
720 for (
int i = 0; i < 200; ++i)
726 writers.push_back(std::thread([&profilingService]()
728 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 BOOST_CHECK(absoluteCounterValue = 5000);
743 BOOST_CHECK_NO_THROW(profilingService.
SetCounterValue(INFERENCES_RUN, 0));
745 BOOST_CHECK(absoluteCounterValue == 0);
749 uint32_t deltaCounterValue = 0;
751 std::thread reader([&profilingService](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]()
764 for (
int i = 0; i < 250; ++i)
770 writers.push_back(std::thread([&profilingService]()
772 for (
int i = 0; i < 200; ++i)
778 writers.push_back(std::thread([&profilingService]()
780 for (
int i = 0; i < 200; ++i)
787 std::for_each(writers.begin(), writers.end(), mem_fn(&std::thread::join));
792 BOOST_CHECK(deltaCounterValue == 5000);
795 options.m_EnableProfiling =
false;
803 BOOST_CHECK(uid >= 1);
805 uint16_t nextUid = 0;
807 BOOST_CHECK(nextUid > uid);
809 std::vector<uint16_t> counterUids;
811 BOOST_CHECK(counterUids.size() == 1);
813 std::vector<uint16_t> nextCounterUids;
815 BOOST_CHECK(nextCounterUids.size() == 2);
816 BOOST_CHECK(nextCounterUids[0] > counterUids[0]);
818 std::vector<uint16_t> counterUidsMultiCore;
819 uint16_t thirdUid = 4;
820 uint16_t numberOfCores = 13;
821 BOOST_CHECK_NO_THROW(counterUidsMultiCore =
GetNextCounterUids(thirdUid, numberOfCores));
822 BOOST_CHECK(counterUidsMultiCore.size() == numberOfCores);
823 BOOST_CHECK(counterUidsMultiCore.front() >= nextCounterUids[0]);
824 for (
size_t i = 1; i < numberOfCores; i++)
826 BOOST_CHECK(counterUidsMultiCore[i] == counterUidsMultiCore[i - 1] + 1);
828 BOOST_CHECK(counterUidsMultiCore.back() == counterUidsMultiCore.front() + numberOfCores - 1);
840 const Category* noCategory =
nullptr;
843 BOOST_CHECK(!noCategory);
846 BOOST_CHECK_THROW(noCategory = counterDirectory.
RegisterCategory(
"invalid category"),
849 BOOST_CHECK(!noCategory);
852 const std::string categoryName =
"some_category";
854 BOOST_CHECK_NO_THROW(category = counterDirectory.
RegisterCategory(categoryName));
856 BOOST_CHECK(category);
857 BOOST_CHECK(category->
m_Name == categoryName);
863 BOOST_CHECK(registeredCategory);
864 BOOST_CHECK(registeredCategory == category);
867 const Category* notRegisteredCategory = counterDirectory.
GetCategory(
"not_registered_category");
869 BOOST_CHECK(!notRegisteredCategory);
872 const Category* anotherCategory =
nullptr;
873 BOOST_CHECK_THROW(anotherCategory = counterDirectory.
RegisterCategory(categoryName),
876 BOOST_CHECK(!anotherCategory);
879 const std::string deviceName =
"some_device";
880 const Device* device =
nullptr;
881 BOOST_CHECK_NO_THROW(device = counterDirectory.
RegisterDevice(deviceName));
884 BOOST_CHECK(device->
m_Uid >= 1);
885 BOOST_CHECK(device->
m_Name == deviceName);
886 BOOST_CHECK(device->
m_Cores == 0);
889 const std::string categoryWoDeviceName =
"some_category_without_device";
890 const Category* categoryWoDevice =
nullptr;
891 BOOST_CHECK_NO_THROW(categoryWoDevice = counterDirectory.
RegisterCategory(categoryWoDeviceName));
893 BOOST_CHECK(categoryWoDevice);
894 BOOST_CHECK(categoryWoDevice->
m_Name == categoryWoDeviceName);
895 BOOST_CHECK(categoryWoDevice->
m_Counters.empty());
898 const Category* categoryInvalidDeviceName =
nullptr;
899 BOOST_CHECK_THROW(categoryInvalidDeviceName =
903 BOOST_CHECK(!categoryInvalidDeviceName);
906 const std::string categoryWValidDeviceName =
"some_category_with_valid_device";
907 const Category* categoryWValidDevice =
nullptr;
908 BOOST_CHECK_NO_THROW(categoryWValidDevice =
911 BOOST_CHECK(categoryWValidDevice);
912 BOOST_CHECK(categoryWValidDevice != category);
913 BOOST_CHECK(categoryWValidDevice->
m_Name == categoryWValidDeviceName);
916 const std::string counterSetName =
"some_counter_set";
918 BOOST_CHECK_NO_THROW(counterSet = counterDirectory.
RegisterCounterSet(counterSetName));
920 BOOST_CHECK(counterSet);
921 BOOST_CHECK(counterSet->
m_Uid >= 1);
922 BOOST_CHECK(counterSet->
m_Name == counterSetName);
923 BOOST_CHECK(counterSet->
m_Count == 0);
926 const std::string categoryWoCounterSetName =
"some_category_without_counter_set";
927 const Category* categoryWoCounterSet =
nullptr;
928 BOOST_CHECK_NO_THROW(categoryWoCounterSet =
931 BOOST_CHECK(categoryWoCounterSet);
932 BOOST_CHECK(categoryWoCounterSet->
m_Name == categoryWoCounterSetName);
935 const std::string categoryWValidCounterSetName =
"some_category_with_valid_counter_set";
936 const Category* categoryWValidCounterSet =
nullptr;
937 BOOST_CHECK_NO_THROW(categoryWValidCounterSet = counterDirectory.
RegisterCategory(categoryWValidCounterSetName));
939 BOOST_CHECK(categoryWValidCounterSet);
940 BOOST_CHECK(categoryWValidCounterSet != category);
941 BOOST_CHECK(categoryWValidCounterSet->
m_Name == categoryWValidCounterSetName);
944 const std::string categoryWValidDeviceAndValidCounterSetName =
"some_category_with_valid_device_and_counter_set";
945 const Category* categoryWValidDeviceAndValidCounterSet =
nullptr;
946 BOOST_CHECK_NO_THROW(categoryWValidDeviceAndValidCounterSet = counterDirectory.
RegisterCategory(
947 categoryWValidDeviceAndValidCounterSetName));
949 BOOST_CHECK(categoryWValidDeviceAndValidCounterSet);
950 BOOST_CHECK(categoryWValidDeviceAndValidCounterSet != category);
951 BOOST_CHECK(categoryWValidDeviceAndValidCounterSet->
m_Name == categoryWValidDeviceAndValidCounterSetName);
963 const Device* noDevice =
nullptr;
966 BOOST_CHECK(!noDevice);
971 BOOST_CHECK(!noDevice);
974 const std::string deviceName =
"some_device";
975 const Device* device =
nullptr;
976 BOOST_CHECK_NO_THROW(device = counterDirectory.
RegisterDevice(deviceName));
979 BOOST_CHECK(device->
m_Name == deviceName);
980 BOOST_CHECK(device->
m_Uid >= 1);
981 BOOST_CHECK(device->
m_Cores == 0);
985 BOOST_CHECK(!unregisteredDevice);
990 BOOST_CHECK(registeredDevice);
991 BOOST_CHECK(registeredDevice == device);
994 const Device* deviceSameName =
nullptr;
997 BOOST_CHECK(!deviceSameName);
1000 const std::string deviceWCoresName =
"some_device_with_cores";
1001 const Device* deviceWCores =
nullptr;
1002 BOOST_CHECK_NO_THROW(deviceWCores = counterDirectory.
RegisterDevice(deviceWCoresName, 2));
1004 BOOST_CHECK(deviceWCores);
1005 BOOST_CHECK(deviceWCores->
m_Name == deviceWCoresName);
1006 BOOST_CHECK(deviceWCores->
m_Uid >= 1);
1007 BOOST_CHECK(deviceWCores->
m_Uid > device->
m_Uid);
1008 BOOST_CHECK(deviceWCores->
m_Cores == 2);
1013 BOOST_CHECK(registeredDeviceWCores);
1014 BOOST_CHECK(registeredDeviceWCores == deviceWCores);
1015 BOOST_CHECK(registeredDeviceWCores != device);
1018 const std::string deviceWCoresWInvalidParentCategoryName =
"some_device_with_cores_with_invalid_parent_category";
1019 const Device* deviceWCoresWInvalidParentCategory =
nullptr;
1020 BOOST_CHECK_THROW(deviceWCoresWInvalidParentCategory =
1021 counterDirectory.
RegisterDevice(deviceWCoresWInvalidParentCategoryName, 3, std::string(
"")),
1024 BOOST_CHECK(!deviceWCoresWInvalidParentCategory);
1027 const std::string deviceWCoresWInvalidParentCategoryName2 =
"some_device_with_cores_with_invalid_parent_category2";
1028 const Device* deviceWCoresWInvalidParentCategory2 =
nullptr;
1029 BOOST_CHECK_THROW(deviceWCoresWInvalidParentCategory2 = counterDirectory.
RegisterDevice(
1030 deviceWCoresWInvalidParentCategoryName2, 3, std::string(
"invalid_parent_category")),
1033 BOOST_CHECK(!deviceWCoresWInvalidParentCategory2);
1036 const std::string categoryName =
"some_category";
1037 const Category* category =
nullptr;
1038 BOOST_CHECK_NO_THROW(category = counterDirectory.
RegisterCategory(categoryName));
1040 BOOST_CHECK(category);
1041 BOOST_CHECK(category->
m_Name == categoryName);
1045 const std::string deviceWCoresWValidParentCategoryName =
"some_device_with_cores_with_valid_parent_category";
1046 const Device* deviceWCoresWValidParentCategory =
nullptr;
1047 BOOST_CHECK_NO_THROW(deviceWCoresWValidParentCategory =
1048 counterDirectory.
RegisterDevice(deviceWCoresWValidParentCategoryName, 4, categoryName));
1050 BOOST_CHECK(deviceWCoresWValidParentCategory);
1051 BOOST_CHECK(deviceWCoresWValidParentCategory->
m_Name == deviceWCoresWValidParentCategoryName);
1052 BOOST_CHECK(deviceWCoresWValidParentCategory->
m_Uid >= 1);
1053 BOOST_CHECK(deviceWCoresWValidParentCategory->
m_Uid > device->
m_Uid);
1054 BOOST_CHECK(deviceWCoresWValidParentCategory->
m_Uid > deviceWCores->
m_Uid);
1055 BOOST_CHECK(deviceWCoresWValidParentCategory->
m_Cores == 4);
1070 BOOST_CHECK(!noCounterSet);
1073 BOOST_CHECK_THROW(noCounterSet = counterDirectory.
RegisterCounterSet(
"invalid name"),
1076 BOOST_CHECK(!noCounterSet);
1079 const std::string counterSetName =
"some_counter_set";
1081 BOOST_CHECK_NO_THROW(counterSet = counterDirectory.
RegisterCounterSet(counterSetName));
1083 BOOST_CHECK(counterSet);
1084 BOOST_CHECK(counterSet->
m_Name == counterSetName);
1085 BOOST_CHECK(counterSet->
m_Uid >= 1);
1086 BOOST_CHECK(counterSet->
m_Count == 0);
1090 BOOST_CHECK(!unregisteredCounterSet);
1095 BOOST_CHECK(registeredCounterSet);
1096 BOOST_CHECK(registeredCounterSet == counterSet);
1099 const CounterSet* counterSetSameName =
nullptr;
1100 BOOST_CHECK_THROW(counterSetSameName = counterDirectory.
RegisterCounterSet(counterSetName),
1103 BOOST_CHECK(!counterSetSameName);
1106 const std::string counterSetWCountName =
"some_counter_set_with_count";
1107 const CounterSet* counterSetWCount =
nullptr;
1108 BOOST_CHECK_NO_THROW(counterSetWCount = counterDirectory.
RegisterCounterSet(counterSetWCountName, 37));
1110 BOOST_CHECK(counterSetWCount);
1111 BOOST_CHECK(counterSetWCount->
m_Name == counterSetWCountName);
1112 BOOST_CHECK(counterSetWCount->
m_Uid >= 1);
1113 BOOST_CHECK(counterSetWCount->
m_Uid > counterSet->
m_Uid);
1114 BOOST_CHECK(counterSetWCount->
m_Count == 37);
1119 BOOST_CHECK(registeredCounterSetWCount);
1120 BOOST_CHECK(registeredCounterSetWCount == counterSetWCount);
1121 BOOST_CHECK(registeredCounterSetWCount != counterSet);
1124 const std::string counterSetWCountWInvalidParentCategoryName =
"some_counter_set_with_count_" 1125 "with_invalid_parent_category";
1126 const CounterSet* counterSetWCountWInvalidParentCategory =
nullptr;
1127 BOOST_CHECK_THROW(counterSetWCountWInvalidParentCategory = counterDirectory.
RegisterCounterSet(
1128 counterSetWCountWInvalidParentCategoryName, 42, std::string(
"")),
1131 BOOST_CHECK(!counterSetWCountWInvalidParentCategory);
1134 const std::string counterSetWCountWInvalidParentCategoryName2 =
"some_counter_set_with_count_" 1135 "with_invalid_parent_category2";
1136 const CounterSet* counterSetWCountWInvalidParentCategory2 =
nullptr;
1137 BOOST_CHECK_THROW(counterSetWCountWInvalidParentCategory2 = counterDirectory.
RegisterCounterSet(
1138 counterSetWCountWInvalidParentCategoryName2, 42, std::string(
"invalid_parent_category")),
1141 BOOST_CHECK(!counterSetWCountWInvalidParentCategory2);
1144 const std::string categoryName =
"some_category";
1145 const Category* category =
nullptr;
1146 BOOST_CHECK_NO_THROW(category = counterDirectory.
RegisterCategory(categoryName));
1148 BOOST_CHECK(category);
1149 BOOST_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 BOOST_CHECK_NO_THROW(counterSetWCountWValidParentCategory = counterDirectory.
RegisterCounterSet(
1157 counterSetWCountWValidParentCategoryName, 42, categoryName));
1159 BOOST_CHECK(counterSetWCountWValidParentCategory);
1160 BOOST_CHECK(counterSetWCountWValidParentCategory->
m_Name == counterSetWCountWValidParentCategoryName);
1161 BOOST_CHECK(counterSetWCountWValidParentCategory->
m_Uid >= 1);
1162 BOOST_CHECK(counterSetWCountWValidParentCategory->
m_Uid > counterSet->
m_Uid);
1163 BOOST_CHECK(counterSetWCountWValidParentCategory->
m_Uid > counterSetWCount->
m_Uid);
1164 BOOST_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 BOOST_CHECK_THROW(counterSetSameCategory =
1171 counterDirectory.
RegisterCounterSet(counterSetSameCategoryName, 0, invalidCategoryName),
1174 BOOST_CHECK(!counterSetSameCategory);
1186 const Counter* noCounter =
nullptr;
1187 BOOST_CHECK_THROW(noCounter =
1198 BOOST_CHECK(!noCounter);
1201 BOOST_CHECK_THROW(noCounter = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1203 "invalid parent category",
1208 "valid description"),
1211 BOOST_CHECK(!noCounter);
1214 BOOST_CHECK_THROW(noCounter = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1216 "valid_parent_category",
1222 "valid description"),
1225 BOOST_CHECK(!noCounter);
1228 BOOST_CHECK_THROW(noCounter = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1230 "valid_parent_category",
1236 "valid description"),
1239 BOOST_CHECK(!noCounter);
1242 BOOST_CHECK_THROW(noCounter = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1244 "valid_parent_category",
1250 "valid description"),
1253 BOOST_CHECK(!noCounter);
1257 noCounter = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1259 "valid_parent_category",
1264 "valid description"),
1267 BOOST_CHECK(!noCounter);
1270 BOOST_CHECK_THROW(noCounter = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1272 "valid_parent_category",
1277 "valid description"),
1280 BOOST_CHECK(!noCounter);
1283 BOOST_CHECK_THROW(noCounter =
1286 "valid_parent_category",
1294 BOOST_CHECK(!noCounter);
1297 BOOST_CHECK_THROW(noCounter = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1299 "valid_parent_category",
1305 "inv@lid description"),
1308 BOOST_CHECK(!noCounter);
1311 BOOST_CHECK_THROW(noCounter = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1313 "valid_parent_category",
1318 "valid description",
1319 std::string(
"Mb/s2")),
1322 BOOST_CHECK(!noCounter);
1325 BOOST_CHECK_THROW(noCounter = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1327 "invalid_parent_category",
1332 "valid description"),
1335 BOOST_CHECK(!noCounter);
1339 BOOST_CHECK(!unregisteredCounter);
1342 const std::string categoryName =
"some_category";
1343 const Category* category =
nullptr;
1344 BOOST_CHECK_NO_THROW(category = counterDirectory.
RegisterCategory(categoryName));
1346 BOOST_CHECK(category);
1347 BOOST_CHECK(category->
m_Name == categoryName);
1351 const Counter* counter =
nullptr;
1352 BOOST_CHECK_NO_THROW(
1353 counter = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1360 "valid description"));
1362 BOOST_CHECK(counter);
1363 BOOST_CHECK(counter->m_MaxCounterUid == counter->m_Uid);
1364 BOOST_CHECK(counter->m_Class == 0);
1365 BOOST_CHECK(counter->m_Interpolation == 1);
1366 BOOST_CHECK(counter->m_Multiplier == 123.45f);
1367 BOOST_CHECK(counter->m_Name ==
"valid name");
1368 BOOST_CHECK(counter->m_Description ==
"valid description");
1369 BOOST_CHECK(counter->m_Units ==
"");
1370 BOOST_CHECK(counter->m_DeviceUid == 0);
1371 BOOST_CHECK(counter->m_CounterSetUid == 0);
1372 BOOST_CHECK(category->
m_Counters.size() == 1);
1373 BOOST_CHECK(category->
m_Counters.back() == counter->m_Uid);
1376 const Counter* counterSameName =
nullptr;
1377 BOOST_CHECK_THROW(counterSameName =
1385 "valid description",
1386 std::string(
"description")),
1389 BOOST_CHECK(!counterSameName);
1392 const Counter* counterWUnits =
nullptr;
1393 BOOST_CHECK_NO_THROW(counterWUnits = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1400 "valid description",
1401 std::string(
"Mnnsq2")));
1403 BOOST_CHECK(counterWUnits);
1404 BOOST_CHECK(counterWUnits->
m_Uid > counter->m_Uid);
1406 BOOST_CHECK(counterWUnits->
m_Class == 0);
1409 BOOST_CHECK(counterWUnits->
m_Name ==
"valid name 2");
1410 BOOST_CHECK(counterWUnits->
m_Description ==
"valid description");
1411 BOOST_CHECK(counterWUnits->
m_Units ==
"Mnnsq2");
1414 BOOST_CHECK(category->
m_Counters.size() == 2);
1418 const Counter* counterWoDevice =
nullptr;
1419 BOOST_CHECK_NO_THROW(counterWoDevice = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1426 "valid description",
1431 BOOST_CHECK(counterWoDevice);
1432 BOOST_CHECK(counterWoDevice->m_Uid > counter->m_Uid);
1433 BOOST_CHECK(counterWoDevice->m_MaxCounterUid == counterWoDevice->m_Uid);
1434 BOOST_CHECK(counterWoDevice->m_Class == 0);
1435 BOOST_CHECK(counterWoDevice->m_Interpolation == 1);
1436 BOOST_CHECK(counterWoDevice->m_Multiplier == 123.45f);
1437 BOOST_CHECK(counterWoDevice->m_Name ==
"valid name 3");
1438 BOOST_CHECK(counterWoDevice->m_Description ==
"valid description");
1439 BOOST_CHECK(counterWoDevice->m_Units ==
"");
1440 BOOST_CHECK(counterWoDevice->m_DeviceUid == 0);
1441 BOOST_CHECK(counterWoDevice->m_CounterSetUid == 0);
1442 BOOST_CHECK(category->
m_Counters.size() == 3);
1443 BOOST_CHECK(category->
m_Counters.back() == counterWoDevice->m_Uid);
1446 BOOST_CHECK_THROW(noCounter = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1453 "valid description",
1459 BOOST_CHECK(!noCounter);
1462 const std::string deviceName =
"some_device";
1463 const Device* device =
nullptr;
1464 BOOST_CHECK_NO_THROW(device = counterDirectory.
RegisterDevice(deviceName));
1466 BOOST_CHECK(device);
1467 BOOST_CHECK(device->
m_Name == deviceName);
1468 BOOST_CHECK(device->
m_Uid >= 1);
1469 BOOST_CHECK(device->
m_Cores == 0);
1472 const Counter* counterWDevice =
nullptr;
1473 BOOST_CHECK_NO_THROW(counterWDevice = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1480 std::string(
"valid description"),
1485 BOOST_CHECK(counterWDevice);
1486 BOOST_CHECK(counterWDevice->
m_Uid > counter->m_Uid);
1488 BOOST_CHECK(counterWDevice->
m_Class == 0);
1491 BOOST_CHECK(counterWDevice->
m_Name ==
"valid name 5");
1492 BOOST_CHECK(counterWDevice->
m_Description ==
"valid description");
1493 BOOST_CHECK(counterWDevice->
m_Units ==
"");
1496 BOOST_CHECK(category->
m_Counters.size() == 4);
1500 const Counter* counterWoCounterSet =
nullptr;
1501 BOOST_CHECK_NO_THROW(counterWoCounterSet = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1508 "valid description",
1514 BOOST_CHECK(counterWoCounterSet);
1515 BOOST_CHECK(counterWoCounterSet->m_Uid > counter->m_Uid);
1516 BOOST_CHECK(counterWoCounterSet->m_MaxCounterUid == counterWoCounterSet->m_Uid);
1517 BOOST_CHECK(counterWoCounterSet->m_Class == 0);
1518 BOOST_CHECK(counterWoCounterSet->m_Interpolation == 1);
1519 BOOST_CHECK(counterWoCounterSet->m_Multiplier == 123.45f);
1520 BOOST_CHECK(counterWoCounterSet->m_Name ==
"valid name 6");
1521 BOOST_CHECK(counterWoCounterSet->m_Description ==
"valid description");
1522 BOOST_CHECK(counterWoCounterSet->m_Units ==
"");
1523 BOOST_CHECK(counterWoCounterSet->m_DeviceUid == 0);
1524 BOOST_CHECK(counterWoCounterSet->m_CounterSetUid == 0);
1525 BOOST_CHECK(category->
m_Counters.size() == 5);
1526 BOOST_CHECK(category->
m_Counters.back() == counterWoCounterSet->m_Uid);
1529 BOOST_CHECK_THROW(noCounter = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1537 std::string(
"valid description"),
1543 BOOST_CHECK(!noCounter);
1546 const Counter* counterWNumberOfCores =
nullptr;
1547 uint16_t numberOfCores = 15;
1548 BOOST_CHECK_NO_THROW(counterWNumberOfCores = counterDirectory.
RegisterCounter(
1549 armnn::profiling::BACKEND_ID, 50,
1550 categoryName, 0, 1, 123.45f,
"valid name 8",
"valid description",
1556 BOOST_CHECK(counterWNumberOfCores);
1557 BOOST_CHECK(counterWNumberOfCores->
m_Uid > counter->m_Uid);
1558 BOOST_CHECK(counterWNumberOfCores->
m_MaxCounterUid == counterWNumberOfCores->
m_Uid + numberOfCores - 1);
1559 BOOST_CHECK(counterWNumberOfCores->
m_Class == 0);
1561 BOOST_CHECK(counterWNumberOfCores->
m_Multiplier == 123.45f);
1562 BOOST_CHECK(counterWNumberOfCores->
m_Name ==
"valid name 8");
1563 BOOST_CHECK(counterWNumberOfCores->
m_Description ==
"valid description");
1564 BOOST_CHECK(counterWNumberOfCores->
m_Units ==
"");
1565 BOOST_CHECK(counterWNumberOfCores->
m_DeviceUid == 0);
1567 BOOST_CHECK(category->
m_Counters.size() == 20);
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 BOOST_CHECK_NO_THROW(multiCoreDevice = counterDirectory.
RegisterDevice(multiCoreDeviceName, 4));
1579 BOOST_CHECK(multiCoreDevice);
1580 BOOST_CHECK(multiCoreDevice->
m_Name == multiCoreDeviceName);
1581 BOOST_CHECK(multiCoreDevice->
m_Uid >= 1);
1582 BOOST_CHECK(multiCoreDevice->
m_Cores == 4);
1585 const Counter* counterWMultiCoreDevice =
nullptr;
1586 BOOST_CHECK_NO_THROW(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 BOOST_CHECK(counterWMultiCoreDevice);
1595 BOOST_CHECK(counterWMultiCoreDevice->
m_Uid > counter->m_Uid);
1597 counterWMultiCoreDevice->
m_Uid + multiCoreDevice->
m_Cores - 1);
1598 BOOST_CHECK(counterWMultiCoreDevice->
m_Class == 0);
1600 BOOST_CHECK(counterWMultiCoreDevice->
m_Multiplier == 123.45f);
1601 BOOST_CHECK(counterWMultiCoreDevice->
m_Name ==
"valid name 9");
1602 BOOST_CHECK(counterWMultiCoreDevice->
m_Description ==
"valid description");
1603 BOOST_CHECK(counterWMultiCoreDevice->
m_Units ==
"");
1604 BOOST_CHECK(counterWMultiCoreDevice->
m_DeviceUid == multiCoreDevice->
m_Uid);
1606 BOOST_CHECK(category->
m_Counters.size() == 24);
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 BOOST_CHECK_NO_THROW(multiCoreDeviceWParentCategory =
1616 counterDirectory.
RegisterDevice(multiCoreDeviceNameWParentCategory, 2, categoryName));
1618 BOOST_CHECK(multiCoreDeviceWParentCategory);
1619 BOOST_CHECK(multiCoreDeviceWParentCategory->
m_Name == multiCoreDeviceNameWParentCategory);
1620 BOOST_CHECK(multiCoreDeviceWParentCategory->
m_Uid >= 1);
1621 BOOST_CHECK(multiCoreDeviceWParentCategory->
m_Cores == 2);
1625 const Counter* counterWMultiCoreDeviceWParentCategory =
nullptr;
1626 uint16_t numberOfCourse = multiCoreDeviceWParentCategory->
m_Cores;
1627 BOOST_CHECK_NO_THROW(counterWMultiCoreDeviceWParentCategory =
1629 armnn::profiling::BACKEND_ID,
1636 "valid description",
1642 BOOST_CHECK(counterWMultiCoreDeviceWParentCategory);
1643 BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->
m_Uid > counter->m_Uid);
1644 BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->
m_MaxCounterUid ==
1645 counterWMultiCoreDeviceWParentCategory->
m_Uid + multiCoreDeviceWParentCategory->
m_Cores - 1);
1646 BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->
m_Class == 0);
1647 BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->
m_Interpolation == 1);
1648 BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->
m_Multiplier == 123.45f);
1649 BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->
m_Name ==
"valid name 10");
1650 BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->
m_Description ==
"valid description");
1651 BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->
m_Units ==
"");
1652 BOOST_CHECK(category->
m_Counters.size() == 26);
1653 for (
size_t i = 0; i < 2; i++)
1656 counterWMultiCoreDeviceWParentCategory->
m_Uid + i);
1660 const std::string counterSetName =
"some_counter_set";
1662 BOOST_CHECK_NO_THROW(counterSet = counterDirectory.
RegisterCounterSet(counterSetName));
1664 BOOST_CHECK(counterSet);
1665 BOOST_CHECK(counterSet->
m_Name == counterSetName);
1666 BOOST_CHECK(counterSet->
m_Uid >= 1);
1667 BOOST_CHECK(counterSet->
m_Count == 0);
1670 const Counter* counterWCounterSet =
nullptr;
1671 BOOST_CHECK_NO_THROW(counterWCounterSet = counterDirectory.
RegisterCounter(
1672 armnn::profiling::BACKEND_ID, 300,
1673 categoryName, 0, 1, 123.45f,
"valid name 11",
"valid description",
1677 counterSet->
m_Uid));
1679 BOOST_CHECK(counterWCounterSet);
1680 BOOST_CHECK(counterWCounterSet->
m_Uid > counter->m_Uid);
1682 BOOST_CHECK(counterWCounterSet->
m_Class == 0);
1684 BOOST_CHECK(counterWCounterSet->
m_Multiplier == 123.45f);
1685 BOOST_CHECK(counterWCounterSet->
m_Name ==
"valid name 11");
1686 BOOST_CHECK(counterWCounterSet->
m_Description ==
"valid description");
1687 BOOST_CHECK(counterWCounterSet->
m_Units ==
"");
1688 BOOST_CHECK(counterWCounterSet->
m_DeviceUid == 0);
1690 BOOST_CHECK(category->
m_Counters.size() == 27);
1691 BOOST_CHECK(category->
m_Counters.back() == counterWCounterSet->
m_Uid);
1694 const Counter* counterWDeviceWCounterSet =
nullptr;
1695 BOOST_CHECK_NO_THROW(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 BOOST_CHECK(counterWDeviceWCounterSet);
1704 BOOST_CHECK(counterWDeviceWCounterSet->m_Uid > counter->m_Uid);
1705 BOOST_CHECK(counterWDeviceWCounterSet->m_MaxCounterUid == counterWDeviceWCounterSet->m_Uid);
1706 BOOST_CHECK(counterWDeviceWCounterSet->m_Class == 0);
1707 BOOST_CHECK(counterWDeviceWCounterSet->m_Interpolation == 1);
1708 BOOST_CHECK(counterWDeviceWCounterSet->m_Multiplier == 123.45f);
1709 BOOST_CHECK(counterWDeviceWCounterSet->m_Name ==
"valid name 12");
1710 BOOST_CHECK(counterWDeviceWCounterSet->m_Description ==
"valid description");
1711 BOOST_CHECK(counterWDeviceWCounterSet->m_Units ==
"");
1712 BOOST_CHECK(counterWDeviceWCounterSet->m_DeviceUid == device->
m_Uid);
1713 BOOST_CHECK(counterWDeviceWCounterSet->m_CounterSetUid == counterSet->
m_Uid);
1714 BOOST_CHECK(category->
m_Counters.size() == 28);
1715 BOOST_CHECK(category->
m_Counters.back() == counterWDeviceWCounterSet->m_Uid);
1718 const std::string anotherCategoryName =
"some_other_category";
1719 const Category* anotherCategory =
nullptr;
1720 BOOST_CHECK_NO_THROW(anotherCategory = counterDirectory.
RegisterCategory(anotherCategoryName));
1722 BOOST_CHECK(anotherCategory);
1723 BOOST_CHECK(anotherCategory != category);
1724 BOOST_CHECK(anotherCategory->
m_Name == anotherCategoryName);
1725 BOOST_CHECK(anotherCategory->
m_Counters.empty());
1728 const Counter* anotherCounter =
nullptr;
1729 BOOST_CHECK_NO_THROW(anotherCounter = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID, 24,
1730 anotherCategoryName, 1, 0, .00043f,
1731 "valid name",
"valid description",
1735 counterSet->
m_Uid));
1737 BOOST_CHECK(anotherCounter);
1738 BOOST_CHECK(anotherCounter->m_MaxCounterUid == anotherCounter->m_Uid);
1739 BOOST_CHECK(anotherCounter->m_Class == 1);
1740 BOOST_CHECK(anotherCounter->m_Interpolation == 0);
1741 BOOST_CHECK(anotherCounter->m_Multiplier == .00043f);
1742 BOOST_CHECK(anotherCounter->m_Name ==
"valid name");
1743 BOOST_CHECK(anotherCounter->m_Description ==
"valid description");
1744 BOOST_CHECK(anotherCounter->m_Units ==
"");
1745 BOOST_CHECK(anotherCounter->m_DeviceUid == device->
m_Uid);
1746 BOOST_CHECK(anotherCounter->m_CounterSetUid == counterSet->
m_Uid);
1747 BOOST_CHECK(anotherCategory->
m_Counters.size() == 1);
1748 BOOST_CHECK(anotherCategory->
m_Counters.back() == anotherCounter->m_Uid);
1759 void Start()
override 1761 void Stop()
override 1767 bool IsCounterRegistered(uint16_t counterUid)
const override 1772 uint16_t GetCounterCount()
const override 1776 uint32_t GetAbsoluteCounterValue(uint16_t counterUid)
const override 1781 uint32_t GetDeltaCounterValue(uint16_t counterUid)
override 1787 const uint32_t familyId = 0;
1788 const uint32_t packetId = 0x40000;
1790 uint32_t version = 1;
1792 std::shared_ptr<armnn::profiling::IBackendProfilingContext>> backendProfilingContext;
1795 TestCaptureThread captureThread;
1796 TestReadCounterValues readCounterValues;
1799 SendThread sendThread(profilingStateMachine, mockBuffer, sendCounterPacket);
1801 uint32_t sizeOfUint32 =
numeric_cast<uint32_t>(
sizeof(uint32_t));
1802 uint32_t sizeOfUint16 =
numeric_cast<uint32_t>(
sizeof(uint16_t));
1806 uint32_t dataLength1 = 8;
1807 uint32_t offset = 0;
1809 std::unique_ptr<unsigned char[]> uniqueData1 = std::make_unique<unsigned char[]>(dataLength1);
1810 unsigned char* data1 =
reinterpret_cast<unsigned char*
>(uniqueData1.get());
1813 offset += sizeOfUint32;
1815 offset += sizeOfUint16;
1818 arm::pipe::Packet packetA(packetId, dataLength1, uniqueData1);
1821 counterIdMap, holder, 10000u, captureThread,
1822 readCounterValues, sendCounterPacket, profilingStateMachine);
1831 BOOST_CHECK_NO_THROW(commandHandler(packetA));
1836 BOOST_TEST(counterIdsA.size() == 2);
1837 BOOST_TEST(counterIdsA[0] == 4000);
1838 BOOST_TEST(counterIdsA[1] == 5000);
1844 uint32_t headerWord0 =
ReadUint32(readBuffer, offset);
1845 offset += sizeOfUint32;
1846 uint32_t headerWord1 =
ReadUint32(readBuffer, offset);
1847 offset += sizeOfUint32;
1848 uint32_t period =
ReadUint32(readBuffer, offset);
1850 BOOST_TEST(((headerWord0 >> 26) & 0x3F) == 0);
1851 BOOST_TEST(((headerWord0 >> 16) & 0x3FF) == 4);
1852 BOOST_TEST(headerWord1 == 8);
1855 uint16_t counterId = 0;
1856 offset += sizeOfUint32;
1858 BOOST_TEST(counterId == 4000);
1859 offset += sizeOfUint16;
1861 BOOST_TEST(counterId == 5000);
1866 uint32_t period2 = 9000;
1867 uint32_t dataLength2 = 4;
1869 std::unique_ptr<unsigned char[]> uniqueData2 = std::make_unique<unsigned char[]>(dataLength2);
1871 WriteUint32(reinterpret_cast<unsigned char*>(uniqueData2.get()), 0, period2);
1873 arm::pipe::Packet packetB(packetId, dataLength2, uniqueData2);
1875 commandHandler(packetB);
1881 BOOST_TEST(counterIdsB.size() == 0);
1887 headerWord0 =
ReadUint32(readBuffer, offset);
1888 offset += sizeOfUint32;
1889 headerWord1 =
ReadUint32(readBuffer, offset);
1890 offset += sizeOfUint32;
1893 BOOST_TEST(((headerWord0 >> 26) & 0x3F) == 0);
1894 BOOST_TEST(((headerWord0 >> 16) & 0x3FF) == 4);
1895 BOOST_TEST(headerWord1 == 4);
1904 virtual void ReportStructure()
override 1906 m_ReportStructureCalled =
true;
1909 bool m_ReportStructureCalled =
false;
1915 TestNotifyBackends() : m_timelineReporting(
false) {}
1916 virtual void NotifyBackendsForTimelineReporting()
override 1918 m_TestNotifyBackendsCalled = m_timelineReporting.load();
1921 bool m_TestNotifyBackendsCalled =
false;
1922 std::atomic<bool> m_timelineReporting;
1925 arm::pipe::PacketVersionResolver packetVersionResolver;
1930 TestReportStructure testReportStructure;
1931 TestNotifyBackends testNotifyBackends;
1935 packetVersionResolver.ResolvePacketVersion(0, 6)
1939 testReportStructure,
1940 testNotifyBackends.m_timelineReporting,
1941 testNotifyBackends);
1945 const uint32_t packetFamily1 = 0;
1946 const uint32_t packetId1 = 6;
1950 arm::pipe::Packet ActivateTimelineReportingPacket(packetHeader1);
1953 activateTimelineReportingCommandHandler.operator()(ActivateTimelineReportingPacket),
armnn::Exception);
1957 activateTimelineReportingCommandHandler.operator()(ActivateTimelineReportingPacket),
armnn::Exception);
1961 activateTimelineReportingCommandHandler.operator()(ActivateTimelineReportingPacket),
armnn::Exception);
1964 activateTimelineReportingCommandHandler.operator()(ActivateTimelineReportingPacket);
1966 BOOST_CHECK(testReportStructure.m_ReportStructureCalled);
1967 BOOST_CHECK(testNotifyBackends.m_TestNotifyBackendsCalled);
1968 BOOST_CHECK(testNotifyBackends.m_timelineReporting.load());
1972 packetVersionResolver.ResolvePacketVersion(0, 7).GetEncodedValue(),
1973 testNotifyBackends.m_timelineReporting,
1975 testNotifyBackends);
1977 const uint32_t packetFamily2 = 0;
1978 const uint32_t packetId2 = 7;
1982 arm::pipe::Packet deactivateTimelineReportingPacket(packetHeader2);
1984 stateMachine.Reset();
1986 deactivateTimelineReportingCommandHandler.operator()(deactivateTimelineReportingPacket),
armnn::Exception);
1990 deactivateTimelineReportingCommandHandler.operator()(deactivateTimelineReportingPacket),
armnn::Exception);
1994 deactivateTimelineReportingCommandHandler.operator()(deactivateTimelineReportingPacket),
armnn::Exception);
1997 deactivateTimelineReportingCommandHandler.operator()(deactivateTimelineReportingPacket);
1999 BOOST_CHECK(!testNotifyBackends.m_TestNotifyBackendsCalled);
2000 BOOST_CHECK(!testNotifyBackends.m_timelineReporting.load());
2005 using namespace armnn;
2022 BOOST_CHECK(readableBuffer ==
nullptr);
2029 const uint32_t packetFamilyId = 0;
2030 const uint32_t connectionPacketId = 0x10000;
2031 const uint32_t version = 1;
2033 uint32_t sizeOfUint32 =
numeric_cast<uint32_t>(
sizeof(uint32_t));
2034 uint32_t sizeOfUint16 =
numeric_cast<uint32_t>(
sizeof(uint16_t));
2037 uint32_t period1 = 10;
2038 uint32_t dataLength1 = 8;
2039 uint32_t offset = 0;
2041 std::unique_ptr<unsigned char[]> uniqueData1 = std::make_unique<unsigned char[]>(dataLength1);
2042 unsigned char* data1 =
reinterpret_cast<unsigned char*
>(uniqueData1.get());
2045 offset += sizeOfUint32;
2047 offset += sizeOfUint16;
2050 arm::pipe::Packet packetA(connectionPacketId, dataLength1, uniqueData1);
2057 SendThread sendThread(profilingState, mockBuffer, sendCounterPacket);
2068 mockProfilingServiceStatus);
2081 BOOST_CHECK_NO_THROW(commandHandler(packetA));
2085 BOOST_CHECK_NO_THROW(commandHandler(packetA));
2089 const uint32_t differentPacketId = 0x40000;
2090 arm::pipe::Packet packetB(differentPacketId, dataLength1, uniqueData1);
2100 mockProfilingServiceStatus);
2116 catch (
const arm::pipe::SocketConnectionException& ex)
2118 BOOST_CHECK(ex.GetSocketFd() == 0);
2119 BOOST_CHECK(ex.GetErrorNo() == 111);
2120 BOOST_CHECK(ex.what()
2121 == std::string(
"SocketProfilingConnection: Cannot connect to stream socket: Connection refused"));
2128 for (
unsigned char c = 0; c < 128; c++)
2130 BOOST_CHECK(arm::pipe::SwTraceCharPolicy::IsValidChar(c));
2134 for (
unsigned char c = 255; c >= 128; c++)
2136 BOOST_CHECK(!arm::pipe::SwTraceCharPolicy::IsValidChar(c));
2143 const unsigned char validChars[] =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_";
2144 for (
unsigned char i = 0; i <
sizeof(validChars) /
sizeof(validChars[0]) - 1; i++)
2146 BOOST_CHECK(arm::pipe::SwTraceNameCharPolicy::IsValidChar(validChars[i]));
2150 for (
unsigned char c = 0; c < 48; c++)
2152 BOOST_CHECK(!arm::pipe::SwTraceNameCharPolicy::IsValidChar(c));
2154 for (
unsigned char c = 58; c < 65; c++)
2156 BOOST_CHECK(!arm::pipe::SwTraceNameCharPolicy::IsValidChar(c));
2158 for (
unsigned char c = 91; c < 95; c++)
2160 BOOST_CHECK(!arm::pipe::SwTraceNameCharPolicy::IsValidChar(c));
2162 for (
unsigned char c = 96; c < 97; c++)
2164 BOOST_CHECK(!arm::pipe::SwTraceNameCharPolicy::IsValidChar(c));
2166 for (
unsigned char c = 123; c < 128; c++)
2168 BOOST_CHECK(!arm::pipe::SwTraceNameCharPolicy::IsValidChar(c));
2172 for (
unsigned char c = 255; c >= 128; c++)
2174 BOOST_CHECK(!arm::pipe::SwTraceNameCharPolicy::IsValidChar(c));
2181 BOOST_CHECK(arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceCharPolicy>(
""));
2182 BOOST_CHECK(arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceCharPolicy>(
"_"));
2183 BOOST_CHECK(arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceCharPolicy>(
"0123"));
2184 BOOST_CHECK(arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceCharPolicy>(
"valid_string"));
2185 BOOST_CHECK(arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceCharPolicy>(
"VALID_string_456"));
2186 BOOST_CHECK(arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceCharPolicy>(
" "));
2187 BOOST_CHECK(arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceCharPolicy>(
"valid string"));
2188 BOOST_CHECK(arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceCharPolicy>(
"!$%"));
2189 BOOST_CHECK(arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceCharPolicy>(
"valid|\\~string#123"));
2192 BOOST_CHECK(!arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceCharPolicy>(
"€£"));
2193 BOOST_CHECK(!arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceCharPolicy>(
"invalid‡string"));
2194 BOOST_CHECK(!arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceCharPolicy>(
"12Ž34"));
2200 BOOST_CHECK(arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
""));
2201 BOOST_CHECK(arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
"_"));
2202 BOOST_CHECK(arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
"0123"));
2203 BOOST_CHECK(arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
"valid_string"));
2204 BOOST_CHECK(arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
"VALID_string_456"));
2207 BOOST_CHECK(!arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
" "));
2208 BOOST_CHECK(!arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
"invalid string"));
2209 BOOST_CHECK(!arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
"!$%"));
2210 BOOST_CHECK(!arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
"invalid|\\~string#123"));
2211 BOOST_CHECK(!arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
"€£"));
2212 BOOST_CHECK(!arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
"invalid‡string"));
2213 BOOST_CHECK(!arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
"12Ž34"));
2216 template <
typename SwTracePolicy>
2220 BOOST_CHECK(arm::pipe::StringToSwTraceString<SwTracePolicy>(testString, buffer));
2223 BOOST_CHECK(!buffer.empty());
2226 BOOST_CHECK(buffer.size() == expectedSize);
2229 BOOST_CHECK(buffer[0] == testString.size() + 1);
2232 BOOST_CHECK(std::memcmp(testString.data(), buffer.data() + 1, testString.size()) == 0);
2235 size_t nullTerminatorIndex =
sizeof(uint32_t) + testString.size();
2236 BOOST_CHECK(reinterpret_cast<unsigned char*>(buffer.data())[nullTerminatorIndex] ==
'\0');
2241 std::vector<uint32_t> buffer;
2244 StringToSwTraceStringTestHelper<arm::pipe::SwTraceCharPolicy>(
"", buffer, 2);
2245 StringToSwTraceStringTestHelper<arm::pipe::SwTraceCharPolicy>(
"_", buffer, 2);
2246 StringToSwTraceStringTestHelper<arm::pipe::SwTraceCharPolicy>(
"0123", buffer, 3);
2247 StringToSwTraceStringTestHelper<arm::pipe::SwTraceCharPolicy>(
"valid_string", buffer, 5);
2248 StringToSwTraceStringTestHelper<arm::pipe::SwTraceCharPolicy>(
"VALID_string_456", buffer, 6);
2249 StringToSwTraceStringTestHelper<arm::pipe::SwTraceCharPolicy>(
" ", buffer, 2);
2250 StringToSwTraceStringTestHelper<arm::pipe::SwTraceCharPolicy>(
"valid string", buffer, 5);
2251 StringToSwTraceStringTestHelper<arm::pipe::SwTraceCharPolicy>(
"!$%", buffer, 2);
2252 StringToSwTraceStringTestHelper<arm::pipe::SwTraceCharPolicy>(
"valid|\\~string#123", buffer, 6);
2255 BOOST_CHECK(!arm::pipe::StringToSwTraceString<arm::pipe::SwTraceCharPolicy>(
"€£", buffer));
2256 BOOST_CHECK(buffer.empty());
2257 BOOST_CHECK(!arm::pipe::StringToSwTraceString<arm::pipe::SwTraceCharPolicy>(
"invalid‡string", buffer));
2258 BOOST_CHECK(buffer.empty());
2259 BOOST_CHECK(!arm::pipe::StringToSwTraceString<arm::pipe::SwTraceCharPolicy>(
"12Ž34", buffer));
2260 BOOST_CHECK(buffer.empty());
2265 std::vector<uint32_t> buffer;
2268 StringToSwTraceStringTestHelper<arm::pipe::SwTraceNameCharPolicy>(
"", buffer, 2);
2269 StringToSwTraceStringTestHelper<arm::pipe::SwTraceNameCharPolicy>(
"_", buffer, 2);
2270 StringToSwTraceStringTestHelper<arm::pipe::SwTraceNameCharPolicy>(
"0123", buffer, 3);
2271 StringToSwTraceStringTestHelper<arm::pipe::SwTraceNameCharPolicy>(
"valid_string", buffer, 5);
2272 StringToSwTraceStringTestHelper<arm::pipe::SwTraceNameCharPolicy>(
"VALID_string_456", buffer, 6);
2275 BOOST_CHECK(!arm::pipe::StringToSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
" ", buffer));
2276 BOOST_CHECK(buffer.empty());
2277 BOOST_CHECK(!arm::pipe::StringToSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
"invalid string", buffer));
2278 BOOST_CHECK(buffer.empty());
2279 BOOST_CHECK(!arm::pipe::StringToSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
"!$%", buffer));
2280 BOOST_CHECK(buffer.empty());
2281 BOOST_CHECK(!arm::pipe::StringToSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
"invalid|\\~string#123", buffer));
2282 BOOST_CHECK(buffer.empty());
2283 BOOST_CHECK(!arm::pipe::StringToSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
"€£", buffer));
2284 BOOST_CHECK(buffer.empty());
2285 BOOST_CHECK(!arm::pipe::StringToSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
"invalid‡string", buffer));
2286 BOOST_CHECK(buffer.empty());
2287 BOOST_CHECK(!arm::pipe::StringToSwTraceString<arm::pipe::SwTraceNameCharPolicy>(
"12Ž34", buffer));
2288 BOOST_CHECK(buffer.empty());
2296 CaptureReader(uint16_t counterSize)
2298 for (uint16_t i = 0; i < counterSize; ++i)
2302 m_CounterSize = counterSize;
2305 bool IsCounterRegistered(uint16_t counterUid)
const override 2311 uint16_t GetCounterCount()
const override 2313 return m_CounterSize;
2316 uint32_t GetAbsoluteCounterValue(uint16_t counterUid)
const override 2318 if (counterUid > m_CounterSize)
2320 BOOST_FAIL(
"Invalid counter Uid");
2322 return m_Data.at(counterUid).load();
2325 uint32_t GetDeltaCounterValue(uint16_t counterUid)
override 2327 if (counterUid > m_CounterSize)
2329 BOOST_FAIL(
"Invalid counter Uid");
2331 return m_Data.at(counterUid).load();
2334 void SetCounterValue(uint16_t counterUid, uint32_t value)
2336 if (counterUid > m_CounterSize)
2338 BOOST_FAIL(
"Invalid counter Uid");
2340 m_Data.at(counterUid).store(value);
2344 std::unordered_map<uint16_t, std::atomic<uint32_t>> m_Data;
2345 uint16_t m_CounterSize;
2351 std::shared_ptr<armnn::profiling::IBackendProfilingContext>> backendProfilingContext;
2354 std::vector<uint16_t> captureIds1 = { 0, 1 };
2355 std::vector<uint16_t> captureIds2;
2359 SendThread sendThread(profilingStateMachine, mockBuffer, sendCounterPacket);
2361 std::vector<uint16_t> counterIds;
2362 CaptureReader captureReader(2);
2364 unsigned int valueA = 10;
2365 unsigned int valueB = 15;
2366 unsigned int numSteps = 5;
2368 PeriodicCounterCapture periodicCounterCapture(std::ref(data), std::ref(sendCounterPacket), captureReader,
2369 counterIdMap, backendProfilingContext);
2371 for (
unsigned int i = 0; i < numSteps; ++i)
2374 captureReader.SetCounterValue(0, valueA * (i + 1));
2375 captureReader.SetCounterValue(1, valueB * (i + 1));
2377 periodicCounterCapture.
Start();
2378 periodicCounterCapture.
Stop();
2383 uint32_t headerWord0 =
ReadUint32(buffer, 0);
2384 uint32_t headerWord1 =
ReadUint32(buffer, 4);
2386 BOOST_TEST(((headerWord0 >> 26) & 0x0000003F) == 3);
2387 BOOST_TEST(((headerWord0 >> 19) & 0x0000007F) == 0);
2388 BOOST_TEST(((headerWord0 >> 16) & 0x00000007) == 0);
2389 BOOST_TEST(headerWord1 == 20);
2391 uint32_t offset = 16;
2392 uint16_t readIndex =
ReadUint16(buffer, offset);
2393 BOOST_TEST(0 == readIndex);
2396 uint32_t readValue =
ReadUint32(buffer, offset);
2397 BOOST_TEST((valueA * numSteps) == readValue);
2401 BOOST_TEST(1 == readIndex);
2405 BOOST_TEST((valueB * numSteps) == readValue);
2412 const uint32_t familyId = 0;
2413 const uint32_t packetId = 3;
2414 const uint32_t version = 1;
2419 SendThread sendThread(profilingStateMachine, mockBuffer1, sendCounterPacket);
2423 sendCounterPacket, sendTimelinePacket, profilingStateMachine);
2425 const uint32_t wrongPacketId = 47;
2426 const uint32_t wrongHeader = (wrongPacketId & 0x000003FF) << 16;
2428 arm::pipe::Packet wrongPacket(wrongHeader);
2439 const uint32_t rightHeader = (packetId & 0x000003FF) << 16;
2441 arm::pipe::Packet rightPacket(rightHeader);
2443 BOOST_CHECK_NO_THROW(commandHandler(rightPacket));
2447 uint32_t header1Word0 =
ReadUint32(readBuffer1, 0);
2448 uint32_t header1Word1 =
ReadUint32(readBuffer1, 4);
2451 BOOST_TEST(((header1Word0 >> 26) & 0x0000003F) == 0);
2452 BOOST_TEST(((header1Word0 >> 16) & 0x000003FF) == 2);
2453 BOOST_TEST(header1Word1 == 24);
2455 uint32_t bodyHeader1Word0 =
ReadUint32(readBuffer1, 8);
2456 uint16_t deviceRecordCount =
numeric_cast<uint16_t>(bodyHeader1Word0 >> 16);
2457 BOOST_TEST(deviceRecordCount == 0);
2461 uint32_t header2Word0 =
ReadUint32(readBuffer2, 0);
2462 uint32_t header2Word1 =
ReadUint32(readBuffer2, 4);
2465 BOOST_TEST(((header2Word0 >> 26) & 0x0000003F) == 1);
2466 BOOST_TEST(((header2Word0 >> 16) & 0x000003FF) == 0);
2467 BOOST_TEST(header2Word1 == 443);
2474 const uint32_t familyId = 0;
2475 const uint32_t packetId = 3;
2476 const uint32_t version = 1;
2481 SendThread sendThread(profilingStateMachine, mockBuffer1, sendCounterPacket);
2485 sendCounterPacket, sendTimelinePacket, profilingStateMachine);
2486 const uint32_t header = (packetId & 0x000003FF) << 16;
2487 const arm::pipe::Packet packet(header);
2490 BOOST_CHECK(device !=
nullptr);
2492 BOOST_CHECK(counterSet !=
nullptr);
2495 "categoryA", 0, 1, 2.0f,
"counterA",
"descA");
2497 "categoryA", 1, 1, 3.0f,
"counterB",
"descB");
2506 BOOST_CHECK_NO_THROW(commandHandler(packet));
2510 const uint32_t header1Word0 =
ReadUint32(readBuffer1, 0);
2511 const uint32_t header1Word1 =
ReadUint32(readBuffer1, 4);
2513 BOOST_TEST(((header1Word0 >> 26) & 0x0000003F) == 0);
2514 BOOST_TEST(((header1Word0 >> 16) & 0x000003FF) == 2);
2515 BOOST_TEST(header1Word1 == 236);
2517 const uint32_t bodyHeaderSizeBytes = bodyHeaderSize *
sizeof(uint32_t);
2519 const uint32_t bodyHeader1Word0 =
ReadUint32(readBuffer1, 8);
2520 const uint32_t bodyHeader1Word1 =
ReadUint32(readBuffer1, 12);
2521 const uint32_t bodyHeader1Word2 =
ReadUint32(readBuffer1, 16);
2522 const uint32_t bodyHeader1Word3 =
ReadUint32(readBuffer1, 20);
2523 const uint32_t bodyHeader1Word4 =
ReadUint32(readBuffer1, 24);
2524 const uint32_t bodyHeader1Word5 =
ReadUint32(readBuffer1, 28);
2525 const uint16_t deviceRecordCount =
numeric_cast<uint16_t>(bodyHeader1Word0 >> 16);
2526 const uint16_t counterSetRecordCount =
numeric_cast<uint16_t>(bodyHeader1Word2 >> 16);
2527 const uint16_t categoryRecordCount =
numeric_cast<uint16_t>(bodyHeader1Word4 >> 16);
2528 BOOST_TEST(deviceRecordCount == 1);
2529 BOOST_TEST(bodyHeader1Word1 == 0 + bodyHeaderSizeBytes);
2530 BOOST_TEST(counterSetRecordCount == 1);
2531 BOOST_TEST(bodyHeader1Word3 == 4 + bodyHeaderSizeBytes);
2532 BOOST_TEST(categoryRecordCount == 1);
2533 BOOST_TEST(bodyHeader1Word5 == 8 + bodyHeaderSizeBytes);
2535 const uint32_t deviceRecordOffset =
ReadUint32(readBuffer1, 32);
2536 BOOST_TEST(deviceRecordOffset == 12);
2538 const uint32_t counterSetRecordOffset =
ReadUint32(readBuffer1, 36);
2539 BOOST_TEST(counterSetRecordOffset == 28);
2541 const uint32_t categoryRecordOffset =
ReadUint32(readBuffer1, 40);
2542 BOOST_TEST(categoryRecordOffset == 48);
2546 const uint32_t header2Word0 =
ReadUint32(readBuffer2, 0);
2547 const uint32_t header2Word1 =
ReadUint32(readBuffer2, 4);
2550 BOOST_TEST(((header2Word0 >> 26) & 0x0000003F) == 1);
2551 BOOST_TEST(((header2Word0 >> 16) & 0x000003FF) == 0);
2552 BOOST_TEST(header2Word1 == 443);
2560 armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
2561 options.m_EnableProfiling =
true;
2570 profilingService.
Update();
2572 profilingService.
Update();
2576 BOOST_CHECK(mockProfilingConnection);
2579 mockProfilingConnection->
Clear();
2582 profilingService.
Update();
2586 mockProfilingConnection, PacketType::StreamMetaData, streamMetadataPacketsize) >= 1);
2596 uint32_t packetFamily = 0;
2597 uint32_t packetId = 1;
2598 uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
2601 arm::pipe::Packet connectionAcknowledgedPacket(header);
2604 mockProfilingConnection->
WritePacket(std::move(connectionAcknowledgedPacket));
2607 BOOST_CHECK(helper.
WaitForPacketsSent(mockProfilingConnection, PacketType::CounterDirectory) == 1);
2613 options.m_EnableProfiling =
false;
2620 armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
2621 options.m_EnableProfiling =
true;
2630 profilingService.
Update();
2632 profilingService.
Update();
2634 profilingService.
Update();
2638 BOOST_CHECK(mockProfilingConnection);
2652 uint32_t packetFamily = 0;
2653 uint32_t packetId = 3;
2654 uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
2657 arm::pipe::Packet requestCounterDirectoryPacket(header);
2660 mockProfilingConnection->
WritePacket(std::move(requestCounterDirectoryPacket));
2664 BOOST_CHECK(helper.
WaitForPacketsSent(mockProfilingConnection, PacketType::CounterDirectory, 652) == 1);
2665 BOOST_CHECK(helper.
WaitForPacketsSent(mockProfilingConnection, PacketType::TimelineMessageDirectory, 451) == 1);
2671 options.m_EnableProfiling =
false;
2678 armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
2679 options.m_EnableProfiling =
true;
2688 profilingService.
Update();
2690 profilingService.
Update();
2692 profilingService.
Update();
2696 BOOST_CHECK(mockProfilingConnection);
2703 mockProfilingConnection->
Clear();
2713 uint32_t packetFamily = 0;
2714 uint32_t packetId = 4;
2715 uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
2717 uint32_t capturePeriod = 123456;
2722 BOOST_CHECK(counters.size() > 1);
2723 uint16_t counterUidA = counters.begin()->first;
2724 uint16_t counterUidB = 9999;
2726 uint32_t length = 8;
2728 auto data = std::make_unique<unsigned char[]>(length);
2735 arm::pipe::Packet periodicCounterSelectionPacket(header, length, data);
2739 mockProfilingConnection->
WritePacket(std::move(periodicCounterSelectionPacket));
2743 BOOST_CHECK(helper.
WaitForPacketsSent(mockProfilingConnection, PacketType::PeriodicCounterSelection, 14) == 1);
2744 BOOST_CHECK(helper.
WaitForPacketsSent(mockProfilingConnection, PacketType::PeriodicCounterCapture, 22) >= 1);
2750 options.m_EnableProfiling =
false;
2757 armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
2758 options.m_EnableProfiling =
true;
2767 profilingService.
Update();
2769 profilingService.
Update();
2771 profilingService.
Update();
2775 BOOST_CHECK(mockProfilingConnection);
2793 uint32_t packetFamily = 0;
2794 uint32_t packetId = 4;
2795 uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
2799 arm::pipe::Packet periodicCounterSelectionPacket(header);
2802 mockProfilingConnection->
WritePacket(std::move(periodicCounterSelectionPacket));
2806 BOOST_CHECK(helper.
WaitForPacketsSent(mockProfilingConnection, PacketType::PeriodicCounterSelection, 12) == 1);
2812 BOOST_CHECK(helper.
WaitForPacketsSent(mockProfilingConnection, PacketType::PeriodicCounterCapture, 0, 0) == 0);
2815 options.m_EnableProfiling =
false;
2822 armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
2823 options.m_EnableProfiling =
true;
2832 profilingService.
Update();
2834 profilingService.
Update();
2836 profilingService.
Update();
2840 BOOST_CHECK(mockProfilingConnection);
2858 uint32_t packetFamily = 0;
2859 uint32_t packetId = 4;
2860 uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
2862 uint32_t capturePeriod = 123456;
2867 BOOST_CHECK(!counters.empty());
2868 uint16_t counterUid = counters.begin()->first;
2870 uint32_t length = 6;
2872 auto data = std::make_unique<unsigned char[]>(length);
2878 arm::pipe::Packet periodicCounterSelectionPacket(header, length, data);
2881 mockProfilingConnection->
WritePacket(std::move(periodicCounterSelectionPacket));
2885 BOOST_CHECK(helper.
WaitForPacketsSent(mockProfilingConnection, PacketType::PeriodicCounterSelection, 14) == 1);
2886 BOOST_CHECK(helper.
WaitForPacketsSent(mockProfilingConnection, PacketType::PeriodicCounterCapture, 22) >= 1);
2892 options.m_EnableProfiling =
false;
2899 armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
2900 options.m_EnableProfiling =
true;
2909 profilingService.
Update();
2911 profilingService.
Update();
2913 profilingService.
Update();
2917 BOOST_CHECK(mockProfilingConnection);
2935 uint32_t packetFamily = 0;
2936 uint32_t packetId = 4;
2937 uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
2939 uint32_t capturePeriod = 123456;
2944 BOOST_CHECK(counters.size() > 1);
2945 uint16_t counterUidA = counters.begin()->first;
2946 uint16_t counterUidB = (counters.begin()++)->first;
2948 uint32_t length = 8;
2950 auto data = std::make_unique<unsigned char[]>(length);
2957 arm::pipe::Packet periodicCounterSelectionPacket(header, length, data);
2960 mockProfilingConnection->
WritePacket(std::move(periodicCounterSelectionPacket));
2964 BOOST_CHECK(helper.
WaitForPacketsSent(mockProfilingConnection, PacketType::PeriodicCounterSelection, 16) == 1);
2965 BOOST_CHECK(helper.
WaitForPacketsSent(mockProfilingConnection, PacketType::PeriodicCounterCapture, 28) >= 1);
2971 options.m_EnableProfiling =
false;
2978 armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
2979 options.m_EnableProfiling =
true;
2992 profilingService.
Update();
2998 profilingService.
Update();
3004 profilingService.
Update();
3008 BOOST_CHECK(mockProfilingConnection);
3019 BOOST_CHECK(mockProfilingConnection->
IsOpen());
3026 BOOST_CHECK(mockProfilingConnection ==
nullptr);
3029 options.m_EnableProfiling =
false;
3036 armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
3037 options.m_EnableProfiling =
true;
3046 profilingService.
Update();
3048 profilingService.
Update();
3050 profilingService.
Update();
3054 BOOST_CHECK(mockProfilingConnection);
3072 uint32_t packetFamily = 0;
3073 uint32_t packetId = 5;
3074 uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
3078 arm::pipe::Packet periodicCounterSelectionPacket(header);
3081 mockProfilingConnection->
WritePacket(std::move(periodicCounterSelectionPacket));
3085 std::this_thread::sleep_for(std::chrono::milliseconds(5));
3092 const auto StreamMetaDataSize =
static_cast<unsigned long>(
3093 helper.
WaitForPacketsSent(mockProfilingConnection, PacketType::StreamMetaData, 0, 0));
3097 options.m_EnableProfiling =
false;
3103 armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
3104 options.m_EnableProfiling =
true;
3111 options.m_EnableProfiling =
false;
3117 armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
3124 options.m_EnableProfiling =
false;
3132 armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
3133 options.m_EnableProfiling =
true;
3137 profilingService.
Update();
3141 std::stringstream ss;
3143 profilingService.
Update();
3146 options.m_EnableProfiling =
false;
3149 streamRedirector.CancelRedirect();
3152 if (ss.str().find(
"Cannot connect to stream socket: Connection refused") == std::string::npos)
3154 std::cout << ss.str();
3155 BOOST_FAIL(
"Expected string not found.");
3163 armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
3167 profilingService.
Update();
3169 options.m_EnableProfiling =
true;
3172 profilingService.
Update();
3176 std::stringstream ss;
3178 profilingService.
Update();
3181 options.m_EnableProfiling =
false;
3184 streamRedirector.CancelRedirect();
3187 if (ss.str().find(
"Cannot connect to stream socket: Connection refused") == std::string::npos)
3189 std::cout << ss.str();
3190 BOOST_FAIL(
"Expected string not found.");
3201 std::stringstream ss;
3205 armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
3206 options.m_EnableProfiling =
true;
3215 profilingService.
Update();
3217 profilingService.
Update();
3221 BOOST_CHECK(mockProfilingConnection);
3230 uint32_t packetFamily = 0;
3231 uint32_t packetId = 37;
3232 uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
3235 arm::pipe::Packet connectionAcknowledgedPacket(header);
3238 mockProfilingConnection->
WritePacket(std::move(connectionAcknowledgedPacket));
3241 profilingService.
Update();
3244 options.m_EnableProfiling =
false;
3247 streamRedirector.CancelRedirect();
3250 if (ss.str().find(
"Functor with requested PacketId=37 and Version=4194304 does not exist") == std::string::npos)
3252 std::cout << ss.str();
3253 BOOST_FAIL(
"Expected string not found.");
3263 std::stringstream ss;
3267 armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
3268 options.m_EnableProfiling =
true;
3279 profilingService.
Update();
3284 BOOST_CHECK(mockProfilingConnection);
3294 uint32_t packetFamily = 0;
3295 uint32_t packetId = 123;
3296 uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
3299 arm::pipe::Packet requestCounterDirectoryPacket(header);
3302 mockProfilingConnection->WritePacket(std::move(requestCounterDirectoryPacket));
3305 profilingService.
Update();
3308 options.m_EnableProfiling =
false;
3311 streamRedirector.CancelRedirect();
3314 if (ss.str().find(
"Functor with requested PacketId=123 and Version=4194304 does not exist") == std::string::npos)
3316 std::cout << ss.str();
3317 BOOST_FAIL(
"Expected string not found.");
3327 std::stringstream ss;
3331 armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
3332 options.m_EnableProfiling =
true;
3341 profilingService.
Update();
3343 profilingService.
Update();
3345 profilingService.
Update();
3349 BOOST_CHECK(mockProfilingConnection);
3359 uint32_t packetFamily = 0;
3360 uint32_t packetId = 999;
3361 uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
3365 arm::pipe::Packet periodicCounterSelectionPacket(header);
3368 mockProfilingConnection->
WritePacket(std::move(periodicCounterSelectionPacket));
3369 profilingService.
Update();
3372 options.m_EnableProfiling =
false;
3376 streamRedirector.CancelRedirect();
3379 if (ss.str().find(
"Functor with requested PacketId=999 and Version=4194304 does not exist") == std::string::npos)
3381 std::cout << ss.str();
3382 BOOST_FAIL(
"Expected string not found.");
3392 uint16_t globalCounterIds = 0;
3397 std::vector<uint16_t> cpuRefCounters = {0, 1, 2, 3};
3398 std::vector<uint16_t> cpuAccCounters = {0, 1};
3400 for (uint16_t backendCounterId : cpuRefCounters)
3402 counterIdMap.
RegisterMapping(globalCounterIds, backendCounterId, cpuRefId);
3405 for (uint16_t backendCounterId : cpuAccCounters)
3407 counterIdMap.
RegisterMapping(globalCounterIds, backendCounterId, cpuAccId);
3411 BOOST_CHECK(counterIdMap.
GetBackendId(0) == (std::pair<uint16_t, armnn::BackendId>(0, cpuRefId)));
3412 BOOST_CHECK(counterIdMap.
GetBackendId(1) == (std::pair<uint16_t, armnn::BackendId>(1, cpuRefId)));
3413 BOOST_CHECK(counterIdMap.
GetBackendId(2) == (std::pair<uint16_t, armnn::BackendId>(2, cpuRefId)));
3414 BOOST_CHECK(counterIdMap.
GetBackendId(3) == (std::pair<uint16_t, armnn::BackendId>(3, cpuRefId)));
3415 BOOST_CHECK(counterIdMap.
GetBackendId(4) == (std::pair<uint16_t, armnn::BackendId>(0, cpuAccId)));
3416 BOOST_CHECK(counterIdMap.
GetBackendId(5) == (std::pair<uint16_t, armnn::BackendId>(1, cpuAccId)));
3418 BOOST_CHECK(counterIdMap.
GetGlobalId(0, cpuRefId) == 0);
3419 BOOST_CHECK(counterIdMap.
GetGlobalId(1, cpuRefId) == 1);
3420 BOOST_CHECK(counterIdMap.
GetGlobalId(2, cpuRefId) == 2);
3421 BOOST_CHECK(counterIdMap.
GetGlobalId(3, cpuRefId) == 3);
3422 BOOST_CHECK(counterIdMap.
GetGlobalId(0, cpuAccId) == 4);
3423 BOOST_CHECK(counterIdMap.
GetGlobalId(1, cpuAccId) == 5);
3428 uint16_t globalCounterIds = armnn::profiling::INFERENCES_RUN;
3432 armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
3433 options.m_EnableProfiling =
true;
3444 BOOST_CHECK(categoryOnePtr);
3447 globalCounterIds = registerBackendCounters.
RegisterDevice(
"deviceOne");
3449 BOOST_CHECK(deviceOnePtr);
3450 BOOST_CHECK(deviceOnePtr->m_Name ==
"deviceOne");
3455 BOOST_CHECK(counterSetOnePtr);
3456 BOOST_CHECK(counterSetOnePtr->m_Name ==
"counterSetOne");
3458 uint16_t newGlobalCounterId = registerBackendCounters.
RegisterCounter(0,
3464 "first test counter");
3465 BOOST_CHECK(newGlobalCounterId = armnn::profiling::INFERENCES_RUN + 1);
3467 BOOST_CHECK(mappedGlobalId == newGlobalCounterId);
3469 BOOST_CHECK(backendMapping.first == 0);
3470 BOOST_CHECK(backendMapping.second == cpuRefId);
3473 options.m_EnableProfiling =
false;
3490 BackendProfiling backendProfilingCpuRef(options, profilingService, cpuRefId);
3491 BackendProfiling backendProfilingCpuAcc(options, profilingService, cpuAccId);
3493 uint16_t initialNumGlobalCounterIds = armnn::profiling::INFERENCES_RUN;
3496 RegisterBackendCounters registerBackendCountersCpuRef(initialNumGlobalCounterIds, cpuRefId, profilingService);
3502 BOOST_CHECK(categoryOnePtr);
3510 std::vector<uint16_t> cpuRefCounters = {0, 1};
3511 std::vector<uint16_t> cpuAccCounters = {0};
3514 uint16_t currentNumGlobalCounterIds = registerBackendCountersCpuRef.
RegisterCounter(
3515 0,
"testCategory", 0, 0, 1.f,
"CpuRefCounter0",
"Zeroth CpuRef Counter");
3516 BOOST_CHECK(currentNumGlobalCounterIds == initialNumGlobalCounterIds + 1);
3518 BOOST_CHECK(mappedGlobalId == currentNumGlobalCounterIds);
3520 BOOST_CHECK(backendMapping.first == 0);
3521 BOOST_CHECK(backendMapping.second == cpuRefId);
3523 currentNumGlobalCounterIds = registerBackendCountersCpuRef.
RegisterCounter(
3524 1,
"testCategory", 0, 0, 1.f,
"CpuRefCounter1",
"First CpuRef Counter");
3525 BOOST_CHECK(currentNumGlobalCounterIds == initialNumGlobalCounterIds + 2);
3527 BOOST_CHECK(mappedGlobalId == currentNumGlobalCounterIds);
3529 BOOST_CHECK(backendMapping.first == 1);
3530 BOOST_CHECK(backendMapping.second == cpuRefId);
3533 RegisterBackendCounters registerBackendCountersCpuAcc(currentNumGlobalCounterIds, cpuAccId, profilingService);
3536 currentNumGlobalCounterIds = registerBackendCountersCpuAcc.
RegisterCounter(
3537 0,
"testCategory", 0, 0, 1.f,
"CpuAccCounter0",
"Zeroth CpuAcc Counter");
3538 BOOST_CHECK(currentNumGlobalCounterIds == initialNumGlobalCounterIds + 3);
3540 BOOST_CHECK(mappedGlobalId == currentNumGlobalCounterIds);
3542 BOOST_CHECK(backendMapping.first == 0);
3543 BOOST_CHECK(backendMapping.second == cpuAccId);
3546 const std::vector<uint16_t> activeGlobalCounterIds = {5};
3547 const std::vector<uint16_t> newActiveGlobalCounterIds = {6, 7};
3549 const uint32_t capturePeriod = 200;
3550 const uint32_t newCapturePeriod = 100;
3553 profilingService.
SetCaptureData(capturePeriod, activeGlobalCounterIds, {});
3556 std::vector<CounterStatus> cpuRefCounterStatus = backendProfilingCpuRef.
GetActiveCounters();
3557 std::vector<CounterStatus> cpuAccCounterStatus = backendProfilingCpuAcc.
GetActiveCounters();
3558 BOOST_CHECK_EQUAL(cpuRefCounterStatus.size(), 1);
3559 BOOST_CHECK_EQUAL(cpuAccCounterStatus.size(), 0);
3562 BOOST_CHECK_EQUAL(cpuRefCounterStatus[0].m_GlobalCounterId, activeGlobalCounterIds[0]);
3563 BOOST_CHECK_EQUAL(cpuRefCounterStatus[0].m_BackendCounterId, cpuRefCounters[0]);
3564 BOOST_CHECK_EQUAL(cpuRefCounterStatus[0].m_SamplingRateInMicroseconds, capturePeriod);
3565 BOOST_CHECK_EQUAL(cpuRefCounterStatus[0].m_Enabled,
true);
3572 BOOST_CHECK_EQUAL(inactiveCpuRefCounter.
m_Enabled,
false);
3579 BOOST_CHECK_EQUAL(inactiveCpuAccCounter.
m_Enabled,
false);
3582 profilingService.
SetCaptureData(newCapturePeriod, newActiveGlobalCounterIds, {});
3587 BOOST_CHECK_EQUAL(cpuRefCounterStatus.size(), 1);
3588 BOOST_CHECK_EQUAL(cpuAccCounterStatus.size(), 1);
3591 BOOST_CHECK_EQUAL(cpuRefCounterStatus[0].m_GlobalCounterId, newActiveGlobalCounterIds[0]);
3592 BOOST_CHECK_EQUAL(cpuRefCounterStatus[0].m_BackendCounterId, cpuRefCounters[1]);
3593 BOOST_CHECK_EQUAL(cpuRefCounterStatus[0].m_SamplingRateInMicroseconds, newCapturePeriod);
3594 BOOST_CHECK_EQUAL(cpuRefCounterStatus[0].m_Enabled,
true);
3597 BOOST_CHECK_EQUAL(cpuAccCounterStatus[0].m_GlobalCounterId, newActiveGlobalCounterIds[1]);
3598 BOOST_CHECK_EQUAL(cpuAccCounterStatus[0].m_BackendCounterId, cpuAccCounters[0]);
3599 BOOST_CHECK_EQUAL(cpuAccCounterStatus[0].m_SamplingRateInMicroseconds, newCapturePeriod);
3600 BOOST_CHECK_EQUAL(cpuAccCounterStatus[0].m_Enabled,
true);
3603 inactiveCpuRefCounter = backendProfilingCpuRef.
GetCounterStatus(cpuRefCounters[0]);
3607 BOOST_CHECK_EQUAL(inactiveCpuRefCounter.
m_Enabled,
false);
3629 mockProfilingService,
3636 std::vector<armnn::profiling::Timestamp> timestamps;
3637 timestamps.push_back(timestamp);
3642 uint32_t headerWord0 =
ReadUint32(readBuffer, 0);
3643 uint32_t headerWord1 =
ReadUint32(readBuffer, 4);
3644 uint64_t readTimestamp =
ReadUint64(readBuffer, 8);
3646 BOOST_TEST(((headerWord0 >> 26) & 0x0000003F) == 3);
3647 BOOST_TEST(((headerWord0 >> 19) & 0x0000007F) == 0);
3648 BOOST_TEST(((headerWord0 >> 16) & 0x00000007) == 0);
3649 BOOST_TEST(headerWord1 == 20);
3650 BOOST_TEST(1000998 == readTimestamp);
3652 uint32_t offset = 16;
3654 uint16_t readIndex =
ReadUint16(readBuffer, offset);
3655 BOOST_TEST(6 == readIndex);
3659 uint32_t readValue =
ReadUint32(readBuffer, offset);
3660 BOOST_TEST(700 == readValue);
3665 BOOST_TEST(8 == readIndex);
3670 BOOST_TEST(93 == readValue);
3678 armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
3679 options.m_EnableProfiling =
true;
3681 BOOST_CHECK(options.m_FileFormat ==
"binary");
3684 options.m_FileFormat =
"json";
3689 profilingService.
Update();
3693 std::stringstream ss;
3698 profilingService.
Update();
3700 streamRedirector.CancelRedirect();
3703 if (ss.str().find(
"Unsupported profiling file format, only binary is supported") == std::string::npos)
3705 std::cout << ss.str();
3706 BOOST_FAIL(
"Expected string not found.");
BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
ProfilingState GetCurrentState() const
const Category * RegisterCategory(const std::string &categoryName) override
void ProfilingCurrentStateThreadImpl(ProfilingStateMachine &states)
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
void StringToSwTraceStringTestHelper(const std::string &testString, std::vector< uint32_t > buffer, size_t expectedSize)
uint32_t GetAbsoluteCounterValue(uint16_t counterUid) const override
uint16_t GetGlobalId(uint16_t backendCounterId, const armnn::BackendId &backendId) const override
std::vector< CounterStatus > GetActiveCounters() override
CPU Execution: Reference C++ kernels.
long WaitForPacketsSent(MockProfilingConnection *mockProfilingConnection, MockProfilingConnection::PacketType packetType, uint32_t length=0, uint32_t timeout=1000)
ProfilingState GetCurrentState() const
void Start(IProfilingConnection &profilingConnection)
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)
void ForceTransitionToState(ProfilingState newState)
uint32_t m_SamplingRateInMicroseconds
std::unordered_map< uint16_t, CounterPtr > Counters
virtual const Category * GetCategory(const std::string &name) const =0
uint16_t RegisterDevice(const std::string &deviceName, uint16_t cores=0, const Optional< std::string > &parentCategoryName=EmptyOptional()) override
uint32_t GetStreamMetaDataPacketSize()
void ForceTransitionToState(ProfilingState newState)
void ReportCounters(const std::vector< Timestamp > &) override
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) 2020 ARM Limited.
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
void CaptureDataReadThreadImpl(const Holder &holder, CaptureData &captureData)
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
CounterStatus GetCounterStatus(uint16_t backendCounterId) override
virtual const Devices & GetDevices() const =0
void MarkRead(IPacketBufferPtr &packetBuffer) override
void SetCapturePeriod(uint32_t capturePeriod)
uint32_t GetCapturePeriod() const
virtual const CounterSet * GetCounterSet(uint16_t uid) const =0
profiling::ProfilingService & GetProfilingService(armnn::Runtime *runtime)
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
uint16_t RegisterCounterSet(const std::string &counterSetName, uint16_t count=0, const Optional< std::string > &parentCategoryName=EmptyOptional()) override
IPacketBufferPtr GetReadableBuffer() 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
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
constexpr unsigned int LOWEST_CAPTURE_PERIOD
The lowest performance data capture interval we support is 10 miliseconds.
BOOST_AUTO_TEST_CASE(CheckConvolution2dLayer)
std::vector< CounterValue > counterValues
IPacketBufferPtr GetReadableBuffer() override
uint16_t RegisterCounter(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
uint16_t m_GlobalCounterId
uint32_t ReadUint32(const IPacketBufferPtr &packetBuffer, unsigned int offset)
MockProfilingConnection * GetMockProfilingConnection()
std::vector< uint16_t > m_Counters
void SetCounterValue(uint16_t counterUid, uint32_t value) override
const Counter * GetCounter(uint16_t uid) const override
BOOST_AUTO_TEST_SUITE_END()
void RegisterCategory(const std::string &categoryName) 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
void CaptureDataWriteThreadImpl(Holder &holder, uint32_t capturePeriod, const std::vector< uint16_t > &counterIds)
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.
BufferManager & GetProfilingBufferManager()
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
void SetStopAfterTimeout(bool stopAfterTimeout)
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
void RegisterMapping(uint16_t globalCounterId, uint16_t backendCounterId, const armnn::BackendId &backendId)
virtual uint16_t GetGlobalId(uint16_t backendCounterId, const armnn::BackendId &backendId) const =0