ArmNN
 22.02
GatordMockTests.cpp File Reference
#include <DirectoryCaptureCommandHandler.hpp>
#include <GatordMockService.hpp>
#include <ProfilingService.hpp>
#include <TimelinePacketWriterFactory.hpp>
#include <Runtime.hpp>
#include <MockBackend.hpp>
#include <common/include/LabelsAndEventClasses.hpp>
#include <common/include/CommandHandlerRegistry.hpp>
#include <armnn/utility/Assert.hpp>
#include <armnn/utility/NumericCast.hpp>
#include <server/include/timelineDecoder/TimelineDirectoryCaptureCommandHandler.hpp>
#include <server/include/timelineDecoder/TimelineDecoder.hpp>
#include <server/include/basePipeServer/ConnectionHandler.hpp>
#include <doctest/doctest.h>

Go to the source code of this file.

Functions

 TEST_SUITE ("GatordMockTests")
 

Function Documentation

◆ TEST_SUITE()

TEST_SUITE ( "GatordMockTests"  )

Definition at line 25 of file GatordMockTests.cpp.

References ARMNN_ASSERT, BufferManager::GetReadableBuffer(), TimelinePacketWriterFactory::GetSendTimelinePacket(), PeriodicCounterCaptureCommandHandler::m_CounterCaptureValues, PeriodicCounterCaptureCommandHandler::m_CurrentPeriodValue, CounterCaptureValues::m_Uids, armnn::numeric_cast(), armnn::profiling::ReadUint32(), armnn::profiling::ReadUint8(), armnn::profiling::uint32_t_size, armnn::profiling::WriteUint16(), armnn::profiling::WriteUint32(), and armnn::profiling::WriteUint64().

