7#ifdef SOFIE_SUPPORT_ROOT_BINARY
15namespace Experimental {
19const std::string SP =
" ";
23 return static_cast<std::underlying_type_t<Options>
>(
opA) |
static_cast<std::underlying_type_t<Options>
>(
opB);
26 return opA |
static_cast<std::underlying_type_t<Options>
>(
opB);
32 return f->second.shape;
36 return f2->second.shape();
40 throw std::runtime_error(
"TMVA SOFIE tensor [" +
name +
"] is an input tensor with unspecified dimension parameter");
44 return f4->second.shape;
50 if (f5->second.second)
51 return std::vector<size_t>{};
53 return std::vector<size_t>{f5->second.first.size()};
57 throw std::runtime_error(
"TMVA SOFIE tensor [" +
name +
"] is a dynamic tensor. Use GetDynamicTensorShape instead of GetTensorShape");
62 throw std::runtime_error(
"TMVA SOFIE tensor [" +
name +
"] for which the shape is requested is not found");
67 return f->second.shape;
70 return f->second.shape;
78 return f->second.shape;
81 return f->second.shape;
85 throw std::runtime_error(
"TMVA SOFIE tensor [" +
name +
"] for which the shape is requested is not dynamic");
87 throw std::runtime_error(
"TMVA SOFIE tensor [" +
name +
"] for which the shape is requested is not found");
93 return f->second.type;
97 return f2->second.type();
101 return f3->second.type;
105 return f4->second.type;
109 return f5->second.type;
119 throw std::runtime_error(
"TMVA SOFIE tensor [" +
name +
"] for which the type is requested is not found, model name: " +
fName);
136 throw std::runtime_error(
"TMVA-SOFIE: input tensor with name " +
input_name +
" already exists \n");
146 throw std::runtime_error(
"TMVA-SOFIE: input tensor with name " +
input_name +
" already exists \n");
158 auto libs =
op->GetStdLibs();
187 throw std::runtime_error(
"TMVA-SOFIE: initialized tensor with name " + tensor_name +
" already exists \n");
197 throw std::runtime_error(
"TMVA-SOFIE: constant tensor with name " + tensor_name +
" already exists \n");
206 throw std::runtime_error(
"TMVA-SOFIE: shape tensor with name " + tensor_name +
" already exists \n");
228 return itr->second.IsConstantTensor();
258 throw std::runtime_error(
"TMVA-SOFIE: intermediate tensor with name " + tensor_name +
" already exists \n");
267 throw std::runtime_error(
"TMVA-SOFIE: intermediate tensor with name " + tensor_name +
" already exists \n");
272 for (
auto &
d : shape) {
274 if (
d.dim !=
size_t(-1)) {
306 throw std::runtime_error(
"TMVA-SOFIE: tensor " + tensor_name +
" not found when trying to update it");
315 throw std::runtime_error(
"TMVA-SOFIE: tensor " + tensor_name +
" not found when trying to get its data");
317 return f->second.sharedptr();
324 throw std::runtime_error(
"TMVA-SOFIE: initialized tensor " + tensor_name +
" not found when trying to get its info");
326 t->second.SetNotWritable();
331 std::stringstream code;
334 std::cout <<
"Total chunks allocated\n";
336 std::cout <<
"..... chunk " <<
chunk->first <<
" size " <<
chunk->second.tensor_size <<
" " <<
chunk->second.tensor_name << std::endl;
342 code <<
"\n // Allocating memory for intermediate tensor " <<
name <<
" with size " <<
size <<
" bytes";
344 << typeName <<
"* tensor_" <<
name <<
" = reinterpret_cast<" << typeName
345 <<
"*>(fIntermediateMemoryPool.data() + " << location <<
");\n";
348 if (
fVerbose) std::cout <<
"*** AllocateIntermediateMemory: Loop on op output tensors\n";
353 auto name = std::string(it);
368 std::string
name = std::string{it.tensor_name};
369 size_t tensor_size = it.tensor_size;
371 std::cout <<
"output tensor " <<
name <<
" size " << tensor_size << std::endl;
376 if (
fVerbose) std::cout <<
".. available chunk " <<
chunk->first <<
" with size = " <<
chunk->second;
378 if (
chunk->second >= tensor_size) {
386 chunk->second -= tensor_size;
392 if (
chunk->second == 0) {
393 if (
fVerbose) std::cout <<
" and deleted since size matches";
396 if (
fVerbose) std::cout << std::endl;
405 if (
fVerbose) std::cout <<
" is extended with a bigger one of size " << tensor_size << std::endl;
409 if (
fVerbose) std::cout << std::endl;
422 if (
fVerbose) std::cout <<
"no chunk available - add in total stack a new chunk with size of tensor and idx : " <<
chunk_idx
430 if (
fVerbose) std::cout <<
"*** CheckAndFlushIntermediateMemory: Loop on input tensors for op " <<
op_idx <<
"\n";
432 if (
fVerbose) std::cout <<
"available chunks before freeing them : \n";
435 if (
fVerbose) std::cout <<
"-- free chunk " <<
chunk->first <<
" size = " <<
chunk->second << std::endl;
439 if (
fVerbose) std::cout <<
".. input tensors : " << it;
441 if (
fVerbose) std::cout <<
" flash condition is met - looping on chunks to find matching one \n";
444 if (
fVerbose) std::cout <<
"--- chunk " <<
chunk->first <<
" , " <<
chunk->second.tensor_name <<
" size " <<
chunk->second.tensor_size;
445 if (
chunk->second.tensor_name == it) {
446 if (
fVerbose) std::cout <<
" -- Found chunk corresponding to input tensor: " <<
chunk->first;
461 if (
fVerbose) std::cout <<
" is adjacent in memory with previous one - merge ";
471 if (
fVerbose) std::cout <<
" merge also with following that is free ";
474 if (
fVerbose) std::cout << std::endl;
479 if (
fVerbose) std::cout <<
" is adjacent in memory with following one - merge \n";
491 if (
fVerbose) std::cout <<
" insert in the available stack the chunk with size " <<
chunk->second.tensor_size << std::endl;
493 chunk->second.tensor_name =
"free";
498 if (
fVerbose) std::cout << std::endl;
519 std::cout <<
"Model is already initialized - skip initialization " << std::endl;
530 if (verbose) std::cout <<
"looking at the tensor " <<
input.first << std::endl;
533 for (
auto &
d :
input.second.shape) {
535 std::string
pname =
d.param;
541 std::cout <<
"Tensor: " <<
input.first <<
" - fix parametric shape " <<
itr->first <<
" to " <<
itr->second << std::endl;
551 if (!shape.empty()) {
563 for (
auto &
d :
input.second.shape) {
600 std::cout <<
"Initializing operator " << i <<
" " <<
typeid(
r).
name() << std::endl;
604 std::string
name = std::string{it};
622 graph->fParentGraph =
this;
623 graph->fIsSubGraph =
true;
632 for (
auto &
e : graph->fNeededBlasRoutines)
635 for (
auto e : graph->fNeededStdLib)
640 graph->fInputTensorNames.emplace_back(
name);
652 std::stringstream
strs;
658 const T *
data = t.second.data<T>();
673 strs <<
"std::vector<" <<
type <<
"> fTensor_" << t.first <<
" = ";
679 strs <<
"const " <<
type <<
" * tensor_" + t.first +
" = fTensor_" + t.first +
".data();\n";
687 fGC +=
"// initialized tensors\n";
703 fGC +=
"std::vector<float> fTensor_" + i.first +
" = std::vector<float>(" + std::to_string(
length) +
");\n";
704 fGC +=
"float * tensor_" + i.first +
" = fTensor_" + i.first +
".data();\n";
713 fGC +=
"\n//--- Allocating session memory pool to be used for allocating intermediate tensors\n";
719 fGC +=
"std::vector<char> fIntermediateMemoryPool = std::vector<char>(" + std::to_string(
memPoolSize) +
");\n\n";
764 fGC +=
"//--- declare the dynamic tensors\n";
767 fGC +=
"std::vector<float> fTensor_" + i.first +
";\n";
768 fGC +=
"float * tensor_" + i.first +
" = nullptr;\n";
770 fGC +=
"std::vector<double> fTensor_" + i.first +
";\n";
771 fGC +=
"double * tensor_" + i.first +
" = nullptr;\n";
773 fGC +=
"std::vector<int64_t> fTensor_" + i.first +
";\n";
774 fGC +=
"int64_t * tensor_" + i.first +
" = nullptr;\n";
787 fGC +=
"\n//---- operator declarations \n";
794 std::stringstream out;
797 out << SP <<
"if (" <<
length <<
" > 0) {\n";
798 out << SP << SP <<
"fTensor_" << i.first <<
".resize(" <<
length <<
");\n";
799 out << SP << SP <<
"tensor_" << i.first <<
" = fTensor_" << i.first <<
".data();\n";
815 for (
auto &
d : shape) {
816 std::string
pName =
d.param;
820 rGC +=
d.param +
",";
828 throw std::runtime_error(
"TMVA-SOFIE: input tensor " +
name +
829 " is of a data type which is not yet supported.");
860 if (outputSize == 1) {
872 for (
size_t i = 0; i < outputSize; i++) {
874 if (i < outputSize - 1)
896 fGC += SP +
"return {";
922 fGC +=
"struct Session {\n";
924 fGC +=
"struct Session_" +
fName +
" {\n";
937 std::cout <<
"\n******************\n analyzing input/output operator " <<
op_idx <<
" "
938 <<
typeid(*op).name() << std::endl;
966 fGC +=
"Session_" + graph->fName +
" fSession_" + graph->fName +
";\n";
976 for (
size_t id = 0;
id <
fOperators.size();
id++) {
977 std::string
opName = std::to_string(
id);
983 std::string fileName =
fName;
990 fGC +=
sessionName +
"(std::string filename =\"" + fileName +
"\"";
1007 fGC +=
"\n//--- reading weights from file\n";
1017 for (
size_t id = 0;
id <
fOperators.size();
id++) {
1029 std::cout <<
"Generating main inference code for " <<
fName << std::endl;
1032 throw std::runtime_error(
"TMVA-SOFIE: output size=0 are not supported");
1036 std::cout <<
"Generating code for operator .... " <<
op_idx << std::endl;
1040 fGC += SP +
"using TMVA::Experimental::SOFIE::UTILITY::FillOutput;\n\n";
1048 fGC += SP +
"FillOutput(tensor_" +
name +
", output_tensor_" +
name +
", " +
n +
");\n";
1058 fGC +=
"}; // end of Session\n\n";
1062void RModel::Generate(std::underlying_type_t<Options> options,
int batchSize,
long pos,
bool verbose)
1082 throw std::runtime_error(
1083 "TMVA-SOFIE: RModel::Generate: cannot use a separate weight file without generating a Session class");
1086 if (
static_cast<std::underlying_type_t<Options>
>(
Options::kGNN) & options)
1103 std::cout <<
"generate session code for subgraph " << graph->fName << std::endl;
1104 graph->GenerateSessionCode();
1109 std::cout <<
"generate Main session code - model " <<
fName << std::endl;
1115 fGC += (
"} //TMVA_SOFIE_" +
fName +
"\n");
1125 fGC +=
" std::ifstream f;\n";
1126 fGC +=
" f.open(filename);\n";
1127 fGC +=
" if (!f.is_open()) {\n";
1128 fGC +=
" throw std::runtime_error(\"tmva-sofie failed to open file \" + filename + \" for input weights\");\n";
1132 fGC +=
" f.seekg(" + std::to_string(pos) +
");\n";
1135 fGC +=
" using TMVA::Experimental::SOFIE::ReadTensorFromStream;\n";
1140 if (!i.second.IsWeightTensor())
continue;
1141 std::string tensor_name =
"tensor_" + i.first;
1144 fGC +=
" ReadTensorFromStream(f, " + tensor_name +
", \"" + tensor_name +
"\", " +
length +
");\n";
1146 std::runtime_error(
"tmva-sofie tensor " + tensor_name +
" with type " +
ConvertTypeToString(i.second.type()) +
" cannot be read from a file");
1149 fGC +=
" f.close();\n";
1154#ifdef SOFIE_SUPPORT_ROOT_BINARY
1156 fGC +=
" std::unique_ptr<TFile> rootFile(TFile::Open(filename.c_str(), \"READ\"));\n";
1157 fGC +=
" if (!rootFile->IsOpen()) {\n";
1158 fGC +=
" throw std::runtime_error(\"tmva-sofie failed to open ROOT file for input weights\");\n";
1162 fGC +=
" if (!rootFile->GetKey(\"" +
dirName +
"\")) {\n";
1163 fGC +=
" throw std::runtime_error(\"tmva-sofie failed to open ROOT directory for input weights\");\n";
1168 if (!i.second.IsWeightTensor())
continue;
1170 std::string tensor_name =
"tensor_" + i.first;
1172 fGC +=
" fTensor_" + i.first +
" = *reinterpret_cast<std::vector<float>*>(rootFile->Get(\"";
1173 fGC +=
dirName +
"/" + tensor_name +
"\"));\n";
1175 fGC +=
" fTensor_" + i.first +
" = *reinterpret_cast<std::vector<double>*>(rootFile->Get(\"";
1176 fGC +=
dirName + +
"/" + tensor_name +
"\"));\n";
1178 fGC +=
" fTensor_" + i.first +
" = *reinterpret_cast<std::vector<int64_t>*>(rootFile->Get(\"";
1179 fGC +=
dirName +
"/" + tensor_name +
"\"));\n";
1181 std::runtime_error(
"tmva-sofie tensor " + tensor_name +
" with type " +
ConvertTypeToString(i.second.type()) +
" cannot be read from a ROOT file");
1187 throw std::runtime_error(
"SOFIE was not built with ROOT file support.");
1214#ifdef SOFIE_SUPPORT_ROOT_BINARY
1216 throw std::runtime_error(
"SOFIE-GNN yet not supports writing to a ROOT file.");
1229 if (!
item.second.IsWeightTensor())
continue;
1234 const float*
data =
item.second.data<
float>();
1239 const double*
data =
item.second.data<
double>();
1244 const int64_t*
data =
item.second.data<int64_t>();
1250 " cannot be written to a ROOT file");
1259 throw std::runtime_error(
"SOFIE was not built with ROOT file support.");
1271 std::runtime_error(
"tmva-sofie failed to open file " +
filename +
" for tensor weight data");
1274 if (!i.second.IsWeightTensor()) {
1278 std::string tensor_name =
"tensor_" + i.first;
1279 f << tensor_name <<
" " <<
length <<
"\n";
1281 const float *
data = i.second.data<
float>();
1282 for (
size_t idx = 0; idx <
length; idx++) {
1285 if (
value != 0. && std::abs(
value) < std::numeric_limits<float>::min() )
value = 0;
1286 f << std::setprecision(std::numeric_limits<float>::max_digits10) <<
value;
1287 f << ( (idx <
length-1) ?
" " :
"\n" );
1291 std::runtime_error(
"tmva-sofie tensor " + tensor_name +
" with type " +
ConvertTypeToString(i.second.type()) +
" cannot be written to a file");
1294 std::runtime_error(
"tmva-sofie failed to write tensor data to file for " + tensor_name);
1305 std::cout <<
"Model requires following inputs:\n";
1307 std::cout <<
"Parametrised Tensor name: " <<
inputInfo.first <<
"\t";
1309 std::cout <<
"shape: [";
1310 for (
size_t i = 0; i <
inputInfo.second.shape.size(); i++) {
1311 if (
inputInfo.second.shape[i].isParam) {
1312 std::cout <<
inputInfo.second.shape[i].param;
1314 std::cout <<
inputInfo.second.shape[i].dim ;
1316 if (i <
inputInfo.second.shape.size() - 1) std::cout <<
",";
1318 std::cout <<
"]" << std::endl;
1322 std::cout <<
"Fully Specified Tensor name: " <<
inputInfo.first <<
"\t";
1324 std::cout <<
"shape: [";
1325 for (
size_t i = 0; i <
inputInfo.second.shape.size(); i++) {
1327 if (i <
inputInfo.second.shape.size() - 1) std::cout <<
",";
1329 std::cout <<
"]" << std::endl;
1335 std::cout <<
"Model initialized the following tensors:\n";
1337 std::cout <<
"Tensor name: \"" << it.first <<
"\"\t";
1339 std::cout <<
"shape: [";
1340 for (
size_t i = 0; i < it.second.shape().
size(); i++) {
1341 std::cout << it.second.shape()[i];
1342 if (i < it.second.shape().size() - 1) std::cout <<
",";
1345 if (it.second.IsConstantTensor()) std::cout <<
" (Constant)";
1346 else if (!it.second.IsWeightTensor()) std::cout <<
" (Not Writable)";
1347 std::cout << std::endl;
1353 std::cout <<
"Model specify the following intermediate tensors:\n";
1355 std::cout <<
"Tensor name: \"" << it.first <<
"\"\t";
1357 std::cout <<
"shape: [";
1358 for (
size_t i = 0; i < it.second.shape.size(); i++) {
1359 std::cout << it.second.shape[i];
1360 if (i < it.second.shape.size() - 1) std::cout <<
",";
1362 std::cout <<
"]" << std::endl;
1368 std::cout <<
"Model specify the following dynamic tensors:\n";
1370 std::cout <<
"Tensor name: \"" << it.first <<
"\"\t";
1372 std::cout <<
"shape: [";
1373 for (
size_t i = 0; i < it.second.shape.size(); i++) {
1374 std::cout << it.second.shape[i].GetVal();
1375 if (i < it.second.shape.size() - 1) std::cout <<
",";
1377 std::cout <<
"]" << std::endl;
1383 std::cout <<
"Model specify the following output tensors:\n";
1385 std::cout <<
"Tensor name: \"" << it <<
"\"\t";
1397 std::cout <<
"Tensor " <<
name <<
" not found in model's initialized tensor list" << std::endl;
1401 std::cout <<
"Tensor name: " << it->first <<
"\t";
1404 std::cout <<
"shape: [";
1405 for (
size_t i = 0; i < it->second.shape().
size(); i++) {
1406 std::cout << it->second.shape()[i];
1407 length *= it->second.shape()[i];
1408 if (
i < it->second.shape().size() - 1) std::cout <<
",";
1410 std::cout <<
"]" << std::endl;
1417 std::cout <<
"data: [" << std::endl;
1420 for (
int i =0; i <
n_print; i++) {
1422 if (i <
n_print - 1) std::cout <<
" ,";
1425 if (
ellipsis) std::cout <<
", ...";
1426 std::cout <<
"]" << std::endl;
1437 size_t pos =
filename.find(
".hxx");
1453 if (
R__b.IsReading()) {
1454 RModel::Class()->ReadBuffer(
R__b,
this);
1456 i.second.CastPersistentToShared();
1461 i.second.CastSharedToPersistent();
1463 RModel::Class()->WriteBuffer(
R__b,
this);
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
winID h TVirtualViewer3D TVirtualGLPainter p
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 r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
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 id
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
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
const_iterator begin() const
const_iterator end() const
Buffer base class used for serializing objects.
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
void GenerateHeaderInfo(std::string &hgname)
void OutputGenerated(std::string filename="", bool append=false)
WeightFileType fWeightFile
void AddBlasRoutines(std::vector< std::string > routines)
void AddNeededStdLib(std::string libname)
void AddShapeParam(const std::string &name, size_t def_value=0)
std::vector< size_t > GetTensorShape(const std::string &name) const
std::vector< Dim > GetDimTensorShape(const std::string &name) const
std::unordered_map< std::string, DynamicTensorInfo > fDynamicTensorInfos
bool IsDynamicTensor(const std::string &name) const
void AddIntermediateTensor(std::string tensor_name, ETensorType type, std::vector< Dim > dim_shape)
void GenerateIntermediateTensorInfo()
void PrintIntermediateTensors()
std::string GenerateInferSignature(bool isdecl=true)
void GenerateOperatorDeclarations()
void PrintOutputTensors()
size_t fWeightsTensorSize
bool CheckIfTensorAlreadyExist(std::string tensor_name)
std::vector< std::unique_ptr< ROperator > > fOperators
void OutputGenerated(std::string filename="", bool append=false)
void AddInputTensorInfo(std::string input_name, ETensorType type, std::vector< Dim > shape)
std::unordered_map< std::string, TensorInfo > fIntermediateTensorInfos
void AddOutputTensorNameList(std::vector< std::string > output_tensor_names)
std::unordered_map< std::string, TensorInfo > fReadyInputTensorInfos
void AddConstantTensor(std::string tensor_name, ETensorType type, std::vector< std::size_t > shape, std::shared_ptr< void > data)
void AddDynamicTensor(std::string tensor_name, ETensorType type, std::vector< Dim > shape)
std::vector< std::string > fDimShapeNames
void AddInitializedTensor(std::string tensor_name, ETensorType type, std::vector< std::size_t > shape, std::shared_ptr< void > data)
std::unordered_map< std::string_view, size_t > fIntermediateTensorFrequencyLookup
! lookup table for intermediate tensor frequency (transient)
void AddInputTensorName(std::string name)
void PrintDynamicTensors()
std::vector< std::string > fOutputTensorNames
void GenerateSessionCode()
bool IsDimInputTensor(const std::string &name) const
void GenerateDynamicTensorInfo()
bool IsShapeTensor(const std::string &name) const
check if a tensor is a shape tensor
bool IsInitializedTensor(const std::string &name) const
size_t fConstantTensorSize
void CheckAndFlushIntermediateMemory(std::span< const std::string_view > op_output_tensors, const size_t &op_idx)
void PrintInitializedTensors()
void AddOperator(std::unique_ptr< ROperator > op, int order_execution=-1)
void HeadInitializedTensors(std::string name, int n_print=50)
bool IsConstantTensor(const std::string &name) const
void Initialize(int batchSize=-1, bool verbose=false)
long WriteInitializedTensorsToFile(std::string filename="")
OptimizationLevel fOptimizationLevel
void Generate(std::underlying_type_t< Options > options, int batchSize=-1, long pos=0, bool verbose=false)
std::vector< Dim > GetDynamicTensorShape(const std::string &name) const
std::unordered_map< std::string, InputTensorInfo > fInputTensorInfos
std::shared_ptr< void > GetInitializedTensorData(std::string tensor_name)
MemoryPoolInfo fIntermediateMemoryInfo
! intermediate memory info (transient)
void GenerateIntermediateMemoryPool()
void ReadInitializedTensorsFromFile(long)
std::string AllocateIntermediateMemory(std::span< const std::string_view > op_output_tensors)
std::unordered_map< std::string, std::pair< std::vector< Dim >, bool > > fShapeTensors
void InitializeSubGraph(std::shared_ptr< RModel > graph)
std::unordered_map< std::string, std::string > fShapeParams
void SetNotWritableInitializedTensor(const std::string &tensor_name)
ETensorType GetTensorType(std::string name) const
void GenerateInitializedTensorInfo()
std::vector< std::string > fInputTensorNames
std::unordered_map< std::string, InitializedTensor > fInitializedTensors
void UpdateInitializedTensor(std::string tensor_name, ETensorType type, std::vector< std::size_t > shape, std::shared_ptr< void > data)
const std::vector< Dim > & GetShapeTensorValues(const std::string &tensor_name) const
std::vector< std::shared_ptr< RModel > > fSubGraphs
! sub-graph models (transient)
bool IsReadyInputTensor(const std::string &name) const
void UpdateOutputTensorList(std::vector< std::string > curr_output_tensor, std::vector< std::string > modify_output_tensor)
void AddShapeTensor(const std::string &name, const std::vector< Dim > &shapeValues, bool scalar=false)
void PrintRequiredInputTensors()
std::string Clean_name(std::string input_tensor_name)
std::size_t ConvertShapeToLength(const std::vector< size_t > &shape)
std::string ConvertDynamicShapeToLength(const std::vector< Dim > &shape)
std::vector< Dim > ConvertShapeToDim(const std::vector< size_t > &shape)
Convert shape from integer format to dynamic one (based on Dim)
constexpr size_t GetTypeSize(ETensorType type)
std::string ConvertValuesToString(size_t n, const T *data)
std::string GenerateConstantTensorCode(const std::pair< std::string, InitializedTensor > &t)
std::vector< size_t > ConvertShapeToInt(const std::vector< Dim > &shape)
Convert shape based on Dim to integer format.
std::string ConvertTypeToString(ETensorType type)
std::underlying_type_t< Options > operator|(Options opA, Options opB)
std::string ConvertDimShapeToLength(const std::vector< Dim > &shape)
std::string ConvertShapeToString(const std::vector< size_t > &shape)
std::string ConvertValToString(T value)
create variable transformations
std::map< size_t, TensorMemoryInfo > total_stack
std::map< size_t, size_t > available_stack