1 // 2 // Copyright © 2017 Arm Ltd. All rights reserved. 3 // SPDX-License-Identifier: MIT 4 // 5 6 #include <doctest/doctest.h> 7 8 #include "ProfilingEvent.hpp" 9 #include "Profiling.hpp" 10 11 #include <thread> 12 13 using namespace armnn; 14 15 TEST_SUITE("ProfilingEvent") 16 { 17 TEST_CASE("ProfilingEventTest") 18 { 19 // Get a reference to the profiler manager. 20 armnn::ProfilerManager& profileManager = armnn::ProfilerManager::GetInstance(); 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. 65 armnn::ProfilerManager& profileManager = armnn::ProfilerManager::GetInstance(); 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 } 108