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 namespace armnn 14 { 15 namespace 16 { 17 static thread_local auto g_Interceptor = std::make_shared<NeonInterceptorScheduler>(arm_compute::Scheduler::get()); 18 } 19 Start()20void NeonTimer::Start() 21 { 22 m_Kernels.clear(); 23 ARMNN_ASSERT(g_Interceptor->GetKernels() == nullptr); 24 g_Interceptor->SetKernels(&m_Kernels); 25 26 m_RealSchedulerType = arm_compute::Scheduler::get_type(); 27 //Note: We can't currently replace a custom scheduler 28 if(m_RealSchedulerType != arm_compute::Scheduler::Type::CUSTOM) 29 { 30 // Keep the real schedule and add NeonInterceptorScheduler as an interceptor 31 m_RealScheduler = &arm_compute::Scheduler::get(); 32 arm_compute::Scheduler::set(std::static_pointer_cast<arm_compute::IScheduler>(g_Interceptor)); 33 } 34 } 35 Stop()36void NeonTimer::Stop() 37 { 38 // Restore real scheduler 39 g_Interceptor->SetKernels(nullptr); 40 arm_compute::Scheduler::set(m_RealSchedulerType); 41 m_RealScheduler = nullptr; 42 } 43 GetMeasurements() const44std::vector<Measurement> NeonTimer::GetMeasurements() const 45 { 46 std::vector<Measurement> measurements = m_Kernels; 47 unsigned int kernel_number = 0; 48 for (auto & kernel : measurements) 49 { 50 std::string kernelName = std::string(this->GetName()) + "/" + std::to_string(kernel_number++) + ": " + kernel 51 .m_Name; 52 kernel.m_Name = kernelName; 53 } 54 return measurements; 55 } 56 GetName() const57const char* NeonTimer::GetName() const 58 { 59 return "NeonKernelTimer"; 60 } 61 62 } 63