blob: 6d99d3f08eb241d84895ef71939b0bbcbfdde400 [file] [log] [blame]
Cathal Corbettd9e55f02023-01-11 13:03:21 +00001//
2// Copyright © 2023 Arm Ltd and Contributors. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5#pragma once
6
7#include <armnn/BackendOptions.hpp>
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
15namespace armnn
16{
17
18enum class TuningLevel
19{
20 None,
21 Rapid,
22 Normal,
23 Exhaustive
24};
25
26inline 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
44inline 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;
54 case TuningLevel::Normal:
55 ARMNN_LOG(info) << "Gpu tuning is activated. TuningLevel: Normal (2)";
56 tuner.set_tuner_mode(arm_compute::CLTunerMode::NORMAL);
57 break;
58 case TuningLevel::Exhaustive:
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
69class ClTunedParameters : public IGpuAccTunedParameters
70{
71public:
72 ClTunedParameters(IGpuAccTunedParameters::Mode mode, IGpuAccTunedParameters::TuningLevel tuningLevel);
73
74 virtual void Load(const char* filename);
75 virtual void Save(const char* filename) const;
76
77 Mode m_Mode;
78 TuningLevel m_TuningLevel;
79
80 arm_compute::CLTuner m_Tuner;
81 arm_compute::CLGEMMHeuristicsHandle m_HeuristicsHandle;
82};
83
84}