ArmNN
 20.08
GatordMockTests.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include <common/include/CommandHandlerRegistry.hpp>
7 #include <server/include/basePipeServer/ConnectionHandler.hpp>
9 #include <GatordMockService.hpp>
11 #include <ProfilingService.hpp>
13 
14 #include <server/include/timelineDecoder/TimelineDirectoryCaptureCommandHandler.hpp>
15 #include <server/include/timelineDecoder/TimelineDecoder.hpp>
16 
17 #include <Runtime.hpp>
18 
19 #include <MockBackend.hpp>
20 
21 #include <boost/cast.hpp>
22 #include <boost/test/test_tools.hpp>
23 #include <boost/test/unit_test_suite.hpp>
24 
25 
26 BOOST_AUTO_TEST_SUITE(GatordMockTests)
27 
28 using namespace armnn;
29 using namespace std::this_thread;
30 using namespace std::chrono_literals;
31 
32 BOOST_AUTO_TEST_CASE(CounterCaptureHandlingTest)
33 {
34  using boost::numeric_cast;
35 
36  arm::pipe::PacketVersionResolver packetVersionResolver;
37 
38  // Data with timestamp, counter idx & counter values
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));
46 
47  // ((uint16_t (2 bytes) + uint32_t (4 bytes)) * 5) + word1 + word2
48  uint32_t dataLength = 38;
49 
50  // Simulate two different packets incoming 500 ms apart
51  uint64_t time = static_cast<uint64_t>(
52  std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now().time_since_epoch())
53  .count());
54 
55  uint64_t time2 = time + 5000;
56 
57  // UniqueData required for Packet class
58  std::unique_ptr<unsigned char[]> uniqueData1 = std::make_unique<unsigned char[]>(dataLength);
59  unsigned char* data1 = reinterpret_cast<unsigned char*>(uniqueData1.get());
60 
61  std::unique_ptr<unsigned char[]> uniqueData2 = std::make_unique<unsigned char[]>(dataLength);
62  unsigned char* data2 = reinterpret_cast<unsigned char*>(uniqueData2.get());
63 
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));
67  // Offset index to point to mem address
68  uint32_t offset = 0;
69 
70  profiling::WriteUint64(data1, offset, time);
71  offset += sizeOfUint64;
72  for (const auto& pair : indexValuePairs)
73  {
74  profiling::WriteUint16(data1, offset, pair.first);
75  offset += sizeOfUint16;
76  profiling::WriteUint32(data1, offset, pair.second);
77  offset += sizeOfUint32;
78  }
79 
80  offset = 0;
81 
82  profiling::WriteUint64(data2, offset, time2);
83  offset += sizeOfUint64;
84  for (const auto& pair : indexValuePairs)
85  {
86  profiling::WriteUint16(data2, offset, pair.first);
87  offset += sizeOfUint16;
88  profiling::WriteUint32(data2, offset, pair.second);
89  offset += sizeOfUint32;
90  }
91 
92  uint32_t headerWord1 = packetVersionResolver.ResolvePacketVersion(0, 4).GetEncodedValue();
93  // Create packet to send through to the command functor
94  arm::pipe::Packet packet1(headerWord1, dataLength, uniqueData1);
95  arm::pipe::Packet packet2(headerWord1, dataLength, uniqueData2);
96 
97  gatordmock::PeriodicCounterCaptureCommandHandler commandHandler(0, 4, headerWord1, true);
98 
99  // Simulate two separate packets coming in to calculate period
100  commandHandler(packet1);
101  commandHandler(packet2);
102 
103  ARMNN_ASSERT(commandHandler.m_CurrentPeriodValue == 5000);
104 
105  for (size_t i = 0; i < commandHandler.m_CounterCaptureValues.m_Uids.size(); ++i)
106  {
107  ARMNN_ASSERT(commandHandler.m_CounterCaptureValues.m_Uids[i] == i);
108  }
109 }
110 
111 void WaitFor(std::function<bool()> predicate, std::string errorMsg, uint32_t timeout = 2000, uint32_t sleepTime = 50)
112 {
113  uint32_t timeSlept = 0;
114  while (!predicate())
115  {
116  if (timeSlept >= timeout)
117  {
118  BOOST_FAIL("Timeout: " + errorMsg);
119  }
120  std::this_thread::sleep_for(std::chrono::milliseconds(sleepTime));
121  timeSlept += sleepTime;
122  }
123 }
124 
125 void CheckTimelineDirectory(arm::pipe::TimelineDirectoryCaptureCommandHandler& commandHandler)
126 {
127  uint32_t uint8_t_size = sizeof(uint8_t);
128  uint32_t uint32_t_size = sizeof(uint32_t);
129  uint32_t uint64_t_size = sizeof(uint64_t);
130  uint32_t threadId_size = sizeof(int);
131 
132  profiling::BufferManager bufferManager(5);
133  profiling::TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager);
134 
135  std::unique_ptr<profiling::ISendTimelinePacket> sendTimelinePacket =
136  timelinePacketWriterFactory.GetSendTimelinePacket();
137 
138  sendTimelinePacket->SendTimelineMessageDirectoryPackage();
139  sendTimelinePacket->Commit();
140 
141  std::vector<arm::pipe::SwTraceMessage> swTraceBufferMessages;
142 
143  unsigned int offset = uint32_t_size * 2;
144 
145  std::unique_ptr<profiling::IPacketBuffer> packetBuffer = bufferManager.GetReadableBuffer();
146 
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;
156 
157  uint32_t declarationSize = profiling::ReadUint32(packetBuffer, offset);
158  offset += uint32_t_size;
159  for(uint32_t i = 0; i < declarationSize; ++i)
160  {
161  swTraceBufferMessages.push_back(arm::pipe::ReadSwTraceMessage(packetBuffer->GetReadableData(),
162  offset,
163  packetBuffer->GetSize()));
164  }
165 
166  for(uint32_t index = 0; index < declarationSize; ++index)
167  {
168  arm::pipe::SwTraceMessage& bufferMessage = swTraceBufferMessages[index];
169  arm::pipe::SwTraceMessage& handlerMessage = commandHandler.m_SwTraceMessages[index];
170 
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);
174 
175  BOOST_CHECK(bufferMessage.m_ArgTypes.size() == handlerMessage.m_ArgTypes.size());
176  for(uint32_t i = 0; i < bufferMessage.m_ArgTypes.size(); ++i)
177  {
178  BOOST_CHECK(bufferMessage.m_ArgTypes[i] == handlerMessage.m_ArgTypes[i]);
179  }
180 
181  BOOST_CHECK(bufferMessage.m_ArgNames.size() == handlerMessage.m_ArgNames.size());
182  for(uint32_t i = 0; i < bufferMessage.m_ArgNames.size(); ++i)
183  {
184  BOOST_CHECK(bufferMessage.m_ArgNames[i] == handlerMessage.m_ArgNames[i]);
185  }
186  }
187 }
188 
189 void CheckTimelinePackets(arm::pipe::TimelineDecoder& timelineDecoder)
190 {
191  unsigned int i = 0; // Use a postfix increment to avoid changing indexes each time the packet gets updated.
192  BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i].m_Guid == profiling::LabelsAndEventClasses::NAME_GUID);
193  BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i++].m_Name == profiling::LabelsAndEventClasses::NAME_LABEL);
194 
195  BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i].m_Guid == profiling::LabelsAndEventClasses::TYPE_GUID);
196  BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i++].m_Name == profiling::LabelsAndEventClasses::TYPE_LABEL);
197 
198  BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i].m_Guid == profiling::LabelsAndEventClasses::INDEX_GUID);
199  BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i++].m_Name == profiling::LabelsAndEventClasses::INDEX_LABEL);
200 
201  BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i].m_Guid == profiling::LabelsAndEventClasses::BACKENDID_GUID);
202  BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i++].m_Name == profiling::LabelsAndEventClasses::BACKENDID_LABEL);
203 
204  BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i].m_Guid == profiling::LabelsAndEventClasses::CHILD_GUID);
205  BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i++].m_Name == profiling::LabelsAndEventClasses::CHILD_LABEL);
206 
207  BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i].m_Guid == profiling::LabelsAndEventClasses::EXECUTION_OF_GUID);
208  BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i++].m_Name ==
210 
211  BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i].m_Guid == profiling::LabelsAndEventClasses::PROCESS_ID_GUID);
212  BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i++].m_Name ==
214 
215  BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i].m_Guid == profiling::LabelsAndEventClasses::LAYER_GUID);
216  BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i++].m_Name == profiling::LabelsAndEventClasses::LAYER);
217 
218  BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i].m_Guid == profiling::LabelsAndEventClasses::WORKLOAD_GUID);
219  BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i++].m_Name == profiling::LabelsAndEventClasses::WORKLOAD);
220 
221  BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i].m_Guid == profiling::LabelsAndEventClasses::NETWORK_GUID);
222  BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i++].m_Name == profiling::LabelsAndEventClasses::NETWORK);
223 
224  BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i].m_Guid == profiling::LabelsAndEventClasses::CONNECTION_GUID);
225  BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i++].m_Name == profiling::LabelsAndEventClasses::CONNECTION);
226 
227  BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i].m_Guid == profiling::LabelsAndEventClasses::INFERENCE_GUID);
228  BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i++].m_Name == profiling::LabelsAndEventClasses::INFERENCE);
229 
230  BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i].m_Guid ==
232  BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i++].m_Name ==
234 
235  BOOST_CHECK(timelineDecoder.GetModel().m_EventClasses[0].m_Guid ==
237  BOOST_CHECK(timelineDecoder.GetModel().m_EventClasses[1].m_Guid ==
239 }
240 
241 BOOST_AUTO_TEST_CASE(GatorDMockEndToEnd)
242 {
243  // The purpose of this test is to setup both sides of the profiling service and get to the point of receiving
244  // performance data.
245 
246  // Setup the mock service to bind to the UDS.
247  std::string udsNamespace = "gatord_namespace";
248 
249  BOOST_CHECK_NO_THROW(arm::pipe::ConnectionHandler connectionHandler(udsNamespace, false));
250 
251  arm::pipe::ConnectionHandler connectionHandler(udsNamespace, false);
252 
253  // Enable the profiling service.
255  options.m_EnableProfiling = true;
256  options.m_TimelineEnabled = true;
257 
258  armnn::profiling::ProfilingService profilingService;
259  profilingService.ResetExternalProfilingOptions(options, true);
260 
261  // Bring the profiling service to the "WaitingForAck" state
262  BOOST_CHECK(profilingService.GetCurrentState() == profiling::ProfilingState::Uninitialised);
263  profilingService.Update();
264  BOOST_CHECK(profilingService.GetCurrentState() == profiling::ProfilingState::NotConnected);
265  profilingService.Update();
266 
267  // Connect the profiling service
268  auto basePipeServer = connectionHandler.GetNewBasePipeServer(false);
269 
270  // Connect the profiling service to the mock Gatord.
271  gatordmock::GatordMockService mockService(std::move(basePipeServer), false);
272 
273  arm::pipe::TimelineDecoder& timelineDecoder = mockService.GetTimelineDecoder();
274  profiling::DirectoryCaptureCommandHandler& directoryCaptureCommandHandler =
275  mockService.GetDirectoryCaptureCommandHandler();
276 
277  // Give the profiling service sending thread time start executing and send the stream metadata.
278  WaitFor([&](){return profilingService.GetCurrentState() == profiling::ProfilingState::WaitingForAck;},
279  "Profiling service did not switch to WaitingForAck state");
280 
281  profilingService.Update();
282  // Read the stream metadata on the mock side.
283  if (!mockService.WaitForStreamMetaData())
284  {
285  BOOST_FAIL("Failed to receive StreamMetaData");
286  }
287  // Send Ack from GatorD
288  mockService.SendConnectionAck();
289  // And start to listen for packets
290  mockService.LaunchReceivingThread();
291 
292  WaitFor([&](){return profilingService.GetCurrentState() == profiling::ProfilingState::Active;},
293  "Profiling service did not switch to Active state");
294 
295  // As part of the default startup of the profiling service a counter directory packet will be sent.
296  WaitFor([&](){return directoryCaptureCommandHandler.ParsedCounterDirectory();},
297  "MockGatord did not receive counter directory packet");
298 
299  // Following that we will receive a collection of well known timeline labels and event classes
300  WaitFor([&](){return timelineDecoder.GetModel().m_EventClasses.size() >= 2;},
301  "MockGatord did not receive well known timeline labels and event classes");
302 
304  // Verify the commonly used timeline packets sent when the profiling service enters the active state
305  CheckTimelinePackets(timelineDecoder);
306 
307  const profiling::ICounterDirectory& serviceCounterDirectory = profilingService.GetCounterDirectory();
308  const profiling::ICounterDirectory& receivedCounterDirectory = directoryCaptureCommandHandler.GetCounterDirectory();
309 
310  // Compare the basics of the counter directory from the service and the one we received over the wire.
311  BOOST_CHECK(serviceCounterDirectory.GetDeviceCount() == receivedCounterDirectory.GetDeviceCount());
312  BOOST_CHECK(serviceCounterDirectory.GetCounterSetCount() == receivedCounterDirectory.GetCounterSetCount());
313  BOOST_CHECK(serviceCounterDirectory.GetCategoryCount() == receivedCounterDirectory.GetCategoryCount());
314  BOOST_CHECK(serviceCounterDirectory.GetCounterCount() == receivedCounterDirectory.GetCounterCount());
315 
316  receivedCounterDirectory.GetDeviceCount();
317  serviceCounterDirectory.GetDeviceCount();
318 
319  const profiling::Devices& serviceDevices = serviceCounterDirectory.GetDevices();
320  for (auto& device : serviceDevices)
321  {
322  // Find the same device in the received counter directory.
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);
327  }
328 
329  const profiling::CounterSets& serviceCounterSets = serviceCounterDirectory.GetCounterSets();
330  for (auto& counterSet : serviceCounterSets)
331  {
332  // Find the same counter set in the received counter directory.
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);
337  }
338 
339  const profiling::Categories& serviceCategories = serviceCounterDirectory.GetCategories();
340  for (auto& category : serviceCategories)
341  {
342  for (auto& receivedCategory : receivedCounterDirectory.GetCategories())
343  {
344  if (receivedCategory->m_Name.compare(category->m_Name) == 0)
345  {
346  // We've found the matching category.
347  // Now look at the interiors of the counters. Start by sorting them.
348  std::sort(category->m_Counters.begin(), category->m_Counters.end());
349  std::sort(receivedCategory->m_Counters.begin(), receivedCategory->m_Counters.end());
350  // When comparing uid's here we need to translate them.
351  std::function<bool(const uint16_t&, const uint16_t&)> comparator =
352  [&directoryCaptureCommandHandler](const uint16_t& first, const uint16_t& second) {
353  uint16_t translated = directoryCaptureCommandHandler.TranslateUIDCopyToOriginal(second);
354  if (translated == first)
355  {
356  return true;
357  }
358  return false;
359  };
360  // Then let vector == do the work.
361  BOOST_CHECK(std::equal(category->m_Counters.begin(), category->m_Counters.end(),
362  receivedCategory->m_Counters.begin(), comparator));
363  break;
364  }
365  }
366  }
367 
368  // Finally check the content of the counters.
369  const profiling::Counters& receivedCounters = receivedCounterDirectory.GetCounters();
370  for (auto& receivedCounter : receivedCounters)
371  {
372  // Translate the Uid and find the corresponding counter in the original counter directory.
373  // Note we can't check m_MaxCounterUid here as it will likely differ between the two counter directories.
374  uint16_t translated = directoryCaptureCommandHandler.TranslateUIDCopyToOriginal(receivedCounter.first);
375  const profiling::Counter* serviceCounter = serviceCounterDirectory.GetCounter(translated);
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);
384  }
385 
386  mockService.WaitForReceivingThread();
387  options.m_EnableProfiling = false;
388  profilingService.ResetExternalProfilingOptions(options, true);
389  // Future tests here will add counters to the ProfilingService, increment values and examine
390  // PeriodicCounterCapture data received. These are yet to be integrated.
391 }
392 
393 BOOST_AUTO_TEST_CASE(GatorDMockTimeLineActivation)
394 {
395  // This test requires the CpuRef backend to be enabled
396  if(!BackendRegistryInstance().IsBackendRegistered("CpuRef"))
397  {
398  return;
399  }
400  armnn::MockBackendInitialiser initialiser;
401  // Setup the mock service to bind to the UDS.
402  std::string udsNamespace = "gatord_namespace";
403 
404  arm::pipe::ConnectionHandler connectionHandler(udsNamespace, false);
405 
407  options.m_ProfilingOptions.m_EnableProfiling = true;
408  options.m_ProfilingOptions.m_TimelineEnabled = true;
409  armnn::Runtime runtime(options);
410 
411  auto basePipeServer = connectionHandler.GetNewBasePipeServer(false);
412  gatordmock::GatordMockService mockService(std::move(basePipeServer), false);
413 
414  // Read the stream metadata on the mock side.
415  if (!mockService.WaitForStreamMetaData())
416  {
417  BOOST_FAIL("Failed to receive StreamMetaData");
418  }
419 
421  armnn::MockBackendProfilingContext *mockBackEndProfilingContext = mockProfilingService.GetContext();
422 
423  // Send Ack from GatorD
424  mockService.SendConnectionAck();
425  // And start to listen for packets
426  mockService.LaunchReceivingThread();
427 
428  // Build and optimize a simple network while we wait
430 
431  IConnectableLayer* input = net->AddInputLayer(0, "input");
432 
433  NormalizationDescriptor descriptor;
434  IConnectableLayer* normalize = net->AddNormalizationLayer(descriptor, "normalization");
435 
436  IConnectableLayer* output = net->AddOutputLayer(0, "output");
437 
438  input->GetOutputSlot(0).Connect(normalize->GetInputSlot(0));
439  normalize->GetOutputSlot(0).Connect(output->GetInputSlot(0));
440 
441  input->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
442  normalize->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
443 
444  std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
445  IOptimizedNetworkPtr optNet = Optimize(*net, backends, runtime.GetDeviceSpec());
446 
448  "MockGatord did not receive counter directory packet");
449 
450  arm::pipe::TimelineDecoder& timelineDecoder = mockService.GetTimelineDecoder();
451 
452  WaitFor([&](){return timelineDecoder.GetModel().m_EventClasses.size() >= 2;},
453  "MockGatord did not receive well known timeline labels");
454 
455  WaitFor([&](){return timelineDecoder.GetModel().m_Entities.size() >= 1;},
456  "MockGatord did not receive mock backend test entity");
457 
458  // Packets we expect from SendWellKnownLabelsAndEventClassesTest
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);
464 
465  mockService.SendDeactivateTimelinePacket();
466 
467  WaitFor([&](){return !mockBackEndProfilingContext->TimelineReportingEnabled();},
468  "Timeline packets were not deactivated");
469 
470  // Load the network into runtime now that timeline reporting is disabled
471  armnn::NetworkId netId;
472  runtime.LoadNetwork(netId, std::move(optNet));
473 
474  // Now activate timeline packets
475  mockService.SendActivateTimelinePacket();
476 
477  WaitFor([&](){return mockBackEndProfilingContext->TimelineReportingEnabled();},
478  "Timeline packets were not activated");
479 
480  // Once TimelineReporting is Enabled additional activateTimelinePackets should be ignored
481  mockService.SendActivateTimelinePacket();
482  mockService.SendActivateTimelinePacket();
483 
484  // Once timeline packets have been reactivated the ActivateTimelineReportingCommandHandler will resend the
485  // SendWellKnownLabelsAndEventClasses and then send the structure of any loaded networks
486  WaitFor([&](){return timelineDecoder.GetModel().m_Labels.size() >= 24;},
487  "MockGatord did not receive well known timeline labels");
488 
489  // Packets we expect from SendWellKnownLabelsAndEventClassesTest * 2 + network above (input, norm, backend, output)
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);
495 
496  mockService.WaitForReceivingThread();
497  GetProfilingService(&runtime).Disconnect();
498 }
499 
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.
Definition: INetwork.hpp:61
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
Definition: Runtime.hpp:71
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()
int NetworkId
Definition: IRuntime.hpp:20
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
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.
Definition: Network.cpp:1014
profiling::ProfilingService & GetProfilingService(armnn::Runtime *runtime)
Definition: TestUtils.cpp:25
static ARMNN_DLLEXPORT ProfilingStaticGuid EXECUTION_OF_GUID
static ARMNN_DLLEXPORT std::string WORKLOAD
std::unique_ptr< IOptimizedNetwork, void(*)(IOptimizedNetwork *network)> IOptimizedNetworkPtr
Definition: INetwork.hpp:593
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)
Definition: Assert.hpp:14
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
Definition: NumericCast.hpp:33
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()
virtual const Counter * GetCounter(uint16_t uid) const =0
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
static ARMNN_DLLEXPORT ProfilingStaticGuid TYPE_GUID
virtual Status LoadNetwork(NetworkId &networkIdOut, IOptimizedNetworkPtr network) override
Loads a complete network into the Runtime.
Definition: Runtime.cpp:47
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
Definition: INetwork.hpp:101
virtual int Connect(IInputSlot &destination)=0
std::unique_ptr< ISendTimelinePacket > GetSendTimelinePacket() const
static ARMNN_DLLEXPORT ProfilingStaticGuid PROCESS_ID_GUID
A NormalizationDescriptor for the NormalizationLayer.
ExternalProfilingOptions m_ProfilingOptions
Definition: IRuntime.hpp:83
const ICounterDirectory & GetCounterDirectory() const
static INetworkPtr Create(NetworkOptions networkOptions={})
Definition: Network.cpp:50
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