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