geopm  3.1.1.dev296+g5916b956
GEOPM - Global Extensible Open Power Manager
LevelZeroIOGroup.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 - 2024 Intel Corporation
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 
6 #ifndef LEVELZEROIOGROUP_HPP_INCLUDE
7 #define LEVELZEROIOGROUP_HPP_INCLUDE
8 
9 #include <map>
10 #include <vector>
11 #include <string>
12 #include <memory>
13 #include <functional>
14 
15 #include "geopm/IOGroup.hpp"
16 #include "LevelZeroSignal.hpp"
17 
18 namespace geopm
19 {
20  class PlatformTopo;
21  class LevelZeroDevicePool;
22  class SaveControl;
23 
25  class LevelZeroIOGroup : public IOGroup
26  {
27  public:
30  const LevelZeroDevicePool &device_pool,
31  std::shared_ptr<SaveControl> save_control_test);
32  virtual ~LevelZeroIOGroup() = default;
33  std::set<std::string> signal_names(void) const override;
34  std::set<std::string> control_names(void) const override;
35  bool is_valid_signal(const std::string &signal_name) const override;
36  bool is_valid_control(const std::string &control_name) const override;
37  int signal_domain_type(const std::string &signal_name) const override;
38  int control_domain_type(const std::string &control_name) const override;
39  int push_signal(const std::string &signal_name, int domain_type,
40  int domain_idx) override;
41  int push_control(const std::string &control_name, int domain_type,
42  int domain_idx) override;
43  void read_batch(void) override;
44  void write_batch(void) override;
45  double sample(int batch_idx) override;
46  void adjust(int batch_idx, double setting) override;
47  double read_signal(const std::string &signal_name, int domain_type,
48  int domain_idx) override;
49  void write_control(const std::string &control_name, int domain_type,
50  int domain_idx, double setting) override;
51  void save_control(void) override;
52  void restore_control(void) override;
53  std::function<double(const std::vector<double> &)> agg_function(
54  const std::string &signal_name) const override;
55  std::function<std::string(double)> format_function(
56  const std::string &signal_name) const override;
57  std::string signal_description(const std::string
58  &signal_name) const override;
59  std::string control_description(const std::string
60  &control_name) const override;
61  int signal_behavior(const std::string &signal_name) const override;
62  void save_control(const std::string &save_path) override;
63  void restore_control(const std::string &save_path) override;
64  std::string name(void) const override;
65  static std::string plugin_name(void);
66  static std::unique_ptr<IOGroup> make_plugin(void);
67  private:
68  void init(void);
69 
70  void register_derivative_signals(void);
71  void register_signal_alias(const std::string &alias_name,
72  const std::string &signal_name);
73  void register_control_alias(const std::string &alias_name,
74  const std::string &control_name);
75 
76  struct control_s {
77  double m_setting;
78  bool m_is_adjusted;
79  };
80 
81  struct signal_info {
82  std::string m_description;
83  int m_domain_type;
84  std::function<double(const std::vector<double> &)> m_agg_function;
85  int behavior;
86  std::function<std::string(double)> m_format_function;
87  std::vector<std::shared_ptr<Signal> > m_signals;
88  std::function<double (unsigned int)> m_devpool_func;
89  double m_scalar;
90  };
91 
92  struct control_info {
93  std::string m_description;
94  std::vector<std::shared_ptr<control_s> > m_controls;
95  int m_domain_type;
96  std::function<double(const std::vector<double> &)> m_agg_function;
97  std::function<std::string(double)> m_format_function;
98  };
99 
100  struct derivative_signal_info
101  {
102  std::string m_description;
103  std::string m_base_name;
104  std::string m_time_name;
105  std::function<double(const std::vector<double> &)> m_agg_function;
106  int m_behavior;
107  double m_nan_replace;
108  };
109 
110  static const std::string M_PLUGIN_NAME;
111  static const std::string M_NAME_PREFIX;
112  const PlatformTopo &m_platform_topo;
113  const LevelZeroDevicePool &m_levelzero_device_pool;
114  bool m_is_batch_read;
115  int m_native_domain;
116 
117  std::map<std::string, signal_info> m_signal_available;
118  std::map<std::string, control_info> m_control_available;
119  std::vector<std::shared_ptr<Signal> > m_signal_pushed;
120  std::vector<std::shared_ptr<control_s> > m_control_pushed;
121  const std::set<std::string> m_special_signal_set;
122  std::map<std::string, derivative_signal_info> m_derivative_signal_map;
123  std::set<int> m_derivative_signal_pushed_set;
124 
125  //GEOPM Domain indexed
126  std::vector<std::pair<double,double> > m_frequency_range;
127  std::vector<double> m_perf_factor;
128 
129  std::shared_ptr<SaveControl> m_mock_save_ctl;
130 
131  bool m_is_perf_factor_enabled;
132  };
133 }
134 #endif
Definition: IOGroup.hpp:21
Definition: LevelZeroDevicePool.hpp:19
IOGroup that provides signals and controls for GPUs.
Definition: LevelZeroIOGroup.hpp:26
std::function< double(const std::vector< double > &)> agg_function(const std::string &signal_name) const override
Return a function that should be used when aggregating the given signal.
Definition: LevelZeroIOGroup.cpp:1446
int signal_domain_type(const std::string &signal_name) const override
Query the domain for a named signal.
Definition: LevelZeroIOGroup.cpp:1019
static std::unique_ptr< IOGroup > make_plugin(void)
Definition: LevelZeroIOGroup.cpp:1516
int push_signal(const std::string &signal_name, int domain_type, int domain_idx) override
Add a signal to the list of signals that is read by read_batch() and sampled by sample().
Definition: LevelZeroIOGroup.cpp:1041
std::function< std::string(double)> format_function(const std::string &signal_name) const override
Returns a function that can be used to convert a signal of the given name into a printable string....
Definition: LevelZeroIOGroup.cpp:1458
std::set< std::string > control_names(void) const override
Returns the names of all controls provided by the IOGroup.
Definition: LevelZeroIOGroup.cpp:997
double read_signal(const std::string &signal_name, int domain_type, int domain_idx) override
Read from platform and interpret into SI units a signal given its name and domain....
Definition: LevelZeroIOGroup.cpp:1264
std::string name(void) const override
Get the IOGroup name.
Definition: LevelZeroIOGroup.cpp:1493
void read_batch(void) override
Read all pushed signals from the platform so that the next call to sample() will reflect the updated ...
Definition: LevelZeroIOGroup.cpp:1178
void restore_control(void) override
Restore all controls to values recorded in previous call to the save() method.
Definition: LevelZeroIOGroup.cpp:1401
static std::string plugin_name(void)
Definition: LevelZeroIOGroup.cpp:1499
std::set< std::string > signal_names(void) const override
Returns the names of all signals provided by the IOGroup.
Definition: LevelZeroIOGroup.cpp:987
int push_control(const std::string &control_name, int domain_type, int domain_idx) override
Add a control to the list of controls that is written by write_batch() and configured with adjust().
Definition: LevelZeroIOGroup.cpp:1133
std::string control_description(const std::string &control_name) const override
Returns a description of the control. This string can be used by tools to generate help text for user...
Definition: LevelZeroIOGroup.cpp:1482
LevelZeroIOGroup()
Definition: LevelZeroIOGroup.cpp:36
void write_control(const std::string &control_name, int domain_type, int domain_idx, double setting) override
Interpret the setting and write setting to the platform. Does not modify the values stored by calling...
Definition: LevelZeroIOGroup.cpp:1303
void write_batch(void) override
Write all of the pushed controls so that values previously given to adjust() are written to the platf...
Definition: LevelZeroIOGroup.cpp:1192
int control_domain_type(const std::string &control_name) const override
Query the domain for a named control.
Definition: LevelZeroIOGroup.cpp:1030
int signal_behavior(const std::string &signal_name) const override
Returns a hint about how a signal will change as a function of time.
Definition: LevelZeroIOGroup.cpp:1504
void adjust(int batch_idx, double setting) override
Adjust a setting for a particular control that was previously pushed with push_control()....
Definition: LevelZeroIOGroup.cpp:1249
double sample(int batch_idx) override
Retrieve signal value from data read by last call to read_batch() for a particular signal previously ...
Definition: LevelZeroIOGroup.cpp:1228
virtual ~LevelZeroIOGroup()=default
std::string signal_description(const std::string &signal_name) const override
Returns a description of the signal. This string can be used by tools to generate help text for users...
Definition: LevelZeroIOGroup.cpp:1470
bool is_valid_signal(const std::string &signal_name) const override
Test if signal_name refers to a signal supported by the group.
Definition: LevelZeroIOGroup.cpp:1007
void save_control(void) override
Save the state of all controls so that any subsequent changes made through the IOGroup can be undone ...
Definition: LevelZeroIOGroup.cpp:1358
bool is_valid_control(const std::string &control_name) const override
Test if control_name refers to a control supported by the group.
Definition: LevelZeroIOGroup.cpp:1013
Definition: PlatformTopo.hpp:28
Definition: Agg.cpp:20
const PlatformTopo & platform_topo(void)
Definition: PlatformTopo.cpp:81