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
5
6#include "Rtypes.h" // for ClassDefNV
7
8#include <ctime>
9#include <fstream>
10#include <iomanip>
11#include <iostream>
12#include <memory>
13#include <set>
14#include <sstream>
15#include <type_traits>
16#include <unordered_map>
17#include <unordered_set>
18#include <vector>
19
21
22enum class Options {
23 kDefault = 0x0,
24 kNoWeightFile = 0x2,
25 // Write the weight tensors in the binary safetensors format
26 // (https://huggingface.co/docs/safetensors) instead of the text format
28};
29
30// Optimization levels inspired by ONNXRuntime.
31// We only get Operator Fusion with the Basic, and
32// memory reuse with Extended. kExtended is enabled
33// by default
35 kBasic = 0x0,
36 kExtended = 0x1,
37};
38
40
41std::underlying_type_t<Options> operator|(Options opA, Options opB);
42std::underlying_type_t<Options> operator|(std::underlying_type_t<Options> opA, Options opB);
43
44// The ROperator interface is an implementation detail of the code generation
45// and deliberately not exposed to the public: only this forward declaration
46// is visible here, the full definition (TMVA/ROperator.hxx) is a private
47// header of the SOFIE libraries.
48class ROperator;
49
51
52private:
53 std::string fFileName; // file name of original model file for identification
54 std::string fParseTime; // UTC date and time string at parsing
55
57
58 std::unordered_set<std::string> fNeededBlasRoutines;
59 // Set to true once GenerateHeaderInfo has emitted the extern "C" declaration
60 // of the BLAS sgemm_ routine (from fNeededBlasRoutines). It lets the
61 // standalone Gemm_Call helper skip emitting a second, duplicate declaration.
62 bool fBlasSgemmDeclared = false;
63
64 std::unordered_set<std::string> fNeededStdLib = {"vector"};
65 std::unordered_set<std::string> fCustomOpHeaders;
66
67 // Inference helper functions (from SOFIE_common) that the generated code
68 // needs. Their standalone definitions are emitted into the generated header
69 // so that it does not depend on including TMVA/SOFIE_common.hxx.
70 std::set<std::string> fNeededHelperFunctions;
71
72 std::string fName = "UnnamedModel";
73 std::string fGC; // generated code
74 bool fUseWeightFile = true;
75
76 // Placeholder tokens emitted by GenerateHeaderInfo and later replaced by
77 // EmitHelperFunctionsCode with the actual helper includes / definitions.
78 // This two-step approach is needed because the full set of required helpers
79 // is only known once all operators (and sub-graphs) have been generated.
80 static constexpr const char *kHelperIncludesMarker = "//@SOFIE_HELPER_INCLUDES@\n";
81 static constexpr const char *kHelperFunctionsMarker = "//@SOFIE_HELPER_FUNCTIONS@\n";
82
83 bool fIsInitialized = false;
84 bool fIsSubGraph = false;
85 bool fUseVDT = false;
86 int fVerbose = 0;
87 int fBatchSize = -1;
88 size_t fConstantTensorSize = 0; // size (in Bytes) of the allocated constant tensors
89 size_t fWeightsTensorSize = 0; // size (in Bytes) of the allocated weight tensors
90 size_t fOtherTensorSize = 0; // size (in Bytes) of intermediate tensors which are not managed by the memory pool
91
93
94 std::unordered_map<std::string, InputTensorInfo> fInputTensorInfos; // input tensors where shape may not fully defined or other graph inputs?
95 std::unordered_map<std::string, TensorInfo> fReadyInputTensorInfos; // input tensors where shape is full defined
96 std::unordered_map<std::string, InitializedTensor> fInitializedTensors;
97 std::unordered_map<std::string, TensorInfo> fIntermediateTensorInfos;
98 std::unordered_map<std::string, DynamicTensorInfo> fDynamicTensorInfos;
99 std::unordered_map<std::string, std::pair<std::vector<Dim>, bool>> fShapeTensors; // constant tensors describing a shape
100 std::unordered_map<std::string, std::string> fShapeParams; // parameters defining the dynamic shape (e.g. batch size), store also its default value
101 std::unordered_set<std::string> fComputedShapeParams; ///<! shape parameters computed at run time by an operator
102 std::unordered_map<std::string, std::string> fAliasTensors; // list of alias tensors
103 std::vector<std::string> fDimShapeNames; // parameter names used to define the shapes
104 std::vector<std::string> fOutputTensorNames;
105 std::vector<std::string> fInputTensorNames; // input tensor names using ONNX order
106
107 // A bare std::unique_ptr<ROperator> would require the complete ROperator
108 // type wherever a destroyed RModel is instantiated; with the
109 // out-of-line-deleter declared here and defined in RModel.cxx the
110 // forward declaration above is enough, so the ROperator interface can stay
111 // private.
113 void operator()(ROperator *ptr) const;
114 };
115 std::vector<std::unique_ptr<ROperator, ROperatorDeleter>> fOperators;
116
117 std::vector<std::shared_ptr<RModel>> fSubGraphs; ///<! sub-graph models (transient)
118 RModel * fParentGraph = nullptr;
119
120 // memory pool information for intermediate tensors
121 MemoryPoolInfo fIntermediateMemoryInfo; ///<! intermediate memory info (transient)
122 std::unordered_map<std::string_view, size_t> fIntermediateTensorFrequencyLookup; ///<! lookup table for intermediate tensor frequency (transient)
123
124 std::string fExtraCodeForDimShapes; // extra code needed for initialization of dynamic parameters (e.g. number of non zero elements in NonZero operator)
125
126public:
127 /**
128 Default constructor. Needed to allow serialization of ROOT objects. See
129 https://root.cern/manual/io_custom_classes/#restrictions-on-types-root-io-can-handle
130 */
131 RModel() = default;
132 RModel(std::string name, std::string parsedtime) : fFileName(std::move(name)), fParseTime(std::move(parsedtime))
133 {
134 fName = fFileName.substr(0, fFileName.rfind("."));
136 }
137
138 // Defined out of line because ROperator is an incomplete type in this
139 // header (the definition is a private implementation header).
143 RModel(RModel const &) = delete;
144 RModel &operator=(RModel const &) = delete;
145
146 int Verbose() const { return fVerbose;}
147
148 std::vector<size_t> GetTensorShape(const std::string & name) const;
149 std::vector<Dim> GetDimTensorShape(const std::string & name) const;
150 std::vector<Dim> GetDynamicTensorShape(const std::string & name) const ;
151
152 // get the values for the tensor representing a shape
153 const std::vector<Dim> & GetShapeTensorValues(const std::string & tensor_name) const;
154
155 ETensorType GetTensorType(std::string name) const;
156
157
158 bool CheckIfTensorAlreadyExist(std::string tensor_name);
159 void AddInputTensorInfo(std::string input_name, ETensorType type, std::vector<Dim> shape);
160 void AddInputTensorInfo(std::string input_name, ETensorType type, std::vector<size_t> shape);
161 void AddOperator(std::unique_ptr<ROperator> op, int order_execution = -1);
162 void AddInitializedTensor(std::string tensor_name, ETensorType type, std::vector<std::size_t> shape,
163 std::shared_ptr<void> data);
164 void AddInitializedTensor(const std::string &tensor_name, ETensorType tensor_type,
165 const std::vector<std::size_t> &shape, void *raw_data);
166 void AddConstantTensor(std::string tensor_name, ETensorType type, std::vector<std::size_t> shape,
167 std::shared_ptr<void> data);
168
169 // Make tensor_name share the memory of orig_tensor_name, for operators such as Reshape
170 // whose output only reinterprets the shape of its input.
171 // Returns false, and registers nothing, when tensor_name needs storage of its own.
172 bool AddAliasTensor(const std::string &tensor_name, const std::string &orig_tensor_name);
173
174 template<class T>
175 void AddConstantTensor(const std::string & name, const std::vector<size_t> & shape, const T * data) {
176 size_t length = ConvertShapeToLength(shape);
177 std::shared_ptr<void> data_ptr(malloc(length * sizeof(T)), free);
178 std::memcpy(data_ptr.get(), (void*) data, length * sizeof(T));
180 }
181 // for boolean can be more convenient passing an std::vector
182 template<class T>
183 void AddConstantTensor(const std::string & name, const std::vector<size_t> & shape, const std::vector<T> & data) {
184 size_t length = data.size();
185 std::shared_ptr<void> data_ptr(malloc(length * sizeof(T)), free);
186 std::copy(data.begin(), data.end(), (T*) data_ptr.get());
187 //std::memcpy(data_ptr.get(), (void*) data, length * sizeof(T));
189 }
190
191 void AddShapeTensor(const std::string & name, const std::vector<Dim> & shapeValues, bool scalar = false);
192
193 void AddExtraCodeForDimShapes(const std::string & code) { fExtraCodeForDimShapes += code; }
194
195 // add and initialize subgraph to the model
196 void InitializeSubGraph(std::shared_ptr<RModel> graph);
197
198 // set a flag to indicate tensor does not need to be written in a weight file
199 // (e.g. shape tensors used as input to define a shape (in Reshape))
200 void SetNotWritableInitializedTensor(const std::string & tensor_name);
201
202 // Check if a tensor is initialized
203 bool IsInitializedTensor(const std::string &name) const;
204 // Check if a tensor is Constant (note a Constant tensor is also initialized)
205 bool IsConstantTensor(const std::string &name) const;
206 bool IsDynamicTensor(const std::string &name) const;
207 // Check if tensor is a input dynamic tensor (without a specified shape, based on Sim structure
208 bool IsDimInputTensor(const std::string &name) const;
209 // check if tensor is a fully specified input tensor
210 bool IsReadyInputTensor(const std::string &name) const;
211 /// check if a tensor is a shape tensor
212 bool IsShapeTensor(const std::string & name) const;
213 /// check if a tensor is a alias tensor
214 bool IsAliasTensor(const std::string & name) const;
215
216 // Add intermediate tensor
217 void AddIntermediateTensor(std::string tensor_name, ETensorType type, std::vector<Dim> dim_shape);
218 void AddIntermediateTensor(std::string tensor_name, ETensorType type, std::vector<std::size_t> shape);
219 // Add an intermediate dynamic tensor
220 void AddDynamicTensor(std::string tensor_name, ETensorType type, std::vector<Dim> shape);
221 // void Add a shape parameter
222 void AddShapeParam(const std::string & name, size_t def_value = 0);
223 /// Declare a shape parameter as computed at run time by an operator (e.g. the number of
224 /// non-zero elements found by NonZero): the operator declares it itself, so it is never a
225 /// Session constructor argument. A later AddShapeParam for the same name has no effect.
226 void AddComputedShapeParam(const std::string &name);
227 bool IsComputedShapeParam(const std::string &name) const { return fComputedShapeParams.count(name) != 0; }
228 void AddInputTensorName(std::string name);
229 void AddOutputTensorNameList(std::vector<std::string> output_tensor_names);
230 void
231 UpdateOutputTensorList(std::vector<std::string> curr_output_tensor, std::vector<std::string> modify_output_tensor);
232 void UpdateInitializedTensor(std::string tensor_name, ETensorType type, std::vector<std::size_t> shape,
233 std::shared_ptr<void> data);
234 std::shared_ptr<void> GetInitializedTensorData(std::string tensor_name);
235
236 template<class T>
237 std::vector<T> GetTensorData(const std::string & name);
238
239 void Initialize(int batchSize = -1, bool verbose = false);
240 void Initialize(const std::map<std::string,size_t> & inputParams, bool verbose = false);
241
242 void Generate(std::underlying_type_t<Options> options, int batchSize = -1, bool verbose = false);
243 void Generate(Options options = Options::kDefault, int batchSize = -1, bool verbose = false)
244 {
245 Generate(static_cast<std::underlying_type_t<Options>>(options), batchSize, verbose);
246 }
247 // generate the infer function signature. If isdecl= false generate the calling infer function
248 // used to infer the sub-graphs
249 std::string GenerateInferSignature(bool isdecl = true);
250
251 // calculate total intermediate memory and position intermediate tensor addresses
252 std::string AllocateIntermediateMemory(std::span<const std::string_view> op_output_tensors);
253 void CheckAndFlushIntermediateMemory(std::span<const std::string_view> op_output_tensors, const size_t& op_idx);
254
256
257 // get the size in bytes of the constant tensors
259 // get the size in bytes of the weight tensors
260 size_t GetWeightsTensorSize() const { return fWeightsTensorSize; }
261 // get the size in bytes of the intermediate tensors which are not part of the memory pool
262 size_t GetOtherTensorSize() const { return fOtherTensorSize; }
263 // get the size in bytes of the intermediate tensors managed by the memory pool
265 return (!fIntermediateMemoryInfo.total_stack.empty())
266 ? fIntermediateMemoryInfo.total_stack.rbegin()->first + fIntermediateMemoryInfo.total_stack.rbegin()->second.tensor_size
267 : 0;
268 }
269
270protected:
271 // internal functions
272 // generate code for the initialized tensors
274 // generate code for the intermediate tensors
276 // generate code for the dynamic tensors
278 // generate code for declarations needed by operators
280 // generate code for inference
281 void GenerateOutput();
282 // generate code for initializing memory pool for intermediate tensors
284 // Generate all session code
285 void GenerateSessionCode();
286 bool IsInputTensorShapeParam(std::string const &name) const;
287 std::vector<std::string> CollectTensorMemberNames(const std::string &input);
289
290public:
291 const std::vector<std::string> & GetInputTensorNames() const { return fInputTensorNames; }
292 const std::vector<std::string> & GetOutputTensorNames() const { return fOutputTensorNames; }
293 const std::vector<std::string> & GetDimShapeNames() const { return fDimShapeNames; }
294
296 long WriteInitializedTensorsToFile(std::string filename = "");
297 // Write the weight tensors as a safetensors payload to a stream or to an
298 // in-memory buffer (e.g. for use with a blob-based Session constructor)
299 void WriteInitializedTensorsToStream(std::ostream &os);
301
302 void PrintSummary() const;
303 void PrintIntermediateTensors() const;
304 void PrintOutputTensors() const;
305 void OutputGenerated(std::string filename = "", bool append = false);
306 void SetFilename(std::string filename) { fName = filename; }
307 std::string GetFilename() { return fName; }
308 const std::string &GetName() const { return fName; }
309
310 void AddBlasRoutines(std::vector<std::string> routines)
311 {
312 for (auto &routine : routines) {
314 }
315 }
316 void AddNeededStdLib(std::string libname)
317 {
318 // if the library is already in the set, insert does nothing, so we don't need to check before inserting
319 fNeededStdLib.insert(std::move(libname));
320 }
322 {
323 fCustomOpHeaders.insert(std::move(filename));
324 }
325 // Register an inference helper function that the generated code needs. See
326 // EmitHelperFunctionsCode for the list of recognised keys.
328 {
329 fNeededHelperFunctions.insert(std::move(name));
330 }
331 const std::set<std::string> &GetNeededHelperFunctions() const { return fNeededHelperFunctions; }
332
333 void GenerateHeaderInfo(std::string &hgname);
334 // Replace the helper markers in the generated code with the standalone
335 // definitions of the helper functions collected in fNeededHelperFunctions.
337 void PrintGenerated(std::ostream &os = std::cout) { os << fGC; }
338 std::string ReturnGenerated() { return fGC; }
339
340 void PrintRequiredInputTensors() const;
341 void PrintInitializedTensors() const;
342 void PrintDynamicTensors() const;
343 void HeadInitializedTensors(std::string name, int n_print = 50);
344
345 // flag to use vdt for fast math functions (e.g. exp in softmax)
346 void SetUseVDT(bool on) {
347 fUseVDT = on;
348 }
349 bool UseVDT() const { return fUseVDT;}
350
351 // RModel is an internal representation that doesn't support ROOT IO (if you need model IO, use ONNX directly).
353};
354
355// need to implement here templated member functions and its specialization
356
357
358template<class T>
359inline std::vector<T> RModel::GetTensorData(const std::string & name) {
360 if (!IsInitializedTensor(name)) return std::vector<T>{};
361 T * data = static_cast<T*>(GetInitializedTensorData(name).get());
363 return std::vector<T>(data, data+size);
364}
365
366template<>
367inline std::vector<Dim> RModel::GetTensorData<Dim>(const std::string & name) {
368 if (!IsShapeTensor(name)) return std::vector<Dim>{};
370}
371
372} // namespace TMVA::Experimental::SOFIE
373
374#endif // TMVA_SOFIE_RMODEL
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
#define ClassDefNV(name, id)
Definition Rtypes.h:351
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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 input
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 length
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void on
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:142
std::string WriteInitializedTensorsToBuffer()
Definition RModel.cxx:1851
void AddShapeParam(const std::string &name, size_t def_value=0)
Definition RModel.cxx:416
void AddNeededHelperFunction(std::string name)
Definition RModel.hxx:327
std::vector< size_t > GetTensorShape(const std::string &name) const
Definition RModel.cxx:108
RModel(RModel const &)=delete
bool IsComputedShapeParam(const std::string &name) const
Definition RModel.hxx:227
std::set< std::string > fNeededHelperFunctions
Definition RModel.hxx:70
std::unordered_set< std::string > fComputedShapeParams
! shape parameters computed at run time by an operator
Definition RModel.hxx:101
std::vector< Dim > GetDimTensorShape(const std::string &name) const
Definition RModel.cxx:144
std::unordered_map< std::string, DynamicTensorInfo > fDynamicTensorInfos
Definition RModel.hxx:98
bool IsDynamicTensor(const std::string &name) const
Definition RModel.cxx:367
const std::vector< std::string > & GetOutputTensorNames() const
Definition RModel.hxx:292
void AddIntermediateTensor(std::string tensor_name, ETensorType type, std::vector< Dim > dim_shape)
Definition RModel.cxx:382
size_t GetIntermediateTensorSize() const
Definition RModel.hxx:264
bool AddAliasTensor(const std::string &tensor_name, const std::string &orig_tensor_name)
Definition RModel.cxx:306
std::string GenerateInferSignature(bool isdecl=true)
Definition RModel.cxx:1181
std::unordered_set< std::string > fNeededBlasRoutines
Definition RModel.hxx:58
bool CheckIfTensorAlreadyExist(std::string tensor_name)
Definition RModel.cxx:201
void GenerateHeaderInfo(std::string &hgname)
Definition RModel.cxx:2082
void GenerateRequiredInputTensorInfo()
To emit the dimensions of the input tensors as a data member of a session, which is helpful when vali...
Definition RModel.cxx:1875
void OutputGenerated(std::string filename="", bool append=false)
Definition RModel.cxx:2169
std::unordered_map< std::string, std::string > fAliasTensors
Definition RModel.hxx:102
void AddInputTensorInfo(std::string input_name, ETensorType type, std::vector< Dim > shape)
Definition RModel.cxx:212
std::unordered_map< std::string, TensorInfo > fIntermediateTensorInfos
Definition RModel.hxx:97
void SetOptimizationLevel(OptimizationLevel optim_level)
Definition RModel.hxx:255
void AddOutputTensorNameList(std::vector< std::string > output_tensor_names)
Definition RModel.cxx:436
std::unordered_map< std::string, TensorInfo > fReadyInputTensorInfos
Definition RModel.hxx:95
void AddConstantTensor(std::string tensor_name, ETensorType type, std::vector< std::size_t > shape, std::shared_ptr< void > data)
Definition RModel.cxx:288
void AddDynamicTensor(std::string tensor_name, ETensorType type, std::vector< Dim > shape)
Definition RModel.cxx:399
std::vector< std::string > fDimShapeNames
Definition RModel.hxx:103
void AddInitializedTensor(std::string tensor_name, ETensorType type, std::vector< std::size_t > shape, std::shared_ptr< void > data)
Definition RModel.cxx:268
std::unordered_map< std::string_view, size_t > fIntermediateTensorFrequencyLookup
! lookup table for intermediate tensor frequency (transient)
Definition RModel.hxx:122
void AddExtraCodeForDimShapes(const std::string &code)
Definition RModel.hxx:193
void AddBlasRoutines(std::vector< std::string > routines)
Definition RModel.hxx:310
void AddInputTensorName(std::string name)
Definition RModel.cxx:231
std::vector< std::string > fOutputTensorNames
Definition RModel.hxx:104
void AddNeededStdLib(std::string libname)
Definition RModel.hxx:316
bool IsDimInputTensor(const std::string &name) const
Definition RModel.cxx:372
bool IsShapeTensor(const std::string &name) const
check if a tensor is a shape tensor
Definition RModel.cxx:341
size_t GetConstantTensorSize() const
Definition RModel.hxx:258
static constexpr const char * kHelperIncludesMarker
Definition RModel.hxx:80
bool IsInitializedTensor(const std::string &name) const
Definition RModel.cxx:354
std::unordered_set< std::string > fNeededStdLib
Definition RModel.hxx:64
bool IsAliasTensor(const std::string &name) const
check if a tensor is a alias tensor
Definition RModel.cxx:345
static constexpr const char * kHelperFunctionsMarker
Definition RModel.hxx:81
void CheckAndFlushIntermediateMemory(std::span< const std::string_view > op_output_tensors, const size_t &op_idx)
Definition RModel.cxx:581
void AddOperator(std::unique_ptr< ROperator > op, int order_execution=-1)
Definition RModel.cxx:235
RModel()=default
Default constructor.
void HeadInitializedTensors(std::string name, int n_print=50)
Definition RModel.cxx:2046
bool IsConstantTensor(const std::string &name) const
Definition RModel.cxx:358
void WriteInitializedTensorsToStream(std::ostream &os)
Definition RModel.cxx:1796
void Initialize(int batchSize=-1, bool verbose=false)
Definition RModel.cxx:662
size_t GetWeightsTensorSize() const
Definition RModel.hxx:260
const std::set< std::string > & GetNeededHelperFunctions() const
Definition RModel.hxx:331
long WriteInitializedTensorsToFile(std::string filename="")
Definition RModel.cxx:1721
OptimizationLevel fOptimizationLevel
Definition RModel.hxx:92
std::vector< std::string > CollectTensorMemberNames(const std::string &input)
Collects all identifiers starting with "tensor_" in the input code, provided that the occurrence is n...
Definition RModel.cxx:1123
std::vector< Dim > GetDynamicTensorShape(const std::string &name) const
Definition RModel.cxx:155
void AddConstantTensor(const std::string &name, const std::vector< size_t > &shape, const std::vector< T > &data)
Definition RModel.hxx:183
void AddNeededCustomHeader(std::string filename)
Definition RModel.hxx:321
std::unordered_map< std::string, InputTensorInfo > fInputTensorInfos
Definition RModel.hxx:94
std::shared_ptr< void > GetInitializedTensorData(std::string tensor_name)
Definition RModel.cxx:459
void AddComputedShapeParam(const std::string &name)
Declare a shape parameter as computed at run time by an operator (e.g.
Definition RModel.cxx:427
MemoryPoolInfo fIntermediateMemoryInfo
! intermediate memory info (transient)
Definition RModel.hxx:121
std::string AllocateIntermediateMemory(std::span< const std::string_view > op_output_tensors)
Definition RModel.cxx:476
std::unordered_map< std::string, std::pair< std::vector< Dim >, bool > > fShapeTensors
Definition RModel.hxx:99
std::vector< std::unique_ptr< ROperator, ROperatorDeleter > > fOperators
Definition RModel.hxx:115
std::vector< T > GetTensorData(const std::string &name)
Definition RModel.hxx:359
void SetFilename(std::string filename)
Definition RModel.hxx:306
void InitializeSubGraph(std::shared_ptr< RModel > graph)
Definition RModel.cxx:818
std::unordered_map< std::string, std::string > fShapeParams
Definition RModel.hxx:100
void SetNotWritableInitializedTensor(const std::string &tensor_name)
Definition RModel.cxx:468
const std::string & GetName() const
Definition RModel.hxx:308
RModel & operator=(RModel const &)=delete
ETensorType GetTensorType(std::string name) const
Definition RModel.cxx:169
std::vector< std::string > fInputTensorNames
Definition RModel.hxx:105
const std::vector< std::string > & GetInputTensorNames() const
Definition RModel.hxx:291
std::unordered_map< std::string, InitializedTensor > fInitializedTensors
Definition RModel.hxx:96
void UpdateInitializedTensor(std::string tensor_name, ETensorType type, std::vector< std::size_t > shape, std::shared_ptr< void > data)
Definition RModel.cxx:450
void Generate(std::underlying_type_t< Options > options, int batchSize=-1, bool verbose=false)
Definition RModel.cxx:1614
const std::vector< Dim > & GetShapeTensorValues(const std::string &tensor_name) const
Definition RModel.cxx:349
std::vector< std::shared_ptr< RModel > > fSubGraphs
! sub-graph models (transient)
Definition RModel.hxx:117
bool IsReadyInputTensor(const std::string &name) const
Definition RModel.cxx:376
void UpdateOutputTensorList(std::vector< std::string > curr_output_tensor, std::vector< std::string > modify_output_tensor)
Definition RModel.cxx:443
const std::vector< std::string > & GetDimShapeNames() const
Definition RModel.hxx:293
void Generate(Options options=Options::kDefault, int batchSize=-1, bool verbose=false)
Definition RModel.hxx:243
RModel(std::string name, std::string parsedtime)
Definition RModel.hxx:132
void AddShapeTensor(const std::string &name, const std::vector< Dim > &shapeValues, bool scalar=false)
Definition RModel.cxx:298
std::unordered_set< std::string > fCustomOpHeaders
Definition RModel.hxx:65
void AddConstantTensor(const std::string &name, const std::vector< size_t > &shape, const T *data)
Definition RModel.hxx:175
void PrintGenerated(std::ostream &os=std::cout)
Definition RModel.hxx:337
bool IsInputTensorShapeParam(std::string const &name) const
Check if a given parameter is used for the shape of an input tensor.
Definition RModel.cxx:1105
std::string Clean_name(std::string input_tensor_name)
std::size_t ConvertShapeToLength(const std::vector< size_t > &shape)
std::underlying_type_t< Options > operator|(Options opA, Options opB)
Definition RModel.cxx:101
std::map< size_t, TensorMemoryInfo > total_stack