ArmNN
 20.02
BackendProfilingTests.cpp File Reference
#include "CounterDirectory.hpp"
#include "CounterIdMap.hpp"
#include "Holder.hpp"
#include "MockBackend.hpp"
#include "MockBackendId.hpp"
#include "PeriodicCounterCapture.hpp"
#include "PeriodicCounterSelectionCommandHandler.hpp"
#include "ProfilingStateMachine.hpp"
#include "ProfilingUtils.hpp"
#include "RequestCounterDirectoryCommandHandler.hpp"
#include <armnn/utility/IgnoreUnused.hpp>
#include <armnn/BackendId.hpp>
#include <armnn/Logging.hpp>
#include <armnn/profiling/ISendTimelinePacket.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/numeric/conversion/cast.hpp>
#include <boost/test/unit_test.hpp>
#include <vector>
#include <cstdint>
#include <limits>
#include <backends/BackendProfiling.hpp>

Go to the source code of this file.

Functions

Packet PacketWriter (uint32_t period, std::vector< uint16_t > countervalues)
 
 BOOST_AUTO_TEST_CASE (BackendProfilingCounterRegisterMockBackendTest)
 
 BOOST_AUTO_TEST_CASE (TestBackendCounters)
 
 BOOST_AUTO_TEST_CASE (TestBackendCounterLogging)
 
 BOOST_AUTO_TEST_CASE (BackendProfilingContextGetSendTimelinePacket)
 
 BOOST_AUTO_TEST_CASE (GetProfilingGuidGenerator)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/5]

BOOST_AUTO_TEST_CASE ( BackendProfilingCounterRegisterMockBackendTest  )

Definition at line 112 of file BackendProfilingTests.cpp.

References BOOST_CHECK(), ProfilingService::ConfigureProfilingService(), IRuntime::Create(), ProfilingService::GetCounterMappings(), ICounterMappings::GetGlobalId(), ProfilingService::Instance(), IRuntime::CreationOptions::ExternalProfilingOptions::m_EnableProfiling, IRuntime::CreationOptions::m_ProfilingOptions, armnn::MockBackendId(), options, profilingService, and ProfilingService::ResetExternalProfilingOptions().

113 {
114  // Reset the profiling service to the uninitialized state
116  options.m_ProfilingOptions.m_EnableProfiling = true;
118  profilingService.ConfigureProfilingService(options.m_ProfilingOptions, true);
119 
120  armnn::MockBackendInitialiser initialiser;
121  // Create a runtime
123 
124  // Check if the MockBackends 3 dummy counters {0, 1, 2-5 (four cores)} are registered
126  const armnn::profiling::ICounterMappings& counterMap = profilingService.GetCounterMappings();
127  BOOST_CHECK(counterMap.GetGlobalId(0, mockId) == 5);
128  BOOST_CHECK(counterMap.GetGlobalId(1, mockId) == 6);
129  BOOST_CHECK(counterMap.GetGlobalId(2, mockId) == 7);
130  BOOST_CHECK(counterMap.GetGlobalId(3, mockId) == 8);
131  BOOST_CHECK(counterMap.GetGlobalId(4, mockId) == 9);
132  BOOST_CHECK(counterMap.GetGlobalId(5, mockId) == 10);
133  options.m_ProfilingOptions.m_EnableProfiling = false;
134  profilingService.ResetExternalProfilingOptions(options.m_ProfilingOptions, true);
135 }
static IRuntimePtr Create(const CreationOptions &options)
Definition: Runtime.cpp:32
static ProfilingService & Instance()
std::unique_ptr< IRuntime, void(*)(IRuntime *runtime)> IRuntimePtr
Definition: IRuntime.hpp:24
constexpr const char * MockBackendId()
ProfilingService & profilingService
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
const ICounterMappings & GetCounterMappings() const override
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
ExternalProfilingOptions m_ProfilingOptions
Definition: IRuntime.hpp:76
ProfilingState ConfigureProfilingService(const ExternalProfilingOptions &options, bool resetProfilingService=false)
virtual uint16_t GetGlobalId(uint16_t backendCounterId, const armnn::BackendId &backendId) const =0

◆ BOOST_AUTO_TEST_CASE() [2/5]

BOOST_AUTO_TEST_CASE ( TestBackendCounters  )

Definition at line 137 of file BackendProfilingTests.cpp.

