ArmNN
 22.02
ProfilingEventTest.cpp File Reference
#include <doctest/doctest.h>
#include "ProfilingEvent.hpp"
#include "Profiling.hpp"
#include <thread>

Go to the source code of this file.

Functions

 TEST_SUITE ("ProfilingEvent")
 

Function Documentation

◆ TEST_SUITE()

TEST_SUITE ( "ProfilingEvent"  )

Definition at line 15 of file ProfilingEventTest.cpp.

References armnn::CpuAcc, ProfilerManager::GetInstance(), Event::GetMeasurements(), Event::GetName(), Event::GetParentEvent(), ProfilerManager::GetProfiler(), armnn::GpuAcc, Event::Start(), and Event::Stop().

16 {
17 TEST_CASE("ProfilingEventTest")
18 {
19  // Get a reference to the profiler manager.
21 
22  const char* eventName = "EventName";
23 
24  Event::Instruments insts1;
25  insts1.emplace_back(std::make_unique<WallClockTimer>());
26  Event testEvent(eventName,
27  nullptr,
28  nullptr,
29  BackendId(),
30  std::move(insts1),
31  EmptyOptional());
32 
33  CHECK_EQ(testEvent.GetName(), "EventName");
34 
35  // start the timer - outer
36  testEvent.Start();
37 
38  // wait for 10 microseconds
39  std::this_thread::sleep_for(std::chrono::microseconds(10));
40 
41  // stop the timer - outer
42  testEvent.Stop();
43 
44  CHECK_GE(testEvent.GetMeasurements().front().m_Value, 10.0);
45 
46  // create a sub event with CpuAcc
47  BackendId cpuAccBackendId(Compute::CpuAcc);
48  Event::Instruments insts2;
49  insts2.emplace_back(std::make_unique<WallClockTimer>());
50  Event testEvent2(eventName,
51  profileManager.GetProfiler(),
52  &testEvent,
53  cpuAccBackendId,
54  std::move(insts2),
55  EmptyOptional());
56 
57  CHECK_EQ(&testEvent, testEvent2.GetParentEvent());
58  CHECK_EQ(profileManager.GetProfiler(), testEvent2.GetProfiler());
59  CHECK(cpuAccBackendId == testEvent2.GetBackendId());
60 }
61 
62 TEST_CASE("ProfilingEventTestOnGpuAcc")
63 {
64  // Get a reference to the profiler manager.
66 
67  const char* eventName = "GPUEvent";
68 
69  Event::Instruments insts1;
70  insts1.emplace_back(std::make_unique<WallClockTimer>());
71  Event testEvent(eventName,
72  nullptr,
73  nullptr,
74  BackendId(),
75  std::move(insts1),
76  EmptyOptional());
77 
78  CHECK_EQ(testEvent.GetName(), "GPUEvent");
79 
80  // start the timer - outer
81  testEvent.Start();
82 
83  // wait for 10 microseconds
84  std::this_thread::sleep_for(std::chrono::microseconds(10));
85 
86  // stop the timer - outer
87  testEvent.Stop();
88 
89  CHECK_GE(testEvent.GetMeasurements().front().m_Value, 10.0);
90 
91  // create a sub event
92  BackendId gpuAccBackendId(Compute::GpuAcc);
93  Event::Instruments insts2;
94  insts2.emplace_back(std::make_unique<WallClockTimer>());
95  Event testEvent2(eventName,
96  profileManager.GetProfiler(),
97  &testEvent,
98  gpuAccBackendId,
99  std::move(insts2),
100  EmptyOptional());
101 
102  CHECK_EQ(&testEvent, testEvent2.GetParentEvent());
103  CHECK_EQ(profileManager.GetProfiler(), testEvent2.GetProfiler());
104  CHECK(gpuAccBackendId == testEvent2.GetBackendId());
105 }
106 
107 }
Event class records measurements reported by BeginEvent()/EndEvent() and returns measurements when Ev...
static ProfilerManager & GetInstance()
Definition: Profiling.cpp:568
std::vector< InstrumentPtr > Instruments
IProfiler * GetProfiler()
Definition: Profiling.cpp:580
EmptyOptional is used to initialize the Optional class in case we want to have default value for an O...
Definition: Optional.hpp:32