7 #include <ConnectionHandler.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;
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;
94 profiling::Packet packet1(headerWord1, dataLength, uniqueData1);
95 profiling::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(std::thread::id);
135 std::unique_ptr<profiling::ISendTimelinePacket> sendTimelinePacket =
138 sendTimelinePacket->SendTimelineMessageDirectoryPackage();
139 sendTimelinePacket->Commit();
141 std::vector<profiling::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);
149 offset += uint8_t_size;
150 uint8_t readPointerBytes =
ReadUint8(packetBuffer, offset);
152 offset += uint8_t_size;
153 uint8_t readThreadIdBytes =
ReadUint8(packetBuffer, offset);
155 offset += uint8_t_size;
159 for(uint32_t i = 0; i < declarationSize; ++i)
164 for(uint32_t index = 0; index < declarationSize; ++index)
174 for(uint32_t i = 0; i < bufferMessage.
m_ArgTypes.size(); ++i)
180 for(uint32_t i = 0; i < bufferMessage.
m_ArgNames.size(); ++i)
232 std::string udsNamespace =
"gatord_namespace";
234 BOOST_CHECK_NO_THROW(armnnProfiling::ConnectionHandler connectionHandler(udsNamespace,
false));
236 armnnProfiling::ConnectionHandler connectionHandler(udsNamespace,
false);
248 profilingService.
Update();
250 profilingService.
Update();
253 auto basePipeServer = connectionHandler.GetNewBasePipeServer(
false);
264 "Profiling service did not switch to WaitingForAck state");
266 profilingService.
Update();
270 BOOST_FAIL(
"Failed to receive StreamMetaData");
278 "Profiling service did not switch to Active state");
282 "MockGatord did not receive counter directory packet");
286 "MockGatord did not receive well known timeline labels and event classes");
305 for (
auto& device : serviceDevices)
308 auto foundDevice = receivedCounterDirectory.
GetDevices().find(device.second->m_Uid);
310 BOOST_CHECK(device.second->m_Name.compare((*foundDevice).second->m_Name) == 0);
311 BOOST_CHECK(device.second->m_Cores == (*foundDevice).second->m_Cores);
315 for (
auto& counterSet : serviceCounterSets)
318 auto foundCounterSet = receivedCounterDirectory.
GetCounterSets().find(counterSet.second->m_Uid);
320 BOOST_CHECK(counterSet.second->m_Name.compare((*foundCounterSet).second->m_Name) == 0);
321 BOOST_CHECK(counterSet.second->m_Count == (*foundCounterSet).second->m_Count);
325 for (
auto& category : serviceCategories)
327 for (
auto& receivedCategory : receivedCounterDirectory.
GetCategories())
329 if (receivedCategory->m_Name.compare(category->m_Name) == 0)
333 std::sort(category->m_Counters.begin(), category->m_Counters.end());
334 std::sort(receivedCategory->m_Counters.begin(), receivedCategory->m_Counters.end());
336 std::function<bool(const uint16_t&, const uint16_t&)> comparator =
337 [&directoryCaptureCommandHandler](
const uint16_t& first,
const uint16_t& second) {
339 if (translated == first)
346 BOOST_CHECK(std::equal(category->m_Counters.begin(), category->m_Counters.end(),
347 receivedCategory->m_Counters.begin(), comparator));
355 for (
auto& receivedCounter : receivedCounters)
362 BOOST_CHECK(serviceCounter->
m_Name.compare(receivedCounter.second->m_Name) == 0);
387 std::string udsNamespace =
"gatord_namespace";
389 armnnProfiling::ConnectionHandler connectionHandler(udsNamespace,
false);
396 auto basePipeServer = connectionHandler.GetNewBasePipeServer(
false);
402 BOOST_FAIL(
"Failed to receive StreamMetaData");
419 IConnectableLayer* normalize = net->AddNormalizationLayer(descriptor,
"normalization");
433 "MockGatord did not receive counter directory packet");
437 WaitFor([&](){
return timelineDecoder.GetModel().m_EventClasses.size() >= 2;},
438 "MockGatord did not receive well known timeline labels");
440 WaitFor([&](){
return timelineDecoder.GetModel().m_Entities.size() >= 1;},
441 "MockGatord did not receive mock backend test entity");
444 BOOST_CHECK(timelineDecoder.GetModel().m_Entities.size() == 1);
445 BOOST_CHECK(timelineDecoder.GetModel().m_EventClasses.size() == 2);
446 BOOST_CHECK(timelineDecoder.GetModel().m_Labels.size() == 10);
447 BOOST_CHECK(timelineDecoder.GetModel().m_Relationships.size() == 0);
448 BOOST_CHECK(timelineDecoder.GetModel().m_Events.size() == 0);
453 "Timeline packets were not deactivated");
463 "Timeline packets were not activated");
467 WaitFor([&](){
return timelineDecoder.GetModel().m_Labels.size() >= 24;},
468 "MockGatord did not receive well known timeline labels");
471 BOOST_CHECK(timelineDecoder.GetModel().m_Entities.size() == 6);
472 BOOST_CHECK(timelineDecoder.GetModel().m_EventClasses.size() == 4);
473 BOOST_CHECK(timelineDecoder.GetModel().m_Labels.size() == 24);
474 BOOST_CHECK(timelineDecoder.GetModel().m_Relationships.size() == 28);
475 BOOST_CHECK(timelineDecoder.GetModel().m_Events.size() == 0);
BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
static ARMNN_DLLEXPORT ProfilingStaticGuid INFERENCE_GUID
void CheckTimelinePackets(timelinedecoder::TimelineDecoder &timelineDecoder)
void CheckTimelineDirectory(timelinedecoder::TimelineDirectoryCaptureCommandHandler &commandHandler)
uint32_t GetEncodedValue()
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.
ProfilingState GetCurrentState() const
std::vector< Label > m_Labels
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
Version ResolvePacketVersion(uint32_t familyId, uint32_t packetId) const
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
timelinedecoder::TimelineDirectoryCaptureCommandHandler & GetTimelineDirectoryCaptureCommandHandler()
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
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
static ARMNN_DLLEXPORT ProfilingStaticGuid WORKLOAD_EXECUTION_GUID
bool ParsedCounterDirectory()
static ARMNN_DLLEXPORT ProfilingStaticGuid ARMNN_PROFILING_EOL_EVENT_CLASS
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.
SwTraceMessage ReadSwTraceMessage(const unsigned char *packetBuffer, unsigned int &offset)
std::vector< profiling::SwTraceMessage > m_SwTraceMessages
virtual const Devices & GetDevices() const =0
static ARMNN_DLLEXPORT ProfilingStaticGuid LAYER_GUID
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)
std::vector< std::string > m_ArgNames
std::vector< char > m_ArgTypes
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::vector< EventClass > m_EventClasses
armnn::profiling::ProfilingService profilingService
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 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
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
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
timelinedecoder::TimelineDecoder & GetTimelineDecoder()
const ICounterDirectory & GetCounterDirectory() const
A NormalizationDescriptor for the NormalizationLayer.
ExternalProfilingOptions m_ProfilingOptions
const ICounterDirectory & GetCounterDirectory() const
static ARMNN_DLLEXPORT ProfilingStaticGuid BACKENDID_GUID
static INetworkPtr Create()
void SendConnectionAck()
Send a connection acknowledged packet back to the client.
static ARMNN_DLLEXPORT std::string INFERENCE
static ARMNN_DLLEXPORT std::string LAYER