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