Release 18.08
[platform/upstream/armnn.git] / src / armnn / NeonTimer.cpp
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // See LICENSE file in the project root for full license information.
4 //
5
6 #include "NeonTimer.hpp"
7 #include "NeonInterceptorScheduler.hpp"
8
9 #include <memory>
10
11 #include <boost/assert.hpp>
12 #include <boost/format.hpp>
13
14 namespace armnn
15 {
16
17 void NeonTimer::Start()
18 {
19     m_Kernels.clear();
20     m_RealSchedulerType = arm_compute::Scheduler::get_type();
21     //Note: We can't currently replace a custom scheduler
22     if(m_RealSchedulerType != arm_compute::Scheduler::Type::CUSTOM)
23     {
24         // Keep the real schedule and add NeonInterceptorScheduler as an interceptor
25         m_RealScheduler  = &arm_compute::Scheduler::get();
26         auto interceptor = std::make_shared<NeonInterceptorScheduler>(m_Kernels, *m_RealScheduler);
27         arm_compute::Scheduler::set(std::static_pointer_cast<arm_compute::IScheduler>(interceptor));
28     }
29 }
30
31 void NeonTimer::Stop()
32 {
33     // Restore real scheduler
34     arm_compute::Scheduler::set(m_RealSchedulerType);
35     m_RealScheduler = nullptr;
36 }
37
38 std::vector<Measurement> NeonTimer::GetMeasurements() const
39 {
40     std::vector<Measurement> measurements = m_Kernels;
41     unsigned int kernel_number = 0;
42     for (auto & kernel : measurements)
43     {
44         std::string kernelName = std::string(this->GetName()) + "/" + std::to_string(kernel_number++) + ": " + kernel
45                 .m_Name;
46         kernel.m_Name = kernelName;
47     }
48     return measurements;
49 }
50
51 const char* NeonTimer::GetName() const
52 {
53     return "NeonKernelTimer";
54 }
55
56 }