Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RModel.hxx
Go to the documentation of this file.
1#ifndef TMVA_SOFIE_RMODEL
2#define TMVA_SOFIE_RMODEL
3
6#include "TMVA/ROperator.hxx"
7
8namespace TMVA {
9namespace Experimental {
10namespace SOFIE {
11
12class RModel: public RModel_Base {
13
14private:
15
16 std::unordered_map<std::string, InputTensorInfo> fInputTensorInfos; //graph input only; not including operator input (intermediate tensors)
17 std::unordered_map<std::string, TensorInfo> fReadyInputTensorInfos;
18 std::unordered_map<std::string, InitializedTensor> fInitializedTensors;
19 std::unordered_map<std::string, TensorInfo> fIntermediateTensorInfos;
20 std::vector<std::string> fOutputTensorNames;
21 std::vector<std::string> fInputTensorNames; //input tensor names using ONNX order
22
23 std::vector<std::unique_ptr<ROperator>> fOperators;
24
25public:
26
27 //explicit move ctor/assn
28 RModel(RModel&& other);
29
30 RModel& operator=(RModel&& other);
31
32 //disallow copy
33 RModel(const RModel& other) = delete;
34 RModel& operator=(const RModel& other) = delete;
35
36 RModel() {}
37 RModel(std::string name, std::string parsedtime): RModel_Base(name, parsedtime) {}
38
39 // For GNN Functions usage
40 RModel(std::string function_name):RModel_Base(function_name) {}
41
42 const std::vector<size_t>& GetTensorShape(std::string name);
43 const ETensorType& GetTensorType(std::string name);
44
45 bool CheckIfTensorAlreadyExist(std::string tensor_name);
46 void AddInputTensorInfo(std::string input_name, ETensorType type, std::vector<Dim> shape);
47 void AddInputTensorInfo(std::string input_name, ETensorType type, std::vector<size_t> shape);
48 void AddOperator(std::unique_ptr<ROperator> op, int order_execution = -1);
49 void AddOperatorReference(ROperator* op, int order_execution = -1) {
50 std::unique_ptr<ROperator> tmp(op);
51 AddOperator(std::move(tmp), order_execution);
52 }
53 void AddInitializedTensor(std::string tensor_name, ETensorType type, std::vector<std::size_t> shape, std::shared_ptr<void> data);
54
55 template <typename T>
56 void AddInitializedTensor(std::string tensor_name, ETensorType type, std::vector<std::size_t> shape, T* raw_data) {
57 int size=1;
58 for(auto item:shape) {
59 size*=(int)item;
60 }
61 std::shared_ptr<void> data(malloc(size * sizeof(T)), free);
62 std::memcpy(data.get(), raw_data, size * sizeof(T));
63 AddInitializedTensor(tensor_name, type, shape, data);
64 }
65
66 // Check if a tensor is initialized
67 bool IsInitializedTensor(const std::string& name) const;
68 void AddIntermediateTensor(std::string tensor_name, ETensorType type, std::vector<std::size_t> shape);
69
70 void AddInputTensorName(std::string name);
71 void AddOutputTensorNameList(std::vector<std::string> outputtensornames);
72 void UpdateOutputTensorList(std::vector<std::string> curr_output_tensor, std::vector<std::string> modify_output_tensor);
73 void UpdateInitializedTensor(std::string tensor_name, ETensorType type, std::vector<std::size_t> shape, std::shared_ptr<void> data);
74 std::shared_ptr<void> GetInitializedTensorData(std::string tensor_name);
75
76 void Initialize(int batchSize=1);
79 void GenerateOutput();
80 void Generate(std::underlying_type_t<Options> options, int batchSize = 1, long pos = 0);
81 void Generate(Options options = Options::kDefault, int batchSize = 1, int pos = 0) {
82 Generate(static_cast<std::underlying_type_t<Options>>(options), batchSize, pos);
83 }
84
85 const std::vector<std::string> & GetInputTensorNames() const {
86 return fInputTensorNames;
87 }
88 const std::vector<std::string> & GetOutputTensorNames() const {
89 return fOutputTensorNames;
90 }
91
93 long WriteInitializedTensorsToFile(std::string filename = "");
94
96 void PrintOutputTensors();
97 void OutputGenerated(std::string filename = "", bool append = false);
98 std::vector<std::string> GetOutputTensorNames() {
99 return fOutputTensorNames;
100 }
101 void SetFilename(std::string filename) {
102 fName = filename;
103 }
104
105 /*
106 template <typename T>
107 void AddInitializedTensor(std::string tensor_name, RTensor<T> new_tensor){
108 //a view only
109 T obj;
110 if (fInitializedTensors.find(tensor_name) != fInitializedTensors.end()){
111 throw std::runtime_error("TMVA-SOFIE: initialized tensor with name " + tensor_name + " already exists \n");
112 }
113 InitializedTensor new_tensor_ {GetTemplatedType(obj), new_tensor.GetShape() , static_cast<void>(new_tensor.GetData())};
114 fInitializedTensors[tensor_name] = new_tensor_;
115 }
116 */
117
120 void HeadInitializedTensors(std::string name, int n_print = 50);
121
122 bool UseSession() const {
123 return fUseSession;
124 }
125
127
129};
130
131}//SOFIE
132}//Experimental
133}//TMVA
134
135#endif //TMVA_SOFIE_RMODEL
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char name[80]
Definition TGX11.cxx:110
#define free
Definition civetweb.c:1539
#define malloc
Definition civetweb.c:1536
void AddOutputTensorNameList(std::vector< std::string > outputtensornames)
Definition RModel.cxx:165
const ETensorType & GetTensorType(std::string name)
Definition RModel.cxx:76
RModel(const RModel &other)=delete
const std::vector< std::string > & GetOutputTensorNames() const
Definition RModel.hxx:88
void AddOperatorReference(ROperator *op, int order_execution=-1)
Definition RModel.hxx:49
void Generate(Options options=Options::kDefault, int batchSize=1, int pos=0)
Definition RModel.hxx:81
void AddIntermediateTensor(std::string tensor_name, ETensorType type, std::vector< std::size_t > shape)
Definition RModel.cxx:156
RModel(std::string function_name)
Definition RModel.hxx:40
bool CheckIfTensorAlreadyExist(std::string tensor_name)
Definition RModel.cxx:97
std::vector< std::unique_ptr< ROperator > > fOperators
Definition RModel.hxx:23
void OutputGenerated(std::string filename="", bool append=false)
Definition RModel.cxx:737
void AddInputTensorInfo(std::string input_name, ETensorType type, std::vector< Dim > shape)
Definition RModel.cxx:104
void Initialize(int batchSize=1)
Definition RModel.cxx:197
std::unordered_map< std::string, TensorInfo > fIntermediateTensorInfos
Definition RModel.hxx:19
std::unordered_map< std::string, TensorInfo > fReadyInputTensorInfos
Definition RModel.hxx:17
void AddInitializedTensor(std::string tensor_name, ETensorType type, std::vector< std::size_t > shape, std::shared_ptr< void > data)
Definition RModel.cxx:140
RModel & operator=(RModel &&other)
Definition RModel.cxx:38
void AddInputTensorName(std::string name)
Definition RModel.cxx:123
std::vector< std::string > fOutputTensorNames
Definition RModel.hxx:20
bool IsInitializedTensor(const std::string &name) const
Definition RModel.cxx:151
void AddInitializedTensor(std::string tensor_name, ETensorType type, std::vector< std::size_t > shape, T *raw_data)
Definition RModel.hxx:56
void AddOperator(std::unique_ptr< ROperator > op, int order_execution=-1)
Definition RModel.cxx:127
void HeadInitializedTensors(std::string name, int n_print=50)
Definition RModel.cxx:701
const std::vector< size_t > & GetTensorShape(std::string name)
Definition RModel.cxx:55
long WriteInitializedTensorsToFile(std::string filename="")
Definition RModel.cxx:538
RModel & operator=(const RModel &other)=delete
void Generate(std::underlying_type_t< Options > options, int batchSize=1, long pos=0)
Definition RModel.cxx:381
std::unordered_map< std::string, InputTensorInfo > fInputTensorInfos
Definition RModel.hxx:16
std::shared_ptr< void > GetInitializedTensorData(std::string tensor_name)
Definition RModel.cxx:188
void SetFilename(std::string filename)
Definition RModel.hxx:101
std::vector< std::string > fInputTensorNames
Definition RModel.hxx:21
const std::vector< std::string > & GetInputTensorNames() const
Definition RModel.hxx:85
std::unordered_map< std::string, InitializedTensor > fInitializedTensors
Definition RModel.hxx:18
void UpdateInitializedTensor(std::string tensor_name, ETensorType type, std::vector< std::size_t > shape, std::shared_ptr< void > data)
Definition RModel.cxx:179
std::vector< std::string > GetOutputTensorNames()
Definition RModel.hxx:98
void UpdateOutputTensorList(std::vector< std::string > curr_output_tensor, std::vector< std::string > modify_output_tensor)
Definition RModel.cxx:172
RModel(std::string name, std::string parsedtime)
Definition RModel.hxx:37
create variable transformations