ArmNN
 24.05
NeonTimer.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017, 2024 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include "NeonTimer.hpp"
8 
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 
21 {
22  m_Kernels.clear();
23  if (g_Interceptor->GetKernels() != nullptr)
24  {
25  throw RuntimeException("This NeonTimer instance has already been started.");
26  }
27  g_Interceptor->SetKernels(&m_Kernels);
28 
29  m_RealSchedulerType = arm_compute::Scheduler::get_type();
30  //Note: We can't currently replace a custom scheduler
31  if(m_RealSchedulerType != arm_compute::Scheduler::Type::CUSTOM)
32  {
33  // Keep the real schedule and add NeonInterceptorScheduler as an interceptor
34  m_RealScheduler = &arm_compute::Scheduler::get();
35  arm_compute::Scheduler::set(armnn::PolymorphicPointerDowncast<arm_compute::IScheduler>(g_Interceptor));
36  }
37 }
38 
40 {
41  // Restore real scheduler
42  g_Interceptor->SetKernels(nullptr);
43  arm_compute::Scheduler::set(m_RealSchedulerType);
44  m_RealScheduler = nullptr;
45 }
46 
48 {
49  return m_Kernels.size() > 0;
50 }
51 
52 std::vector<Measurement> NeonTimer::GetMeasurements() const
53 {
54  std::vector<Measurement> measurements = m_Kernels;
55  unsigned int kernel_number = 0;
56  for (auto & kernel : measurements)
57  {
58  std::string kernelName = std::string(this->GetName()) + "/" + std::to_string(kernel_number++) + ": " + kernel
59  .m_Name;
60  kernel.m_Name = kernelName;
61  }
62  return measurements;
63 }
64 
65 const char* NeonTimer::GetName() const
66 {
67  return "NeonKernelTimer";
68 }
69 
70 }
armnn::NeonTimer::GetMeasurements
std::vector< Measurement > GetMeasurements() const override
Definition: NeonTimer.cpp:52
armnn::NeonTimer::Stop
void Stop() override
Definition: NeonTimer.cpp:39
armnn::NeonTimer::GetName
const char * GetName() const override
Definition: NeonTimer.cpp:65
NeonInterceptorScheduler.hpp
PolymorphicDowncast.hpp
armnn::RuntimeException
Definition: Exceptions.hpp:120
armnn::NeonTimer::HasKernelMeasurements
bool HasKernelMeasurements() const override
Definition: NeonTimer.cpp:47
armnn::NeonTimer::Start
void Start() override
Definition: NeonTimer.cpp:20
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition: 01_00_quick_start.dox:6
NeonTimer.hpp