Logo ROOT  
Reference Guide
RModel.hxx
Go to the documentation of this file.
1#ifndef TMVA_SOFIE_RMODEL
2#define TMVA_SOFIE_RMODEL
3
4#include <unordered_set>
5#include <vector>
6#include <unordered_map>
7#include <iostream>
8#include <memory>
9#include <ctime>
10#include <set>
11#include <iomanip>
12#include <fstream>
13#include <sstream>
14#include "TMVA/SOFIE_common.hxx"
15#include "TMVA/ROperator.hxx"
16#include "TBuffer.h"
17
18namespace TMVA{
19namespace Experimental{
20namespace SOFIE{
21
22class RModel: public TObject{
23
24private:
25
26 std::unordered_map<std::string, InputTensorInfo> fInputTensorInfos; //graph input only; not including operator input (intermediate tensors)
27 std::unordered_map<std::string, TensorInfo> fReadyInputTensorInfos;
28 std::unordered_map<std::string, InitializedTensor> fInitializedTensors;
29 std::unordered_map<std::string, TensorInfo> fIntermediateTensorInfos;
30 std::vector<std::string> fOutputTensorNames;
31
32 std::vector<std::unique_ptr<ROperator>> fOperators;
33
34 std::string fName="UnnamedModel";
35 std::string fFileName; //file name of original model file for identification
36 std::string fParseTime; //UTC date and time string at parsing
37
38
39 std::string fGC; //generated code
40 std::unordered_set<std::string> fNeededBlasRoutines;
41
42 const std::unordered_set<std::string> fAllowedStdLib = {"vector", "algorithm", "cmath"};
43 std::unordered_set<std::string> fNeededStdLib = {"vector"};
44
45
46
47public:
48
49 //explicit move ctor/assn
50 RModel(RModel&& other);
51
52 RModel& operator=(RModel&& other);
53
54 //disallow copy
55 RModel(const RModel& other) = delete;
56 RModel& operator=(const RModel& other) = delete;
57
59 RModel(std::string name, std::string parsedtime);
60
61 const std::vector<size_t>& GetTensorShape(std::string name);
62 const ETensorType& GetTensorType(std::string name);
63
64 bool CheckIfTensorAlreadyExist(std::string tensor_name);
65 void AddInputTensorInfo(std::string input_name, ETensorType type, std::vector<Dim> shape);
66 void AddInputTensorInfo(std::string input_name, ETensorType type, std::vector<size_t> shape);
67 void AddOperator(std::unique_ptr<ROperator> op, int order_execution = -1);
68 void AddInitializedTensor(std::string tensor_name, ETensorType type, std::vector<std::size_t> shape, std::shared_ptr<void> data);
69 void AddIntermediateTensor(std::string tensor_name, ETensorType type, std::vector<std::size_t> shape);
70 void AddBlasRoutines(std::vector<std::string> routines) {
71 for (auto &routine : routines) {
72 fNeededBlasRoutines.insert(routine);
73 }
74 }
75 void AddNeededStdLib(std::string libname) {
76 if (fAllowedStdLib.find(libname) != fAllowedStdLib.end()) {
77 fNeededStdLib.insert(libname);
78 }
79 }
80 void AddOutputTensorNameList(std::vector<std::string> outputtensornames);
81 void UpdateInitializedTensor(std::string tensor_name, ETensorType type, std::vector<std::size_t> shape, std::shared_ptr<void> data);
82 std::shared_ptr<void> GetInitializedTensorData(std::string tensor_name);
83
84
85 void Initialize();
86 void Generate();
87
89 std::cout << fGC;
90 }
92 void OutputGenerated(std::string filename = "");
93
94
95/*
96 template <typename T>
97 void AddInitializedTensor(std::string tensor_name, RTensor<T> new_tensor){
98 //a view only
99 T obj;
100 if (fInitializedTensors.find(tensor_name) != fInitializedTensors.end()){
101 throw std::runtime_error("TMVA-SOFIE: initialized tensor with name " + tensor_name + " already exists \n");
102 }
103 InitializedTensor new_tensor_ {GetTemplatedType(obj), new_tensor.GetShape() , static_cast<void>(new_tensor.GetData())};
104 fInitializedTensors[tensor_name] = new_tensor_;
105 }
106*/
107
110 void HeadInitializedTensors(std::string name, int n_print = 50);
111
113 /*
114 for (auto& i: fInitializedTensors){
115 free(i.second.data);
116 }
117 */
118 }
119 ClassDef(RModel,1);
120};
121
122}//SOFIE
123}//Experimental
124}//TMVA
125
126#endif //TMVA_SOFIE_RMODEL
#define ClassDef(name, id)
Definition: Rtypes.h:325
char name[80]
Definition: TGX11.cxx:110
int type
Definition: TGX11.cxx:121
void AddOutputTensorNameList(std::vector< std::string > outputtensornames)
Definition: RModel.cxx:143
const ETensorType & GetTensorType(std::string name)
Definition: RModel.cxx:68
RModel(const RModel &other)=delete
void AddIntermediateTensor(std::string tensor_name, ETensorType type, std::vector< std::size_t > shape)
Definition: RModel.cxx:134
std::unordered_set< std::string > fNeededBlasRoutines
Definition: RModel.hxx:40
bool CheckIfTensorAlreadyExist(std::string tensor_name)
Definition: RModel.cxx:89
std::vector< std::unique_ptr< ROperator > > fOperators
Definition: RModel.hxx:32
void AddInputTensorInfo(std::string input_name, ETensorType type, std::vector< Dim > shape)
Definition: RModel.cxx:96
std::unordered_map< std::string, TensorInfo > fIntermediateTensorInfos
Definition: RModel.hxx:29
std::unordered_map< std::string, TensorInfo > fReadyInputTensorInfos
Definition: RModel.hxx:27
void AddInitializedTensor(std::string tensor_name, ETensorType type, std::vector< std::size_t > shape, std::shared_ptr< void > data)
Definition: RModel.cxx:123
RModel & operator=(RModel &&other)
Definition: RModel.cxx:27
void AddBlasRoutines(std::vector< std::string > routines)
Definition: RModel.hxx:70
std::vector< std::string > fOutputTensorNames
Definition: RModel.hxx:30
void AddNeededStdLib(std::string libname)
Definition: RModel.hxx:75
std::unordered_set< std::string > fNeededStdLib
Definition: RModel.hxx:43
void AddOperator(std::unique_ptr< ROperator > op, int order_execution=-1)
Definition: RModel.cxx:115
void HeadInitializedTensors(std::string name, int n_print=50)
Definition: RModel.cxx:361
void OutputGenerated(std::string filename="")
Definition: RModel.cxx:401
const std::vector< size_t > & GetTensorShape(std::string name)
Definition: RModel.cxx:47
RModel & operator=(const RModel &other)=delete
std::unordered_map< std::string, InputTensorInfo > fInputTensorInfos
Definition: RModel.hxx:26
std::shared_ptr< void > GetInitializedTensorData(std::string tensor_name)
Definition: RModel.cxx:158
const std::unordered_set< std::string > fAllowedStdLib
Definition: RModel.hxx:42
std::unordered_map< std::string, InitializedTensor > fInitializedTensors
Definition: RModel.hxx:28
void UpdateInitializedTensor(std::string tensor_name, ETensorType type, std::vector< std::size_t > shape, std::shared_ptr< void > data)
Definition: RModel.cxx:149
Mother of all ROOT objects.
Definition: TObject.h:37
create variable transformations