References armnn::profiling::Active, BOOST_CHECK(), armnn::CpuAcc, Version::GetEncodedValue(), armnn::GpuAcc, ProfilingService::Instance(), IRuntime::CreationOptions::ExternalProfilingOptions::m_EnableProfiling, IRuntime::CreationOptions::m_ProfilingOptions, armnn::profiling::NotConnected, options, PacketWriter(), profilingService, CounterIdMap::RegisterMapping(), PacketVersionResolver::ResolvePacketVersion(), ProfilingStateMachine::TransitionToState(), and armnn::profiling::WaitingForAck.

138 {
139  Holder holder;
140  PacketVersionResolver packetVersionResolver;
141  ProfilingStateMachine stateMachine;
142  ReadCounterVals readCounterVals;
143  CounterIdMap counterIdMap;
144  MockBackendSendCounterPacket sendCounterPacket;
145 
148 
150  options.m_ProfilingOptions.m_EnableProfiling = true;
151 
153 
154  std::unique_ptr<armnn::profiling::IBackendProfiling> cpuBackendProfilingPtr =
155  std::make_unique<BackendProfiling>(options, profilingService, cpuAccId);
156  std::unique_ptr<armnn::profiling::IBackendProfiling> gpuBackendProfilingPtr =
157  std::make_unique<BackendProfiling>(options, profilingService, gpuAccId);
158 
159  std::shared_ptr<armnn::profiling::IBackendProfilingContext> cpuProfilingContextPtr =
160  std::make_shared<armnn::MockBackendProfilingContext>(cpuBackendProfilingPtr);
161  std::shared_ptr<armnn::profiling::IBackendProfilingContext> gpuProfilingContextPtr =
162  std::make_shared<armnn::MockBackendProfilingContext>(gpuBackendProfilingPtr);
163 
164  std::unordered_map<armnn::BackendId,
165  std::shared_ptr<armnn::profiling::IBackendProfilingContext>> backendProfilingContexts;
166 
167  backendProfilingContexts[cpuAccId] = cpuProfilingContextPtr;
168  backendProfilingContexts[gpuAccId] = gpuProfilingContextPtr;
169 
170  uint16_t globalId = 5;
171 
172  counterIdMap.RegisterMapping(globalId++, 0, cpuAccId);
173  counterIdMap.RegisterMapping(globalId++, 1, cpuAccId);
174  counterIdMap.RegisterMapping(globalId++, 2, cpuAccId);
175 
176  counterIdMap.RegisterMapping(globalId++, 0, gpuAccId);
177  counterIdMap.RegisterMapping(globalId++, 1, gpuAccId);
178  counterIdMap.RegisterMapping(globalId++, 2, gpuAccId);
179 
180  backendProfilingContexts[cpuAccId] = cpuProfilingContextPtr;
181  backendProfilingContexts[gpuAccId] = gpuProfilingContextPtr;
182 
183  PeriodicCounterCapture periodicCounterCapture(holder, sendCounterPacket, readCounterVals,
184  counterIdMap, backendProfilingContexts);
185 
186  uint16_t maxArmnnCounterId = 4;
187 
188  PeriodicCounterSelectionCommandHandler periodicCounterSelectionCommandHandler(0,
189  4,
190  packetVersionResolver.ResolvePacketVersion(0, 4).GetEncodedValue(),
191  backendProfilingContexts,
192  counterIdMap,
193  holder,
194  maxArmnnCounterId,
195  periodicCounterCapture,
196  readCounterVals,
197  sendCounterPacket,
198  stateMachine);
199 
200  stateMachine.TransitionToState(ProfilingState::NotConnected);
201  stateMachine.TransitionToState(ProfilingState::WaitingForAck);
202  stateMachine.TransitionToState(ProfilingState::Active);
203 
204  uint32_t period = 12345u;
205 
206  std::vector<uint16_t> cpuCounters{5, 6, 7};
207  std::vector<uint16_t> gpuCounters{8, 9, 10};
208 
209  // Request only gpu counters
210  periodicCounterSelectionCommandHandler(PacketWriter(period, gpuCounters));
211  periodicCounterCapture.Stop();
212 
213  std::set<armnn::BackendId> activeIds = holder.GetCaptureData().GetActiveBackends();
214  BOOST_CHECK(activeIds.size() == 1);
215  BOOST_CHECK(activeIds.find(gpuAccId) != activeIds.end());
216 
217  std::vector<Timestamp> recievedTimestamp = sendCounterPacket.GetTimestamps();
218 
219  BOOST_CHECK(recievedTimestamp[0].timestamp == period);
220  BOOST_CHECK(recievedTimestamp.size() == 1);
221  BOOST_CHECK(recievedTimestamp[0].counterValues.size() == gpuCounters.size());
222  for (unsigned long i=0; i< gpuCounters.size(); ++i)
223  {
224  BOOST_CHECK(recievedTimestamp[0].counterValues[i].counterId == gpuCounters[i]);
225  BOOST_CHECK(recievedTimestamp[0].counterValues[i].counterValue == i + 1u);
226  }
227  sendCounterPacket.ClearTimestamps();
228 
229  // Request only cpu counters
230  periodicCounterSelectionCommandHandler(PacketWriter(period, cpuCounters));
231  periodicCounterCapture.Stop();
232 
233  activeIds = holder.GetCaptureData().GetActiveBackends();
234  BOOST_CHECK(activeIds.size() == 1);
235  BOOST_CHECK(activeIds.find(cpuAccId) != activeIds.end());
236 
237  recievedTimestamp = sendCounterPacket.GetTimestamps();
238 
239  BOOST_CHECK(recievedTimestamp[0].timestamp == period);
240  BOOST_CHECK(recievedTimestamp.size() == 1);
241  BOOST_CHECK(recievedTimestamp[0].counterValues.size() == cpuCounters.size());
242  for (unsigned long i=0; i< cpuCounters.size(); ++i)
243  {
244  BOOST_CHECK(recievedTimestamp[0].counterValues[i].counterId == cpuCounters[i]);
245  BOOST_CHECK(recievedTimestamp[0].counterValues[i].counterValue == i + 1u);
246  }
247  sendCounterPacket.ClearTimestamps();
248 
249  // Request combination of cpu & gpu counters with new period
250  period = 12222u;
251  periodicCounterSelectionCommandHandler(PacketWriter(period, {cpuCounters[0], gpuCounters[2],
252  gpuCounters[1], cpuCounters[1], gpuCounters[0]}));
253  periodicCounterCapture.Stop();
254 
255  activeIds = holder.GetCaptureData().GetActiveBackends();
256  BOOST_CHECK(activeIds.size() == 2);
257  BOOST_CHECK(activeIds.find(cpuAccId) != activeIds.end());
258  BOOST_CHECK(activeIds.find(gpuAccId) != activeIds.end());
259 
260  recievedTimestamp = sendCounterPacket.GetTimestamps();
261 
262  BOOST_CHECK(recievedTimestamp[0].timestamp == period);
263  BOOST_CHECK(recievedTimestamp[1].timestamp == period);
264 
265  BOOST_CHECK(recievedTimestamp.size() == 2);
266  BOOST_CHECK(recievedTimestamp[0].counterValues.size() == 2);
267  BOOST_CHECK(recievedTimestamp[1].counterValues.size() == gpuCounters.size());
268 
269  BOOST_CHECK(recievedTimestamp[0].counterValues[0].counterId == cpuCounters[0]);
270  BOOST_CHECK(recievedTimestamp[0].counterValues[0].counterValue == 1u);
271  BOOST_CHECK(recievedTimestamp[0].counterValues[1].counterId == cpuCounters[1]);
272  BOOST_CHECK(recievedTimestamp[0].counterValues[1].counterValue == 2u);
273 
274  for (unsigned long i=0; i< gpuCounters.size(); ++i)
275  {
276  BOOST_CHECK(recievedTimestamp[1].counterValues[i].counterId == gpuCounters[i]);
277  BOOST_CHECK(recievedTimestamp[1].counterValues[i].counterValue == i + 1u);
278  }
279 
280  sendCounterPacket.ClearTimestamps();
281 
282  // Request all counters
283  std::vector<uint16_t> counterValues;
284  counterValues.insert(counterValues.begin(), cpuCounters.begin(), cpuCounters.end());
285  counterValues.insert(counterValues.begin(), gpuCounters.begin(), gpuCounters.end());
286 
287  periodicCounterSelectionCommandHandler(PacketWriter(period, counterValues));
288  periodicCounterCapture.Stop();
289 
290  activeIds = holder.GetCaptureData().GetActiveBackends();
291  BOOST_CHECK(activeIds.size() == 2);
292  BOOST_CHECK(activeIds.find(cpuAccId) != activeIds.end());
293  BOOST_CHECK(activeIds.find(gpuAccId) != activeIds.end());
294 
295  recievedTimestamp = sendCounterPacket.GetTimestamps();
296 
297  BOOST_CHECK(recievedTimestamp[0].counterValues.size() == cpuCounters.size());
298  for (unsigned long i=0; i< cpuCounters.size(); ++i)
299  {
300  BOOST_CHECK(recievedTimestamp[0].counterValues[i].counterId == cpuCounters[i]);
301  BOOST_CHECK(recievedTimestamp[0].counterValues[i].counterValue == i + 1u);
302  }
303 
304  BOOST_CHECK(recievedTimestamp[1].counterValues.size() == gpuCounters.size());
305  for (unsigned long i=0; i< gpuCounters.size(); ++i)
306  {
307  BOOST_CHECK(recievedTimestamp[1].counterValues[i].counterId == gpuCounters[i]);
308  BOOST_CHECK(recievedTimestamp[1].counterValues[i].counterValue == i + 1u);
309  }
310  sendCounterPacket.ClearTimestamps();
311 
312  // Request random counters with duplicates and invalid counters
313  counterValues = {0, 0, 200, cpuCounters[2], gpuCounters[0],3 ,30, cpuCounters[0],cpuCounters[2], gpuCounters[1], 3,
314  90, 0, 30, gpuCounters[0], gpuCounters[0]};
315 
316  periodicCounterSelectionCommandHandler(PacketWriter(period, counterValues));
317  periodicCounterCapture.Stop();
318 
319  activeIds = holder.GetCaptureData().GetActiveBackends();
320  BOOST_CHECK(activeIds.size() == 2);
321  BOOST_CHECK(activeIds.find(cpuAccId) != activeIds.end());
322  BOOST_CHECK(activeIds.find(gpuAccId) != activeIds.end());
323 
324  recievedTimestamp = sendCounterPacket.GetTimestamps();
325 
326  BOOST_CHECK(recievedTimestamp.size() == 2);
327 
328  BOOST_CHECK(recievedTimestamp[0].counterValues.size() == 2);
329 
330  BOOST_CHECK(recievedTimestamp[0].counterValues[0].counterId == cpuCounters[0]);
331  BOOST_CHECK(recievedTimestamp[0].counterValues[0].counterValue == 1u);
332  BOOST_CHECK(recievedTimestamp[0].counterValues[1].counterId == cpuCounters[2]);
333  BOOST_CHECK(recievedTimestamp[0].counterValues[1].counterValue == 3u);
334 
335  BOOST_CHECK(recievedTimestamp[1].counterValues.size() == 2);
336 
337  BOOST_CHECK(recievedTimestamp[1].counterValues[0].counterId == gpuCounters[0]);
338  BOOST_CHECK(recievedTimestamp[1].counterValues[0].counterValue == 1u);
339  BOOST_CHECK(recievedTimestamp[1].counterValues[1].counterId == gpuCounters[1]);
340  BOOST_CHECK(recievedTimestamp[1].counterValues[1].counterValue == 2u);
341 
342  sendCounterPacket.ClearTimestamps();
343 
344  // Request no counters
345  periodicCounterSelectionCommandHandler(PacketWriter(period, {}));
346  periodicCounterCapture.Stop();
347 
348  activeIds = holder.GetCaptureData().GetActiveBackends();
349  BOOST_CHECK(activeIds.size() == 0);
350 
351  recievedTimestamp = sendCounterPacket.GetTimestamps();
352  BOOST_CHECK(recievedTimestamp.size() == 0);
353 
354  sendCounterPacket.ClearTimestamps();
355 
356  // Request period of zero
357  periodicCounterSelectionCommandHandler(PacketWriter(0, counterValues));
358  periodicCounterCapture.Stop();
359 
360  activeIds = holder.GetCaptureData().GetActiveBackends();
361  BOOST_CHECK(activeIds.size() == 0);
362 
363  recievedTimestamp = sendCounterPacket.GetTimestamps();
364  BOOST_CHECK(recievedTimestamp.size() == 0);
365 }
static ProfilingService & Instance()
Version ResolvePacketVersion(uint32_t familyId, uint32_t packetId) const
ProfilingService & profilingService
void RegisterMapping(uint16_t globalCounterId, uint16_t backendCounterId, const armnn::BackendId &backendId) override
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
Packet PacketWriter(uint32_t period, std::vector< uint16_t > countervalues)
GPU Execution: OpenCL: ArmCompute.
CPU Execution: NEON: ArmCompute.
void TransitionToState(ProfilingState newState)
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
ExternalProfilingOptions m_ProfilingOptions
Definition: IRuntime.hpp:76