26 {
27 using namespace armnn;
28 using namespace std::this_thread;
29 using namespace std::chrono_literals;
30 
31 TEST_CASE("CounterCaptureHandlingTest")
32 {
33  arm::pipe::PacketVersionResolver packetVersionResolver;
34 
35  // Data with timestamp, counter idx & counter values
36  std::vector<std::pair<uint16_t, uint32_t>> indexValuePairs;
37  indexValuePairs.reserve(5);
38  indexValuePairs.emplace_back(std::make_pair<uint16_t, uint32_t>(0, 100));
39  indexValuePairs.emplace_back(std::make_pair<uint16_t, uint32_t>(1, 200));
40  indexValuePairs.emplace_back(std::make_pair<uint16_t, uint32_t>(2, 300));
41  indexValuePairs.emplace_back(std::make_pair<uint16_t, uint32_t>(3, 400));
42  indexValuePairs.emplace_back(std::make_pair<uint16_t, uint32_t>(4, 500));
43 
44  // ((uint16_t (2 bytes) + uint32_t (4 bytes)) * 5) + word1 + word2
45  uint32_t dataLength = 38;
46 
47  // Simulate two different packets incoming 500 ms apart
48  uint64_t time = static_cast<uint64_t>(
49  std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now().time_since_epoch())
50  .count());
51 
52  uint64_t time2 = time + 5000;
53 
54  // UniqueData required for Packet class
55  std::unique_ptr<unsigned char[]> uniqueData1 = std::make_unique<unsigned char[]>(dataLength);
56  unsigned char* data1 = reinterpret_cast<unsigned char*>(uniqueData1.get());
57 
58  std::unique_ptr<unsigned char[]> uniqueData2 = std::make_unique<unsigned char[]>(dataLength);
59  unsigned char* data2 = reinterpret_cast<unsigned char*>(uniqueData2.get());
60 
61  uint32_t sizeOfUint64 = armnn::numeric_cast<uint32_t>(sizeof(uint64_t));
62  uint32_t sizeOfUint32 = armnn::numeric_cast<uint32_t>(sizeof(uint32_t));
63  uint32_t sizeOfUint16 = armnn::numeric_cast<uint32_t>(sizeof(uint16_t));
64  // Offset index to point to mem address
65  uint32_t offset = 0;
66 
67  profiling::WriteUint64(data1, offset, time);
68  offset += sizeOfUint64;
69  for (const auto& pair : indexValuePairs)
70  {
71  profiling::WriteUint16(data1, offset, pair.first);
72  offset += sizeOfUint16;
73  profiling::WriteUint32(data1, offset, pair.second);
74  offset += sizeOfUint32;
75  }
76 
77  offset = 0;
78 
79  profiling::WriteUint64(data2, offset, time2);
80  offset += sizeOfUint64;
81  for (const auto& pair : indexValuePairs)
82  {
83  profiling::WriteUint16(data2, offset, pair.first);
84  offset += sizeOfUint16;
85  profiling::WriteUint32(data2, offset, pair.second);
86  offset += sizeOfUint32;
87  }
88 
89  uint32_t headerWord1 = packetVersionResolver.ResolvePacketVersion(0, 4).GetEncodedValue();
90  // Create packet to send through to the command functor
91  arm::pipe::Packet packet1(headerWord1, dataLength, uniqueData1);
92  arm::pipe::Packet packet2(headerWord1, dataLength, uniqueData2);
93 
94  gatordmock::PeriodicCounterCaptureCommandHandler commandHandler(0, 4, headerWord1, true);
95 
96  // Simulate two separate packets coming in to calculate period
97  commandHandler(packet1);
98  commandHandler(packet2);
99 
100  ARMNN_ASSERT(commandHandler.m_CurrentPeriodValue == 5000);
101 
102  for (size_t i = 0; i < commandHandler.m_CounterCaptureValues.m_Uids.size(); ++i)
103  {
104  ARMNN_ASSERT(commandHandler.m_CounterCaptureValues.m_Uids[i] == i);
105  }
106 }
107 
108 void WaitFor(std::function<bool()> predicate, std::string errorMsg, uint32_t timeout = 2000, uint32_t sleepTime = 50)
109 {
110  uint32_t timeSlept = 0;
111  while (!predicate())
112  {
113  if (timeSlept >= timeout)
114  {
115  FAIL("Timeout: " << errorMsg);
116  }
117  std::this_thread::sleep_for(std::chrono::milliseconds(sleepTime));
118  timeSlept += sleepTime;
119  }
120 }
121 
122 void CheckTimelineDirectory(arm::pipe::TimelineDirectoryCaptureCommandHandler& commandHandler)
123 {
124  uint32_t uint8_t_size = sizeof(uint8_t);
125  uint32_t uint32_t_size = sizeof(uint32_t);
126  uint32_t uint64_t_size = sizeof(uint64_t);
127  uint32_t threadId_size = sizeof(int);
128 
129  profiling::BufferManager bufferManager(5);
130  profiling::TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager);
131 
132  std::unique_ptr<profiling::ISendTimelinePacket> sendTimelinePacket =
133  timelinePacketWriterFactory.GetSendTimelinePacket();
134 
135  sendTimelinePacket->SendTimelineMessageDirectoryPackage();
136  sendTimelinePacket->Commit();
137 
138  std::vector<arm::pipe::SwTraceMessage> swTraceBufferMessages;
139 
140  unsigned int offset = uint32_t_size * 2;
141 
142  std::unique_ptr<profiling::IPacketBuffer> packetBuffer = bufferManager.GetReadableBuffer();
143 
144  uint8_t readStreamVersion = ReadUint8(packetBuffer, offset);
145  CHECK(readStreamVersion == 4);
146  offset += uint8_t_size;
147  uint8_t readPointerBytes = ReadUint8(packetBuffer, offset);
148  CHECK(readPointerBytes == uint64_t_size);
149  offset += uint8_t_size;
150  uint8_t readThreadIdBytes = ReadUint8(packetBuffer, offset);
151  CHECK(readThreadIdBytes == threadId_size);
152  offset += uint8_t_size;
153 
154  uint32_t declarationSize = profiling::ReadUint32(packetBuffer, offset);
155  offset += uint32_t_size;
156  for(uint32_t i = 0; i < declarationSize; ++i)
157  {
158  swTraceBufferMessages.push_back(arm::pipe::ReadSwTraceMessage(packetBuffer->GetReadableData(),
159  offset,
160  packetBuffer->GetSize()));
161  }
162 
163  for(uint32_t index = 0; index < declarationSize; ++index)
164  {
165  arm::pipe::SwTraceMessage& bufferMessage = swTraceBufferMessages[index];
166  arm::pipe::SwTraceMessage& handlerMessage = commandHandler.m_SwTraceMessages[index];
167 
168  CHECK(bufferMessage.m_Name == handlerMessage.m_Name);
169  CHECK(bufferMessage.m_UiName == handlerMessage.m_UiName);
170  CHECK(bufferMessage.m_Id == handlerMessage.m_Id);
171 
172  CHECK(bufferMessage.m_ArgTypes.size() == handlerMessage.m_ArgTypes.size());
173  for(uint32_t i = 0; i < bufferMessage.m_ArgTypes.size(); ++i)
174  {
175  CHECK(bufferMessage.m_ArgTypes[i] == handlerMessage.m_ArgTypes[i]);
176  }
177 
178  CHECK(bufferMessage.m_ArgNames.size() == handlerMessage.m_ArgNames.size());
179  for(uint32_t i = 0; i < bufferMessage.m_ArgNames.size(); ++i)
180  {
181  CHECK(bufferMessage.m_ArgNames[i] == handlerMessage.m_ArgNames[i]);
182  }
183  }
184 }
185 
186 void CheckTimelinePackets(arm::pipe::TimelineDecoder& timelineDecoder)
187 {
188  unsigned int i = 0; // Use a postfix increment to avoid changing indexes each time the packet gets updated.
189  timelineDecoder.ApplyToModel([&](arm::pipe::TimelineDecoder::Model& m) {
190  CHECK(m.m_Labels[i].m_Guid == profiling::LabelsAndEventClasses::NAME_GUID);
191  CHECK(m.m_Labels[i++].m_Name == profiling::LabelsAndEventClasses::NAME_LABEL);
192 
193  CHECK(m.m_Labels[i].m_Guid == profiling::LabelsAndEventClasses::TYPE_GUID);
194  CHECK(m.m_Labels[i++].m_Name == profiling::LabelsAndEventClasses::TYPE_LABEL);
195 
196  CHECK(m.m_Labels[i].m_Guid == profiling::LabelsAndEventClasses::INDEX_GUID);
197  CHECK(m.m_Labels[i++].m_Name == profiling::LabelsAndEventClasses::INDEX_LABEL);
198 
199  CHECK(m.m_Labels[i].m_Guid == profiling::LabelsAndEventClasses::BACKENDID_GUID);
200  CHECK(m.m_Labels[i++].m_Name == profiling::LabelsAndEventClasses::BACKENDID_LABEL);
201 
202  CHECK(m.m_Labels[i].m_Guid == profiling::LabelsAndEventClasses::CHILD_GUID);
203  CHECK(m.m_Labels[i++].m_Name == profiling::LabelsAndEventClasses::CHILD_LABEL);
204 
205  CHECK(m.m_Labels[i].m_Guid == profiling::LabelsAndEventClasses::EXECUTION_OF_GUID);
206  CHECK(m.m_Labels[i++].m_Name ==
207  profiling::LabelsAndEventClasses::EXECUTION_OF_LABEL);
208 
209  CHECK(m.m_Labels[i].m_Guid == profiling::LabelsAndEventClasses::PROCESS_ID_GUID);
210  CHECK(m.m_Labels[i++].m_Name ==
211  profiling::LabelsAndEventClasses::PROCESS_ID_LABEL);
212 
213  CHECK(m.m_Labels[i].m_Guid == profiling::LabelsAndEventClasses::LAYER_GUID);
214  CHECK(m.m_Labels[i++].m_Name == profiling::LabelsAndEventClasses::LAYER);
215 
216  CHECK(m.m_Labels[i].m_Guid == profiling::LabelsAndEventClasses::WORKLOAD_GUID);
217  CHECK(m.m_Labels[i++].m_Name == profiling::LabelsAndEventClasses::WORKLOAD);
218 
219  CHECK(m.m_Labels[i].m_Guid == profiling::LabelsAndEventClasses::NETWORK_GUID);
220  CHECK(m.m_Labels[i++].m_Name == profiling::LabelsAndEventClasses::NETWORK);
221 
222  CHECK(m.m_Labels[i].m_Guid == profiling::LabelsAndEventClasses::CONNECTION_GUID);
223  CHECK(m.m_Labels[i++].m_Name == profiling::LabelsAndEventClasses::CONNECTION);
224 
225  CHECK(m.m_Labels[i].m_Guid == profiling::LabelsAndEventClasses::INFERENCE_GUID);
226  CHECK(m.m_Labels[i++].m_Name == profiling::LabelsAndEventClasses::INFERENCE);
227 
228  CHECK(m.m_Labels[i].m_Guid ==
229  profiling::LabelsAndEventClasses::WORKLOAD_EXECUTION_GUID);
230  CHECK(m.m_Labels[i++].m_Name ==
231  profiling::LabelsAndEventClasses::WORKLOAD_EXECUTION);
232 
233  CHECK(m.m_EventClasses[0].m_Guid ==
234  profiling::LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS);
235  CHECK(m.m_EventClasses[1].m_Guid ==
236  profiling::LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS);
237  });
238 }
239 
240 TEST_CASE("GatorDMockEndToEnd")
241 {
242  // The purpose of this test is to setup both sides of the profiling service and get to the point of receiving
243  // performance data.
244 
245  // Setup the mock service to bind to the UDS.
246  std::string udsNamespace = "gatord_namespace";
247 
248  CHECK_NOTHROW(arm::pipe::ConnectionHandler connectionHandler(udsNamespace, false));
249 
250  arm::pipe::ConnectionHandler connectionHandler(udsNamespace, false);
251 
252  // Enable the profiling service.
254  options.m_EnableProfiling = true;
255  options.m_TimelineEnabled = true;
256 
257  armnn::profiling::ProfilingService profilingService;
258  profilingService.ResetExternalProfilingOptions(options, true);
259 
260  // Bring the profiling service to the "WaitingForAck" state
261  CHECK(profilingService.GetCurrentState() == profiling::ProfilingState::Uninitialised);
262  profilingService.Update();
263  CHECK(profilingService.GetCurrentState() == profiling::ProfilingState::NotConnected);
264  profilingService.Update();
265 
266  // Connect the profiling service
267  auto basePipeServer = connectionHandler.GetNewBasePipeServer(false);
268 
269  // Connect the profiling service to the mock Gatord.
270  gatordmock::GatordMockService mockService(std::move(basePipeServer), false);
271 
272  arm::pipe::TimelineDecoder& timelineDecoder = mockService.GetTimelineDecoder();
273  profiling::DirectoryCaptureCommandHandler& directoryCaptureCommandHandler =
274  mockService.GetDirectoryCaptureCommandHandler();
275 
276  // Give the profiling service sending thread time start executing and send the stream metadata.
277  WaitFor([&](){return profilingService.GetCurrentState() == profiling::ProfilingState::WaitingForAck;},
278  "Profiling service did not switch to WaitingForAck state");
279 
280  profilingService.Update();
281  // Read the stream metadata on the mock side.
282  if (!mockService.WaitForStreamMetaData())
283  {
284  FAIL("Failed to receive StreamMetaData");
285  }
286  // Send Ack from GatorD
287  mockService.SendConnectionAck();
288  // And start to listen for packets
289  mockService.LaunchReceivingThread();
290 
291  WaitFor([&](){return profilingService.GetCurrentState() == profiling::ProfilingState::Active;},
292  "Profiling service did not switch to Active state");
293 
294  // As part of the default startup of the profiling service a counter directory packet will be sent.
295  WaitFor([&](){return directoryCaptureCommandHandler.ParsedCounterDirectory();},
296  "MockGatord did not receive counter directory packet");
297 
298  // Following that we will receive a collection of well known timeline labels and event classes
299  WaitFor([&](){return timelineDecoder.ApplyToModel([&](arm::pipe::TimelineDecoder::Model& m){
300  return m.m_EventClasses.size() >= 2;});},
301  "MockGatord did not receive well known timeline labels and event classes");
302 
303  CheckTimelineDirectory(mockService.GetTimelineDirectoryCaptureCommandHandler());
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  CHECK(serviceCounterDirectory.GetDeviceCount() == receivedCounterDirectory.GetDeviceCount());
312  CHECK(serviceCounterDirectory.GetCounterSetCount() == receivedCounterDirectory.GetCounterSetCount());
313  CHECK(serviceCounterDirectory.GetCategoryCount() == receivedCounterDirectory.GetCategoryCount());
314  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  CHECK(foundDevice != receivedCounterDirectory.GetDevices().end());
325  CHECK(device.second->m_Name.compare((*foundDevice).second->m_Name) == 0);
326  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  CHECK(foundCounterSet != receivedCounterDirectory.GetCounterSets().end());
335  CHECK(counterSet.second->m_Name.compare((*foundCounterSet).second->m_Name) == 0);
336  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  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  CHECK(serviceCounter->m_DeviceUid == receivedCounter.second->m_DeviceUid);
377  CHECK(serviceCounter->m_Name.compare(receivedCounter.second->m_Name) == 0);
378  CHECK(serviceCounter->m_CounterSetUid == receivedCounter.second->m_CounterSetUid);
379  CHECK(serviceCounter->m_Multiplier == receivedCounter.second->m_Multiplier);
380  CHECK(serviceCounter->m_Interpolation == receivedCounter.second->m_Interpolation);
381  CHECK(serviceCounter->m_Class == receivedCounter.second->m_Class);
382  CHECK(serviceCounter->m_Units.compare(receivedCounter.second->m_Units) == 0);
383  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 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::RuntimeImpl 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  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 
447  WaitFor([&](){return mockService.GetDirectoryCaptureCommandHandler().ParsedCounterDirectory();},
448  "MockGatord did not receive counter directory packet");
449 
450  arm::pipe::TimelineDecoder& timelineDecoder = mockService.GetTimelineDecoder();
451 
452  WaitFor([&](){return timelineDecoder.ApplyToModel([&](arm::pipe::TimelineDecoder::Model& m){
453  return m.m_EventClasses.size() >= 2;});},
454  "MockGatord did not receive well known timeline labels");
455 
456  WaitFor([&](){return timelineDecoder.ApplyToModel([&](arm::pipe::TimelineDecoder::Model& m){
457  return m.m_Entities.size() >= 1;});},
458  "MockGatord did not receive mock backend test entity");
459 
460  // Packets we expect from SendWellKnownLabelsAndEventClassesTest
461  timelineDecoder.ApplyToModel([&](const arm::pipe::TimelineDecoder::Model& m){
462  CHECK(m.m_Entities.size() == 1);
463  CHECK(m.m_EventClasses.size() == 2);
464  CHECK(m.m_Labels.size() == 15);
465  CHECK(m.m_Relationships.size() == 0);
466  CHECK(m.m_Events.size() == 0);
467  });
468 
469  mockService.SendDeactivateTimelinePacket();
470 
471  WaitFor([&](){return !mockBackEndProfilingContext->TimelineReportingEnabled();},
472  "Timeline packets were not deactivated");
473 
474  // Load the network into runtime now that timeline reporting is disabled
475  armnn::NetworkId netId;
476  runtime.LoadNetwork(netId, std::move(optNet));
477 
478  // Now activate timeline packets
479  mockService.SendActivateTimelinePacket();
480 
481  WaitFor([&](){return mockBackEndProfilingContext->TimelineReportingEnabled();},
482  "Timeline packets were not activated");
483 
484  // Once TimelineReporting is Enabled additional activateTimelinePackets should be ignored
485  mockService.SendActivateTimelinePacket();
486  mockService.SendActivateTimelinePacket();
487 
488  // Once timeline packets have been reactivated the ActivateTimelineReportingCommandHandler will resend the
489  // SendWellKnownLabelsAndEventClasses and then send the structure of any loaded networks
490  WaitFor([&](){return timelineDecoder.ApplyToModel([&](arm::pipe::TimelineDecoder::Model& m){
491  return m.m_Labels.size() >= 24;});},
492  "MockGatord did not receive well known timeline labels");
493 
494  // Packets we expect from SendWellKnownLabelsAndEventClassesTest * 2 + network above (input, norm, backend, output)
495  timelineDecoder.ApplyToModel([&](const arm::pipe::TimelineDecoder::Model& m){
496  CHECK(m.m_Entities.size() == 6);
497  CHECK(m.m_EventClasses.size() == 4);
498  CHECK(m.m_Labels.size() == 34);
499  CHECK(m.m_Relationships.size() == 15);
500  CHECK(m.m_Events.size() == 0);
501  });
502 
503  mockService.WaitForReceivingThread();
504  GetProfilingService(&runtime).Disconnect();
505 }
506 
507 }
profiling::ProfilingService & GetProfilingService(armnn::RuntimeImpl *runtime)
Definition: TestUtils.cpp:57
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
Definition: INetwork.hpp:66
CPU Execution: Reference C++ kernels.
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
virtual uint16_t GetCounterCount() const =0
BackendRegistry & BackendRegistryInstance()
uint8_t ReadUint8(const IPacketBufferPtr &packetBuffer, unsigned int offset)
Copyright (c) 2021 ARM Limited and Contributors.
virtual const CounterSets & GetCounterSets() const =0
virtual uint16_t GetCategoryCount() const =0
bool m_EnableProfiling
Indicates whether external profiling is enabled or not.
Definition: IRuntime.hpp:136
virtual void SetTensorInfo(const TensorInfo &tensorInfo)=0
std::unordered_map< uint16_t, CounterSetPtr > CounterSets
virtual const Categories & GetCategories() const =0
virtual const Devices & GetDevices() const =0
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:1680
int NetworkId
Definition: IRuntime.hpp:25
std::unique_ptr< IOptimizedNetwork, void(*)(IOptimizedNetwork *network)> IOptimizedNetworkPtr
Definition: INetwork.hpp:242
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
virtual uint16_t GetDeviceCount() const =0
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14
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
virtual uint16_t GetCounterSetCount() const =0
A class that implements a Mock Gatord server.
MockBackendProfilingContext * GetContext()
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
bool m_TimelineEnabled
Indicates whether external timeline profiling is enabled or not.
Definition: IRuntime.hpp:138
virtual const IOutputSlot & GetOutputSlot(unsigned int index) const =0
Get the const output slot handle by slot index.
virtual const Counters & GetCounters() const =0
std::unordered_map< uint16_t, DevicePtr > Devices
std::unique_ptr< INetwork, void(*)(INetwork *network)> INetworkPtr
Definition: INetwork.hpp:241
virtual int Connect(IInputSlot &destination)=0
A NormalizationDescriptor for the NormalizationLayer.
ExternalProfilingOptions m_ProfilingOptions
Definition: IRuntime.hpp:151
const ICounterDirectory & GetCounterDirectory() const
static INetworkPtr Create(NetworkOptions networkOptions={})
Definition: Network.cpp:492