geopm  3.1.1.dev272+gdfb40a8d
GEOPM - Global Extensible Open Power Manager
DomainNetMapImp.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 DOMAINNETMAPIMP_HPP_INCLUDE
7 #define DOMAINNETMAPIMP_HPP_INCLUDE
8 
9 #include "DomainNetMap.hpp"
10 
11 #include <memory>
12 #include <set>
13 
14 #include "geopm/json11.hpp"
15 
16 #include "DenseLayer.hpp"
17 #include "LocalNeuralNet.hpp"
18 #include "TensorOneD.hpp"
19 #include "TensorTwoD.hpp"
20 #include "NNFactory.hpp"
21 
22 namespace geopm
23 {
24  class PlatformIO;
25 
27  {
28  public:
29  DomainNetMapImp(const std::string &nn_path, geopm_domain_e domain_type,
30  int domain_index);
31 
32  DomainNetMapImp(const std::string &nn_path, geopm_domain_e domain_type,
33  int domain_index, PlatformIO &plat_io,
34  std::shared_ptr<NNFactory> nn_factory);
35 
36  void sample() override;
38  // In this case, region classification names annotated with domain type and index.
39  std::vector<std::string> trace_names() const override;
43  std::vector<double> trace_values() const override;
48  std::map<std::string, double> last_output() const override;
49 
50  private:
51  std::shared_ptr<DenseLayer> json_to_DenseLayer(const json11::Json &obj) const;
52  TensorOneD json_to_TensorOneD(const json11::Json &obj) const;
53  TensorTwoD json_to_TensorTwoD(const json11::Json &obj) const;
54 
55  PlatformIO &m_platform_io;
56  std::shared_ptr<NNFactory> m_nn_factory;
57 
58  struct m_signal_s
59  {
60  int batch_idx;
61  double signal;
62  };
63 
64  struct m_delta_signal_s
65  {
66  int batch_idx_num;
67  int batch_idx_den;
68  double signal_num;
69  double signal_den;
70  double signal_num_last;
71  double signal_den_last;
72  };
73 
74  static const std::set<std::string> M_EXPECTED_KEYS;
75  // Size in bytes
76  static constexpr int M_MAX_NNET_SIZE = 1024 * 1024;
77  std::shared_ptr<LocalNeuralNet> m_neural_net;
78 
79  TensorOneD m_last_output;
80  std::vector<m_signal_s> m_signal_inputs;
81  std::vector<m_delta_signal_s> m_delta_inputs;
82  std::vector<std::string> m_trace_outputs;
83  };
84 }
85 
86 #endif /* DOMAINNETMAPIMP_HPP_INCLUDE */
Class to load neural net from file, sample signals specified in that file, feed those signals into th...
Definition: DomainNetMap.hpp:22
Definition: DomainNetMapImp.hpp:27
std::vector< double > trace_values() const override
Populates trace values from last_output for each index within each domain type. In this case,...
Definition: DomainNetMap.cpp:328
std::map< std::string, double > last_output() const override
Populates a map of trace names to the latest output from the neural net. In this case,...
Definition: DomainNetMap.cpp:335
std::vector< std::string > trace_names() const override
Generates the names for trace columns from the appropriate field in the neural net.
Definition: DomainNetMap.cpp:323
void sample() override
Samples latest signals for a specific domain and applies the resulting TensorOneD state to the neural...
Definition: DomainNetMap.cpp:302
DomainNetMapImp(const std::string &nn_path, geopm_domain_e domain_type, int domain_index)
Definition: DomainNetMap.cpp:40
Class to store and perform operations on 1D Tensors, aka vectors, suitable for use in feed-forward ne...
Definition: TensorOneD.hpp:21
Class to manage data and operations related to 2D Tensors required for neural net inference.
Definition: TensorTwoD.hpp:22
Definition: Accumulator.cpp:12