◆ BOOST_AUTO_TEST_CASE() [3/5]

BOOST_AUTO_TEST_CASE ( TestBackendCounterLogging  )

Definition at line 367 of file BackendProfilingTests.cpp.

References armnn::profiling::Active, BOOST_CHECK(), armnn::CpuAcc, armnn::Fatal, Version::GetEncodedValue(), armnn::GpuAcc, ProfilingService::Instance(), IRuntime::CreationOptions::ExternalProfilingOptions::m_EnableProfiling, IRuntime::CreationOptions::m_ProfilingOptions, armnn::profiling::NotConnected, options, PacketWriter(), profilingService, PacketVersionResolver::ResolvePacketVersion(), armnn::SetAllLoggingSinks(), armnn::SetLogFilter(), ProfilingStateMachine::TransitionToState(), armnn::profiling::WaitingForAck, and armnn::Warning.

368 {
369  std::stringstream ss;
370 
371  struct StreamRedirector
372  {
373  public:
374  StreamRedirector(std::ostream &stream, std::streambuf *newStreamBuffer)
375  : m_Stream(stream), m_BackupBuffer(m_Stream.rdbuf(newStreamBuffer))
376  {}
377 
379  { m_Stream.rdbuf(m_BackupBuffer); }
380 
381  private:
382  std::ostream &m_Stream;
383  std::streambuf *m_BackupBuffer;
384  };
385 
386  Holder holder;
387  PacketVersionResolver packetVersionResolver;
388  ProfilingStateMachine stateMachine;
389  ReadCounterVals readCounterVals;
390  StreamRedirector redirect(std::cout, ss.rdbuf());
391  CounterIdMap counterIdMap;
392  MockBackendSendCounterPacket sendCounterPacket;
393 
396 
398  options.m_ProfilingOptions.m_EnableProfiling = true;
399 
401 
402  std::unique_ptr<armnn::profiling::IBackendProfiling> cpuBackendProfilingPtr =
403  std::make_unique<BackendProfiling>(options, profilingService, cpuAccId);
404 
405  std::shared_ptr<armnn::profiling::IBackendProfilingContext> cpuProfilingContextPtr =
406  std::make_shared<armnn::MockBackendProfilingContext>(cpuBackendProfilingPtr);
407 
408  std::unordered_map<armnn::BackendId,
409  std::shared_ptr<armnn::profiling::IBackendProfilingContext>> backendProfilingContexts;
410 
411  uint16_t globalId = 5;
412  counterIdMap.RegisterMapping(globalId, 0, cpuAccId);
413  backendProfilingContexts[cpuAccId] = cpuProfilingContextPtr;
414 
415  PeriodicCounterCapture periodicCounterCapture(holder, sendCounterPacket, readCounterVals,
416  counterIdMap, backendProfilingContexts);
417 
418  uint16_t maxArmnnCounterId = 4;
419 
420  PeriodicCounterSelectionCommandHandler periodicCounterSelectionCommandHandler(0,
421  4,
422  packetVersionResolver.ResolvePacketVersion(0, 4).GetEncodedValue(),
423  backendProfilingContexts,
424  counterIdMap,
425  holder,
426  maxArmnnCounterId,
427  periodicCounterCapture,
428  readCounterVals,
429  sendCounterPacket,
430  stateMachine);
431 
432  stateMachine.TransitionToState(ProfilingState::NotConnected);
433  stateMachine.TransitionToState(ProfilingState::WaitingForAck);
434  stateMachine.TransitionToState(ProfilingState::Active);
435 
436  uint32_t period = 15939u;
437 
438  armnn::SetAllLoggingSinks(true, false, false);
440  periodicCounterSelectionCommandHandler(PacketWriter(period, {5}));
441  periodicCounterCapture.Stop();
443 
444  BOOST_CHECK(boost::contains(ss.str(), "ActivateCounters example test error"));
445 }
static ProfilingService & Instance()
void SetAllLoggingSinks(bool standardOut, bool debugOut, bool coloured)
Definition: Logging.cpp:146
Version ResolvePacketVersion(uint32_t familyId, uint32_t packetId) const
ProfilingService & profilingService
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
Packet PacketWriter(uint32_t period, std::vector< uint16_t > countervalues)
void SetLogFilter(LogSeverity level)
Definition: Logging.cpp:28
GPU Execution: OpenCL: ArmCompute.
CPU Execution: NEON: ArmCompute.
void TransitionToState(ProfilingState newState)
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
ExternalProfilingOptions m_ProfilingOptions
Definition: IRuntime.hpp:76

