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