geopm  3.1.1.dev272+gdfb40a8d
GEOPM - Global Extensible Open Power Manager
DCGMIOGroup.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 DCGMIOGROUP_HPP_INCLUDE
7 #define DCGMIOGROUP_HPP_INCLUDE
8 
9 #include <map>
10 #include <vector>
11 #include <string>
12 #include <memory>
13 
14 #include "geopm/IOGroup.hpp"
15 
16 namespace geopm
17 {
18  class PlatformTopo;
19  class DCGMDevicePool;
20 
22  class DCGMIOGroup : public IOGroup
23  {
24  public:
25  DCGMIOGroup();
27  ~DCGMIOGroup();
28  std::set<std::string> signal_names(void) const override;
29  std::set<std::string> control_names(void) const override;
30  bool is_valid_signal(const std::string &signal_name) const override;
31  bool is_valid_control(const std::string &control_name) const override;
32  int signal_domain_type(const std::string &signal_name) const override;
33  int control_domain_type(const std::string &control_name) const override;
34  int push_signal(const std::string &signal_name, int domain_type, int domain_idx) override;
35  int push_control(const std::string &control_name, int domain_type, int domain_idx) override;
36  void read_batch(void) override;
37  void write_batch(void) override;
38  double sample(int batch_idx) override;
39  void adjust(int batch_idx, double setting) override;
40  double read_signal(const std::string &signal_name, int domain_type, int domain_idx) override;
41  void write_control(const std::string &control_name, int domain_type, int domain_idx, double setting) override;
42  void save_control(void) override;
43  void restore_control(void) override;
44  std::function<double(const std::vector<double> &)> agg_function(const std::string &signal_name) const override;
45  std::function<std::string(double)> format_function(const std::string &signal_name) const override;
46  std::string signal_description(const std::string &signal_name) const override;
47  std::string control_description(const std::string &control_name) const override;
48  int signal_behavior(const std::string &signal_name) const override;
49  void save_control(const std::string &save_path) override;
50  void restore_control(const std::string &save_path) override;
51  std::string name(void) const override;
52  static std::string plugin_name(void);
53  static std::unique_ptr<geopm::IOGroup> make_plugin(void);
54  private:
55  void register_signal_alias(const std::string &alias_name, const std::string &signal_name);
56  void register_control_alias(const std::string &alias_name, const std::string &control_name);
57 
58  const PlatformTopo &m_platform_topo;
59  DCGMDevicePool &m_dcgm_device_pool;
60  bool m_is_batch_read;
61 
62  struct signal_s
63  {
64  double m_value;
65  bool m_do_read;
66  };
67 
68  struct control_s
69  {
70  double m_setting;
71  bool m_is_adjusted;
72  };
73 
74  struct signal_info {
75  std::string m_description;
76  std::vector<std::shared_ptr<signal_s> > m_signals;
77  std::function<double (unsigned int)> m_devpool_func;
78  std::function<double(const std::vector<double> &)> m_agg_function;
79  std::function<std::string(double)> m_format_function;
80  };
81 
82  struct control_info {
83  std::string m_description;
84  std::vector<std::shared_ptr<control_s> > m_controls;
85  std::function<double(const std::vector<double> &)> m_agg_function;
86  std::function<std::string(double)> m_format_function;
87  };
88 
89  std::map<std::string, signal_info> m_signal_available;
90  std::map<std::string, control_info> m_control_available;
91  std::vector<std::shared_ptr<signal_s> > m_signal_pushed;
92  std::vector<std::shared_ptr<control_s> > m_control_pushed;
93  };
94 }
95 #endif
Definition: DCGMDevicePool.hpp:17
IOGroup that provides signals and controls for DCGM GPUs.
Definition: DCGMIOGroup.hpp:23
int control_domain_type(const std::string &control_name) const override
Query the domain for a named control.
Definition: DCGMIOGroup.cpp:163
void adjust(int batch_idx, double setting) override
Adjust a setting for a particular control that was previously pushed with push_control()....
Definition: DCGMIOGroup.cpp:305
bool is_valid_control(const std::string &control_name) const override
Test if control_name refers to a control supported by the group.
Definition: DCGMIOGroup.cpp:151
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: DCGMIOGroup.cpp:351
bool is_valid_signal(const std::string &signal_name) const override
Test if signal_name refers to a signal supported by the group.
Definition: DCGMIOGroup.cpp:145
std::string name(void) const override
Get the IOGroup name.
Definition: DCGMIOGroup.cpp:464
~DCGMIOGroup()
Definition: DCGMIOGroup.cpp:120
void restore_control(void) override
Restore all controls to values recorded in previous call to the save() method.
Definition: DCGMIOGroup.cpp:396
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: DCGMIOGroup.cpp:413
void save_control(void) override
Save the state of all controls so that any subsequent changes made through the IOGroup can be undone ...
Definition: DCGMIOGroup.cpp:387
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: DCGMIOGroup.cpp:169
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: DCGMIOGroup.cpp:448
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: DCGMIOGroup.cpp:213
DCGMIOGroup()
Definition: DCGMIOGroup.cpp:26
double sample(int batch_idx) override
Retrieve signal value from data read by last call to read_batch() for a particular signal previously ...
Definition: DCGMIOGroup.cpp:289
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: DCGMIOGroup.cpp:459
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: DCGMIOGroup.cpp:317
std::set< std::string > signal_names(void) const override
Returns the names of all signals provided by the IOGroup.
Definition: DCGMIOGroup.cpp:125
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: DCGMIOGroup.cpp:425
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: DCGMIOGroup.cpp:437
static std::unique_ptr< geopm::IOGroup > make_plugin(void)
Definition: DCGMIOGroup.cpp:476
void read_batch(void) override
Read all pushed signals from the platform so that the next call to sample() will reflect the updated ...
Definition: DCGMIOGroup.cpp:252
static std::string plugin_name(void)
Definition: DCGMIOGroup.cpp:470
int signal_domain_type(const std::string &signal_name) const override
Query the domain for a named signal.
Definition: DCGMIOGroup.cpp:157
std::set< std::string > control_names(void) const override
Returns the names of all controls provided by the IOGroup.
Definition: DCGMIOGroup.cpp:135
void write_batch(void) override
Write all of the pushed controls so that values previously given to adjust() are written to the platf...
Definition: DCGMIOGroup.cpp:276
Definition: IOGroup.hpp:21
Definition: PlatformTopo.hpp:28
Definition: Agg.cpp:20
const PlatformTopo & platform_topo(void)
Definition: PlatformTopo.cpp:81