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