◆ BOOST_AUTO_TEST_CASE() [4/5]

BOOST_AUTO_TEST_CASE ( BackendProfilingContextGetSendTimelinePacket  )

Definition at line 447 of file BackendProfilingTests.cpp.

References BOOST_CHECK(), ProfilingService::ConfigureProfilingService(), IRuntime::Create(), MockBackendProfilingContext::GetBackendProfiling(), MockBackendProfilingService::GetContext(), ProfilingService::Instance(), MockBackendProfilingService::Instance(), IRuntime::CreationOptions::ExternalProfilingOptions::m_EnableProfiling, IRuntime::CreationOptions::m_ProfilingOptions, options, profilingService, and ProfilingService::ResetExternalProfilingOptions().

448 {
449  // Reset the profiling service to the uninitialized state
451  options.m_ProfilingOptions.m_EnableProfiling = true;
453  profilingService.ConfigureProfilingService(options.m_ProfilingOptions, true);
454 
455  armnn::MockBackendInitialiser initialiser;
456  // Create a runtime. During this the mock backend will be registered and context returned.
459  armnn::MockBackendProfilingContext *mockBackEndProfilingContext = mockProfilingService.GetContext();
460  // Check that there is a valid context set.
461  BOOST_CHECK(mockBackEndProfilingContext);
462  armnn::IBackendInternal::IBackendProfilingPtr& backendProfilingIface =
463  mockBackEndProfilingContext->GetBackendProfiling();
464  BOOST_CHECK(backendProfilingIface);
465 
466  // Now for the meat of the test. We're just going to send a random packet and make sure there
467  // are no exceptions or errors. The sending of packets is already tested in SendTimelinePacketTests.
468  std::unique_ptr<armnn::profiling::ISendTimelinePacket> timelinePacket =
469  backendProfilingIface->GetSendTimelinePacket();
470  // Send TimelineEntityClassBinaryPacket
471  const uint64_t entityBinaryPacketProfilingGuid = 123456u;
472  timelinePacket->SendTimelineEntityBinaryPacket(entityBinaryPacketProfilingGuid);
473  timelinePacket->Commit();
474 
475  // Reset the profiling servie after the test.
476  options.m_ProfilingOptions.m_EnableProfiling = false;
477  profilingService.ResetExternalProfilingOptions(options.m_ProfilingOptions, true);
478 }
static IRuntimePtr Create(const CreationOptions &options)
Definition: Runtime.cpp:32
static ProfilingService & Instance()
std::unique_ptr< IRuntime, void(*)(IRuntime *runtime)> IRuntimePtr
Definition: IRuntime.hpp:24
ProfilingService & profilingService
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
std::unique_ptr< armnn::profiling::IBackendProfiling > IBackendProfilingPtr
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
static MockBackendProfilingService & Instance()
MockBackendProfilingContext * GetContext()
IBackendInternal::IBackendProfilingPtr & GetBackendProfiling()
Definition: MockBackend.hpp:39
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
ExternalProfilingOptions m_ProfilingOptions
Definition: IRuntime.hpp:76
ProfilingState ConfigureProfilingService(const ExternalProfilingOptions &options, bool resetProfilingService=false)

