6 #include <common/include/CommandHandlerRegistry.hpp> 7 #include <server/include/basePipeServer/ConnectionHandler.hpp> 14 #include <server/include/timelineDecoder/TimelineDirectoryCaptureCommandHandler.hpp> 15 #include <server/include/timelineDecoder/TimelineDecoder.hpp> 21 #include <boost/cast.hpp> 22 #include <boost/test/test_tools.hpp> 23 #include <boost/test/unit_test_suite.hpp> 28 using namespace armnn;
36 arm::pipe::PacketVersionResolver packetVersionResolver;
39 std::vector<std::pair<uint16_t, uint32_t>> indexValuePairs;
40 indexValuePairs.reserve(5);
41 indexValuePairs.emplace_back(std::make_pair<uint16_t, uint32_t>(0, 100));
42 indexValuePairs.emplace_back(std::make_pair<uint16_t, uint32_t>(1, 200));
43 indexValuePairs.emplace_back(std::make_pair<uint16_t, uint32_t>(2, 300));
44 indexValuePairs.emplace_back(std::make_pair<uint16_t, uint32_t>(3, 400));
45 indexValuePairs.emplace_back(std::make_pair<uint16_t, uint32_t>(4, 500));
48 uint32_t dataLength = 38;
51 uint64_t time =
static_cast<uint64_t
>(
52 std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now().time_since_epoch())
55 uint64_t time2 = time + 5000;
58 std::unique_ptr<unsigned char[]> uniqueData1 = std::make_unique<unsigned char[]>(dataLength);
59 unsigned char* data1 =
reinterpret_cast<unsigned char*
>(uniqueData1.get());
61 std::unique_ptr<unsigned char[]> uniqueData2 = std::make_unique<unsigned char[]>(dataLength);
62 unsigned char* data2 =
reinterpret_cast<unsigned char*
>(uniqueData2.get());
64 uint32_t sizeOfUint64 =
numeric_cast<uint32_t>(
sizeof(uint64_t));
65 uint32_t sizeOfUint32 =
numeric_cast<uint32_t>(
sizeof(uint32_t));
66 uint32_t sizeOfUint16 =
numeric_cast<uint32_t>(
sizeof(uint16_t));
71 offset += sizeOfUint64;
72 for (
const auto& pair : indexValuePairs)
75 offset += sizeOfUint16;
77 offset += sizeOfUint32;
83 offset += sizeOfUint64;
84 for (
const auto& pair : indexValuePairs)
87 offset += sizeOfUint16;
89 offset += sizeOfUint32;
92 uint32_t headerWord1 = packetVersionResolver.ResolvePacketVersion(0, 4).GetEncodedValue();
94 arm::pipe::Packet packet1(headerWord1, dataLength, uniqueData1);
95 arm::pipe::Packet packet2(headerWord1, dataLength, uniqueData2);
100 commandHandler(packet1);
101 commandHandler(packet2);
111 void WaitFor(std::function<
bool()> predicate, std::string errorMsg, uint32_t timeout = 2000, uint32_t sleepTime = 50)
113 uint32_t timeSlept = 0;
116 if (timeSlept >= timeout)
118 BOOST_FAIL(
"Timeout: " + errorMsg);
120 std::this_thread::sleep_for(std::chrono::milliseconds(sleepTime));
121 timeSlept += sleepTime;
127 uint32_t uint8_t_size =
sizeof(uint8_t);
129 uint32_t uint64_t_size =
sizeof(uint64_t);
130 uint32_t threadId_size =
sizeof(int);
135 std::unique_ptr<profiling::ISendTimelinePacket> sendTimelinePacket =
138 sendTimelinePacket->SendTimelineMessageDirectoryPackage();
139 sendTimelinePacket->Commit();
141 std::vector<arm::pipe::SwTraceMessage> swTraceBufferMessages;
143 unsigned int offset = uint32_t_size * 2;
145 std::unique_ptr<profiling::IPacketBuffer> packetBuffer = bufferManager.
GetReadableBuffer();
147 uint8_t readStreamVersion =
ReadUint8(packetBuffer, offset);
148 BOOST_CHECK(readStreamVersion == 4);
149 offset += uint8_t_size;
150 uint8_t readPointerBytes =
ReadUint8(packetBuffer, offset);
151 BOOST_CHECK(readPointerBytes == uint64_t_size);
152 offset += uint8_t_size;
153 uint8_t readThreadIdBytes =
ReadUint8(packetBuffer, offset);
154 BOOST_CHECK(readThreadIdBytes == threadId_size);
155 offset += uint8_t_size;
159 for(uint32_t i = 0; i < declarationSize; ++i)
161 swTraceBufferMessages.push_back(arm::pipe::ReadSwTraceMessage(packetBuffer->GetReadableData(),
163 packetBuffer->GetSize()));
166 for(uint32_t index = 0; index < declarationSize; ++index)
168 arm::pipe::SwTraceMessage& bufferMessage = swTraceBufferMessages[index];
169 arm::pipe::SwTraceMessage& handlerMessage = commandHandler.m_SwTraceMessages[index];
171 BOOST_CHECK(bufferMessage.m_Name == handlerMessage.m_Name);
172 BOOST_CHECK(bufferMessage.m_UiName == handlerMessage.m_UiName);
173 BOOST_CHECK(bufferMessage.m_Id == handlerMessage.m_Id);
175 BOOST_CHECK(bufferMessage.m_ArgTypes.size() == handlerMessage.m_ArgTypes.size());
176 for(uint32_t i = 0; i < bufferMessage.m_ArgTypes.size(); ++i)
178 BOOST_CHECK(bufferMessage.m_ArgTypes[i] == handlerMessage.m_ArgTypes[i]);
181 BOOST_CHECK(bufferMessage.m_ArgNames.size() == handlerMessage.m_ArgNames.size());
182 for(uint32_t i = 0; i < bufferMessage.m_ArgNames.size(); ++i)
184 BOOST_CHECK(bufferMessage.m_ArgNames[i] == handlerMessage.m_ArgNames[i]);
208 BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i++].m_Name ==
212 BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i++].m_Name ==
230 BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i].m_Guid ==
232 BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i++].m_Name ==
235 BOOST_CHECK(timelineDecoder.GetModel().m_EventClasses[0].m_Guid ==
237 BOOST_CHECK(timelineDecoder.GetModel().m_EventClasses[1].m_Guid ==
247 std::string udsNamespace =
"gatord_namespace";
249 BOOST_CHECK_NO_THROW(arm::pipe::ConnectionHandler connectionHandler(udsNamespace,
false));
251 arm::pipe::ConnectionHandler connectionHandler(udsNamespace,
false);
263 profilingService.
Update();
265 profilingService.
Update();
268 auto basePipeServer = connectionHandler.GetNewBasePipeServer(
false);
279 "Profiling service did not switch to WaitingForAck state");
281 profilingService.
Update();
285 BOOST_FAIL(
"Failed to receive StreamMetaData");
293 "Profiling service did not switch to Active state");
297 "MockGatord did not receive counter directory packet");
300 WaitFor([&](){
return timelineDecoder.GetModel().m_EventClasses.size() >= 2;},
301 "MockGatord did not receive well known timeline labels and event classes");
320 for (
auto& device : serviceDevices)
323 auto foundDevice = receivedCounterDirectory.
GetDevices().find(device.second->m_Uid);
324 BOOST_CHECK(foundDevice != receivedCounterDirectory.
GetDevices().end());
325 BOOST_CHECK(device.second->m_Name.compare((*foundDevice).second->m_Name) == 0);
326 BOOST_CHECK(device.second->m_Cores == (*foundDevice).second->m_Cores);
330 for (
auto& counterSet : serviceCounterSets)
333 auto foundCounterSet = receivedCounterDirectory.
GetCounterSets().find(counterSet.second->m_Uid);
334 BOOST_CHECK(foundCounterSet != receivedCounterDirectory.
GetCounterSets().end());
335 BOOST_CHECK(counterSet.second->m_Name.compare((*foundCounterSet).second->m_Name) == 0);
336 BOOST_CHECK(counterSet.second->m_Count == (*foundCounterSet).second->m_Count);
340 for (
auto& category : serviceCategories)
342 for (
auto& receivedCategory : receivedCounterDirectory.
GetCategories())
344 if (receivedCategory->m_Name.compare(category->m_Name) == 0)
348 std::sort(category->m_Counters.begin(), category->m_Counters.end());
349 std::sort(receivedCategory->m_Counters.begin(), receivedCategory->m_Counters.end());
351 std::function<bool(const uint16_t&, const uint16_t&)> comparator =
352 [&directoryCaptureCommandHandler](
const uint16_t& first,
const uint16_t& second) {
354 if (translated == first)
361 BOOST_CHECK(std::equal(category->m_Counters.begin(), category->m_Counters.end(),
362 receivedCategory->m_Counters.begin(), comparator));
370 for (
auto& receivedCounter : receivedCounters)
376 BOOST_CHECK(serviceCounter->
m_DeviceUid == receivedCounter.second->m_DeviceUid);
377 BOOST_CHECK(serviceCounter->
m_Name.compare(receivedCounter.second->m_Name) == 0);
378 BOOST_CHECK(serviceCounter->
m_CounterSetUid == receivedCounter.second->m_CounterSetUid);
379 BOOST_CHECK(serviceCounter->
m_Multiplier == receivedCounter.second->m_Multiplier);
380 BOOST_CHECK(serviceCounter->
m_Interpolation == receivedCounter.second->m_Interpolation);
381 BOOST_CHECK(serviceCounter->
m_Class == receivedCounter.second->m_Class);
382 BOOST_CHECK(serviceCounter->
m_Units.compare(receivedCounter.second->m_Units) == 0);
383 BOOST_CHECK(serviceCounter->
m_Description.compare(receivedCounter.second->m_Description) == 0);
402 std::string udsNamespace =
"gatord_namespace";
404 arm::pipe::ConnectionHandler connectionHandler(udsNamespace,
false);
411 auto basePipeServer = connectionHandler.GetNewBasePipeServer(
false);
417 BOOST_FAIL(
"Failed to receive StreamMetaData");
434 IConnectableLayer* normalize = net->AddNormalizationLayer(descriptor,
"normalization");
448 "MockGatord did not receive counter directory packet");
452 WaitFor([&](){
return timelineDecoder.GetModel().m_EventClasses.size() >= 2;},
453 "MockGatord did not receive well known timeline labels");
455 WaitFor([&](){
return timelineDecoder.GetModel().m_Entities.size() >= 1;},
456 "MockGatord did not receive mock backend test entity");
459 BOOST_CHECK(timelineDecoder.GetModel().m_Entities.size() == 1);
460 BOOST_CHECK(timelineDecoder.GetModel().m_EventClasses.size() == 2);
461 BOOST_CHECK(timelineDecoder.GetModel().m_Labels.size() == 15);
462 BOOST_CHECK(timelineDecoder.GetModel().m_Relationships.size() == 0);
463 BOOST_CHECK(timelineDecoder.GetModel().m_Events.size() == 0);
468 "Timeline packets were not deactivated");
478 "Timeline packets were not activated");
486 WaitFor([&](){
return timelineDecoder.GetModel().m_Labels.size() >= 24;},
487 "MockGatord did not receive well known timeline labels");
490 BOOST_CHECK(timelineDecoder.GetModel().m_Entities.size() == 6);
491 BOOST_CHECK(timelineDecoder.GetModel().m_EventClasses.size() == 4);
492 BOOST_CHECK(timelineDecoder.GetModel().m_Labels.size() == 34);
493 BOOST_CHECK(timelineDecoder.GetModel().m_Relationships.size() == 15);
494 BOOST_CHECK(timelineDecoder.GetModel().m_Events.size() == 0);
BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
static ARMNN_DLLEXPORT ProfilingStaticGuid INFERENCE_GUID
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
static ARMNN_DLLEXPORT std::string WORKLOAD_EXECUTION
static ARMNN_DLLEXPORT std::string TYPE_LABEL
CPU Execution: Reference C++ kernels.
arm::pipe::TimelineDirectoryCaptureCommandHandler & GetTimelineDirectoryCaptureCommandHandler()
ProfilingState GetCurrentState() const
uint16_t TranslateUIDCopyToOriginal(uint16_t copyUid)
Given a Uid that came from a copy of the counter directory translate it to the original.
virtual const IDeviceSpec & GetDeviceSpec() const override
void WriteUint16(const IPacketBufferPtr &packetBuffer, unsigned int offset, uint16_t value)
void WriteUint32(const IPacketBufferPtr &packetBuffer, unsigned int offset, uint32_t value)
std::unordered_map< uint16_t, CounterPtr > Counters
void CheckTimelinePackets(arm::pipe::TimelineDecoder &timelineDecoder)
static ARMNN_DLLEXPORT std::string NAME_LABEL
virtual uint16_t GetCounterCount() const =0
BackendRegistry & BackendRegistryInstance()
uint8_t ReadUint8(const IPacketBufferPtr &packetBuffer, unsigned int offset)
Copyright (c) 2020 ARM Limited.
void SendDeactivateTimelinePacket()
Send a deactivate timeline packet back to the client.
virtual const CounterSets & GetCounterSets() const =0
static ARMNN_DLLEXPORT std::string BACKENDID_LABEL
virtual uint16_t GetCategoryCount() const =0
static ARMNN_DLLEXPORT ProfilingStaticGuid CONNECTION_GUID
void SendActivateTimelinePacket()
Send a activate timeline packet back to the client.
static ARMNN_DLLEXPORT ProfilingStaticGuid WORKLOAD_GUID
static ARMNN_DLLEXPORT std::string EXECUTION_OF_LABEL
static ARMNN_DLLEXPORT ProfilingStaticGuid WORKLOAD_EXECUTION_GUID
bool ParsedCounterDirectory()
static ARMNN_DLLEXPORT ProfilingStaticGuid ARMNN_PROFILING_EOL_EVENT_CLASS
void CheckTimelineDirectory(arm::pipe::TimelineDirectoryCaptureCommandHandler &commandHandler)
virtual void SetTensorInfo(const TensorInfo &tensorInfo)=0
std::unordered_map< uint16_t, CounterSetPtr > CounterSets
static ARMNN_DLLEXPORT ProfilingStaticGuid NAME_GUID
static ARMNN_DLLEXPORT ProfilingStaticGuid ARMNN_PROFILING_SOL_EVENT_CLASS
virtual const Categories & GetCategories() const =0
static ARMNN_DLLEXPORT std::string NETWORK
bool WaitForStreamMetaData()
Once the connection is open wait to receive the stream meta data packet from the client.
virtual const Devices & GetDevices() const =0
static ARMNN_DLLEXPORT ProfilingStaticGuid LAYER_GUID
arm::pipe::TimelineDecoder & GetTimelineDecoder()
IOptimizedNetworkPtr Optimize(const INetwork &network, const std::vector< BackendId > &backendPreferences, const IDeviceSpec &deviceSpec, const OptimizerOptions &options=OptimizerOptions(), Optional< std::vector< std::string > &> messages=EmptyOptional())
Create an optimized version of the network.
profiling::ProfilingService & GetProfilingService(armnn::Runtime *runtime)
static ARMNN_DLLEXPORT ProfilingStaticGuid EXECUTION_OF_GUID
static ARMNN_DLLEXPORT std::string WORKLOAD
uint64_t m_CurrentPeriodValue
std::unique_ptr< IOptimizedNetwork, void(*)(IOptimizedNetwork *network)> IOptimizedNetworkPtr
static ARMNN_DLLEXPORT std::string INDEX_LABEL
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
virtual uint16_t GetDeviceCount() const =0
#define ARMNN_ASSERT(COND)
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
BOOST_AUTO_TEST_CASE(CheckConvolution2dLayer)
bool LaunchReceivingThread()
Start the thread that will receive all packets and print them nicely to stdout.
IPacketBufferPtr GetReadableBuffer() override
static MockBackendProfilingService & Instance()
CounterCaptureValues m_CounterCaptureValues
virtual const Counter * GetCounter(uint16_t uid) const =0
std::vector< uint16_t > m_Uids
void WriteUint64(const std::unique_ptr< IPacketBuffer > &packetBuffer, unsigned int offset, uint64_t value)
uint32_t ReadUint32(const IPacketBufferPtr &packetBuffer, unsigned int offset)
std::unordered_set< CategoryPtr > Categories
profiling::DirectoryCaptureCommandHandler & GetDirectoryCaptureCommandHandler()
virtual uint16_t GetCounterSetCount() const =0
static ARMNN_DLLEXPORT ProfilingStaticGuid NETWORK_GUID
A class that implements a Mock Gatord server.
MockBackendProfilingContext * GetContext()
static ARMNN_DLLEXPORT std::string CONNECTION
BOOST_AUTO_TEST_SUITE_END()
static ARMNN_DLLEXPORT std::string PROCESS_ID_LABEL
static ARMNN_DLLEXPORT ProfilingStaticGuid INDEX_GUID
std::string m_Description
bool TimelineReportingEnabled()
static ARMNN_DLLEXPORT ProfilingStaticGuid TYPE_GUID
virtual Status LoadNetwork(NetworkId &networkIdOut, IOptimizedNetworkPtr network) override
Loads a complete network into the Runtime.
virtual const IInputSlot & GetInputSlot(unsigned int index) const =0
Get a const input slot handle by slot index.
virtual const IOutputSlot & GetOutputSlot(unsigned int index) const =0
Get the const output slot handle by slot index.
virtual const Counters & GetCounters() const =0
static ARMNN_DLLEXPORT std::string CHILD_LABEL
void WaitFor(std::function< bool()> predicate, std::string errorMsg, uint32_t timeout=2000, uint32_t sleepTime=50)
std::unordered_map< uint16_t, DevicePtr > Devices
void WaitForReceivingThread()
This is a placeholder method to prevent main exiting.
std::unique_ptr< INetwork, void(*)(INetwork *network)> INetworkPtr
virtual int Connect(IInputSlot &destination)=0
std::unique_ptr< ISendTimelinePacket > GetSendTimelinePacket() const
static ARMNN_DLLEXPORT ProfilingStaticGuid PROCESS_ID_GUID
const ICounterDirectory & GetCounterDirectory() const
A NormalizationDescriptor for the NormalizationLayer.
ExternalProfilingOptions m_ProfilingOptions
const ICounterDirectory & GetCounterDirectory() const
static INetworkPtr Create(NetworkOptions networkOptions={})
static ARMNN_DLLEXPORT ProfilingStaticGuid BACKENDID_GUID
void SendConnectionAck()
Send a connection acknowledged packet back to the client.
static ARMNN_DLLEXPORT std::string INFERENCE
static ARMNN_DLLEXPORT ProfilingStaticGuid CHILD_GUID
static ARMNN_DLLEXPORT std::string LAYER