ArmNN
 21.11
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 
7 #include <GatordMockService.hpp>
8 #include <ProfilingService.hpp>
10 #include <Runtime.hpp>
11 #include <MockBackend.hpp>
12 
13 #include <common/include/LabelsAndEventClasses.hpp>
14 #include <common/include/CommandHandlerRegistry.hpp>
15 
16 #include <armnn/utility/Assert.hpp>
18 
19 #include <server/include/timelineDecoder/TimelineDirectoryCaptureCommandHandler.hpp>
20 #include <server/include/timelineDecoder/TimelineDecoder.hpp>
21 #include <server/include/basePipeServer/ConnectionHandler.hpp>
22 
23 #include <doctest/doctest.h>
24 
25 TEST_SUITE("GatordMockTests")
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  CHECK(timelineDecoder.GetModel().m_Labels[i].m_Guid == profiling::LabelsAndEventClasses::NAME_GUID);
190  CHECK(timelineDecoder.GetModel().m_Labels[i++].m_Name == profiling::LabelsAndEventClasses::NAME_LABEL);
191 
192  CHECK(timelineDecoder.GetModel().m_Labels[i].m_Guid == profiling::LabelsAndEventClasses::TYPE_GUID);
193  CHECK(timelineDecoder.GetModel().m_Labels[i++].m_Name == profiling::LabelsAndEventClasses::TYPE_LABEL);
194 
195  CHECK(timelineDecoder.GetModel().m_Labels[i].m_Guid == profiling::LabelsAndEventClasses::INDEX_GUID);
196  CHECK(timelineDecoder.GetModel().m_Labels[i++].m_Name == profiling::LabelsAndEventClasses::INDEX_LABEL);
197 
198  CHECK(timelineDecoder.GetModel().m_Labels[i].m_Guid == profiling::LabelsAndEventClasses::BACKENDID_GUID);
199  CHECK(timelineDecoder.GetModel().m_Labels[i++].m_Name == profiling::LabelsAndEventClasses::BACKENDID_LABEL);
200 
201  CHECK(timelineDecoder.GetModel().m_Labels[i].m_Guid == profiling::LabelsAndEventClasses::CHILD_GUID);
202  CHECK(timelineDecoder.GetModel().m_Labels[i++].m_Name == profiling::LabelsAndEventClasses::CHILD_LABEL);
203 
204  CHECK(timelineDecoder.GetModel().m_Labels[i].m_Guid == profiling::LabelsAndEventClasses::EXECUTION_OF_GUID);
205  CHECK(timelineDecoder.GetModel().m_Labels[i++].m_Name ==
206  profiling::LabelsAndEventClasses::EXECUTION_OF_LABEL);
207 
208  CHECK(timelineDecoder.GetModel().m_Labels[i].m_Guid == profiling::LabelsAndEventClasses::PROCESS_ID_GUID);
209  CHECK(timelineDecoder.GetModel().m_Labels[i++].m_Name ==
210  profiling::LabelsAndEventClasses::PROCESS_ID_LABEL);
211 
212  CHECK(timelineDecoder.GetModel().m_Labels[i].m_Guid == profiling::LabelsAndEventClasses::LAYER_GUID);
213  CHECK(timelineDecoder.GetModel().m_Labels[i++].m_Name == profiling::LabelsAndEventClasses::LAYER);
214 
215  CHECK(timelineDecoder.GetModel().m_Labels[i].m_Guid == profiling::LabelsAndEventClasses::WORKLOAD_GUID);
216  CHECK(timelineDecoder.GetModel().m_Labels[i++].m_Name == profiling::LabelsAndEventClasses::WORKLOAD);
217 
218  CHECK(timelineDecoder.GetModel().m_Labels[i].m_Guid == profiling::LabelsAndEventClasses::NETWORK_GUID);
219  CHECK(timelineDecoder.GetModel().m_Labels[i++].m_Name == profiling::LabelsAndEventClasses::NETWORK);
220 
221  CHECK(timelineDecoder.GetModel().m_Labels[i].m_Guid == profiling::LabelsAndEventClasses::CONNECTION_GUID);
222  CHECK(timelineDecoder.GetModel().m_Labels[i++].m_Name == profiling::LabelsAndEventClasses::CONNECTION);
223 
224  CHECK(timelineDecoder.GetModel().m_Labels[i].m_Guid == profiling::LabelsAndEventClasses::INFERENCE_GUID);
225  CHECK(timelineDecoder.GetModel().m_Labels[i++].m_Name == profiling::LabelsAndEventClasses::INFERENCE);
226 
227  CHECK(timelineDecoder.GetModel().m_Labels[i].m_Guid ==
228  profiling::LabelsAndEventClasses::WORKLOAD_EXECUTION_GUID);
229  CHECK(timelineDecoder.GetModel().m_Labels[i++].m_Name ==
230  profiling::LabelsAndEventClasses::WORKLOAD_EXECUTION);
231 
232  CHECK(timelineDecoder.GetModel().m_EventClasses[0].m_Guid ==
233  profiling::LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS);
234  CHECK(timelineDecoder.GetModel().m_EventClasses[1].m_Guid ==
235  profiling::LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS);
236 }
237 
238 TEST_CASE("GatorDMockEndToEnd")
239 {
240  // The purpose of this test is to setup both sides of the profiling service and get to the point of receiving
241  // performance data.
242 
243  // Setup the mock service to bind to the UDS.
244  std::string udsNamespace = "gatord_namespace";
245 
246  CHECK_NOTHROW(arm::pipe::ConnectionHandler connectionHandler(udsNamespace, false));
247 
248  arm::pipe::ConnectionHandler connectionHandler(udsNamespace, false);
249 
250  // Enable the profiling service.
252  options.m_EnableProfiling = true;
253  options.m_TimelineEnabled = true;
254 
255  armnn::profiling::ProfilingService profilingService;
256  profilingService.ResetExternalProfilingOptions(options, true);
257 
258  // Bring the profiling service to the "WaitingForAck" state
259  CHECK(profilingService.GetCurrentState() == profiling::ProfilingState::Uninitialised);
260  profilingService.Update();
261  CHECK(profilingService.GetCurrentState() == profiling::ProfilingState::NotConnected);
262  profilingService.Update();
263 
264  // Connect the profiling service
265  auto basePipeServer = connectionHandler.GetNewBasePipeServer(false);
266 
267  // Connect the profiling service to the mock Gatord.
268  gatordmock::GatordMockService mockService(std::move(basePipeServer), false);
269 
270  arm::pipe::TimelineDecoder& timelineDecoder = mockService.GetTimelineDecoder();
271  profiling::DirectoryCaptureCommandHandler& directoryCaptureCommandHandler =
272  mockService.GetDirectoryCaptureCommandHandler();
273 
274  // Give the profiling service sending thread time start executing and send the stream metadata.
275  WaitFor([&](){return profilingService.GetCurrentState() == profiling::ProfilingState::WaitingForAck;},
276  "Profiling service did not switch to WaitingForAck state");
277 
278  profilingService.Update();
279  // Read the stream metadata on the mock side.
280  if (!mockService.WaitForStreamMetaData())
281  {
282  FAIL("Failed to receive StreamMetaData");
283  }
284  // Send Ack from GatorD
285  mockService.SendConnectionAck();
286  // And start to listen for packets
287  mockService.LaunchReceivingThread();
288 
289  WaitFor([&](){return profilingService.GetCurrentState() == profiling::ProfilingState::Active;},
290  "Profiling service did not switch to Active state");
291 
292  // As part of the default startup of the profiling service a counter directory packet will be sent.
293  WaitFor([&](){return directoryCaptureCommandHandler.ParsedCounterDirectory();},
294  "MockGatord did not receive counter directory packet");
295 
296  // Following that we will receive a collection of well known timeline labels and event classes
297  WaitFor([&](){return timelineDecoder.GetModel().m_EventClasses.size() >= 2;},
298  "MockGatord did not receive well known timeline labels and event classes");
299 
300  CheckTimelineDirectory(mockService.GetTimelineDirectoryCaptureCommandHandler());
301  // Verify the commonly used timeline packets sent when the profiling service enters the active state
302  CheckTimelinePackets(timelineDecoder);
303 
304  const profiling::ICounterDirectory& serviceCounterDirectory = profilingService.GetCounterDirectory();
305  const profiling::ICounterDirectory& receivedCounterDirectory = directoryCaptureCommandHandler.GetCounterDirectory();
306 
307  // Compare the basics of the counter directory from the service and the one we received over the wire.
308  CHECK(serviceCounterDirectory.GetDeviceCount() == receivedCounterDirectory.GetDeviceCount());
309  CHECK(serviceCounterDirectory.GetCounterSetCount() == receivedCounterDirectory.GetCounterSetCount());
310  CHECK(serviceCounterDirectory.GetCategoryCount() == receivedCounterDirectory.GetCategoryCount());
311  CHECK(serviceCounterDirectory.GetCounterCount() == receivedCounterDirectory.GetCounterCount());
312 
313  receivedCounterDirectory.GetDeviceCount();
314  serviceCounterDirectory.GetDeviceCount();
315 
316  const profiling::Devices& serviceDevices = serviceCounterDirectory.GetDevices();
317  for (auto& device : serviceDevices)
318  {
319  // Find the same device in the received counter directory.
320  auto foundDevice = receivedCounterDirectory.GetDevices().find(device.second->m_Uid);
321  CHECK(foundDevice != receivedCounterDirectory.GetDevices().end());
322  CHECK(device.second->m_Name.compare((*foundDevice).second->m_Name) == 0);
323  CHECK(device.second->m_Cores == (*foundDevice).second->m_Cores);
324  }
325 
326  const profiling::CounterSets& serviceCounterSets = serviceCounterDirectory.GetCounterSets();
327  for (auto& counterSet : serviceCounterSets)
328  {
329  // Find the same counter set in the received counter directory.
330  auto foundCounterSet = receivedCounterDirectory.GetCounterSets().find(counterSet.second->m_Uid);
331  CHECK(foundCounterSet != receivedCounterDirectory.GetCounterSets().end());
332  CHECK(counterSet.second->m_Name.compare((*foundCounterSet).second->m_Name) == 0);
333  CHECK(counterSet.second->m_Count == (*foundCounterSet).second->m_Count);
334  }
335 
336  const profiling::Categories& serviceCategories = serviceCounterDirectory.GetCategories();
337  for (auto& category : serviceCategories)
338  {
339  for (auto& receivedCategory : receivedCounterDirectory.GetCategories())
340  {
341  if (receivedCategory->m_Name.compare(category->m_Name) == 0)
342  {
343  // We've found the matching category.
344  // Now look at the interiors of the counters. Start by sorting them.
345  std::sort(category->m_Counters.begin(), category->m_Counters.end());
346  std::sort(receivedCategory->m_Counters.begin(), receivedCategory->m_Counters.end());
347  // When comparing uid's here we need to translate them.
348  std::function<bool(const uint16_t&, const uint16_t&)> comparator =
349  [&directoryCaptureCommandHandler](const uint16_t& first, const uint16_t& second) {
350  uint16_t translated = directoryCaptureCommandHandler.TranslateUIDCopyToOriginal(second);
351  if (translated == first)
352  {
353  return true;
354  }
355  return false;
356  };
357  // Then let vector == do the work.
358  CHECK(std::equal(category->m_Counters.begin(), category->m_Counters.end(),
359  receivedCategory->m_Counters.begin(), comparator));
360  break;
361  }
362  }
363  }
364 
365  // Finally check the content of the counters.
366  const profiling::Counters& receivedCounters = receivedCounterDirectory.GetCounters();
367  for (auto& receivedCounter : receivedCounters)
368  {
369  // Translate the Uid and find the corresponding counter in the original counter directory.
370  // Note we can't check m_MaxCounterUid here as it will likely differ between the two counter directories.
371  uint16_t translated = directoryCaptureCommandHandler.TranslateUIDCopyToOriginal(receivedCounter.first);
372  const profiling::Counter* serviceCounter = serviceCounterDirectory.GetCounter(translated);
373  CHECK(serviceCounter->m_DeviceUid == receivedCounter.second->m_DeviceUid);
374  CHECK(serviceCounter->m_Name.compare(receivedCounter.second->m_Name) == 0);
375  CHECK(serviceCounter->m_CounterSetUid == receivedCounter.second->m_CounterSetUid);
376  CHECK(serviceCounter->m_Multiplier == receivedCounter.second->m_Multiplier);
377  CHECK(serviceCounter->m_Interpolation == receivedCounter.second->m_Interpolation);
378  CHECK(serviceCounter->m_Class == receivedCounter.second->m_Class);
379  CHECK(serviceCounter->m_Units.compare(receivedCounter.second->m_Units) == 0);
380  CHECK(serviceCounter->m_Description.compare(receivedCounter.second->m_Description) == 0);
381  }
382 
383  mockService.WaitForReceivingThread();
384  options.m_EnableProfiling = false;
385  profilingService.ResetExternalProfilingOptions(options, true);
386  // Future tests here will add counters to the ProfilingService, increment values and examine
387  // PeriodicCounterCapture data received. These are yet to be integrated.
388 }
389 
390 TEST_CASE("GatorDMockTimeLineActivation")
391 {
392  // This test requires the CpuRef backend to be enabled
393  if(!BackendRegistryInstance().IsBackendRegistered("CpuRef"))
394  {
395  return;
396  }
397  armnn::MockBackendInitialiser initialiser;
398  // Setup the mock service to bind to the UDS.
399  std::string udsNamespace = "gatord_namespace";
400 
401  arm::pipe::ConnectionHandler connectionHandler(udsNamespace, false);
402 
404  options.m_ProfilingOptions.m_EnableProfiling = true;
405  options.m_ProfilingOptions.m_TimelineEnabled = true;
406  armnn::RuntimeImpl runtime(options);
407 
408  auto basePipeServer = connectionHandler.GetNewBasePipeServer(false);
409  gatordmock::GatordMockService mockService(std::move(basePipeServer), false);
410 
411  // Read the stream metadata on the mock side.
412  if (!mockService.WaitForStreamMetaData())
413  {
414  FAIL("Failed to receive StreamMetaData");
415  }
416 
418  armnn::MockBackendProfilingContext *mockBackEndProfilingContext = mockProfilingService.GetContext();
419 
420  // Send Ack from GatorD
421  mockService.SendConnectionAck();
422  // And start to listen for packets
423  mockService.LaunchReceivingThread();
424 
425  // Build and optimize a simple network while we wait
427 
428  IConnectableLayer* input = net->AddInputLayer(0, "input");
429 
430  NormalizationDescriptor descriptor;
431  IConnectableLayer* normalize = net->AddNormalizationLayer(descriptor, "normalization");
432 
433  IConnectableLayer* output = net->AddOutputLayer(0, "output");
434 
435  input->GetOutputSlot(0).Connect(normalize->GetInputSlot(0));
436  normalize->GetOutputSlot(0).Connect(output->GetInputSlot(0));
437 
438  input->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
439  normalize->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
440 
441  std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
442  IOptimizedNetworkPtr optNet = Optimize(*net, backends, runtime.GetDeviceSpec());
443 
444  WaitFor([&](){return mockService.GetDirectoryCaptureCommandHandler().ParsedCounterDirectory();},
445  "MockGatord did not receive counter directory packet");
446 
447  arm::pipe::TimelineDecoder& timelineDecoder = mockService.GetTimelineDecoder();
448 
449  WaitFor([&](){return timelineDecoder.GetModel().m_EventClasses.size() >= 2;},
450  "MockGatord did not receive well known timeline labels");
451 
452  WaitFor([&](){return timelineDecoder.GetModel().m_Entities.size() >= 1;},
453  "MockGatord did not receive mock backend test entity");
454 
455  // Packets we expect from SendWellKnownLabelsAndEventClassesTest
456  CHECK(timelineDecoder.GetModel().m_Entities.size() == 1);
457  CHECK(timelineDecoder.GetModel().m_EventClasses.size() == 2);
458  CHECK(timelineDecoder.GetModel().m_Labels.size() == 15);
459  CHECK(timelineDecoder.GetModel().m_Relationships.size() == 0);
460  CHECK(timelineDecoder.GetModel().m_Events.size() == 0);
461 
462  mockService.SendDeactivateTimelinePacket();
463 
464  WaitFor([&](){return !mockBackEndProfilingContext->TimelineReportingEnabled();},
465  "Timeline packets were not deactivated");
466 
467  // Load the network into runtime now that timeline reporting is disabled
468  armnn::NetworkId netId;
469  runtime.LoadNetwork(netId, std::move(optNet));
470 
471  // Now activate timeline packets
472  mockService.SendActivateTimelinePacket();
473 
474  WaitFor([&](){return mockBackEndProfilingContext->TimelineReportingEnabled();},
475  "Timeline packets were not activated");
476 
477  // Once TimelineReporting is Enabled additional activateTimelinePackets should be ignored
478  mockService.SendActivateTimelinePacket();
479  mockService.SendActivateTimelinePacket();
480 
481  // Once timeline packets have been reactivated the ActivateTimelineReportingCommandHandler will resend the
482  // SendWellKnownLabelsAndEventClasses and then send the structure of any loaded networks
483  WaitFor([&](){return timelineDecoder.GetModel().m_Labels.size() >= 24;},
484  "MockGatord did not receive well known timeline labels");
485 
486  // Packets we expect from SendWellKnownLabelsAndEventClassesTest * 2 + network above (input, norm, backend, output)
487  CHECK(timelineDecoder.GetModel().m_Entities.size() == 6);
488  CHECK(timelineDecoder.GetModel().m_EventClasses.size() == 4);
489  CHECK(timelineDecoder.GetModel().m_Labels.size() == 34);
490  CHECK(timelineDecoder.GetModel().m_Relationships.size() == 15);
491  CHECK(timelineDecoder.GetModel().m_Events.size() == 0);
492 
493  mockService.WaitForReceivingThread();
494  GetProfilingService(&runtime).Disconnect();
495 }
496 
497 }
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:61
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
virtual uint16_t GetCounterCount() const =0
BackendRegistry & BackendRegistryInstance()
Status LoadNetwork(NetworkId &networkIdOut, IOptimizedNetworkPtr network)
Loads a complete network into the Runtime.
Definition: Runtime.cpp:145
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
virtual uint16_t GetCategoryCount() const =0
bool m_EnableProfiling
Indicates whether external profiling is enabled or not.
Definition: IRuntime.hpp:169
void SendActivateTimelinePacket()
Send a activate timeline packet back to the client.
virtual void SetTensorInfo(const TensorInfo &tensorInfo)=0
std::unordered_map< uint16_t, CounterSetPtr > CounterSets
virtual const Categories & GetCategories() const =0
bool WaitForStreamMetaData()
Once the connection is open wait to receive the stream meta data packet from the client.
virtual const Devices & GetDevices() const =0
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:1605
const IDeviceSpec & GetDeviceSpec() const
Definition: Runtime.hpp:86
TEST_SUITE("GatordMockTests")
int NetworkId
Definition: IRuntime.hpp:25
std::unique_ptr< IOptimizedNetwork, void(*)(IOptimizedNetwork *network)> IOptimizedNetworkPtr
Definition: INetwork.hpp:198
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
virtual uint16_t GetDeviceCount() const =0
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14
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
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:171
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
void WaitForReceivingThread()
This is a placeholder method to prevent main exiting.
std::unique_ptr< INetwork, void(*)(INetwork *network)> INetworkPtr
Definition: INetwork.hpp:197
virtual int Connect(IInputSlot &destination)=0
std::unique_ptr< ISendTimelinePacket > GetSendTimelinePacket() const
A NormalizationDescriptor for the NormalizationLayer.
ExternalProfilingOptions m_ProfilingOptions
Definition: IRuntime.hpp:184
const ICounterDirectory & GetCounterDirectory() const
static INetworkPtr Create(NetworkOptions networkOptions={})
Definition: Network.cpp:478
void SendConnectionAck()
Send a connection acknowledged packet back to the client.