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; //input tensors where shape is not defined or other graph inputs?
17 std::unordered_map<std::string, TensorInfo> fReadyInputTensorInfos; // input tensors where shape is full defined
18 std::unordered_map<std::string, InitializedTensor> fInitializedTensors;
19 std::unordered_map<std::string, TensorInfo> fIntermediateTensorInfos;
20 std::unordered_map<std::string, DynamicTensorInfo> fDynamicTensorInfos;
21 std::unordered_map<std::string, std::string> fShapeParams; // parameters defining the dynamic shape (e.g. batch size), store also its default value
22 std::vector<std::string> fOutputTensorNames;
23 std::vector<std::string> fInputTensorNames; //input tensor names using ONNX order
24
25 std::vector<std::unique_ptr<ROperator>> fOperators;
26
27 const std::string SP = " ";
28
29public:
30
31 //explicit move ctor/assn
32 RModel(RModel&& other);
33
34 RModel& operator=(RModel&& other);
35
36 //disallow copy
37 RModel(const RModel& other) = delete;
38 RModel& operator=(const RModel& other) = delete;
39
40 RModel() {}
41 RModel(std::string name, std::string parsedtime): RModel_Base(name, parsedtime) {}
42
43 // For GNN Functions usage
44 RModel(std::string function_name):RModel_Base(function_name) {}
45
46 const std::vector<size_t>& GetTensorShape(std::string name);
47 std::vector<Dim> GetDynamicTensorShape(std::string name);
48 const ETensorType& GetTensorType(std::string name);
49
50 bool CheckIfTensorAlreadyExist(std::string tensor_name);
51 void AddInputTensorInfo(std::string input_name, ETensorType type, std::vector<Dim> shape);
52 void AddInputTensorInfo(std::string input_name, ETensorType type, std::vector<size_t> shape);
53 void AddOperator(std::unique_ptr<ROperator> op, int order_execution = -1);
54 void AddOperatorReference(ROperator* op, int order_execution = -1) {
55 std::unique_ptr<ROperator> tmp(op);
56 AddOperator(std::move(tmp), order_execution);
57 }
58 void AddInitializedTensor(std::string tensor_name, ETensorType type, std::vector<std::size_t> shape, std::shared_ptr<void> data);
59
60 template <typename T>
61 void AddInitializedTensor(std::string tensor_name, ETensorType type, std::vector<std::size_t> shape, T* raw_data) {
62 int size=1;
63 for(auto item:shape) {
64 size*=(int)item;
65 }
66 std::shared_ptr<void> data(malloc(size * sizeof(T)), free);
67 std::memcpy(data.get(), raw_data, size * sizeof(T));
68 AddInitializedTensor(tensor_name, type, shape, data);
69 }
70
71 // Check if a tensor is initialized
72 bool IsInitializedTensor(const std::string& name) const;
73 bool IsDynamicTensor(const std::string& name) const;
74 bool IsInputTensor(const std::string& name) const;
75
76 // Add intermediate tensor
77 void AddIntermediateTensor(std::string tensor_name, ETensorType type, std::vector<Dim> dim_shape);
78 void AddIntermediateTensor(std::string tensor_name, ETensorType type, std::vector<std::size_t> shape);
79 // Add an intermediate dynamic tensor
80 void AddDynamicTensor(std::string tensor_name, ETensorType type, std::vector<Dim> shape);
81
82 void AddInputTensorName(std::string name);
83 void AddOutputTensorNameList(std::vector<std::string> output_tensor_names);
84 void UpdateOutputTensorList(std::vector<std::string> curr_output_tensor, std::vector<std::string> modify_output_tensor);
85 void UpdateInitializedTensor(std::string tensor_name, ETensorType type, std::vector<std::size_t> shape, std::shared_ptr<void> data);
86 std::shared_ptr<void> GetInitializedTensorData(std::string tensor_name);
87
88 void Initialize(int batchSize = -1, bool verbose = false);
92 void GenerateOutput();
93 void Generate(std::underlying_type_t<Options> options, int batchSize = -1, long pos = 0);
94 void Generate(Options options = Options::kDefault, int batchSize = -1, int pos = 0) {
95 Generate(static_cast<std::underlying_type_t<Options>>(options), batchSize, pos);
96 }
97
98 const std::vector<std::string> & GetInputTensorNames() const {
99 return fInputTensorNames;
100 }
101 const std::vector<std::string> & GetOutputTensorNames() const {
102 return fOutputTensorNames;
103 }
104
106 long WriteInitializedTensorsToFile(std::string filename = "");
107
109 void PrintOutputTensors();
110 void OutputGenerated(std::string filename = "", bool append = false);
111 std::vector<std::string> GetOutputTensorNames() {
112 return fOutputTensorNames;
113 }
114 void SetFilename(std::string filename) {
115 fName = filename;
116 }
117
118 /*
119 template <typename T>
120 void AddInitializedTensor(std::string tensor_name, RTensor<T> new_tensor){
121 //a view only
122 T obj;
123 if (fInitializedTensors.find(tensor_name) != fInitializedTensors.end()){
124 throw std::runtime_error("TMVA-SOFIE: initialized tensor with name " + tensor_name + " already exists \n");
125 }
126 InitializedTensor new_tensor_ {GetTemplatedType(obj), new_tensor.GetShape() , static_cast<void>(new_tensor.GetData())};
127 fInitializedTensors[tensor_name] = new_tensor_;
128 }
129 */
130
133 void PrintDynamicTensors();
134 void HeadInitializedTensors(std::string name, int n_print = 50);
135
136 bool UseSession() const {
137 return fUseSession;
138 }
139
141
143};
144
145}//SOFIE
146}//Experimental
147}//TMVA
148
149#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 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 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 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
const ETensorType & GetTensorType(std::string name)
Definition RModel.cxx:91
std::unordered_map< std::string, DynamicTensorInfo > fDynamicTensorInfos
Definition RModel.hxx:20
bool IsDynamicTensor(const std::string &name) const
Definition RModel.cxx:177
RModel(const RModel &other)=delete
const std::vector< std::string > & GetOutputTensorNames() const
Definition RModel.hxx:101
void AddIntermediateTensor(std::string tensor_name, ETensorType type, std::vector< Dim > dim_shape)
Definition RModel.cxx:187
std::vector< Dim > GetDynamicTensorShape(std::string name)
Definition RModel.cxx:79
void AddOperatorReference(ROperator *op, int order_execution=-1)
Definition RModel.hxx:54
RModel(std::string function_name)
Definition RModel.hxx:44
bool CheckIfTensorAlreadyExist(std::string tensor_name)
Definition RModel.cxx:116
std::vector< std::unique_ptr< ROperator > > fOperators
Definition RModel.hxx:25
void OutputGenerated(std::string filename="", bool append=false)
Definition RModel.cxx:923
void AddInputTensorInfo(std::string input_name, ETensorType type, std::vector< Dim > shape)
Definition RModel.cxx:125
std::unordered_map< std::string, TensorInfo > fIntermediateTensorInfos
Definition RModel.hxx:19
void AddOutputTensorNameList(std::vector< std::string > output_tensor_names)
Definition RModel.cxx:225
std::unordered_map< std::string, TensorInfo > fReadyInputTensorInfos
Definition RModel.hxx:17
void AddDynamicTensor(std::string tensor_name, ETensorType type, std::vector< Dim > shape)
Definition RModel.cxx:204
void AddInitializedTensor(std::string tensor_name, ETensorType type, std::vector< std::size_t > shape, std::shared_ptr< void > data)
Definition RModel.cxx:161
RModel & operator=(RModel &&other)
Definition RModel.cxx:39
void AddInputTensorName(std::string name)
Definition RModel.cxx:144
std::vector< std::string > fOutputTensorNames
Definition RModel.hxx:22
bool IsInitializedTensor(const std::string &name) const
Definition RModel.cxx:172
void AddInitializedTensor(std::string tensor_name, ETensorType type, std::vector< std::size_t > shape, T *raw_data)
Definition RModel.hxx:61
void AddOperator(std::unique_ptr< ROperator > op, int order_execution=-1)
Definition RModel.cxx:148
void HeadInitializedTensors(std::string name, int n_print=50)
Definition RModel.cxx:887
void Initialize(int batchSize=-1, bool verbose=false)
Definition RModel.cxx:257
const std::vector< size_t > & GetTensorShape(std::string name)
Definition RModel.cxx:56
bool IsInputTensor(const std::string &name) const
Definition RModel.cxx:181
long WriteInitializedTensorsToFile(std::string filename="")
Definition RModel.cxx:703
RModel & operator=(const RModel &other)=delete
void Generate(std::underlying_type_t< Options > options, int batchSize=-1, long pos=0)
Definition RModel.cxx:529
std::unordered_map< std::string, InputTensorInfo > fInputTensorInfos
Definition RModel.hxx:16
std::shared_ptr< void > GetInitializedTensorData(std::string tensor_name)
Definition RModel.cxx:248
void SetFilename(std::string filename)
Definition RModel.hxx:114
std::unordered_map< std::string, std::string > fShapeParams
Definition RModel.hxx:21
void Generate(Options options=Options::kDefault, int batchSize=-1, int pos=0)
Definition RModel.hxx:94
std::vector< std::string > fInputTensorNames
Definition RModel.hxx:23
const std::vector< std::string > & GetInputTensorNames() const
Definition RModel.hxx:98
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:239
std::vector< std::string > GetOutputTensorNames()
Definition RModel.hxx:111
void UpdateOutputTensorList(std::vector< std::string > curr_output_tensor, std::vector< std::string > modify_output_tensor)
Definition RModel.cxx:232
RModel(std::string name, std::string parsedtime)
Definition RModel.hxx:41
create variable transformations