ArmNN
 21.02
ProfilingEventTest.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include <boost/test/unit_test.hpp>
7 
8 #include "ProfilingEvent.hpp"
9 #include "Profiling.hpp"
10 
11 #include <thread>
12 
13 using namespace armnn;
14 
15 BOOST_AUTO_TEST_SUITE(ProfilingEvent)
16 
17 BOOST_AUTO_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 
32  BOOST_CHECK_EQUAL(testEvent.GetName(), "EventName");
33 
34  // start the timer - outer
35  testEvent.Start();
36 
37  // wait for 10 microseconds
38  std::this_thread::sleep_for(std::chrono::microseconds(10));
39 
40  // stop the timer - outer
41  testEvent.Stop();
42 
43  BOOST_CHECK_GE(testEvent.GetMeasurements().front().m_Value, 10.0);
44 
45  // create a sub event with CpuAcc
46  BackendId cpuAccBackendId(Compute::CpuAcc);
47  Event::Instruments insts2;
48  insts2.emplace_back(std::make_unique<WallClockTimer>());
49  Event testEvent2(eventName,
50  profileManager.GetProfiler(),
51  &testEvent,
52  cpuAccBackendId,
53  std::move(insts2));
54 
55  BOOST_CHECK_EQUAL(&testEvent, testEvent2.GetParentEvent());
56  BOOST_CHECK_EQUAL(profileManager.GetProfiler(), testEvent2.GetProfiler());
57  BOOST_CHECK(cpuAccBackendId == testEvent2.GetBackendId());
58 }
59 
60 BOOST_AUTO_TEST_CASE(ProfilingEventTestOnGpuAcc)
61 {
62  // Get a reference to the profiler manager.
64 
65  const char* eventName = "GPUEvent";
66 
67  Event::Instruments insts1;
68  insts1.emplace_back(std::make_unique<WallClockTimer>());
69  Event testEvent(eventName,
70  nullptr,
71  nullptr,
72  BackendId(),
73  std::move(insts1));
74 
75  BOOST_CHECK_EQUAL(testEvent.GetName(), "GPUEvent");
76 
77  // start the timer - outer
78  testEvent.Start();
79 
80  // wait for 10 microseconds
81  std::this_thread::sleep_for(std::chrono::microseconds(10));
82 
83  // stop the timer - outer
84  testEvent.Stop();
85 
86  BOOST_CHECK_GE(testEvent.GetMeasurements().front().m_Value, 10.0);
87 
88  // create a sub event
89  BackendId gpuAccBackendId(Compute::GpuAcc);
90  Event::Instruments insts2;
91  insts2.emplace_back(std::make_unique<WallClockTimer>());
92  Event testEvent2(eventName,
93  profileManager.GetProfiler(),
94  &testEvent,
95  gpuAccBackendId,
96  std::move(insts2));
97 
98  BOOST_CHECK_EQUAL(&testEvent, testEvent2.GetParentEvent());
99  BOOST_CHECK_EQUAL(profileManager.GetProfiler(), testEvent2.GetProfiler());
100  BOOST_CHECK(gpuAccBackendId == testEvent2.GetBackendId());
101 }
102 
BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
Event class records measurements reported by BeginEvent()/EndEvent() and returns measurements when Ev...
static ProfilerManager & GetInstance()
Definition: Profiling.cpp:489
std::vector< InstrumentPtr > Instruments
const std::string & GetName() const
Get the name of the event.
Copyright (c) 2021 ARM Limited and Contributors.
void Start()
Start the Event.
void Stop()
Stop the Event.
IProfiler * GetProfiler()
Definition: Profiling.cpp:501
const std::vector< Measurement > GetMeasurements() const
Get the recorded measurements calculated between Start() and Stop()
GPU Execution: OpenCL: ArmCompute.
BOOST_AUTO_TEST_CASE(CheckConvolution2dLayer)
BOOST_AUTO_TEST_SUITE_END()
CPU Execution: NEON: ArmCompute.
const Event * GetParentEvent() const
Get the pointer of the parent event.