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 ==
'_';
40 if (s.empty() || std::isdigit(
static_cast<unsigned char>(s[0])))
51 return "tensor_" +
name;
57 return static_cast<std::underlying_type_t<Options>
>(
opA) |
static_cast<std::underlying_type_t<Options>
>(
opB);
60 return opA |
static_cast<std::underlying_type_t<Options>
>(
opB);
67 return f->second.shape;
71 return f2->second.shape();
75 throw std::runtime_error(
"TMVA SOFIE tensor [" +
name +
"] is an input tensor with unspecified dimension parameter");
79 return f4->second.shape;
85 if (f5->second.second)
86 return std::vector<size_t>{};
88 return std::vector<size_t>{f5->second.first.size()};
92 throw std::runtime_error(
"TMVA SOFIE tensor [" +
name +
"] is a dynamic tensor. Use GetDynamicTensorShape instead of GetTensorShape");
97 throw std::runtime_error(
"TMVA SOFIE tensor [" +
name +
"] for which the shape is requested is not found");
102 return f->second.shape;
105 return f->second.shape;
113 return f->second.shape;
116 return f->second.shape;
120 throw std::runtime_error(
"TMVA SOFIE tensor [" +
name +
"] for which the shape is requested is not dynamic");
122 throw std::runtime_error(
"TMVA SOFIE tensor [" +
name +
"] for which the shape is requested is not found");
128 return f->second.type;
132 return f2->second.type();
136 return f3->second.type;
140 return f4->second.type;
144 return f5->second.type;
154 throw std::runtime_error(
"TMVA SOFIE tensor [" +
name +
"] for which the type is requested is not found, model name: " +
fName);
171 throw std::runtime_error(
"TMVA-SOFIE: input tensor with name " +
input_name +
" already exists \n");
181 throw std::runtime_error(
"TMVA-SOFIE: input tensor with name " +
input_name +
" already exists \n");
194 auto libs =
op->GetStdLibs();
226 throw std::runtime_error(
"TMVA-SOFIE: initialized tensor with name " + tensor_name +
" already exists \n");
233 const std::vector<std::size_t> &shape,
void *
raw_data)
246 throw std::runtime_error(
"TMVA-SOFIE: constant tensor with name " + tensor_name +
" already exists \n");
255 throw std::runtime_error(
"TMVA-SOFIE: shape tensor with name " + tensor_name +
" already exists \n");
265 throw std::runtime_error(
"TMVA-SOFIE: alias tensor with name " + tensor_name +
" already exists \n");
292 return itr->second.IsConstantTensor();
322 throw std::runtime_error(
"TMVA-SOFIE: intermediate tensor with name " + tensor_name +
" already exists \n");
331 throw std::runtime_error(
"TMVA-SOFIE: intermediate tensor with name " + tensor_name +
" already exists \n");
336 for (
auto &
d : shape) {
338 if (
d.dim !=
size_t(-1)) {
370 throw std::runtime_error(
"TMVA-SOFIE: tensor " + tensor_name +
" not found when trying to update it");
379 throw std::runtime_error(
"TMVA-SOFIE: tensor " + tensor_name +
" not found when trying to get its data");
381 return f->second.sharedptr();
388 throw std::runtime_error(
"TMVA-SOFIE: initialized tensor " + tensor_name +
" not found when trying to get its info");
390 t->second.SetNotWritable();
395 std::stringstream code;
398 std::cout <<
"Total chunks allocated\n";
400 std::cout <<
"..... chunk " <<
chunk->first <<
" size " <<
chunk->second.tensor_size <<
" " <<
chunk->second.tensor_name << std::endl;
406 code <<
"\n // Allocating memory for intermediate tensor " <<
name <<
" with size " <<
size <<
" bytes";
408 << typeName <<
"* " <<
TensorMember(
name) <<
" = reinterpret_cast<" << typeName
409 <<
"*>(fIntermediateMemoryPool.data() + " << location <<
");\n";
412 if (
fVerbose) std::cout <<
"*** AllocateIntermediateMemory: Loop on op output tensors\n";
417 auto name = std::string(it);
437 std::string
name = std::string{it.tensor_name};
438 size_t tensor_size = it.tensor_size;
440 std::cout <<
"output tensor " <<
name <<
" size " << tensor_size << std::endl;
445 if (
fVerbose) std::cout <<
".. available chunk " <<
chunk->first <<
" with size = " <<
chunk->second;
447 if (
chunk->second >= tensor_size) {
455 chunk->second -= tensor_size;
461 if (
chunk->second == 0) {
462 if (
fVerbose) std::cout <<
" and deleted since size matches";
465 if (
fVerbose) std::cout << std::endl;
474 if (
fVerbose) std::cout <<
" is extended with a bigger one of size " << tensor_size << std::endl;
478 if (
fVerbose) std::cout << std::endl;
491 if (
fVerbose) std::cout <<
"no chunk available - add in total stack a new chunk with size of tensor and idx : " <<
chunk_idx
499 if (
fVerbose) std::cout <<
"*** CheckAndFlushIntermediateMemory: Loop on input tensors for op " <<
op_idx <<
"\n";
501 if (
fVerbose) std::cout <<
"available chunks before freeing them : \n";
504 if (
fVerbose) std::cout <<
"-- free chunk " <<
chunk->first <<
" size = " <<
chunk->second << std::endl;
508 if (
fVerbose) std::cout <<
".. input tensors : " <<
iv;
515 if (
fVerbose) std::cout <<
" flash condition is met - looping on chunks to find matching one \n";
518 if (
fVerbose) std::cout <<
"--- chunk " <<
chunk->first <<
" , " <<
chunk->second.tensor_name <<
" size " <<
chunk->second.tensor_size;
519 if (
chunk->second.tensor_name == it) {
520 if (
fVerbose) std::cout <<
" -- Found chunk corresponding to input tensor: " <<
chunk->first;
535 if (
fVerbose) std::cout <<
" is adjacent in memory with previous one - merge ";
545 if (
fVerbose) std::cout <<
" merge also with following that is free ";
548 if (
fVerbose) std::cout << std::endl;
553 if (
fVerbose) std::cout <<
" is adjacent in memory with following one - merge \n";
565 if (
fVerbose) std::cout <<
" insert in the available stack the chunk with size " <<
chunk->second.tensor_size << std::endl;
567 chunk->second.tensor_name =
"free";
572 if (
fVerbose) std::cout << std::endl;
593 std::cout <<
"Model is already initialized - skip initialization " << std::endl;
605 if (verbose) std::cout <<
"looking at the tensor " <<
input.first << std::endl;
608 for (
auto &
d :
input.second.shape) {
610 std::string
pname =
d.param;
616 std::cout <<
"Tensor: " <<
input.first <<
" - fix parametric shape " <<
itr->first <<
" to " <<
itr->second << std::endl;
626 if (!shape.empty()) {
638 for (
auto &
d :
input.second.shape) {
664 std::cout <<
"Initializing operator " << i <<
" " <<
typeid(
r).
name() << std::endl;
668 std::string
name = std::string{it};
680 std::string
name = std::string{it};
696 it.second.SetWritable();
698 std::cout <<
"Initialized tensor " << it.first <<
" is flagged as not writable but is used by non constant operators, set it as writable \n";
704 it.second.SetConstant();
712 if (it.second.IsWeightTensor()) {
739 graph->fParentGraph =
this;
740 graph->fIsSubGraph =
true;
749 for (
auto &
e : graph->fNeededBlasRoutines)
752 for (
auto e : graph->fNeededStdLib)
757 graph->fInputTensorNames.emplace_back(
name);
769 std::stringstream
strs;
776 const T *
data = t.second.data<T>();
793 strs <<
"std::vector<" <<
type <<
"> fTensor_" << t.first <<
" = ";
807 fGC +=
"// initialized (weights and constant) tensors\n";
811 if (i.second.IsNotWritable())
continue;
817 const float *
data = i.second.data<
float>();
818 for (
size_t idx = 0; idx <
length; idx++) {
819 if (std::is_floating_point<float>::value) {
820 if (std::isinf(
data[idx]) || std::isnan(
data[idx])) {
845 fGC +=
"std::vector<float> fTensor_" + i.first +
" = std::vector<float>(" + std::to_string(
length) +
");\n";
846 fGC +=
"float * " +
TensorMember(i.first) +
" = fTensor_" + i.first +
".data();\n";
855 fGC +=
"\n//--- Allocating session memory pool to be used for allocating intermediate tensors\n";
861 fGC +=
"std::vector<char> fIntermediateMemoryPool = std::vector<char>(" + std::to_string(
memPoolSize) +
");\n\n";
911 fGC +=
"//--- declare the dynamic tensors\n";
915 fGC +=
"//--- dynamic tensors pool\n";
916 fGC +=
"std::vector<char> fDynamicMemoryPool;\n";
927 fGC +=
"\n//---- operator declarations \n";
939 std::cout <<
"generating code for dynamic tensor management" << std::endl;
943 std::stringstream out;
944 out <<
"// dynamic tensor memory management\n";
945 out <<
SP <<
"std::vector<TMVA::Experimental::SOFIE::TensorLifeInfo> dynamicTensorInfos;\n";
950 std::vector<std::pair<std::string, ETensorType>>
tensors;
954 for (
auto &it :
op->GetOpOutputTensors()) {
957 std::cout <<
"Looping on operator " <<
op_index <<
" " <<
typeid(*op_ptr).name() << std::endl;
960 std::string
name = std::string(it);
976 std::cout <<
"op " <<
op_index <<
"tensor_" <<
name <<
" begin " << begin <<
" " <<
" end " << end << std::endl;
977 throw std::runtime_error(
"TMVA-SOFIE: RModel::GenerateDynamicTensorInfo: tensor_" +
name +
" has end before begin");
981 out <<
SP <<
"dynamicTensorInfos.push_back( {" << begin <<
", " << end <<
", " <<
type_size <<
"* (" << tensor_size <<
") });"
982 <<
" // tensor_" <<
name << std::endl;
988 out <<
"\n" <<
SP <<
"auto memory_result = OrganizeMemory(dynamicTensorInfos);\n\n";
989 out <<
"// allocating now the memory\n";
990 out <<
SP <<
"fDynamicMemoryPool = std::vector<char>(memory_result.total_bytes);\n";
991 out <<
SP <<
"int idx = 0;\n";
993 out <<
SP <<
"tensor_" << it.first <<
" = reinterpret_cast<" <<
ConvertTypeToString(it.second) <<
" *>(fDynamicMemoryPool.data() + memory_result.offsets[idx++]);\n";
1001 std::cout <<
"Dynamic tensors " << i.first <<
" is not in list of operator input/output " << std::endl;
1006 throw std::runtime_error(
"TMVA-SOFIE: RModel::GenerateDynamicTensorInfo - some tensors are not in input/output list");
1017 for (
auto &
d : shape) {
1032 const std::string
target =
"tensor_";
1034 std::vector<std::string>
result;
1036 for (
size_t i = 0; i <
input.size();) {
1045 std::size_t
j = i +
target.size();
1098 for (
auto &
d : shape) {
1099 std::string
pName =
d.param;
1103 rGC +=
d.param +
",";
1110 if (
type ==
"other")
1111 throw std::runtime_error(
"TMVA-SOFIE: input tensor " +
name +
1112 " is of a data type which is not yet supported.");
1115 rGC +=
"tensor_" +
name +
",";
1134 if (!
name.empty()) {
1135 name[0] = std::toupper(
static_cast<unsigned char>(
name[0]));
1152 if (outputSize == 1) {
1164 for (
size_t i = 0; i < outputSize; i++) {
1166 if (i < outputSize - 1)
1203 fGC +=
SP +
"size_t " + dim.param +
" = 0;\n";
1218 for (
auto &
d : shape) {
1219 std::string
pName =
d.param;
1225 fGC +=
SP +
SP +
"throw std::runtime_error(\"TMVA-SOFIE: dynamic input tensor shape parameter " +
1226 d.param +
" exceeds the initialized maximum allowed shape.\");\n";
1249 fGC +=
SP +
"return {";
1310 std::cout <<
"\n******************\n analyzing input/output operator " <<
op_idx <<
" "
1311 <<
typeid(*op).name() << std::endl;
1336 fGC +=
"\n// dynamic shape parameters\n";
1347 fGC +=
"Session_" + graph->fName +
" fSession_" + graph->fName +
";\n";
1354 for (
size_t id = 0;
id <
fOperators.size();
id++) {
1355 std::string
opName = std::to_string(
id);
1361 std::string fileName =
fName;
1366 fileName +=
".root";
1368 fGC +=
sessionName +
"(std::string filename =\"" + fileName +
"\"";
1397 fGC +=
"\n//--- reading weights from file\n";
1407 for (
size_t id = 0;
id <
fOperators.size();
id++) {
1419 fGC +=
"}; // end of Session\n\n";
1429 std::cout <<
"Generating main inference code for " <<
fName << std::endl;
1432 throw std::runtime_error(
"TMVA-SOFIE: output size=0 are not supported");
1438 std::cout <<
"Generating code for operator .... " <<
op_idx << std::endl;
1451 fGC +=
" auto &" +
name +
" = session." +
name +
";\n";
1463 fGC +=
" " + dim.param +
"_output = " + dim.param +
";\n";
1467 std::string t =
"session.tensor_" +
name;
1469 fGC +=
" std::copy(" + t +
", " + t +
" + " + std::to_string(
length) +
", tensor_" +
name +
");\n";
1477void RModel::Generate(std::underlying_type_t<Options> options,
int batchSize,
long pos,
bool verbose)
1497 throw std::runtime_error(
1498 "TMVA-SOFIE: RModel::Generate: cannot use a separate weight file without generating a Session class");
1501 if (
static_cast<std::underlying_type_t<Options>
>(
Options::kGNN) & options)
1513 std::cout <<
"Warning: Force having a Session since model has dynamic tensors " << std::endl;
1525 std::cout <<
"generate session code for subgraph " << graph->fName << std::endl;
1526 graph->GenerateSessionCode();
1531 std::cout <<
"generate Main session code - model " <<
fName << std::endl;
1537 fGC += (
"} //TMVA_SOFIE_" +
fName +
"\n");
1549 fGC +=
" std::ifstream f;\n";
1550 fGC +=
" f.open(filename);\n";
1551 fGC +=
" if (!f.is_open()) {\n";
1552 fGC +=
" throw std::runtime_error(\"tmva-sofie failed to open file \" + filename + \" for input weights\");\n";
1556 fGC +=
" f.seekg(" + std::to_string(pos) +
");\n";
1559 fGC +=
" using TMVA::Experimental::SOFIE::ReadTensorFromStream;\n";
1564 if (!i.second.IsWeightTensor())
continue;
1565 std::string tensor_name =
"tensor_" + i.first;
1568 fGC +=
" ReadTensorFromStream(f, " + tensor_name +
", \"" + tensor_name +
"\", " +
length +
");\n";
1570 throw std::runtime_error(
"tmva-sofie tensor " + tensor_name +
" with type " +
ConvertTypeToString(i.second.type()) +
" cannot be read from a file");
1573 fGC +=
" f.close();\n";
1578#ifdef SOFIE_SUPPORT_ROOT_BINARY
1580 fGC +=
" std::unique_ptr<TFile> rootFile(TFile::Open(filename.c_str(), \"READ\"));\n";
1581 fGC +=
" if (!rootFile->IsOpen()) {\n";
1582 fGC +=
" throw std::runtime_error(\"tmva-sofie failed to open ROOT file for input weights\");\n";
1586 fGC +=
" if (!rootFile->GetKey(\"" +
dirName +
"\")) {\n";
1587 fGC +=
" throw std::runtime_error(\"tmva-sofie failed to open ROOT directory for input weights\");\n";
1592 if (!i.second.IsWeightTensor())
continue;
1594 std::string tensor_name =
"tensor_" + i.first;
1596 fGC +=
" fTensor_" + i.first +
" = *reinterpret_cast<std::vector<float>*>(rootFile->Get(\"";
1597 fGC +=
dirName +
"/" + tensor_name +
"\"));\n";
1599 fGC +=
" fTensor_" + i.first +
" = *reinterpret_cast<std::vector<double>*>(rootFile->Get(\"";
1600 fGC +=
dirName + +
"/" + tensor_name +
"\"));\n";
1602 fGC +=
" fTensor_" + i.first +
" = *reinterpret_cast<std::vector<int64_t>*>(rootFile->Get(\"";
1603 fGC +=
dirName +
"/" + tensor_name +
"\"));\n";
1605 throw std::runtime_error(
"tmva-sofie tensor " + tensor_name +
" with type " +
ConvertTypeToString(i.second.type()) +
" cannot be read from a ROOT file");
1611 throw std::runtime_error(
"SOFIE was not built with ROOT file support.");
1638#ifdef SOFIE_SUPPORT_ROOT_BINARY
1640 throw std::runtime_error(
"SOFIE-GNN yet not supports writing to a ROOT file.");
1653 if (!
item.second.IsWeightTensor())
continue;
1658 const float*
data =
item.second.data<
float>();
1663 const double*
data =
item.second.data<
double>();
1668 const int64_t*
data =
item.second.data<int64_t>();
1674 " cannot be written to a ROOT file");
1683 throw std::runtime_error(
"SOFIE was not built with ROOT file support.");
1695 std::runtime_error(
"tmva-sofie failed to open file " +
filename +
" for tensor weight data");
1698 if (!i.second.IsWeightTensor()) {
1702 std::string tensor_name =
"tensor_" + i.first;
1703 f << tensor_name <<
" " <<
length <<
"\n";
1705 const float *
data = i.second.data<
float>();
1706 for (
size_t idx = 0; idx <
length; idx++) {
1709 if (
value != 0. && std::abs(
value) < std::numeric_limits<float>::min() )
value = 0;
1711 if (std::isinf(
value))
1712 f << (
value > 0 ?
"inf" :
"-inf");
1713 else if (std::isnan(
value))
1716 f << std::setprecision(std::numeric_limits<float>::max_digits10) <<
value;
1717 f << ( (idx <
length-1) ?
" " :
"\n" );
1721 throw std::runtime_error(
"tmva-sofie tensor " + tensor_name +
" with type " +
ConvertTypeToString(i.second.type()) +
" cannot be written to a file");
1724 throw std::runtime_error(
"tmva-sofie failed to write tensor data to file for " + tensor_name);
1735 std::cout <<
"Summary of model " <<
GetName() << std::endl;
1742 for (
auto &
t_in :
r.GetOpInputTensors()) std::cout <<
t_in <<
" ";
1743 std::cout <<
" ----> ";
1744 for (
auto &
t_out :
r.GetOpOutputTensors()) std::cout <<
t_out <<
" ";
1745 std::cout << std::endl;
1753 fGC +=
"\n// Input tensor dimensions\n";
1754 fGC +=
"using TMVA::Experimental::SOFIE::SingleDim;\n";
1755 fGC +=
"using TMVA::Experimental::SOFIE::TensorDims;\n";
1756 fGC +=
"using TMVA::Experimental::SOFIE::makeDims;\n\n";
1765 fGC +=
"constexpr std::array<SingleDim, " + std::to_string(shape.size()) +
"> dim_" +
name +
"{";
1766 for (std::size_t
iDim = 0;
iDim < shape.size(); ++
iDim) {
1767 auto const &dim = shape[
iDim];
1769 fGC +=
"SingleDim{\"" + dim.GetVal() +
"\"}";
1771 fGC +=
"SingleDim{" + dim.GetVal() +
"}";
1773 if (
iDim != shape.size() - 1) {
1779 fGC +=
"\nconstexpr std::array<TensorDims, " + std::to_string(
fInputTensorNames.size()) +
"> inputTensorDims{\n";
1782 fGC +=
SP +
"makeDims(dim_" +
name +
")";
1792 "\nconstexpr bool hasDynamicInputTensors{" + std::string{
hasDynamicInputTensors ?
"true" :
"false"} +
"};\n\n";
1794 fGC +=
"\n// Output tensor dimensions\n";
1802 fGC +=
"constexpr std::array<SingleDim, " + std::to_string(shape.size()) +
"> dim_" +
name +
"{";
1803 for (std::size_t
iDim = 0;
iDim < shape.size(); ++
iDim) {
1804 auto const &dim = shape[
iDim];
1806 fGC +=
"SingleDim{\"" + dim.GetVal() +
"\"}";
1808 fGC +=
"SingleDim{" + dim.GetVal() +
"}";
1810 if (
iDim != shape.size() - 1) {
1816 fGC +=
"\nconstexpr std::array<TensorDims, " + std::to_string(
fOutputTensorNames.size()) +
"> outputTensorDims{\n";
1819 fGC +=
SP +
"makeDims(dim_" +
name +
")";
1828 "\nconstexpr bool hasDynamicOutputTensors{" + std::string{
hasDynamicOutputTensors ?
"true" :
"false"} +
"};\n\n";
1832 std::cout <<
"Model requires following inputs:\n";
1834 std::cout <<
"Parametrised Tensor name: " <<
inputInfo.first <<
"\t";
1836 std::cout <<
"shape: [";
1837 for (
size_t i = 0; i <
inputInfo.second.shape.size(); i++) {
1838 if (
inputInfo.second.shape[i].isParam) {
1839 std::cout <<
inputInfo.second.shape[i].param;
1841 std::cout <<
inputInfo.second.shape[i].dim ;
1843 if (i <
inputInfo.second.shape.size() - 1) std::cout <<
",";
1845 std::cout <<
"]" << std::endl;
1849 std::cout <<
"Fully Specified Tensor name: " <<
inputInfo.first <<
"\t";
1851 std::cout <<
"shape: [";
1852 for (
size_t i = 0; i <
inputInfo.second.shape.size(); i++) {
1854 if (i <
inputInfo.second.shape.size() - 1) std::cout <<
",";
1856 std::cout <<
"]" << std::endl;
1862 std::cout <<
"Model initialized the following tensors:\n";
1864 std::cout <<
"Tensor name: \"" << it.first <<
"\"\t";
1866 std::cout <<
"shape: [";
1867 for (
size_t i = 0; i < it.second.shape().
size(); i++) {
1868 std::cout << it.second.shape()[i];
1869 if (i < it.second.shape().size() - 1) std::cout <<
",";
1872 if (it.second.IsConstantTensor()) std::cout <<
" (Constant)";
1873 if (it.second.IsNotWritable()) std::cout <<
" (Not Writable)";
1874 std::cout << std::endl;
1880 std::cout <<
"Model specify the following intermediate tensors:\n";
1882 std::cout <<
"Tensor name: \"" << it.first <<
"\"\t";
1884 std::cout <<
"shape: [";
1885 for (
size_t i = 0; i < it.second.shape.size(); i++) {
1886 std::cout << it.second.shape[i];
1887 if (i < it.second.shape.size() - 1) std::cout <<
",";
1889 std::cout <<
"]" << std::endl;
1895 std::cout <<
"Model specify the following dynamic tensors:\n";
1897 std::cout <<
"Tensor name: \"" << it.first <<
"\"\t";
1899 std::cout <<
"shape: [";
1900 for (
size_t i = 0; i < it.second.shape.size(); i++) {
1901 std::cout << it.second.shape[i].GetVal();
1902 if (i < it.second.shape.size() - 1) std::cout <<
",";
1904 std::cout <<
"]" << std::endl;
1910 std::cout <<
"Model specify the following output tensors:\n";
1912 std::cout <<
"Tensor name: \"" << it <<
"\"\t";
1917 std::cout <<
"with shape not yet defined" << std::endl;
1926 std::cout <<
"Tensor " <<
name <<
" not found in model's initialized tensor list" << std::endl;
1930 std::cout <<
"Tensor name: " << it->first <<
"\t";
1933 std::cout <<
"shape: [";
1934 for (
size_t i = 0; i < it->second.shape().
size(); i++) {
1935 std::cout << it->second.shape()[i];
1936 length *= it->second.shape()[i];
1937 if (
i < it->second.shape().size() - 1) std::cout <<
",";
1939 std::cout <<
"]" << std::endl;
1946 std::cout <<
"data: [" << std::endl;
1949 for (
int i =0; i <
n_print; i++) {
1951 if (i <
n_print - 1) std::cout <<
" ,";
1954 if (
ellipsis) std::cout <<
", ...";
1955 std::cout <<
"]" << std::endl;
1966 size_t pos =
filename.find(
".hxx");
1982 if (
R__b.IsReading()) {
1983 RModel::Class()->ReadBuffer(
R__b,
this);
1985 i.second.CastPersistentToShared();
1990 i.second.CastSharedToPersistent();
1992 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)
std::string fExtraCodeForDimShapes
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