◆ BOOST_AUTO_TEST_CASE() [5/5]

BOOST_AUTO_TEST_CASE ( GetProfilingGuidGenerator  )

Definition at line 480 of file BackendProfilingTests.cpp.

References BOOST_AUTO_TEST_SUITE_END(), BOOST_CHECK(), ProfilingService::ConfigureProfilingService(), IRuntime::Create(), MockBackendProfilingContext::GetBackendProfiling(), MockBackendProfilingService::GetContext(), ProfilingService::Instance(), MockBackendProfilingService::Instance(), IRuntime::CreationOptions::ExternalProfilingOptions::m_EnableProfiling, IRuntime::CreationOptions::m_ProfilingOptions, IProfilingGuidGenerator::NextGuid(), options, profilingService, and ProfilingService::ResetExternalProfilingOptions().

481 {
482  // Reset the profiling service to the uninitialized state
484  options.m_ProfilingOptions.m_EnableProfiling = true;
486  profilingService.ConfigureProfilingService(options.m_ProfilingOptions, true);
487 
488  armnn::MockBackendInitialiser initialiser;
489  // Create a runtime. During this the mock backend will be registered and context returned.
492  armnn::MockBackendProfilingContext *mockBackEndProfilingContext = mockProfilingService.GetContext();
493  // Check that there is a valid context set.
494  BOOST_CHECK(mockBackEndProfilingContext);
495  armnn::IBackendInternal::IBackendProfilingPtr& backendProfilingIface =
496  mockBackEndProfilingContext->GetBackendProfiling();
497  BOOST_CHECK(backendProfilingIface);
498 
499  // Get the Guid generator and check the getting two Guid's results in the second being greater than the first.
500  armnn::profiling::IProfilingGuidGenerator& guidGenerator = backendProfilingIface->GetProfilingGuidGenerator();
501  BOOST_CHECK(backendProfilingIface);
502  const armnn::profiling::ProfilingDynamicGuid& firstGuid = guidGenerator.NextGuid();
503  BOOST_CHECK(firstGuid);
504  const armnn::profiling::ProfilingDynamicGuid& secondGuid = guidGenerator.NextGuid();
505  BOOST_CHECK(secondGuid > firstGuid);
506 
507  // Reset the profiling servie after the test.
508  options.m_ProfilingOptions.m_EnableProfiling = false;
509  profilingService.ResetExternalProfilingOptions(options.m_ProfilingOptions, true);
510 }
virtual ProfilingDynamicGuid NextGuid()=0
Return the next random Guid in the sequence.
static IRuntimePtr Create(const CreationOptions &options)
Definition: Runtime.cpp:32
static ProfilingService & Instance()
Strongly typed guids to distinguish between those generated at runtime, and those that are statically...
Definition: Types.hpp:294
std::unique_ptr< IRuntime, void(*)(IRuntime *runtime)> IRuntimePtr
Definition: IRuntime.hpp:24
ProfilingService & profilingService
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
std::unique_ptr< armnn::profiling::IBackendProfiling > IBackendProfilingPtr
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
static MockBackendProfilingService & Instance()
MockBackendProfilingContext * GetContext()
IBackendInternal::IBackendProfilingPtr & GetBackendProfiling()
Definition: MockBackend.hpp:39
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
ExternalProfilingOptions m_ProfilingOptions
Definition: IRuntime.hpp:76
ProfilingState ConfigureProfilingService(const ExternalProfilingOptions &options, bool resetProfilingService=false)

