telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame^] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // See LICENSE file in the project root for full license information. |
| 4 | // |
| 5 | #include <boost/test/unit_test.hpp> |
| 6 | |
| 7 | #include "ProfilingEvent.hpp" |
| 8 | #include "Profiling.hpp" |
| 9 | #include <thread> |
| 10 | |
| 11 | using namespace armnn; |
| 12 | |
| 13 | BOOST_AUTO_TEST_SUITE(ProfilingEvent) |
| 14 | |
| 15 | BOOST_AUTO_TEST_CASE(ProfilingEventTest) |
| 16 | { |
| 17 | // Get a reference to the profiler manager. |
| 18 | armnn::ProfilerManager& profileManager = armnn::ProfilerManager::GetInstance(); |
| 19 | |
| 20 | const char* eventName = "EventName"; |
| 21 | |
| 22 | Event::Instruments insts1; |
| 23 | insts1.emplace_back(std::make_unique<WallClockTimer>()); |
| 24 | Event testEvent(eventName, |
| 25 | nullptr, |
| 26 | nullptr, |
| 27 | armnn::Compute::Undefined, |
| 28 | std::move(insts1)); |
| 29 | |
| 30 | BOOST_CHECK_EQUAL(testEvent.GetName(), "EventName"); |
| 31 | |
| 32 | // start the timer - outer |
| 33 | testEvent.Start(); |
| 34 | |
| 35 | // wait for 10 milliseconds |
| 36 | std::this_thread::sleep_for(std::chrono::milliseconds(10)); |
| 37 | |
| 38 | // stop the timer - outer |
| 39 | testEvent.Stop(); |
| 40 | |
| 41 | BOOST_CHECK_GE(testEvent.GetMeasurements().front().m_Value, 10.0); |
| 42 | |
| 43 | // create a sub event with CpuAcc |
| 44 | Event::Instruments insts2; |
| 45 | insts2.emplace_back(std::make_unique<WallClockTimer>()); |
| 46 | Event testEvent2(eventName, |
| 47 | profileManager.GetProfiler(), |
| 48 | &testEvent, |
| 49 | Compute::CpuAcc, |
| 50 | std::move(insts2)); |
| 51 | |
| 52 | BOOST_CHECK_EQUAL(&testEvent, testEvent2.GetParentEvent()); |
| 53 | BOOST_CHECK_EQUAL(profileManager.GetProfiler(), testEvent2.GetProfiler()); |
| 54 | BOOST_CHECK_EQUAL(Compute::CpuAcc, testEvent2.GetComputeDevice()); |
| 55 | } |
| 56 | |
| 57 | BOOST_AUTO_TEST_CASE(ProfilingEventTestOnGpuAcc) |
| 58 | { |
| 59 | // Get a reference to the profiler manager. |
| 60 | armnn::ProfilerManager& profileManager = armnn::ProfilerManager::GetInstance(); |
| 61 | |
| 62 | const char* eventName = "GPUEvent"; |
| 63 | |
| 64 | Event::Instruments insts1; |
| 65 | insts1.emplace_back(std::make_unique<WallClockTimer>()); |
| 66 | Event testEvent(eventName, |
| 67 | nullptr, |
| 68 | nullptr, |
| 69 | armnn::Compute::Undefined, |
| 70 | std::move(insts1)); |
| 71 | |
| 72 | BOOST_CHECK_EQUAL(testEvent.GetName(), "GPUEvent"); |
| 73 | |
| 74 | // start the timer - outer |
| 75 | testEvent.Start(); |
| 76 | |
| 77 | // wait for 10 milliseconds |
| 78 | std::this_thread::sleep_for(std::chrono::milliseconds(10)); |
| 79 | |
| 80 | // stop the timer - outer |
| 81 | testEvent.Stop(); |
| 82 | |
| 83 | BOOST_CHECK_GE(testEvent.GetMeasurements().front().m_Value, 10.0); |
| 84 | |
| 85 | // create a sub event |
| 86 | Event::Instruments insts2; |
| 87 | insts2.emplace_back(std::make_unique<WallClockTimer>()); |
| 88 | Event testEvent2(eventName, profileManager.GetProfiler(), &testEvent, Compute::GpuAcc, std::move(insts2)); |
| 89 | |
| 90 | BOOST_CHECK_EQUAL(&testEvent, testEvent2.GetParentEvent()); |
| 91 | BOOST_CHECK_EQUAL(profileManager.GetProfiler(), testEvent2.GetProfiler()); |
| 92 | BOOST_CHECK_EQUAL(Compute::GpuAcc, testEvent2.GetComputeDevice()); |
| 93 | } |
| 94 | |
| 95 | BOOST_AUTO_TEST_SUITE_END() |