8#ifdef SOFIE_SUPPORT_ROOT_BINARY
19const std::string
SP =
" ";
21void ReplaceAll(std::string &str,
const std::string &from,
const std::string &to)
24 while ((pos = str.find(from, pos)) != std::string::npos) {
25 str.replace(pos, from.length(), to);
32 return std::isalnum(
static_cast<unsigned char>(
c)) ||
c ==
'_';
38 return "tensor_" +
name;
44 return static_cast<std::underlying_type_t<Options>
>(
opA) |
static_cast<std::underlying_type_t<Options>
>(
opB);
47 return opA |
static_cast<std::underlying_type_t<Options>
>(
opB);
54 return f->second.shape;
58 return f2->second.shape();
62 throw std::runtime_error(
"TMVA SOFIE tensor [" +
name +
"] is an input tensor with unspecified dimension parameter");
66 return f4->second.shape;
72 if (f5->second.second)
73 return std::vector<size_t>{};
75 return std::vector<size_t>{f5->second.first.size()};
79 throw std::runtime_error(
"TMVA SOFIE tensor [" +
name +
"] is a dynamic tensor. Use GetDynamicTensorShape instead of GetTensorShape");
84 throw std::runtime_error(
"TMVA SOFIE tensor [" +
name +
"] for which the shape is requested is not found");
89 return f->second.shape;
92 return f->second.shape;
100 return f->second.shape;
103 return f->second.shape;
107 throw std::runtime_error(
"TMVA SOFIE tensor [" +
name +
"] for which the shape is requested is not dynamic");
109 throw std::runtime_error(
"TMVA SOFIE tensor [" +
name +
"] for which the shape is requested is not found");
115 return f->second.type;
119 return f2->second.type();
123 return f3->second.type;
127 return f4->second.type;
131 return f5->second.type;
141 throw std::runtime_error(
"TMVA SOFIE tensor [" +
name +
"] for which the type is requested is not found, model name: " +
fName);
158 throw std::runtime_error(
"TMVA-SOFIE: input tensor with name " +
input_name +
" already exists \n");
168 throw std::runtime_error(
"TMVA-SOFIE: input tensor with name " +
input_name +
" already exists \n");
180 auto libs =
op->GetStdLibs();
209 throw std::runtime_error(
"TMVA-SOFIE: initialized tensor with name " + tensor_name +
" already exists \n");
219 throw std::runtime_error(
"TMVA-SOFIE: constant tensor with name " + tensor_name +
" already exists \n");
228 throw std::runtime_error(
"TMVA-SOFIE: shape tensor with name " + tensor_name +
" already exists \n");
238 throw std::runtime_error(
"TMVA-SOFIE: alias tensor with name " + tensor_name +
" already exists \n");
265 return itr->second.IsConstantTensor();
295 throw std::runtime_error(
"TMVA-SOFIE: intermediate tensor with name " + tensor_name +
" already exists \n");
304 throw std::runtime_error(
"TMVA-SOFIE: intermediate tensor with name " + tensor_name +
" already exists \n");
309 for (
auto &
d : shape) {
311 if (
d.dim !=
size_t(-1)) {
343 throw std::runtime_error(
"TMVA-SOFIE: tensor " + tensor_name +
" not found when trying to update it");
352 throw std::runtime_error(
"TMVA-SOFIE: tensor " + tensor_name +
" not found when trying to get its data");
354 return f->second.sharedptr();
361 throw std::runtime_error(
"TMVA-SOFIE: initialized tensor " + tensor_name +
" not found when trying to get its info");
363 t->second.SetNotWritable();
368 std::stringstream code;
371 std::cout <<
"Total chunks allocated\n";
373 std::cout <<
"..... chunk " <<
chunk->first <<
" size " <<
chunk->second.tensor_size <<
" " <<
chunk->second.tensor_name << std::endl;
379 code <<
"\n // Allocating memory for intermediate tensor " <<
name <<
" with size " <<
size <<
" bytes";
381 << typeName <<
"* " <<
TensorMember(
name) <<
" = reinterpret_cast<" << typeName
382 <<
"*>(fIntermediateMemoryPool.data() + " << location <<
");\n";
385 if (
fVerbose) std::cout <<
"*** AllocateIntermediateMemory: Loop on op output tensors\n";
390 auto name = std::string(it);
410 std::string
name = std::string{it.tensor_name};
411 size_t tensor_size = it.tensor_size;
413 std::cout <<
"output tensor " <<
name <<
" size " << tensor_size << std::endl;
418 if (
fVerbose) std::cout <<
".. available chunk " <<
chunk->first <<
" with size = " <<
chunk->second;
420 if (
chunk->second >= tensor_size) {
428 chunk->second -= tensor_size;
434 if (
chunk->second == 0) {
435 if (
fVerbose) std::cout <<
" and deleted since size matches";
438 if (
fVerbose) std::cout << std::endl;
447 if (
fVerbose) std::cout <<
" is extended with a bigger one of size " << tensor_size << std::endl;
451 if (
fVerbose) std::cout << std::endl;
464 if (
fVerbose) std::cout <<
"no chunk available - add in total stack a new chunk with size of tensor and idx : " <<
chunk_idx
472 if (
fVerbose) std::cout <<
"*** CheckAndFlushIntermediateMemory: Loop on input tensors for op " <<
op_idx <<
"\n";
474 if (
fVerbose) std::cout <<
"available chunks before freeing them : \n";
477 if (
fVerbose) std::cout <<
"-- free chunk " <<
chunk->first <<
" size = " <<
chunk->second << std::endl;
481 if (
fVerbose) std::cout <<
".. input tensors : " <<
iv;
488 if (
fVerbose) std::cout <<
" flash condition is met - looping on chunks to find matching one \n";
491 if (
fVerbose) std::cout <<
"--- chunk " <<
chunk->first <<
" , " <<
chunk->second.tensor_name <<
" size " <<
chunk->second.tensor_size;
492 if (
chunk->second.tensor_name == it) {
493 if (
fVerbose) std::cout <<
" -- Found chunk corresponding to input tensor: " <<
chunk->first;
508 if (
fVerbose) std::cout <<
" is adjacent in memory with previous one - merge ";
518 if (
fVerbose) std::cout <<
" merge also with following that is free ";
521 if (
fVerbose) std::cout << std::endl;
526 if (
fVerbose) std::cout <<
" is adjacent in memory with following one - merge \n";
538 if (
fVerbose) std::cout <<
" insert in the available stack the chunk with size " <<
chunk->second.tensor_size << std::endl;
540 chunk->second.tensor_name =
"free";
545 if (
fVerbose) std::cout << std::endl;
566 std::cout <<
"Model is already initialized - skip initialization " << std::endl;
578 if (verbose) std::cout <<
"looking at the tensor " <<
input.first << std::endl;
581 for (
auto &
d :
input.second.shape) {
583 std::string
pname =
d.param;
589 std::cout <<
"Tensor: " <<
input.first <<
" - fix parametric shape " <<
itr->first <<
" to " <<
itr->second << std::endl;
599 if (!shape.empty()) {
611 for (
auto &
d :
input.second.shape) {
637 std::cout <<
"Initializing operator " << i <<
" " <<
typeid(
r).
name() << std::endl;
641 std::string
name = std::string{it};
653 std::string
name = std::string{it};
669 it.second.SetWritable();
671 std::cout <<
"Initialized tensor " << it.first <<
" is flagged as not writable but is used by non constant operators, set it as writable \n";
677 it.second.SetConstant();
685 if (it.second.IsWeightTensor()) {
712 graph->fParentGraph =
this;
713 graph->fIsSubGraph =
true;
722 for (
auto &
e : graph->fNeededBlasRoutines)
725 for (
auto e : graph->fNeededStdLib)
730 graph->fInputTensorNames.emplace_back(
name);
742 std::stringstream
strs;
749 const T *
data = t.second.data<T>();
765 strs <<
"std::vector<" <<
type <<
"> fTensor_" << t.first <<
" = ";
779 fGC +=
"// initialized (weights and constant) tensors\n";
783 if (i.second.IsNotWritable())
continue;
804 fGC +=
"std::vector<float> fTensor_" + i.first +
" = std::vector<float>(" + std::to_string(
length) +
");\n";
805 fGC +=
"float * " +
TensorMember(i.first) +
" = fTensor_" + i.first +
".data();\n";
814 fGC +=
"\n//--- Allocating session memory pool to be used for allocating intermediate tensors\n";
820 fGC +=
"std::vector<char> fIntermediateMemoryPool = std::vector<char>(" + std::to_string(
memPoolSize) +
");\n\n";
870 fGC +=
"//--- declare the dynamic tensors\n";
874 fGC +=
"//--- dynamic tensors pool\n";
875 fGC +=
"std::vector<char> fDynamicMemoryPool;\n";
886 fGC +=
"\n//---- operator declarations \n";
898 std::cout <<
"generating code for dynamic tensor management" << std::endl;
902 std::stringstream out;
903 out <<
"// dynamic tensor memory management\n";
904 out <<
SP <<
"std::vector<TMVA::Experimental::SOFIE::TensorLifeInfo> dynamicTensorInfos;\n";
909 std::vector<std::pair<std::string, ETensorType>>
tensors;
913 for (
auto &it :
op->GetOpOutputTensors()) {
916 std::cout <<
"Looping on operator " <<
op_index <<
" " <<
typeid(*op_ptr).name() << std::endl;
919 std::string
name = std::string(it);
935 std::cout <<
"op " <<
op_index <<
"tensor_" <<
name <<
" begin " << begin <<
" " <<
" end " << end << std::endl;
936 throw std::runtime_error(
"TMVA-SOFIE: RModel::GenerateDynamicTensorInfo: tensor_" +
name +
" has end before begin");
940 out <<
SP <<
"dynamicTensorInfos.push_back( {" << begin <<
", " << end <<
", " <<
type_size <<
"* (" << tensor_size <<
") });"
941 <<
" // tensor_" <<
name << std::endl;
947 out <<
"\n" <<
SP <<
"auto memory_result = OrganizeMemory(dynamicTensorInfos);\n\n";
948 out <<
"// allocating now the memory\n";
949 out <<
SP <<
"fDynamicMemoryPool = std::vector<char>(memory_result.total_bytes);\n";
950 out <<
SP <<
"int idx = 0;\n";
952 out <<
SP <<
"tensor_" << it.first <<
" = reinterpret_cast<" <<
ConvertTypeToString(it.second) <<
" *>(fDynamicMemoryPool.data() + memory_result.offsets[idx++]);\n";
960 std::cout <<
"Dynamic tensors " << i.first <<
" is not in list of operator input/output " << std::endl;
965 throw std::runtime_error(
"TMVA-SOFIE: RModel::GenerateDynamicTensorInfo - some tensors are not in input/output list");
976 for (
auto &
d : shape) {
991 const std::string
target =
"tensor_";
993 std::vector<std::string>
result;
995 for (
size_t i = 0; i <
input.size();) {
1004 std::size_t
j = i +
target.size();
1057 for (
auto &
d : shape) {
1058 std::string
pName =
d.param;
1062 rGC +=
d.param +
",";
1069 if (
type ==
"other")
1070 throw std::runtime_error(
"TMVA-SOFIE: input tensor " +
name +
1071 " is of a data type which is not yet supported.");
1074 rGC +=
"tensor_" +
name +
",";
1093 if (!
name.empty()) {
1094 name[0] = std::toupper(
static_cast<unsigned char>(
name[0]));
1111 if (outputSize == 1) {
1123 for (
size_t i = 0; i < outputSize; i++) {
1125 if (i < outputSize - 1)
1152 fGC +=
SP +
"size_t " + dim.param +
" = 0;\n";
1167 for (
auto &
d : shape) {
1168 std::string
pName =
d.param;
1174 fGC +=
SP +
SP +
"throw std::runtime_error(\"TMVA-SOFIE: dynamic input tensor shape parameter " +
1175 d.param +
" exceeds the initialized maximum allowed shape.\");\n";
1198 fGC +=
SP +
"return {";
1259 std::cout <<
"\n******************\n analyzing input/output operator " <<
op_idx <<
" "
1260 <<
typeid(*op).name() << std::endl;
1295 fGC +=
"Session_" + graph->fName +
" fSession_" + graph->fName +
";\n";
1302 for (
size_t id = 0;
id <
fOperators.size();
id++) {
1303 std::string
opName = std::to_string(
id);
1309 std::string fileName =
fName;
1314 fileName +=
".root";
1316 fGC +=
sessionName +
"(std::string filename =\"" + fileName +
"\"";
1344 fGC +=
"\n//--- reading weights from file\n";
1354 for (
size_t id = 0;
id <
fOperators.size();
id++) {
1366 fGC +=
"}; // end of Session\n\n";
1376 std::cout <<
"Generating main inference code for " <<
fName << std::endl;
1379 throw std::runtime_error(
"TMVA-SOFIE: output size=0 are not supported");
1385 std::cout <<
"Generating code for operator .... " <<
op_idx << std::endl;
1398 fGC +=
" auto &" +
name +
" = session." +
name +
";\n";
1410 fGC +=
" " + dim.param +
"_output = " + dim.param +
";\n";
1414 std::string t =
"session.tensor_" +
name;
1416 fGC +=
" std::copy(" + t +
", " + t +
" + " + std::to_string(
length) +
", tensor_" +
name +
");\n";
1424void RModel::Generate(std::underlying_type_t<Options> options,
int batchSize,
long pos,
bool verbose)
1444 throw std::runtime_error(
1445 "TMVA-SOFIE: RModel::Generate: cannot use a separate weight file without generating a Session class");
1448 if (
static_cast<std::underlying_type_t<Options>
>(
Options::kGNN) & options)
1460 std::cout <<
"Warning: Force having a Session since model has dynamic tensors " << std::endl;
1472 std::cout <<
"generate session code for subgraph " << graph->fName << std::endl;
1473 graph->GenerateSessionCode();
1478 std::cout <<
"generate Main session code - model " <<
fName << std::endl;
1484 fGC += (
"} //TMVA_SOFIE_" +
fName +
"\n");
1496 fGC +=
" std::ifstream f;\n";
1497 fGC +=
" f.open(filename);\n";
1498 fGC +=
" if (!f.is_open()) {\n";
1499 fGC +=
" throw std::runtime_error(\"tmva-sofie failed to open file \" + filename + \" for input weights\");\n";
1503 fGC +=
" f.seekg(" + std::to_string(pos) +
");\n";
1506 fGC +=
" using TMVA::Experimental::SOFIE::ReadTensorFromStream;\n";
1511 if (!i.second.IsWeightTensor())
continue;
1512 std::string tensor_name =
"tensor_" + i.first;
1515 fGC +=
" ReadTensorFromStream(f, " + tensor_name +
", \"" + tensor_name +
"\", " +
length +
");\n";
1517 throw std::runtime_error(
"tmva-sofie tensor " + tensor_name +
" with type " +
ConvertTypeToString(i.second.type()) +
" cannot be read from a file");
1520 fGC +=
" f.close();\n";
1525#ifdef SOFIE_SUPPORT_ROOT_BINARY
1527 fGC +=
" std::unique_ptr<TFile> rootFile(TFile::Open(filename.c_str(), \"READ\"));\n";
1528 fGC +=
" if (!rootFile->IsOpen()) {\n";
1529 fGC +=
" throw std::runtime_error(\"tmva-sofie failed to open ROOT file for input weights\");\n";
1533 fGC +=
" if (!rootFile->GetKey(\"" +
dirName +
"\")) {\n";
1534 fGC +=
" throw std::runtime_error(\"tmva-sofie failed to open ROOT directory for input weights\");\n";
1539 if (!i.second.IsWeightTensor())
continue;
1541 std::string tensor_name =
"tensor_" + i.first;
1543 fGC +=
" fTensor_" + i.first +
" = *reinterpret_cast<std::vector<float>*>(rootFile->Get(\"";
1544 fGC +=
dirName +
"/" + tensor_name +
"\"));\n";
1546 fGC +=
" fTensor_" + i.first +
" = *reinterpret_cast<std::vector<double>*>(rootFile->Get(\"";
1547 fGC +=
dirName + +
"/" + tensor_name +
"\"));\n";
1549 fGC +=
" fTensor_" + i.first +
" = *reinterpret_cast<std::vector<int64_t>*>(rootFile->Get(\"";
1550 fGC +=
dirName +
"/" + tensor_name +
"\"));\n";
1552 std::runtime_error(
"tmva-sofie tensor " + tensor_name +
" with type " +
ConvertTypeToString(i.second.type()) +
" cannot be read from a ROOT file");
1558 throw std::runtime_error(
"SOFIE was not built with ROOT file support.");
1585#ifdef SOFIE_SUPPORT_ROOT_BINARY
1587 throw std::runtime_error(
"SOFIE-GNN yet not supports writing to a ROOT file.");
1600 if (!
item.second.IsWeightTensor())
continue;
1605 const float*
data =
item.second.data<
float>();
1610 const double*
data =
item.second.data<
double>();
1615 const int64_t*
data =
item.second.data<int64_t>();
1621 " cannot be written to a ROOT file");
1630 throw std::runtime_error(
"SOFIE was not built with ROOT file support.");
1642 std::runtime_error(
"tmva-sofie failed to open file " +
filename +
" for tensor weight data");
1645 if (!i.second.IsWeightTensor()) {
1649 std::string tensor_name =
"tensor_" + i.first;
1650 f << tensor_name <<
" " <<
length <<
"\n";
1652 const float *
data = i.second.data<
float>();
1653 for (
size_t idx = 0; idx <
length; idx++) {
1656 if (
value != 0. && std::abs(
value) < std::numeric_limits<float>::min() )
value = 0;
1658 if (std::isinf(
value))
1659 f << (
value > 0 ?
"inf" :
"-inf");
1660 else if (std::isnan(
value))
1663 f << std::setprecision(std::numeric_limits<float>::max_digits10) <<
value;
1664 f << ( (idx <
length-1) ?
" " :
"\n" );
1668 throw std::runtime_error(
"tmva-sofie tensor " + tensor_name +
" with type " +
ConvertTypeToString(i.second.type()) +
" cannot be written to a file");
1671 std::runtime_error(
"tmva-sofie failed to write tensor data to file for " + tensor_name);
1682 std::cout <<
"Summary of model " <<
GetName() << std::endl;
1689 for (
auto &
t_in :
r.GetOpInputTensors()) std::cout <<
t_in <<
" ";
1690 std::cout <<
" ----> ";
1691 for (
auto &
t_out :
r.GetOpOutputTensors()) std::cout <<
t_out <<
" ";
1692 std::cout << std::endl;
1700 fGC +=
"\n// Input tensor dimensions\n";
1701 fGC +=
"using TMVA::Experimental::SOFIE::SingleDim;\n";
1702 fGC +=
"using TMVA::Experimental::SOFIE::TensorDims;\n";
1703 fGC +=
"using TMVA::Experimental::SOFIE::makeDims;\n\n";
1712 fGC +=
"constexpr std::array<SingleDim, " + std::to_string(shape.size()) +
"> dim_" +
name +
"{";
1713 for (std::size_t
iDim = 0;
iDim < shape.size(); ++
iDim) {
1714 auto const &dim = shape[
iDim];
1716 fGC +=
"SingleDim{\"" + dim.GetVal() +
"\"}";
1718 fGC +=
"SingleDim{" + dim.GetVal() +
"}";
1720 if (
iDim != shape.size() - 1) {
1726 fGC +=
"\nconstexpr std::array<TensorDims, " + std::to_string(
fInputTensorNames.size()) +
"> inputTensorDims{\n";
1729 fGC +=
SP +
"makeDims(dim_" +
name +
")";
1739 "\nconstexpr bool hasDynamicInputTensors{" + std::string{
hasDynamicInputTensors ?
"true" :
"false"} +
"};\n\n";
1743 std::cout <<
"Model requires following inputs:\n";
1745 std::cout <<
"Parametrised Tensor name: " <<
inputInfo.first <<
"\t";
1747 std::cout <<
"shape: [";
1748 for (
size_t i = 0; i <
inputInfo.second.shape.size(); i++) {
1749 if (
inputInfo.second.shape[i].isParam) {
1750 std::cout <<
inputInfo.second.shape[i].param;
1752 std::cout <<
inputInfo.second.shape[i].dim ;
1754 if (i <
inputInfo.second.shape.size() - 1) std::cout <<
",";
1756 std::cout <<
"]" << std::endl;
1760 std::cout <<
"Fully Specified Tensor name: " <<
inputInfo.first <<
"\t";
1762 std::cout <<
"shape: [";
1763 for (
size_t i = 0; i <
inputInfo.second.shape.size(); i++) {
1765 if (i <
inputInfo.second.shape.size() - 1) std::cout <<
",";
1767 std::cout <<
"]" << std::endl;
1773 std::cout <<
"Model initialized the following tensors:\n";
1775 std::cout <<
"Tensor name: \"" << it.first <<
"\"\t";
1777 std::cout <<
"shape: [";
1778 for (
size_t i = 0; i < it.second.shape().
size(); i++) {
1779 std::cout << it.second.shape()[i];
1780 if (i < it.second.shape().size() - 1) std::cout <<
",";
1783 if (it.second.IsConstantTensor()) std::cout <<
" (Constant)";
1784 if (it.second.IsNotWritable()) std::cout <<
" (Not Writable)";
1785 std::cout << std::endl;
1791 std::cout <<
"Model specify the following intermediate tensors:\n";
1793 std::cout <<
"Tensor name: \"" << it.first <<
"\"\t";
1795 std::cout <<
"shape: [";
1796 for (
size_t i = 0; i < it.second.shape.size(); i++) {
1797 std::cout << it.second.shape[i];
1798 if (i < it.second.shape.size() - 1) std::cout <<
",";
1800 std::cout <<
"]" << std::endl;
1806 std::cout <<
"Model specify the following dynamic tensors:\n";
1808 std::cout <<
"Tensor name: \"" << it.first <<
"\"\t";
1810 std::cout <<
"shape: [";
1811 for (
size_t i = 0; i < it.second.shape.size(); i++) {
1812 std::cout << it.second.shape[i].GetVal();
1813 if (i < it.second.shape.size() - 1) std::cout <<
",";
1815 std::cout <<
"]" << std::endl;
1821 std::cout <<
"Model specify the following output tensors:\n";
1823 std::cout <<
"Tensor name: \"" << it <<
"\"\t";
1828 std::cout <<
"with shape not yet defined" << std::endl;
1837 std::cout <<
"Tensor " <<
name <<
" not found in model's initialized tensor list" << std::endl;
1841 std::cout <<
"Tensor name: " << it->first <<
"\t";
1844 std::cout <<
"shape: [";
1845 for (
size_t i = 0; i < it->second.shape().
size(); i++) {
1846 std::cout << it->second.shape()[i];
1847 length *= it->second.shape()[i];
1848 if (
i < it->second.shape().size() - 1) std::cout <<
",";
1850 std::cout <<
"]" << std::endl;
1857 std::cout <<
"data: [" << std::endl;
1860 for (
int i =0; i <
n_print; i++) {
1862 if (i <
n_print - 1) std::cout <<
" ,";
1865 if (
ellipsis) std::cout <<
", ...";
1866 std::cout <<
"]" << std::endl;
1877 size_t pos =
filename.find(
".hxx");
1893 if (
R__b.IsReading()) {
1894 RModel::Class()->ReadBuffer(
R__b,
this);
1896 i.second.CastPersistentToShared();
1901 i.second.CastSharedToPersistent();
1903 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 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 target
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 Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
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)
const std::string & GetName() const
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
void PrintIntermediateTensors() 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 AddAliasTensor(const std::string &tensor_name, const std::string &orig_tensor_name)
void AddIntermediateTensor(std::string tensor_name, ETensorType type, std::vector< Dim > dim_shape)
void GenerateIntermediateTensorInfo()
std::string GenerateInferSignature(bool isdecl=true)
void GenerateOperatorDeclarations()
size_t fWeightsTensorSize
bool CheckIfTensorAlreadyExist(std::string tensor_name)
std::vector< std::unique_ptr< ROperator > > fOperators
void GenerateRequiredInputTensorInfo()
To emit the dimensions of the input tensors as a data member of a session, which is helpful when vali...
void OutputGenerated(std::string filename="", bool append=false)
std::unordered_map< std::string, std::string > fAliasTensors
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)
std::vector< std::string > fOutputTensorNames
void PrintRequiredInputTensors() const
void GenerateSessionCode()
bool IsDimInputTensor(const std::string &name) const
void GenerateDynamicTensorInfo()
void PrintDynamicTensors() const
bool IsShapeTensor(const std::string &name) const
check if a tensor is a shape tensor
bool IsInitializedTensor(const std::string &name) const
bool IsAliasTensor(const std::string &name) const
check if a tensor is a alias tensor
size_t fConstantTensorSize
void CheckAndFlushIntermediateMemory(std::span< const std::string_view > op_output_tensors, const size_t &op_idx)
void AddOperator(std::unique_ptr< ROperator > op, int order_execution=-1)
void PrintOutputTensors() const
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)
void PrintSummary() const
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...
std::vector< Dim > GetDynamicTensorShape(const std::string &name) const
void PrintInitializedTensors() 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)
bool IsInputTensorShapeParam(std::string const &name) const
Check if a given parameter is used for the shape of an input tensor.
std::string Clean_name(std::string input_tensor_name)
std::string ConvertDimShapeToString(const std::vector< Dim > &shape)
std::size_t ConvertShapeToLength(const std::vector< size_t > &shape)
std::string ConvertValuesToString(size_t n, const T *data, size_t maxprint=-1)
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 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)
std::map< size_t, TensorMemoryInfo > total_stack
std::map< size_t, size_t > available_stack