◆ PacketWriter()

Packet PacketWriter ( uint32_t  period,
std::vector< uint16_t >  countervalues 
)

Definition at line 91 of file BackendProfilingTests.cpp.

References BOOST_AUTO_TEST_SUITE(), armnn::profiling::WriteUint16(), and armnn::profiling::WriteUint32().

Referenced by BOOST_AUTO_TEST_CASE().

92 {
93  const uint32_t packetId = 0x40000;
94  uint32_t offset = 0;
95  uint32_t dataLength = static_cast<uint32_t>(4 + countervalues.size() * 2);
96  std::unique_ptr<unsigned char[]> uniqueData = std::make_unique<unsigned char[]>(dataLength);
97  unsigned char* data1 = reinterpret_cast<unsigned char*>(uniqueData.get());
98 
99  WriteUint32(data1, offset, period);
100  offset += 4;
101  for (auto countervalue : countervalues)
102  {
103  WriteUint16(data1, offset, countervalue);
104  offset += 2;
105  }
106 
107  return {packetId, dataLength, uniqueData};
108 }
void WriteUint16(const IPacketBufferPtr &packetBuffer, unsigned int offset, uint16_t value)
void WriteUint32(const IPacketBufferPtr &packetBuffer, unsigned int offset, uint32_t value)