ArmNN
 24.02
ArmComputeTuningUtils.hpp
Go to the documentation of this file.
1 //
2 // Copyright © 2023 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 #pragma once
6 
8 #include <armnn/IRuntime.hpp>
9 #include <armnn/Logging.hpp>
10 
11 #include <arm_compute/runtime/CL/CLTuner.h>
12 #include <arm_compute/runtime/CL/CLTunerTypes.h>
13 #include <arm_compute/runtime/CL/CLGEMMHeuristicsHandle.h>
14 
15 namespace armnn
16 {
17 
18 enum class TuningLevel
19 {
20  None,
21  Rapid,
22  Normal,
24 };
25 
26 inline TuningLevel ParseTuningLevel(const BackendOptions::Var& value, TuningLevel defaultValue)
27 {
28  if (value.IsInt())
29  {
30  int v = value.AsInt();
31  if (v > static_cast<int>(TuningLevel::Exhaustive) ||
32  v < static_cast<int>(TuningLevel::None))
33  {
34  ARMNN_LOG(warning) << "Invalid GpuAcc tuning level ("<< v << ") selected. "
35  "Using default(" << static_cast<int>(defaultValue) << ")";
36  } else
37  {
38  return static_cast<TuningLevel>(v);
39  }
40  }
41  return defaultValue;
42 }
43 
44 inline void ConfigureTuner(arm_compute::CLTuner &tuner, TuningLevel level)
45 {
46  tuner.set_tune_new_kernels(true); // Turn on tuning initially.
47 
48  switch (level)
49  {
50  case TuningLevel::Rapid:
51  ARMNN_LOG(info) << "Gpu tuning is activated. TuningLevel: Rapid (1)";
52  tuner.set_tuner_mode(arm_compute::CLTunerMode::RAPID);
53  break;
55  ARMNN_LOG(info) << "Gpu tuning is activated. TuningLevel: Normal (2)";
56  tuner.set_tuner_mode(arm_compute::CLTunerMode::NORMAL);
57  break;
59  ARMNN_LOG(info) << "Gpu tuning is activated. TuningLevel: Exhaustive (3)";
60  tuner.set_tuner_mode(arm_compute::CLTunerMode::EXHAUSTIVE);
61  break;
62  case TuningLevel::None:
63  default:
64  tuner.set_tune_new_kernels(false); // Turn off tuning. Set to "use" only mode.
65  break;
66  }
67 }
68 
70 {
71 public:
73 
74  virtual void Load(const char* filename);
75  virtual void Save(const char* filename) const;
76 
79 
80  arm_compute::CLTuner m_Tuner;
81  arm_compute::CLGEMMHeuristicsHandle m_HeuristicsHandle;
82 };
83 
84 }
armnn::TuningLevel::Exhaustive
@ Exhaustive
armnn::IGpuAccTunedParameters::Mode
Mode
Definition: IRuntime.hpp:316
IRuntime.hpp
armnn::BackendOptions::Var::AsInt
int AsInt() const
Definition: BackendOptions.hpp:120
armnn::ClTunedParameters::m_Mode
Mode m_Mode
Definition: ArmComputeTuningUtils.hpp:77
armnn::TuningLevel::None
@ None
armnn::ClTunedParameters::ClTunedParameters
ClTunedParameters(IGpuAccTunedParameters::Mode mode, IGpuAccTunedParameters::TuningLevel tuningLevel)
Definition: ArmComputeTuningUtils.cpp:28
armnn::IGpuAccTunedParameters::TuningLevel
TuningLevel
Definition: IRuntime.hpp:322
armnn::ClTunedParameters::m_Tuner
arm_compute::CLTuner m_Tuner
Definition: ArmComputeTuningUtils.hpp:80
ARMNN_LOG
#define ARMNN_LOG(severity)
Definition: Logging.hpp:212
armnn::ClTunedParameters
Definition: ArmComputeTuningUtils.hpp:69
armnn::BackendOptions::Var::IsInt
bool IsInt() const
Definition: BackendOptions.hpp:113
Logging.hpp
armnn::ParseTuningLevel
TuningLevel ParseTuningLevel(const BackendOptions::Var &value, TuningLevel defaultValue)
Definition: ArmComputeTuningUtils.hpp:26
armnn::ConfigureTuner
void ConfigureTuner(arm_compute::CLTuner &tuner, TuningLevel level)
Definition: ArmComputeTuningUtils.hpp:44
armnn::ClTunedParameters::Load
virtual void Load(const char *filename)
Loads an existing set of tuned parameters from the given file.
Definition: ArmComputeTuningUtils.cpp:36
armnn::BoostLogSeverityMapping::info
@ info
armnn::ClTunedParameters::Save
virtual void Save(const char *filename) const
Saves the current set of tuned parameters to the given file.
Definition: ArmComputeTuningUtils.cpp:48
armnn::TuningLevel::Rapid
@ Rapid
armnn::TuningLevel::Normal
@ Normal
armnn::BackendOptions::Var
Very basic type safe variant.
Definition: BackendOptions.hpp:38
BackendOptions.hpp
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition: 01_00_quick_start.dox:6
armnn::BoostLogSeverityMapping::warning
@ warning
armnn::TuningLevel
TuningLevel
Definition: ArmComputeTuningUtils.hpp:18
armnn::ClTunedParameters::m_TuningLevel
TuningLevel m_TuningLevel
Definition: ArmComputeTuningUtils.hpp:78
armnn::ClTunedParameters::m_HeuristicsHandle
arm_compute::CLGEMMHeuristicsHandle m_HeuristicsHandle
Definition: ArmComputeTuningUtils.hpp:81
armnn::IGpuAccTunedParameters
Manages a set of GpuAcc parameters which have been tuned for maximum performance.
Definition: IRuntime.hpp:313