12 #include <common/include/SocketConnectionException.hpp> 14 #include <CounterDirectory.hpp> 39 #include <boost/algorithm/string.hpp> 40 #include <boost/numeric/conversion/cast.hpp> 85 BOOST_CHECK(testKey1 == testKey2 && testKey2 == testKey1);
86 BOOST_CHECK(testKey0 == testKey1 && testKey1 == testKey2 && testKey0 == testKey2);
96 std::sort(vect.begin(), vect.end());
142 SendThread sendThread(profilingStateMachine, mockBuffer, sendCounterPacket);
146 sendCounterPacket, sendTimelinePacket,
147 profilingStateMachine);
150 commandHandlerRegistry.
RegisterFunctor(&connectionAcknowledgedCommandHandler);
155 CommandHandler commandHandler0(1,
true, commandHandlerRegistry, packetVersionResolver);
159 commandHandler0.
Start(testProfilingConnectionBase);
161 commandHandler0.
Start(testProfilingConnectionBase);
164 for (
int i = 0; i < 10; i++)
170 std::this_thread::sleep_for(std::chrono::milliseconds(2));
176 commandHandler0.
Stop();
183 CommandHandler commandHandler1(1,
true, commandHandlerRegistry, packetVersionResolver);
185 commandHandler1.
Start(testProfilingConnectionTimeOutError);
187 for (
int i = 0; i < 10; i++)
193 std::this_thread::sleep_for(std::chrono::milliseconds(2));
198 uint32_t timeout = 50;
199 uint32_t timeSlept = 0;
202 if (timeSlept >= timeout)
204 BOOST_FAIL(
"Timeout: The command handler loop did not stop after the timeout");
206 std::this_thread::sleep_for(std::chrono::milliseconds(1));
210 commandHandler1.
Stop();
216 commandHandler1.
Start(testProfilingConnectionBadAckPacket);
217 commandHandler1.
Stop();
224 commandHandler1.
Start(testProfilingConnectionTimeOutError);
227 for (
int i = 0; i < 10; i++)
233 std::this_thread::sleep_for(std::chrono::milliseconds(2));
235 commandHandler1.
Stop();
241 CommandHandler commandHandler2(1,
false, commandHandlerRegistry, packetVersionResolver);
243 commandHandler2.Start(testProfilingConnectionArmnnError);
246 for (
int i = 0; i < 10; i++)
252 std::this_thread::sleep_for(std::chrono::milliseconds(2));
256 commandHandler2.Stop();
286 BOOST_CHECK(version5.GetEncodedValue() == 4194304);
292 std::unique_ptr<unsigned char[]> packetData0 = std::make_unique<unsigned char[]>(length);
293 std::unique_ptr<unsigned char[]> packetData1 = std::make_unique<unsigned char[]>(0);
294 std::unique_ptr<unsigned char[]> nullPacketData;
296 Packet packetTest0(472580096, length, packetData0);
306 BOOST_CHECK_NO_THROW(
Packet packetTest2(472580096, 0, nullPacketData));
308 Packet packetTest3(472580096, 0, nullPacketData);
312 const unsigned char* packetTest0Data = packetTest0.
GetData();
313 Packet packetTest4(std::move(packetTest0));
329 uint32_t version = 1;
340 std::map<CommandHandlerKey, CommandHandlerFunctor*> registry;
342 registry.insert(std::make_pair(keyB, &testFunctorB));
343 registry.insert(std::make_pair(keyA, &testFunctorA));
344 registry.insert(std::make_pair(keyC, &testFunctorC));
347 auto it = registry.begin();
354 std::unique_ptr<unsigned char[]> packetDataA;
355 std::unique_ptr<unsigned char[]> packetDataB;
356 std::unique_ptr<unsigned char[]> packetDataC;
358 Packet packetA(500000000, 0, packetDataA);
359 Packet packetB(600000000, 0, packetDataB);
360 Packet packetC(400000000, 0, packetDataC);
382 uint32_t version = 1;
396 std::unique_ptr<unsigned char[]> packetDataA;
397 std::unique_ptr<unsigned char[]> packetDataB;
398 std::unique_ptr<unsigned char[]> packetDataC;
400 Packet packetA(500000000, 0, packetDataA);
401 Packet packetB(600000000, 0, packetDataB);
402 Packet packetC(400000000, 0, packetDataC);
434 std::random_device device;
435 std::mt19937 generator(device());
436 std::uniform_int_distribution<uint32_t> distribution(std::numeric_limits<uint32_t>::min(),
437 std::numeric_limits<uint32_t>::max());
440 const Version expectedVersion(1, 0, 0);
444 constexpr
unsigned int numTests = 10u;
446 for (
unsigned int i = 0u; i < numTests; ++i)
448 const uint32_t familyId = distribution(generator);
449 const uint32_t packetId = distribution(generator);
452 BOOST_TEST(resolvedVersion == expectedVersion);
551 std::map<uint32_t, std::vector<uint16_t>> periodIdMap;
552 std::vector<uint16_t> counterIds;
553 uint32_t numThreads = 10;
554 for (uint32_t i = 0; i < numThreads; ++i)
556 counterIds.emplace_back(i);
557 periodIdMap.insert(std::make_pair(i, counterIds));
581 BOOST_CHECK(captureData.GetCounterIds() == periodIdMap[2]);
583 std::map<uint32_t, CaptureData> captureDataIdMap;
584 for (uint32_t i = 0; i < numThreads; ++i)
587 captureDataIdMap.insert(std::make_pair(i, perThreadCaptureData));
590 std::vector<std::thread> threadsVect;
591 std::vector<std::thread> readThreadsVect;
592 for (uint32_t i = 0; i < numThreads; ++i)
594 threadsVect.emplace_back(
598 BOOST_CHECK(captureDataIdMap.at(i).GetCapturePeriod() == 0);
599 BOOST_CHECK(captureDataIdMap.at(i).GetCounterIds().empty());
600 readThreadsVect.emplace_back(
604 for (uint32_t i = 0; i < numThreads; ++i)
606 threadsVect[i].join();
607 readThreadsVect[i].join();
612 for (uint32_t i = 0; i < numThreads; ++i)
614 CaptureData perThreadCaptureData = captureDataIdMap.at(i);
622 std::vector<uint16_t> counterIds = { 42, 29, 13 };
634 secondCaptureData = captureData;
635 BOOST_CHECK(secondCaptureData.GetCapturePeriod() == 150);
636 BOOST_CHECK(secondCaptureData.GetCounterIds() == counterIds);
639 CaptureData copyConstructedCaptureData(captureData);
641 BOOST_CHECK(copyConstructedCaptureData.GetCapturePeriod() == 150);
642 BOOST_CHECK(copyConstructedCaptureData.GetCounterIds() == counterIds);
647 armnn::Runtime::CreationOptions::ExternalProfilingOptions
options;
651 profilingService.
Update();
657 armnn::Runtime::CreationOptions::ExternalProfilingOptions
options;
663 profilingService.
Update();
666 options.m_EnableProfiling =
true;
671 profilingService.
Update();
674 options.m_EnableProfiling =
false;
680 armnn::Runtime::CreationOptions::ExternalProfilingOptions
options;
681 options.m_EnableProfiling =
true;
685 profilingService.
Update();
693 std::vector<std::thread> writers;
695 for (
int i = 0; i < 100; ++i)
700 armnn::profiling::REGISTERED_BACKENDS));
704 armnn::profiling::UNREGISTERED_BACKENDS));
709 armnn::profiling::INFERENCES_RUN,
713 armnn::profiling::INFERENCES_RUN,
716 std::for_each(writers.begin(), writers.end(), mem_fn(&std::thread::join));
718 uint32_t counterValue = 0;
720 (profilingService.
GetCounterValue(armnn::profiling::UNREGISTERED_BACKENDS)
721 - profilingService.
GetCounterValue(armnn::profiling::REGISTERED_BACKENDS)));
724 BOOST_CHECK_NO_THROW(profilingService.
SetCounterValue(armnn::profiling::UNREGISTERED_BACKENDS, 4));
725 BOOST_CHECK_NO_THROW(counterValue = profilingService.
GetCounterValue(armnn::profiling::UNREGISTERED_BACKENDS));
728 options.m_EnableProfiling =
false;
738 uint16_t nextUid = 0;
742 std::vector<uint16_t> counterUids;
746 std::vector<uint16_t> nextCounterUids;
751 std::vector<uint16_t> counterUidsMultiCore;
752 uint16_t thirdUid = 4;
753 uint16_t numberOfCores = 13;
754 BOOST_CHECK_NO_THROW(counterUidsMultiCore =
GetNextCounterUids(thirdUid, numberOfCores));
755 BOOST_CHECK(counterUidsMultiCore.size() == numberOfCores);
756 BOOST_CHECK(counterUidsMultiCore.front() >= nextCounterUids[0]);
757 for (
size_t i = 1; i < numberOfCores; i++)
759 BOOST_CHECK(counterUidsMultiCore[i] == counterUidsMultiCore[i - 1] + 1);
761 BOOST_CHECK(counterUidsMultiCore.back() == counterUidsMultiCore.front() + numberOfCores - 1);
773 const Category* noCategory =
nullptr;
779 BOOST_CHECK_THROW(noCategory = counterDirectory.
RegisterCategory(
"invalid category"),
785 const std::string categoryName =
"some_category";
787 BOOST_CHECK_NO_THROW(category = counterDirectory.
RegisterCategory(categoryName));
800 const Category* notRegisteredCategory = counterDirectory.
GetCategory(
"not_registered_category");
805 const Category* anotherCategory =
nullptr;
806 BOOST_CHECK_THROW(anotherCategory = counterDirectory.
RegisterCategory(categoryName),
812 const std::string deviceName =
"some_device";
813 const Device* device =
nullptr;
814 BOOST_CHECK_NO_THROW(device = counterDirectory.
RegisterDevice(deviceName));
822 const std::string categoryWoDeviceName =
"some_category_without_device";
823 const Category* categoryWoDevice =
nullptr;
824 BOOST_CHECK_NO_THROW(categoryWoDevice = counterDirectory.
RegisterCategory(categoryWoDeviceName));
831 const Category* categoryInvalidDeviceName =
nullptr;
832 BOOST_CHECK_THROW(categoryInvalidDeviceName =
839 const std::string categoryWValidDeviceName =
"some_category_with_valid_device";
840 const Category* categoryWValidDevice =
nullptr;
841 BOOST_CHECK_NO_THROW(categoryWValidDevice =
849 const std::string counterSetName =
"some_counter_set";
851 BOOST_CHECK_NO_THROW(counterSet = counterDirectory.
RegisterCounterSet(counterSetName));
859 const std::string categoryWoCounterSetName =
"some_category_without_counter_set";
860 const Category* categoryWoCounterSet =
nullptr;
861 BOOST_CHECK_NO_THROW(categoryWoCounterSet =
868 const std::string categoryWValidCounterSetName =
"some_category_with_valid_counter_set";
869 const Category* categoryWValidCounterSet =
nullptr;
870 BOOST_CHECK_NO_THROW(categoryWValidCounterSet = counterDirectory.
RegisterCategory(categoryWValidCounterSetName));
877 const std::string categoryWValidDeviceAndValidCounterSetName =
"some_category_with_valid_device_and_counter_set";
878 const Category* categoryWValidDeviceAndValidCounterSet =
nullptr;
879 BOOST_CHECK_NO_THROW(categoryWValidDeviceAndValidCounterSet = counterDirectory.
RegisterCategory(
880 categoryWValidDeviceAndValidCounterSetName));
882 BOOST_CHECK(categoryWValidDeviceAndValidCounterSet);
883 BOOST_CHECK(categoryWValidDeviceAndValidCounterSet != category);
884 BOOST_CHECK(categoryWValidDeviceAndValidCounterSet->
m_Name == categoryWValidDeviceAndValidCounterSetName);
896 const Device* noDevice =
nullptr;
907 const std::string deviceName =
"some_device";
908 const Device* device =
nullptr;
909 BOOST_CHECK_NO_THROW(device = counterDirectory.
RegisterDevice(deviceName));
927 const Device* deviceSameName =
nullptr;
933 const std::string deviceWCoresName =
"some_device_with_cores";
934 const Device* deviceWCores =
nullptr;
935 BOOST_CHECK_NO_THROW(deviceWCores = counterDirectory.
RegisterDevice(deviceWCoresName, 2));
947 BOOST_CHECK(registeredDeviceWCores == deviceWCores);
951 const std::string deviceWCoresWInvalidParentCategoryName =
"some_device_with_cores_with_invalid_parent_category";
952 const Device* deviceWCoresWInvalidParentCategory =
nullptr;
953 BOOST_CHECK_THROW(deviceWCoresWInvalidParentCategory =
954 counterDirectory.
RegisterDevice(deviceWCoresWInvalidParentCategoryName, 3, std::string(
"")),
960 const std::string deviceWCoresWInvalidParentCategoryName2 =
"some_device_with_cores_with_invalid_parent_category2";
961 const Device* deviceWCoresWInvalidParentCategory2 =
nullptr;
962 BOOST_CHECK_THROW(deviceWCoresWInvalidParentCategory2 = counterDirectory.
RegisterDevice(
963 deviceWCoresWInvalidParentCategoryName2, 3, std::string(
"invalid_parent_category")),
969 const std::string categoryName =
"some_category";
971 BOOST_CHECK_NO_THROW(category = counterDirectory.
RegisterCategory(categoryName));
978 const std::string deviceWCoresWValidParentCategoryName =
"some_device_with_cores_with_valid_parent_category";
979 const Device* deviceWCoresWValidParentCategory =
nullptr;
980 BOOST_CHECK_NO_THROW(deviceWCoresWValidParentCategory =
981 counterDirectory.
RegisterDevice(deviceWCoresWValidParentCategoryName, 4, categoryName));
984 BOOST_CHECK(deviceWCoresWValidParentCategory->
m_Name == deviceWCoresWValidParentCategoryName);
1006 BOOST_CHECK_THROW(noCounterSet = counterDirectory.
RegisterCounterSet(
"invalid name"),
1012 const std::string counterSetName =
"some_counter_set";
1014 BOOST_CHECK_NO_THROW(counterSet = counterDirectory.
RegisterCounterSet(counterSetName));
1032 const CounterSet* counterSetSameName =
nullptr;
1033 BOOST_CHECK_THROW(counterSetSameName = counterDirectory.
RegisterCounterSet(counterSetName),
1039 const std::string counterSetWCountName =
"some_counter_set_with_count";
1040 const CounterSet* counterSetWCount =
nullptr;
1041 BOOST_CHECK_NO_THROW(counterSetWCount = counterDirectory.
RegisterCounterSet(counterSetWCountName, 37));
1053 BOOST_CHECK(registeredCounterSetWCount == counterSetWCount);
1054 BOOST_CHECK(registeredCounterSetWCount != counterSet);
1057 const std::string counterSetWCountWInvalidParentCategoryName =
"some_counter_set_with_count_" 1058 "with_invalid_parent_category";
1059 const CounterSet* counterSetWCountWInvalidParentCategory =
nullptr;
1060 BOOST_CHECK_THROW(counterSetWCountWInvalidParentCategory = counterDirectory.
RegisterCounterSet(
1061 counterSetWCountWInvalidParentCategoryName, 42, std::string(
"")),
1064 BOOST_CHECK(!counterSetWCountWInvalidParentCategory);
1067 const std::string counterSetWCountWInvalidParentCategoryName2 =
"some_counter_set_with_count_" 1068 "with_invalid_parent_category2";
1069 const CounterSet* counterSetWCountWInvalidParentCategory2 =
nullptr;
1070 BOOST_CHECK_THROW(counterSetWCountWInvalidParentCategory2 = counterDirectory.
RegisterCounterSet(
1071 counterSetWCountWInvalidParentCategoryName2, 42, std::string(
"invalid_parent_category")),
1074 BOOST_CHECK(!counterSetWCountWInvalidParentCategory2);
1077 const std::string categoryName =
"some_category";
1078 const Category* category =
nullptr;
1079 BOOST_CHECK_NO_THROW(category = counterDirectory.
RegisterCategory(categoryName));
1086 const std::string counterSetWCountWValidParentCategoryName =
"some_counter_set_with_count_" 1087 "with_valid_parent_category";
1088 const CounterSet* counterSetWCountWValidParentCategory =
nullptr;
1089 BOOST_CHECK_NO_THROW(counterSetWCountWValidParentCategory = counterDirectory.
RegisterCounterSet(
1090 counterSetWCountWValidParentCategoryName, 42, categoryName));
1092 BOOST_CHECK(counterSetWCountWValidParentCategory);
1093 BOOST_CHECK(counterSetWCountWValidParentCategory->
m_Name == counterSetWCountWValidParentCategoryName);
1100 const std::string counterSetSameCategoryName =
"some_counter_set_with_invalid_parent_category";
1101 const std::string invalidCategoryName =
"";
1102 const CounterSet* counterSetSameCategory =
nullptr;
1103 BOOST_CHECK_THROW(counterSetSameCategory =
1104 counterDirectory.
RegisterCounterSet(counterSetSameCategoryName, 0, invalidCategoryName),
1119 const Counter* noCounter =
nullptr;
1120 BOOST_CHECK_THROW(noCounter =
1134 BOOST_CHECK_THROW(noCounter = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1136 "invalid parent category",
1141 "valid description"),
1147 BOOST_CHECK_THROW(noCounter = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1149 "valid_parent_category",
1155 "valid description"),
1161 BOOST_CHECK_THROW(noCounter = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1163 "valid_parent_category",
1169 "valid description"),
1175 BOOST_CHECK_THROW(noCounter = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1177 "valid_parent_category",
1183 "valid description"),
1190 noCounter = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1192 "valid_parent_category",
1197 "valid description"),
1203 BOOST_CHECK_THROW(noCounter = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1205 "valid_parent_category",
1210 "valid description"),
1216 BOOST_CHECK_THROW(noCounter =
1219 "valid_parent_category",
1230 BOOST_CHECK_THROW(noCounter = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1232 "valid_parent_category",
1238 "inv@lid description"),
1244 BOOST_CHECK_THROW(noCounter = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1246 "valid_parent_category",
1251 "valid description",
1252 std::string(
"Mb/s2")),
1258 BOOST_CHECK_THROW(noCounter = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1260 "invalid_parent_category",
1265 "valid description"),
1275 const std::string categoryName =
"some_category";
1276 const Category* category =
nullptr;
1277 BOOST_CHECK_NO_THROW(category = counterDirectory.
RegisterCategory(categoryName));
1284 const Counter* counter =
nullptr;
1285 BOOST_CHECK_NO_THROW(
1286 counter = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1293 "valid description"));
1296 BOOST_CHECK(counter->m_MaxCounterUid == counter->m_Uid);
1301 BOOST_CHECK(counter->m_Description ==
"valid description");
1309 const Counter* counterSameName =
nullptr;
1310 BOOST_CHECK_THROW(counterSameName =
1318 "valid description",
1319 std::string(
"description")),
1325 const Counter* counterWUnits =
nullptr;
1326 BOOST_CHECK_NO_THROW(counterWUnits = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1333 "valid description",
1334 std::string(
"Mnnsq2")));
1351 const Counter* counterWoDevice =
nullptr;
1352 BOOST_CHECK_NO_THROW(counterWoDevice = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1359 "valid description",
1365 BOOST_CHECK(counterWoDevice->m_Uid > counter->m_Uid);
1366 BOOST_CHECK(counterWoDevice->m_MaxCounterUid == counterWoDevice->m_Uid);
1368 BOOST_CHECK(counterWoDevice->m_Interpolation == 1);
1369 BOOST_CHECK(counterWoDevice->m_Multiplier == 123.45f);
1370 BOOST_CHECK(counterWoDevice->m_Name ==
"valid name 3");
1371 BOOST_CHECK(counterWoDevice->m_Description ==
"valid description");
1374 BOOST_CHECK(counterWoDevice->m_CounterSetUid == 0);
1379 BOOST_CHECK_THROW(noCounter = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1386 "valid description",
1395 const std::string deviceName =
"some_device";
1396 const Device* device =
nullptr;
1397 BOOST_CHECK_NO_THROW(device = counterDirectory.
RegisterDevice(deviceName));
1405 const Counter* counterWDevice =
nullptr;
1406 BOOST_CHECK_NO_THROW(counterWDevice = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1413 std::string(
"valid description"),
1433 const Counter* counterWoCounterSet =
nullptr;
1434 BOOST_CHECK_NO_THROW(counterWoCounterSet = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1441 "valid description",
1448 BOOST_CHECK(counterWoCounterSet->m_Uid > counter->m_Uid);
1449 BOOST_CHECK(counterWoCounterSet->m_MaxCounterUid == counterWoCounterSet->m_Uid);
1451 BOOST_CHECK(counterWoCounterSet->m_Interpolation == 1);
1452 BOOST_CHECK(counterWoCounterSet->m_Multiplier == 123.45f);
1453 BOOST_CHECK(counterWoCounterSet->m_Name ==
"valid name 6");
1454 BOOST_CHECK(counterWoCounterSet->m_Description ==
"valid description");
1456 BOOST_CHECK(counterWoCounterSet->m_DeviceUid == 0);
1457 BOOST_CHECK(counterWoCounterSet->m_CounterSetUid == 0);
1462 BOOST_CHECK_THROW(noCounter = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID,
1470 std::string(
"valid description"),
1479 const Counter* counterWNumberOfCores =
nullptr;
1480 uint16_t numberOfCores = 15;
1481 BOOST_CHECK_NO_THROW(counterWNumberOfCores = counterDirectory.
RegisterCounter(
1482 armnn::profiling::BACKEND_ID, 50,
1483 categoryName, 0, 1, 123.45f,
"valid name 8",
"valid description",
1501 for (
size_t i = 0; i < numberOfCores; i++)
1504 counterWNumberOfCores->
m_Uid + i);
1508 const std::string multiCoreDeviceName =
"some_multi_core_device";
1509 const Device* multiCoreDevice =
nullptr;
1510 BOOST_CHECK_NO_THROW(multiCoreDevice = counterDirectory.
RegisterDevice(multiCoreDeviceName, 4));
1518 const Counter* counterWMultiCoreDevice =
nullptr;
1519 BOOST_CHECK_NO_THROW(counterWMultiCoreDevice = counterDirectory.
RegisterCounter(
1520 armnn::profiling::BACKEND_ID, 19, categoryName, 0, 1,
1521 123.45f,
"valid name 9",
"valid description",
1524 multiCoreDevice->
m_Uid,
1530 counterWMultiCoreDevice->
m_Uid + multiCoreDevice->
m_Cores - 1);
1540 for (
size_t i = 0; i < 4; i++)
1546 const std::string multiCoreDeviceNameWParentCategory =
"some_multi_core_device_with_parent_category";
1547 const Device* multiCoreDeviceWParentCategory =
nullptr;
1548 BOOST_CHECK_NO_THROW(multiCoreDeviceWParentCategory =
1549 counterDirectory.
RegisterDevice(multiCoreDeviceNameWParentCategory, 2, categoryName));
1552 BOOST_CHECK(multiCoreDeviceWParentCategory->
m_Name == multiCoreDeviceNameWParentCategory);
1558 const Counter* counterWMultiCoreDeviceWParentCategory =
nullptr;
1559 uint16_t numberOfCourse = multiCoreDeviceWParentCategory->
m_Cores;
1560 BOOST_CHECK_NO_THROW(counterWMultiCoreDeviceWParentCategory =
1568 "valid description",
1574 BOOST_CHECK(counterWMultiCoreDeviceWParentCategory);
1575 BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->
m_Uid > counter->m_Uid);
1577 counterWMultiCoreDeviceWParentCategory->
m_Uid + multiCoreDeviceWParentCategory->
m_Cores - 1);
1585 for (
size_t i = 0; i < 2; i++)
1588 counterWMultiCoreDeviceWParentCategory->
m_Uid + i);
1592 const std::string counterSetName =
"some_counter_set";
1594 BOOST_CHECK_NO_THROW(counterSet = counterDirectory.
RegisterCounterSet(counterSetName));
1602 const Counter* counterWCounterSet =
nullptr;
1603 BOOST_CHECK_NO_THROW(counterWCounterSet = counterDirectory.
RegisterCounter(
1604 armnn::profiling::BACKEND_ID, 300,
1605 categoryName, 0, 1, 123.45f,
"valid name 11",
"valid description",
1609 counterSet->
m_Uid));
1626 const Counter* counterWDeviceWCounterSet =
nullptr;
1627 BOOST_CHECK_NO_THROW(counterWDeviceWCounterSet = counterDirectory.
RegisterCounter(
1628 armnn::profiling::BACKEND_ID, 23,
1629 categoryName, 0, 1, 123.45f,
"valid name 12",
"valid description",
1633 counterSet->
m_Uid));
1636 BOOST_CHECK(counterWDeviceWCounterSet->m_Uid > counter->m_Uid);
1637 BOOST_CHECK(counterWDeviceWCounterSet->m_MaxCounterUid == counterWDeviceWCounterSet->m_Uid);
1638 BOOST_CHECK(counterWDeviceWCounterSet->m_Class == 0);
1639 BOOST_CHECK(counterWDeviceWCounterSet->m_Interpolation == 1);
1640 BOOST_CHECK(counterWDeviceWCounterSet->m_Multiplier == 123.45f);
1641 BOOST_CHECK(counterWDeviceWCounterSet->m_Name ==
"valid name 12");
1642 BOOST_CHECK(counterWDeviceWCounterSet->m_Description ==
"valid description");
1643 BOOST_CHECK(counterWDeviceWCounterSet->m_Units ==
"");
1645 BOOST_CHECK(counterWDeviceWCounterSet->m_CounterSetUid == counterSet->
m_Uid);
1650 const std::string anotherCategoryName =
"some_other_category";
1651 const Category* anotherCategory =
nullptr;
1652 BOOST_CHECK_NO_THROW(anotherCategory = counterDirectory.
RegisterCategory(anotherCategoryName));
1660 const Counter* anotherCounter =
nullptr;
1661 BOOST_CHECK_NO_THROW(anotherCounter = counterDirectory.
RegisterCounter(armnn::profiling::BACKEND_ID, 24,
1662 anotherCategoryName, 1, 0, .00043f,
1663 "valid name",
"valid description",
1667 counterSet->
m_Uid));
1670 BOOST_CHECK(anotherCounter->m_MaxCounterUid == anotherCounter->m_Uid);
1672 BOOST_CHECK(anotherCounter->m_Interpolation == 0);
1673 BOOST_CHECK(anotherCounter->m_Multiplier == .00043f);
1674 BOOST_CHECK(anotherCounter->m_Name ==
"valid name");
1675 BOOST_CHECK(anotherCounter->m_Description ==
"valid description");
1691 void Start()
override 1693 void Stop()
override 1699 bool IsCounterRegistered(uint16_t counterUid)
const override 1704 uint16_t GetCounterCount()
const override 1708 uint32_t GetCounterValue(uint16_t counterUid)
const override 1714 const uint32_t familyId = 0;
1715 const uint32_t packetId = 0x40000;
1717 uint32_t version = 1;
1719 std::shared_ptr<armnn::profiling::IBackendProfilingContext>> backendProfilingContext;
1722 TestCaptureThread captureThread;
1723 TestReadCounterValues readCounterValues;
1726 SendThread sendThread(profilingStateMachine, mockBuffer, sendCounterPacket);
1728 uint32_t sizeOfUint32 =
numeric_cast<uint32_t>(
sizeof(uint32_t));
1729 uint32_t sizeOfUint16 =
numeric_cast<uint32_t>(
sizeof(uint16_t));
1733 uint32_t dataLength1 = 8;
1734 uint32_t offset = 0;
1736 std::unique_ptr<unsigned char[]> uniqueData1 = std::make_unique<unsigned char[]>(dataLength1);
1737 unsigned char* data1 =
reinterpret_cast<unsigned char*
>(uniqueData1.get());
1740 offset += sizeOfUint32;
1742 offset += sizeOfUint16;
1745 Packet packetA(packetId, dataLength1, uniqueData1);
1748 counterIdMap, holder, 10000u, captureThread,
1749 readCounterValues, sendCounterPacket, profilingStateMachine);
1758 BOOST_CHECK_NO_THROW(commandHandler(packetA));
1763 BOOST_TEST(counterIdsA.size() == 2);
1764 BOOST_TEST(counterIdsA[0] == 4000);
1765 BOOST_TEST(counterIdsA[1] == 5000);
1771 uint32_t headerWord0 =
ReadUint32(readBuffer, offset);
1772 offset += sizeOfUint32;
1773 uint32_t headerWord1 =
ReadUint32(readBuffer, offset);
1774 offset += sizeOfUint32;
1775 uint32_t period =
ReadUint32(readBuffer, offset);
1777 BOOST_TEST(((headerWord0 >> 26) & 0x3F) == 0);
1778 BOOST_TEST(((headerWord0 >> 16) & 0x3FF) == 4);
1779 BOOST_TEST(headerWord1 == 8);
1782 uint16_t counterId = 0;
1783 offset += sizeOfUint32;
1785 BOOST_TEST(counterId == 4000);
1786 offset += sizeOfUint16;
1788 BOOST_TEST(counterId == 5000);
1793 uint32_t period2 = 9000;
1794 uint32_t dataLength2 = 4;
1796 std::unique_ptr<unsigned char[]> uniqueData2 = std::make_unique<unsigned char[]>(dataLength2);
1798 WriteUint32(reinterpret_cast<unsigned char*>(uniqueData2.get()), 0, period2);
1800 Packet packetB(packetId, dataLength2, uniqueData2);
1802 commandHandler(packetB);
1808 BOOST_TEST(counterIdsB.size() == 0);
1814 headerWord0 =
ReadUint32(readBuffer, offset);
1815 offset += sizeOfUint32;
1816 headerWord1 =
ReadUint32(readBuffer, offset);
1817 offset += sizeOfUint32;
1820 BOOST_TEST(((headerWord0 >> 26) & 0x3F) == 0);
1821 BOOST_TEST(((headerWord0 >> 16) & 0x3FF) == 4);
1822 BOOST_TEST(headerWord1 == 4);
1830 const uint32_t packetFamilyId = 0;
1831 const uint32_t connectionPacketId = 0x10000;
1832 const uint32_t version = 1;
1834 uint32_t sizeOfUint32 =
numeric_cast<uint32_t>(
sizeof(uint32_t));
1835 uint32_t sizeOfUint16 =
numeric_cast<uint32_t>(
sizeof(uint16_t));
1838 uint32_t period1 = 10;
1839 uint32_t dataLength1 = 8;
1840 uint32_t offset = 0;
1842 std::unique_ptr<unsigned char[]> uniqueData1 = std::make_unique<unsigned char[]>(dataLength1);
1843 unsigned char* data1 =
reinterpret_cast<unsigned char*
>(uniqueData1.get());
1846 offset += sizeOfUint32;
1848 offset += sizeOfUint16;
1851 Packet packetA(connectionPacketId, dataLength1, uniqueData1);
1858 SendThread sendThread(profilingState, mockBuffer, sendCounterPacket);
1862 sendCounterPacket, sendTimelinePacket, profilingState);
1875 BOOST_CHECK_NO_THROW(commandHandler(packetA));
1879 BOOST_CHECK_NO_THROW(commandHandler(packetA));
1883 const uint32_t differentPacketId = 0x40000;
1884 Packet packetB(differentPacketId, dataLength1, uniqueData1);
1888 counterDirectory, sendCounterPacket,
1889 sendTimelinePacket, profilingState);
1905 catch (armnnProfiling::SocketConnectionException& ex)
1910 == std::string(
"SocketProfilingConnection: Cannot connect to stream socket: Connection refused"));
1917 for (
unsigned char c = 0; c < 128; c++)
1923 for (
unsigned char c = 255; c >= 128; c++)
1932 const unsigned char validChars[] =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_";
1933 for (
unsigned char i = 0; i <
sizeof(validChars) /
sizeof(validChars[0]) - 1; i++)
1939 for (
unsigned char c = 0; c < 48; c++)
1943 for (
unsigned char c = 58; c < 65; c++)
1947 for (
unsigned char c = 91; c < 95; c++)
1951 for (
unsigned char c = 96; c < 97; c++)
1955 for (
unsigned char c = 123; c < 128; c++)
1961 for (
unsigned char c = 255; c >= 128; c++)
1970 BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>(
""));
1971 BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>(
"_"));
1972 BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>(
"0123"));
1973 BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>(
"valid_string"));
1974 BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>(
"VALID_string_456"));
1975 BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>(
" "));
1976 BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>(
"valid string"));
1977 BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>(
"!$%"));
1978 BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>(
"valid|\\~string#123"));
1981 BOOST_CHECK(!IsValidSwTraceString<SwTraceCharPolicy>(
"€£"));
1982 BOOST_CHECK(!IsValidSwTraceString<SwTraceCharPolicy>(
"invalid‡string"));
1983 BOOST_CHECK(!IsValidSwTraceString<SwTraceCharPolicy>(
"12Ž34"));
1989 BOOST_CHECK(IsValidSwTraceString<SwTraceNameCharPolicy>(
""));
1990 BOOST_CHECK(IsValidSwTraceString<SwTraceNameCharPolicy>(
"_"));
1991 BOOST_CHECK(IsValidSwTraceString<SwTraceNameCharPolicy>(
"0123"));
1992 BOOST_CHECK(IsValidSwTraceString<SwTraceNameCharPolicy>(
"valid_string"));
1993 BOOST_CHECK(IsValidSwTraceString<SwTraceNameCharPolicy>(
"VALID_string_456"));
1996 BOOST_CHECK(!IsValidSwTraceString<SwTraceNameCharPolicy>(
" "));
1997 BOOST_CHECK(!IsValidSwTraceString<SwTraceNameCharPolicy>(
"invalid string"));
1998 BOOST_CHECK(!IsValidSwTraceString<SwTraceNameCharPolicy>(
"!$%"));
1999 BOOST_CHECK(!IsValidSwTraceString<SwTraceNameCharPolicy>(
"invalid|\\~string#123"));
2000 BOOST_CHECK(!IsValidSwTraceString<SwTraceNameCharPolicy>(
"€£"));
2001 BOOST_CHECK(!IsValidSwTraceString<SwTraceNameCharPolicy>(
"invalid‡string"));
2002 BOOST_CHECK(!IsValidSwTraceString<SwTraceNameCharPolicy>(
"12Ž34"));
2005 template <
typename SwTracePolicy>
2009 BOOST_CHECK(StringToSwTraceString<SwTracePolicy>(testString, buffer));
2021 BOOST_CHECK(std::memcmp(testString.data(), buffer.data() + 1, testString.size()) == 0);
2024 size_t nullTerminatorIndex =
sizeof(uint32_t) + testString.size();
2025 BOOST_CHECK(reinterpret_cast<unsigned char*>(buffer.data())[nullTerminatorIndex] ==
'\0');
2030 std::vector<uint32_t> buffer;
2033 StringToSwTraceStringTestHelper<SwTraceCharPolicy>(
"", buffer, 2);
2034 StringToSwTraceStringTestHelper<SwTraceCharPolicy>(
"_", buffer, 2);
2035 StringToSwTraceStringTestHelper<SwTraceCharPolicy>(
"0123", buffer, 3);
2036 StringToSwTraceStringTestHelper<SwTraceCharPolicy>(
"valid_string", buffer, 5);
2037 StringToSwTraceStringTestHelper<SwTraceCharPolicy>(
"VALID_string_456", buffer, 6);
2038 StringToSwTraceStringTestHelper<SwTraceCharPolicy>(
" ", buffer, 2);
2039 StringToSwTraceStringTestHelper<SwTraceCharPolicy>(
"valid string", buffer, 5);
2040 StringToSwTraceStringTestHelper<SwTraceCharPolicy>(
"!$%", buffer, 2);
2041 StringToSwTraceStringTestHelper<SwTraceCharPolicy>(
"valid|\\~string#123", buffer, 6);
2044 BOOST_CHECK(!StringToSwTraceString<SwTraceCharPolicy>(
"€£", buffer));
2046 BOOST_CHECK(!StringToSwTraceString<SwTraceCharPolicy>(
"invalid‡string", buffer));
2048 BOOST_CHECK(!StringToSwTraceString<SwTraceCharPolicy>(
"12Ž34", buffer));
2054 std::vector<uint32_t> buffer;
2057 StringToSwTraceStringTestHelper<SwTraceNameCharPolicy>(
"", buffer, 2);
2058 StringToSwTraceStringTestHelper<SwTraceNameCharPolicy>(
"_", buffer, 2);
2059 StringToSwTraceStringTestHelper<SwTraceNameCharPolicy>(
"0123", buffer, 3);
2060 StringToSwTraceStringTestHelper<SwTraceNameCharPolicy>(
"valid_string", buffer, 5);
2061 StringToSwTraceStringTestHelper<SwTraceNameCharPolicy>(
"VALID_string_456", buffer, 6);
2064 BOOST_CHECK(!StringToSwTraceString<SwTraceNameCharPolicy>(
" ", buffer));
2066 BOOST_CHECK(!StringToSwTraceString<SwTraceNameCharPolicy>(
"invalid string", buffer));
2068 BOOST_CHECK(!StringToSwTraceString<SwTraceNameCharPolicy>(
"!$%", buffer));
2070 BOOST_CHECK(!StringToSwTraceString<SwTraceNameCharPolicy>(
"invalid|\\~string#123", buffer));
2072 BOOST_CHECK(!StringToSwTraceString<SwTraceNameCharPolicy>(
"€£", buffer));
2074 BOOST_CHECK(!StringToSwTraceString<SwTraceNameCharPolicy>(
"invalid‡string", buffer));
2076 BOOST_CHECK(!StringToSwTraceString<SwTraceNameCharPolicy>(
"12Ž34", buffer));
2085 CaptureReader(uint16_t counterSize)
2087 for (uint16_t i = 0; i < counterSize; ++i)
2091 m_CounterSize = counterSize;
2094 bool IsCounterRegistered(uint16_t counterUid)
const override 2100 uint16_t GetCounterCount()
const override 2102 return m_CounterSize;
2105 uint32_t GetCounterValue(uint16_t counterUid)
const override 2107 if (counterUid > m_CounterSize)
2109 BOOST_FAIL(
"Invalid counter Uid");
2111 return m_Data.at(counterUid).load();
2114 void SetCounterValue(uint16_t counterUid, uint32_t value)
2116 if (counterUid > m_CounterSize)
2118 BOOST_FAIL(
"Invalid counter Uid");
2120 m_Data.at(counterUid).store(value);
2124 std::unordered_map<uint16_t, std::atomic<uint32_t>> m_Data;
2125 uint16_t m_CounterSize;
2131 std::shared_ptr<armnn::profiling::IBackendProfilingContext>> backendProfilingContext;
2134 std::vector<uint16_t> captureIds1 = { 0, 1 };
2135 std::vector<uint16_t> captureIds2;
2139 SendThread sendThread(profilingStateMachine, mockBuffer, sendCounterPacket);
2141 std::vector<uint16_t> counterIds;
2142 CaptureReader captureReader(2);
2144 unsigned int valueA = 10;
2145 unsigned int valueB = 15;
2146 unsigned int numSteps = 5;
2148 PeriodicCounterCapture periodicCounterCapture(std::ref(data), std::ref(sendCounterPacket), captureReader,
2149 counterIdMap, backendProfilingContext);
2151 for (
unsigned int i = 0; i < numSteps; ++i)
2154 captureReader.SetCounterValue(0, valueA * (i + 1));
2155 captureReader.SetCounterValue(1, valueB * (i + 1));
2157 periodicCounterCapture.
Start();
2158 periodicCounterCapture.
Stop();
2163 uint32_t headerWord0 =
ReadUint32(buffer, 0);
2164 uint32_t headerWord1 =
ReadUint32(buffer, 4);
2166 BOOST_TEST(((headerWord0 >> 26) & 0x0000003F) == 3);
2167 BOOST_TEST(((headerWord0 >> 19) & 0x0000007F) == 0);
2168 BOOST_TEST(((headerWord0 >> 16) & 0x00000007) == 0);
2169 BOOST_TEST(headerWord1 == 20);
2171 uint32_t offset = 16;
2172 uint16_t readIndex =
ReadUint16(buffer, offset);
2173 BOOST_TEST(0 == readIndex);
2176 uint32_t readValue =
ReadUint32(buffer, offset);
2177 BOOST_TEST((valueA * numSteps) == readValue);
2181 BOOST_TEST(1 == readIndex);
2185 BOOST_TEST((valueB * numSteps) == readValue);
2192 const uint32_t familyId = 0;
2193 const uint32_t packetId = 3;
2194 const uint32_t version = 1;
2199 SendThread sendThread(profilingStateMachine, mockBuffer1, sendCounterPacket);
2203 sendCounterPacket, sendTimelinePacket, profilingStateMachine);
2205 const uint32_t wrongPacketId = 47;
2206 const uint32_t wrongHeader = (wrongPacketId & 0x000003FF) << 16;
2208 Packet wrongPacket(wrongHeader);
2219 const uint32_t rightHeader = (packetId & 0x000003FF) << 16;
2221 Packet rightPacket(rightHeader);
2223 BOOST_CHECK_NO_THROW(commandHandler(rightPacket));
2227 uint32_t header1Word0 =
ReadUint32(readBuffer1, 0);
2228 uint32_t header1Word1 =
ReadUint32(readBuffer1, 4);
2231 BOOST_TEST(((header1Word0 >> 26) & 0x0000003F) == 0);
2232 BOOST_TEST(((header1Word0 >> 16) & 0x000003FF) == 2);
2233 BOOST_TEST(header1Word1 == 24);
2235 uint32_t bodyHeader1Word0 =
ReadUint32(readBuffer1, 8);
2236 uint16_t deviceRecordCount =
numeric_cast<uint16_t>(bodyHeader1Word0 >> 16);
2237 BOOST_TEST(deviceRecordCount == 0);
2241 uint32_t header2Word0 =
ReadUint32(readBuffer2, 0);
2242 uint32_t header2Word1 =
ReadUint32(readBuffer2, 4);
2245 BOOST_TEST(((header2Word0 >> 26) & 0x0000003F) == 1);
2246 BOOST_TEST(((header2Word0 >> 16) & 0x000003FF) == 0);
2247 BOOST_TEST(header2Word1 == 419);
2254 const uint32_t familyId = 0;
2255 const uint32_t packetId = 3;
2256 const uint32_t version = 1;
2261 SendThread sendThread(profilingStateMachine, mockBuffer1, sendCounterPacket);
2265 sendCounterPacket, sendTimelinePacket, profilingStateMachine);
2266 const uint32_t header = (packetId & 0x000003FF) << 16;
2275 "categoryA", 0, 1, 2.0f,
"counterA",
"descA");
2277 "categoryA", 1, 1, 3.0f,
"counterB",
"descB");
2286 BOOST_CHECK_NO_THROW(commandHandler(packet));
2290 uint32_t header1Word0 =
ReadUint32(readBuffer1, 0);
2291 uint32_t header1Word1 =
ReadUint32(readBuffer1, 4);
2293 BOOST_TEST(((header1Word0 >> 26) & 0x0000003F) == 0);
2294 BOOST_TEST(((header1Word0 >> 16) & 0x000003FF) == 2);
2295 BOOST_TEST(header1Word1 == 236);
2297 uint32_t bodyHeader1Word0 =
ReadUint32(readBuffer1, 8);
2298 uint32_t bodyHeader1Word1 =
ReadUint32(readBuffer1, 12);
2299 uint32_t bodyHeader1Word2 =
ReadUint32(readBuffer1, 16);
2300 uint32_t bodyHeader1Word3 =
ReadUint32(readBuffer1, 20);
2301 uint32_t bodyHeader1Word4 =
ReadUint32(readBuffer1, 24);
2302 uint32_t bodyHeader1Word5 =
ReadUint32(readBuffer1, 28);
2303 uint16_t deviceRecordCount =
numeric_cast<uint16_t>(bodyHeader1Word0 >> 16);
2304 uint16_t counterSetRecordCount =
numeric_cast<uint16_t>(bodyHeader1Word2 >> 16);
2305 uint16_t categoryRecordCount =
numeric_cast<uint16_t>(bodyHeader1Word4 >> 16);
2306 BOOST_TEST(deviceRecordCount == 1);
2307 BOOST_TEST(bodyHeader1Word1 == 0);
2308 BOOST_TEST(counterSetRecordCount == 1);
2309 BOOST_TEST(bodyHeader1Word3 == 4);
2310 BOOST_TEST(categoryRecordCount == 1);
2311 BOOST_TEST(bodyHeader1Word5 == 8);
2313 uint32_t deviceRecordOffset =
ReadUint32(readBuffer1, 32);
2314 BOOST_TEST(deviceRecordOffset == 0);
2316 uint32_t counterSetRecordOffset =
ReadUint32(readBuffer1, 36);
2317 BOOST_TEST(counterSetRecordOffset == 20);
2319 uint32_t categoryRecordOffset =
ReadUint32(readBuffer1, 40);
2320 BOOST_TEST(categoryRecordOffset == 44);
2324 uint32_t header2Word0 =
ReadUint32(readBuffer2, 0);
2325 uint32_t header2Word1 =
ReadUint32(readBuffer2, 4);
2328 BOOST_TEST(((header2Word0 >> 26) & 0x0000003F) == 1);
2329 BOOST_TEST(((header2Word0 >> 16) & 0x000003FF) == 0);
2330 BOOST_TEST(header2Word1 == 419);
2340 unsigned int processNameSize = processName.empty() ? 0 :
boost::numeric_cast<
unsigned int>(processName.size()) + 1;
2341 unsigned int streamMetadataPacketsize = 118 + processNameSize;
2344 armnn::Runtime::CreationOptions::ExternalProfilingOptions
options;
2345 options.m_EnableProfiling =
true;
2351 profilingService.
Update();
2353 profilingService.
Update();
2360 mockProfilingConnection->
Clear();
2363 profilingService.
Update();
2377 uint32_t packetFamily = 0;
2378 uint32_t packetId = 1;
2379 uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
2382 Packet connectionAcknowledgedPacket(header);
2385 mockProfilingConnection->
WritePacket(std::move(connectionAcknowledgedPacket));
2394 options.m_EnableProfiling =
false;
2404 armnn::Runtime::CreationOptions::ExternalProfilingOptions
options;
2405 options.m_EnableProfiling =
true;
2411 profilingService.
Update();
2413 profilingService.
Update();
2415 profilingService.
Update();
2433 uint32_t packetFamily = 0;
2434 uint32_t packetId = 3;
2435 uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
2438 Packet requestCounterDirectoryPacket(header);
2441 mockProfilingConnection->
WritePacket(std::move(requestCounterDirectoryPacket));
2452 options.m_EnableProfiling =
false;
2462 armnn::Runtime::CreationOptions::ExternalProfilingOptions
options;
2463 options.m_EnableProfiling =
true;
2469 profilingService.
Update();
2471 profilingService.
Update();
2473 profilingService.
Update();
2484 mockProfilingConnection->
Clear();
2494 uint32_t packetFamily = 0;
2495 uint32_t packetId = 4;
2496 uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
2498 uint32_t capturePeriod = 123456;
2504 uint16_t counterUidA = counters.begin()->first;
2505 uint16_t counterUidB = 9999;
2507 uint32_t length = 8;
2509 auto data = std::make_unique<unsigned char[]>(length);
2515 Packet periodicCounterSelectionPacket(header, length, data);
2519 mockProfilingConnection->
WritePacket(std::move(periodicCounterSelectionPacket));
2530 options.m_EnableProfiling =
false;
2540 armnn::Runtime::CreationOptions::ExternalProfilingOptions
options;
2541 options.m_EnableProfiling =
true;
2547 profilingService.
Update();
2549 profilingService.
Update();
2551 profilingService.
Update();
2573 uint32_t packetFamily = 0;
2574 uint32_t packetId = 4;
2575 uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
2578 Packet periodicCounterSelectionPacket(header);
2581 mockProfilingConnection->
WritePacket(std::move(periodicCounterSelectionPacket));
2594 options.m_EnableProfiling =
false;
2604 armnn::Runtime::CreationOptions::ExternalProfilingOptions
options;
2605 options.m_EnableProfiling =
true;
2611 profilingService.
Update();
2613 profilingService.
Update();
2615 profilingService.
Update();
2637 uint32_t packetFamily = 0;
2638 uint32_t packetId = 4;
2639 uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
2641 uint32_t capturePeriod = 123456;
2647 uint16_t counterUid = counters.begin()->first;
2649 uint32_t length = 6;
2651 auto data = std::make_unique<unsigned char[]>(length);
2656 Packet periodicCounterSelectionPacket(header, length, data);
2660 mockProfilingConnection->
WritePacket(std::move(periodicCounterSelectionPacket));
2671 options.m_EnableProfiling =
false;
2680 armnn::Runtime::CreationOptions::ExternalProfilingOptions
options;
2681 options.m_EnableProfiling =
true;
2687 profilingService.
Update();
2689 profilingService.
Update();
2691 profilingService.
Update();
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;
2723 uint16_t counterUidA = counters.begin()->first;
2724 uint16_t counterUidB = (counters.begin()++)->first;
2726 uint32_t length = 8;
2728 auto data = std::make_unique<unsigned char[]>(length);
2734 Packet periodicCounterSelectionPacket(header, length, data);
2738 mockProfilingConnection->
WritePacket(std::move(periodicCounterSelectionPacket));
2749 options.m_EnableProfiling =
false;
2758 armnn::Runtime::CreationOptions::ExternalProfilingOptions
options;
2759 options.m_EnableProfiling =
true;
2769 profilingService.
Update();
2775 profilingService.
Update();
2781 profilingService.
Update();
2806 options.m_EnableProfiling =
false;
2815 armnn::Runtime::CreationOptions::ExternalProfilingOptions
options;
2816 options.m_EnableProfiling =
true;
2822 profilingService.
Update();
2824 profilingService.
Update();
2826 profilingService.
Update();
2848 uint32_t packetFamily = 0;
2849 uint32_t packetId = 5;
2850 uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
2853 Packet periodicCounterSelectionPacket(header);
2856 mockProfilingConnection->
WritePacket(std::move(periodicCounterSelectionPacket));
2860 std::this_thread::sleep_for(std::chrono::milliseconds(5));
2867 const auto StreamMetaDataSize =
static_cast<unsigned long>(
2872 options.m_EnableProfiling =
false;
2878 armnn::Runtime::CreationOptions::ExternalProfilingOptions
options;
2879 options.m_EnableProfiling =
true;
2886 options.m_EnableProfiling =
false;
2892 armnn::Runtime::CreationOptions::ExternalProfilingOptions
options;
2899 options.m_EnableProfiling =
false;
2907 armnn::Runtime::CreationOptions::ExternalProfilingOptions
options;
2908 options.m_EnableProfiling =
true;
2912 profilingService.
Update();
2916 std::stringstream ss;
2918 profilingService.
Update();
2921 options.m_EnableProfiling =
false;
2924 streamRedirector.CancelRedirect();
2927 if (!boost::contains(ss.str(),
"Cannot connect to stream socket: Connection refused"))
2929 std::cout << ss.str();
2930 BOOST_FAIL(
"Expected string not found.");
2938 armnn::Runtime::CreationOptions::ExternalProfilingOptions
options;
2942 profilingService.
Update();
2944 options.m_EnableProfiling =
true;
2947 profilingService.
Update();
2951 std::stringstream ss;
2953 profilingService.
Update();
2956 options.m_EnableProfiling =
false;
2959 streamRedirector.CancelRedirect();
2962 if (!boost::contains(ss.str(),
"Cannot connect to stream socket: Connection refused"))
2964 std::cout << ss.str();
2965 BOOST_FAIL(
"Expected string not found.");
2977 std::stringstream ss;
2981 armnn::Runtime::CreationOptions::ExternalProfilingOptions
options;
2982 options.m_EnableProfiling =
true;
2988 profilingService.
Update();
2990 profilingService.
Update();
3003 uint32_t packetFamily = 0;
3004 uint32_t packetId = 37;
3005 uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
3008 Packet connectionAcknowledgedPacket(header);
3011 mockProfilingConnection->
WritePacket(std::move(connectionAcknowledgedPacket));
3014 profilingService.
Update();
3017 options.m_EnableProfiling =
false;
3020 streamRedirector.CancelRedirect();
3023 if (!boost::contains(ss.str(),
"Functor with requested PacketId=37 and Version=4194304 does not exist"))
3025 std::cout << ss.str();
3026 BOOST_FAIL(
"Expected string not found.");
3038 std::stringstream ss;
3042 armnn::Runtime::CreationOptions::ExternalProfilingOptions
options;
3043 options.m_EnableProfiling =
true;
3051 profilingService.
Update();
3066 uint32_t packetFamily = 0;
3067 uint32_t packetId = 123;
3068 uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
3071 Packet requestCounterDirectoryPacket(header);
3074 mockProfilingConnection->WritePacket(std::move(requestCounterDirectoryPacket));
3077 profilingService.
Update();
3080 options.m_EnableProfiling =
false;
3083 streamRedirector.CancelRedirect();
3086 if (!boost::contains(ss.str(),
"Functor with requested PacketId=123 and Version=4194304 does not exist"))
3088 std::cout << ss.str();
3089 BOOST_FAIL(
"Expected string not found.");
3101 std::stringstream ss;
3105 armnn::Runtime::CreationOptions::ExternalProfilingOptions
options;
3106 options.m_EnableProfiling =
true;
3112 profilingService.
Update();
3114 profilingService.
Update();
3116 profilingService.
Update();
3130 uint32_t packetFamily = 0;
3131 uint32_t packetId = 999;
3132 uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
3135 Packet periodicCounterSelectionPacket(header);
3138 mockProfilingConnection->
WritePacket(std::move(periodicCounterSelectionPacket));
3139 profilingService.
Update();
3142 options.m_EnableProfiling =
false;
3146 streamRedirector.CancelRedirect();
3149 if (!boost::contains(ss.str(),
"Functor with requested PacketId=999 and Version=4194304 does not exist"))
3151 std::cout << ss.str();
3152 BOOST_FAIL(
"Expected string not found.");
3162 uint16_t globalCounterIds = 0;
3167 std::vector<uint16_t> cpuRefCounters = {0, 1, 2, 3};
3168 std::vector<uint16_t> cpuAccCounters = {0, 1};
3170 for (uint16_t backendCounterId : cpuRefCounters)
3172 counterIdMap.
RegisterMapping(globalCounterIds, backendCounterId, cpuRefId);
3175 for (uint16_t backendCounterId : cpuAccCounters)
3177 counterIdMap.
RegisterMapping(globalCounterIds, backendCounterId, cpuAccId);
3198 uint16_t globalCounterIds = armnn::profiling::INFERENCES_RUN;
3204 armnn::Runtime::CreationOptions::ExternalProfilingOptions
options;
3205 options.m_EnableProfiling =
true;
3215 globalCounterIds = registerBackendCounters.
RegisterDevice(
"deviceOne");
3224 BOOST_CHECK(counterSetOnePtr->m_Name ==
"counterSetOne");
3226 uint16_t newGlobalCounterId = registerBackendCounters.
RegisterCounter(0,
3232 "first test counter");
3233 BOOST_CHECK(newGlobalCounterId = armnn::profiling::INFERENCES_RUN + 1);
3235 BOOST_CHECK(mappedGlobalId == newGlobalCounterId);
3241 options.m_EnableProfiling =
false;
3258 BackendProfiling backendProfilingCpuRef(options, profilingService, cpuRefId);
3259 BackendProfiling backendProfilingCpuAcc(options, profilingService, cpuAccId);
3261 uint16_t initialNumGlobalCounterIds = armnn::profiling::INFERENCES_RUN;
3278 std::vector<uint16_t> cpuRefCounters = {0, 1};
3279 std::vector<uint16_t> cpuAccCounters = {0};
3282 uint16_t currentNumGlobalCounterIds = registerBackendCountersCpuRef.
RegisterCounter(
3283 0,
"testCategory", 0, 0, 1.f,
"CpuRefCounter0",
"Zeroth CpuRef Counter");
3284 BOOST_CHECK(currentNumGlobalCounterIds == initialNumGlobalCounterIds + 1);
3286 BOOST_CHECK(mappedGlobalId == currentNumGlobalCounterIds);
3291 currentNumGlobalCounterIds = registerBackendCountersCpuRef.
RegisterCounter(
3292 1,
"testCategory", 0, 0, 1.f,
"CpuRefCounter1",
"First CpuRef Counter");
3293 BOOST_CHECK(currentNumGlobalCounterIds == initialNumGlobalCounterIds + 2);
3295 BOOST_CHECK(mappedGlobalId == currentNumGlobalCounterIds);
3304 currentNumGlobalCounterIds = registerBackendCountersCpuAcc.
RegisterCounter(
3305 0,
"testCategory", 0, 0, 1.f,
"CpuAccCounter0",
"Zeroth CpuAcc Counter");
3306 BOOST_CHECK(currentNumGlobalCounterIds == initialNumGlobalCounterIds + 3);
3308 BOOST_CHECK(mappedGlobalId == currentNumGlobalCounterIds);
3314 const std::vector<uint16_t> activeGlobalCounterIds = {5};
3315 const std::vector<uint16_t> newActiveGlobalCounterIds = {6, 7};
3317 const uint32_t capturePeriod = 200;
3318 const uint32_t newCapturePeriod = 100;
3321 profilingService.
SetCaptureData(capturePeriod, activeGlobalCounterIds, {});
3324 std::vector<CounterStatus> cpuRefCounterStatus = backendProfilingCpuRef.
GetActiveCounters();
3325 std::vector<CounterStatus> cpuAccCounterStatus = backendProfilingCpuAcc.
GetActiveCounters();
3326 BOOST_CHECK_EQUAL(cpuRefCounterStatus.size(), 1);
3327 BOOST_CHECK_EQUAL(cpuAccCounterStatus.size(), 0);
3330 BOOST_CHECK_EQUAL(cpuRefCounterStatus[0].m_GlobalCounterId, activeGlobalCounterIds[0]);
3331 BOOST_CHECK_EQUAL(cpuRefCounterStatus[0].m_BackendCounterId, cpuRefCounters[0]);
3332 BOOST_CHECK_EQUAL(cpuRefCounterStatus[0].m_SamplingRateInMicroseconds, capturePeriod);
3333 BOOST_CHECK_EQUAL(cpuRefCounterStatus[0].m_Enabled,
true);
3340 BOOST_CHECK_EQUAL(inactiveCpuRefCounter.
m_Enabled,
false);
3347 BOOST_CHECK_EQUAL(inactiveCpuAccCounter.
m_Enabled,
false);
3350 profilingService.
SetCaptureData(newCapturePeriod, newActiveGlobalCounterIds, {});
3355 BOOST_CHECK_EQUAL(cpuRefCounterStatus.size(), 1);
3356 BOOST_CHECK_EQUAL(cpuAccCounterStatus.size(), 1);
3359 BOOST_CHECK_EQUAL(cpuRefCounterStatus[0].m_GlobalCounterId, newActiveGlobalCounterIds[0]);
3360 BOOST_CHECK_EQUAL(cpuRefCounterStatus[0].m_BackendCounterId, cpuRefCounters[1]);
3361 BOOST_CHECK_EQUAL(cpuRefCounterStatus[0].m_SamplingRateInMicroseconds, newCapturePeriod);
3362 BOOST_CHECK_EQUAL(cpuRefCounterStatus[0].m_Enabled,
true);
3365 BOOST_CHECK_EQUAL(cpuAccCounterStatus[0].m_GlobalCounterId, newActiveGlobalCounterIds[1]);
3366 BOOST_CHECK_EQUAL(cpuAccCounterStatus[0].m_BackendCounterId, cpuAccCounters[0]);
3367 BOOST_CHECK_EQUAL(cpuAccCounterStatus[0].m_SamplingRateInMicroseconds, newCapturePeriod);
3368 BOOST_CHECK_EQUAL(cpuAccCounterStatus[0].m_Enabled,
true);
3371 inactiveCpuRefCounter = backendProfilingCpuRef.
GetCounterStatus(cpuRefCounters[0]);
3375 BOOST_CHECK_EQUAL(inactiveCpuRefCounter.
m_Enabled,
false);
3397 mockProfilingService,
3404 std::vector<armnn::profiling::Timestamp> timestamps;
3405 timestamps.push_back(timestamp);
3410 uint32_t headerWord0 =
ReadUint32(readBuffer, 0);
3411 uint32_t headerWord1 =
ReadUint32(readBuffer, 4);
3412 uint64_t readTimestamp =
ReadUint64(readBuffer, 8);
3414 BOOST_TEST(((headerWord0 >> 26) & 0x0000003F) == 3);
3415 BOOST_TEST(((headerWord0 >> 19) & 0x0000007F) == 0);
3416 BOOST_TEST(((headerWord0 >> 16) & 0x00000007) == 0);
3417 BOOST_TEST(headerWord1 == 20);
3418 BOOST_TEST(1000998 == readTimestamp);
3420 uint32_t offset = 16;
3422 uint16_t readIndex =
ReadUint16(readBuffer, offset);
3423 BOOST_TEST(6 == readIndex);
3427 uint32_t readValue =
ReadUint32(readBuffer, offset);
3428 BOOST_TEST(700 == readValue);
3433 BOOST_TEST(8 == readIndex);
3438 BOOST_TEST(93 == readValue);
BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
uint32_t GetFamilyId() const
static ProfilingService & Instance()
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)
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)
uint32_t GetCounterValue(uint16_t counterUid) const override
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
Version ResolvePacketVersion(uint32_t familyId, uint32_t packetId) const
uint32_t GetPacketClass() const
void ForceTransitionToState(ProfilingState newState)
void ReportCounters(const std::vector< Timestamp > &) override
std::string GetProcessName()
uint32_t GetPacketId() const
CommandHandlerFunctor * GetFunctor(uint32_t familyId, uint32_t packetId, uint32_t version) const
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
uint32_t GetPacketId() const
virtual const Device * GetDevice(uint16_t uid) const =0
unsigned long GetWrittenDataSize()
void IgnoreUnused(Ts &&...)
virtual const CounterSets & GetCounterSets() const =0
ProfilingService & profilingService
void RegisterMapping(uint16_t globalCounterId, uint16_t backendCounterId, const armnn::BackendId &backendId) override
uint32_t IncrementCounterValue(uint16_t counterUid) override
uint32_t GetVersion() const
void CaptureDataReadThreadImpl(const Holder &holder, CaptureData &captureData)
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
virtual const Categories & GetCategories() const =0
uint16_t GetNextUid(bool peekOnly)
uint32_t GetPacketFamily() const
uint16_t GetDeviceCount() const 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
CaptureData GetCaptureData() const
void RegisterFunctor(CommandHandlerFunctor *functor, uint32_t familyId, uint32_t packetId, uint32_t version)
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 GetPacketType() const
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
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
uint32_t GetLength() const
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
uint32_t GetVersion() const
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.
uint32_t GetHeader() const
static bool IsValidChar(unsigned char c)
void SetCounterIds(const std::vector< uint16_t > &counterIds)
bool WritePacket(const unsigned char *buffer, uint32_t length) override
uint32_t GetPacketId() const
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 unsigned char * GetData() const
const CounterSet * GetCounterSet(uint16_t uid) const override
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
ExternalProfilingOptions m_ProfilingOptions
const ICounterDirectory & GetCounterDirectory() const
ProfilingState ConfigureProfilingService(const ExternalProfilingOptions &options, bool resetProfilingService=false)
void RegisterMapping(uint16_t globalCounterId, uint16_t backendCounterId, const armnn::BackendId &backendId) override
FileOnlyHelperService helper
uint16_t m_BackendCounterId
static bool IsValidChar(unsigned char c)
virtual uint16_t GetGlobalId(uint16_t backendCounterId, const armnn::BackendId &backendId) const =0