6 #include <common/include/CommandHandlerRegistry.hpp> 7 #include <server/include/basePipeServer/ConnectionHandler.hpp> 16 #include <server/include/timelineDecoder/TimelineDirectoryCaptureCommandHandler.hpp> 17 #include <server/include/timelineDecoder/TimelineDecoder.hpp> 23 #include <boost/test/test_tools.hpp> 24 #include <boost/test/unit_test_suite.hpp> 28 using namespace armnn;
34 arm::pipe::PacketVersionResolver packetVersionResolver;
37 std::vector<std::pair<uint16_t, uint32_t>> indexValuePairs;
38 indexValuePairs.reserve(5);
39 indexValuePairs.emplace_back(std::make_pair<uint16_t, uint32_t>(0, 100));
40 indexValuePairs.emplace_back(std::make_pair<uint16_t, uint32_t>(1, 200));
41 indexValuePairs.emplace_back(std::make_pair<uint16_t, uint32_t>(2, 300));
42 indexValuePairs.emplace_back(std::make_pair<uint16_t, uint32_t>(3, 400));
43 indexValuePairs.emplace_back(std::make_pair<uint16_t, uint32_t>(4, 500));
46 uint32_t dataLength = 38;
49 uint64_t time =
static_cast<uint64_t
>(
50 std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now().time_since_epoch())
53 uint64_t time2 = time + 5000;
56 std::unique_ptr<unsigned char[]> uniqueData1 = std::make_unique<unsigned char[]>(dataLength);
57 unsigned char* data1 =
reinterpret_cast<unsigned char*
>(uniqueData1.get());
59 std::unique_ptr<unsigned char[]> uniqueData2 = std::make_unique<unsigned char[]>(dataLength);
60 unsigned char* data2 =
reinterpret_cast<unsigned char*
>(uniqueData2.get());
69 offset += sizeOfUint64;
70 for (
const auto& pair : indexValuePairs)
73 offset += sizeOfUint16;
75 offset += sizeOfUint32;
81 offset += sizeOfUint64;
82 for (
const auto& pair : indexValuePairs)
85 offset += sizeOfUint16;
87 offset += sizeOfUint32;
90 uint32_t headerWord1 = packetVersionResolver.ResolvePacketVersion(0, 4).GetEncodedValue();
92 arm::pipe::Packet packet1(headerWord1, dataLength, uniqueData1);
93 arm::pipe::Packet packet2(headerWord1, dataLength, uniqueData2);
98 commandHandler(packet1);
99 commandHandler(packet2);
109 void WaitFor(std::function<
bool()> predicate, std::string errorMsg, uint32_t timeout = 2000, uint32_t sleepTime = 50)
111 uint32_t timeSlept = 0;
114 if (timeSlept >= timeout)
116 BOOST_FAIL(
"Timeout: " + errorMsg);
118 std::this_thread::sleep_for(std::chrono::milliseconds(sleepTime));
119 timeSlept += sleepTime;
125 uint32_t uint8_t_size =
sizeof(uint8_t);
127 uint32_t uint64_t_size =
sizeof(uint64_t);
128 uint32_t threadId_size =
sizeof(int);
133 std::unique_ptr<profiling::ISendTimelinePacket> sendTimelinePacket =
136 sendTimelinePacket->SendTimelineMessageDirectoryPackage();
137 sendTimelinePacket->Commit();
139 std::vector<arm::pipe::SwTraceMessage> swTraceBufferMessages;
141 unsigned int offset = uint32_t_size * 2;
143 std::unique_ptr<profiling::IPacketBuffer> packetBuffer = bufferManager.
GetReadableBuffer();
145 uint8_t readStreamVersion =
ReadUint8(packetBuffer, offset);
146 BOOST_CHECK(readStreamVersion == 4);
147 offset += uint8_t_size;
148 uint8_t readPointerBytes =
ReadUint8(packetBuffer, offset);
149 BOOST_CHECK(readPointerBytes == uint64_t_size);
150 offset += uint8_t_size;
151 uint8_t readThreadIdBytes =
ReadUint8(packetBuffer, offset);
152 BOOST_CHECK(readThreadIdBytes == threadId_size);
153 offset += uint8_t_size;
157 for(uint32_t i = 0; i < declarationSize; ++i)
159 swTraceBufferMessages.push_back(arm::pipe::ReadSwTraceMessage(packetBuffer->GetReadableData(),
161 packetBuffer->GetSize()));
164 for(uint32_t index = 0; index < declarationSize; ++index)
166 arm::pipe::SwTraceMessage& bufferMessage = swTraceBufferMessages[index];
167 arm::pipe::SwTraceMessage& handlerMessage = commandHandler.m_SwTraceMessages[index];
169 BOOST_CHECK(bufferMessage.m_Name == handlerMessage.m_Name);
170 BOOST_CHECK(bufferMessage.m_UiName == handlerMessage.m_UiName);
171 BOOST_CHECK(bufferMessage.m_Id == handlerMessage.m_Id);
173 BOOST_CHECK(bufferMessage.m_ArgTypes.size() == handlerMessage.m_ArgTypes.size());
174 for(uint32_t i = 0; i < bufferMessage.m_ArgTypes.size(); ++i)
176 BOOST_CHECK(bufferMessage.m_ArgTypes[i] == handlerMessage.m_ArgTypes[i]);
179 BOOST_CHECK(bufferMessage.m_ArgNames.size() == handlerMessage.m_ArgNames.size());
180 for(uint32_t i = 0; i < bufferMessage.m_ArgNames.size(); ++i)
182 BOOST_CHECK(bufferMessage.m_ArgNames[i] == handlerMessage.m_ArgNames[i]);
206 BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i++].m_Name ==
210 BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i++].m_Name ==
228 BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i].m_Guid ==
230 BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i++].m_Name ==
233 BOOST_CHECK(timelineDecoder.GetModel().m_EventClasses[0].m_Guid ==
235 BOOST_CHECK(timelineDecoder.GetModel().m_EventClasses[1].m_Guid ==
245 std::string udsNamespace =
"gatord_namespace";
247 BOOST_CHECK_NO_THROW(arm::pipe::ConnectionHandler connectionHandler(udsNamespace,
false));
249 arm::pipe::ConnectionHandler connectionHandler(udsNamespace,
false);
261 profilingService.
Update();
263 profilingService.
Update();
266 auto basePipeServer = connectionHandler.GetNewBasePipeServer(
false);
277 "Profiling service did not switch to WaitingForAck state");
279 profilingService.
Update();
283 BOOST_FAIL(
"Failed to receive StreamMetaData");
291 "Profiling service did not switch to Active state");
295 "MockGatord did not receive counter directory packet");
298 WaitFor([&](){
return timelineDecoder.GetModel().m_EventClasses.size() >= 2;},
299 "MockGatord did not receive well known timeline labels and event classes");
318 for (
auto& device : serviceDevices)
321 auto foundDevice = receivedCounterDirectory.
GetDevices().find(device.second->m_Uid);
322 BOOST_CHECK(foundDevice != receivedCounterDirectory.
GetDevices().end());
323 BOOST_CHECK(device.second->m_Name.compare((*foundDevice).second->m_Name) == 0);
324 BOOST_CHECK(device.second->m_Cores == (*foundDevice).second->m_Cores);
328 for (
auto& counterSet : serviceCounterSets)
331 auto foundCounterSet = receivedCounterDirectory.
GetCounterSets().find(counterSet.second->m_Uid);
332 BOOST_CHECK(foundCounterSet != receivedCounterDirectory.
GetCounterSets().end());
333 BOOST_CHECK(counterSet.second->m_Name.compare((*foundCounterSet).second->m_Name) == 0);
334 BOOST_CHECK(counterSet.second->m_Count == (*foundCounterSet).second->m_Count);
338 for (
auto& category : serviceCategories)
340 for (
auto& receivedCategory : receivedCounterDirectory.
GetCategories())
342 if (receivedCategory->m_Name.compare(category->m_Name) == 0)
346 std::sort(category->m_Counters.begin(), category->m_Counters.end());
347 std::sort(receivedCategory->m_Counters.begin(), receivedCategory->m_Counters.end());
349 std::function<bool(const uint16_t&, const uint16_t&)> comparator =
350 [&directoryCaptureCommandHandler](
const uint16_t& first,
const uint16_t& second) {
352 if (translated == first)
359 BOOST_CHECK(std::equal(category->m_Counters.begin(), category->m_Counters.end(),
360 receivedCategory->m_Counters.begin(), comparator));
368 for (
auto& receivedCounter : receivedCounters)
374 BOOST_CHECK(serviceCounter->
m_DeviceUid == receivedCounter.second->m_DeviceUid);
375 BOOST_CHECK(serviceCounter->
m_Name.compare(receivedCounter.second->m_Name) == 0);
376 BOOST_CHECK(serviceCounter->
m_CounterSetUid == receivedCounter.second->m_CounterSetUid);
377 BOOST_CHECK(serviceCounter->
m_Multiplier == receivedCounter.second->m_Multiplier);
378 BOOST_CHECK(serviceCounter->
m_Interpolation == receivedCounter.second->m_Interpolation);
379 BOOST_CHECK(serviceCounter->
m_Class == receivedCounter.second->m_Class);
380 BOOST_CHECK(serviceCounter->
m_Units.compare(receivedCounter.second->m_Units) == 0);
381 BOOST_CHECK(serviceCounter->
m_Description.compare(receivedCounter.second->m_Description) == 0);
400 std::string udsNamespace =
"gatord_namespace";
402 arm::pipe::ConnectionHandler connectionHandler(udsNamespace,
false);
409 auto basePipeServer = connectionHandler.GetNewBasePipeServer(
false);
415 BOOST_FAIL(
"Failed to receive StreamMetaData");
432 IConnectableLayer* normalize = net->AddNormalizationLayer(descriptor,
"normalization");
446 "MockGatord did not receive counter directory packet");
450 WaitFor([&](){
return timelineDecoder.GetModel().m_EventClasses.size() >= 2;},
451 "MockGatord did not receive well known timeline labels");
453 WaitFor([&](){
return timelineDecoder.GetModel().m_Entities.size() >= 1;},
454 "MockGatord did not receive mock backend test entity");
457 BOOST_CHECK(timelineDecoder.GetModel().m_Entities.size() == 1);
458 BOOST_CHECK(timelineDecoder.GetModel().m_EventClasses.size() == 2);
459 BOOST_CHECK(timelineDecoder.GetModel().m_Labels.size() == 15);
460 BOOST_CHECK(timelineDecoder.GetModel().m_Relationships.size() == 0);
461 BOOST_CHECK(timelineDecoder.GetModel().m_Events.size() == 0);
466 "Timeline packets were not deactivated");
476 "Timeline packets were not activated");
484 WaitFor([&](){
return timelineDecoder.GetModel().m_Labels.size() >= 24;},
485 "MockGatord did not receive well known timeline labels");
488 BOOST_CHECK(timelineDecoder.GetModel().m_Entities.size() == 6);
489 BOOST_CHECK(timelineDecoder.GetModel().m_EventClasses.size() == 4);
490 BOOST_CHECK(timelineDecoder.GetModel().m_Labels.size() == 34);
491 BOOST_CHECK(timelineDecoder.GetModel().m_Relationships.size() == 15);
492 BOOST_CHECK(timelineDecoder.GetModel().m_Events.size() == 0);
BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
static ARMNN_DLLEXPORT ProfilingStaticGuid INFERENCE_GUID
profiling::ProfilingService & GetProfilingService(armnn::RuntimeImpl *runtime)
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.
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()
Status LoadNetwork(NetworkId &networkIdOut, IOptimizedNetworkPtr network)
Loads a complete network into the Runtime.
uint8_t ReadUint8(const IPacketBufferPtr &packetBuffer, unsigned int offset)
Copyright (c) 2021 ARM Limited and Contributors.
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.
const IDeviceSpec & GetDeviceSpec() const
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)
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 const IInputSlot & GetInputSlot(unsigned int index) const =0
Get a const input slot handle by slot index.
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
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