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");
236 throw std::runtime_error(
"TMVA-SOFIE: constant tensor with name " + tensor_name +
" already exists \n");
245 throw std::runtime_error(
"TMVA-SOFIE: shape tensor with name " + tensor_name +
" already exists \n");
255 throw std::runtime_error(
"TMVA-SOFIE: alias tensor with name " + tensor_name +
" already exists \n");
282 return itr->second.IsConstantTensor();
312 throw std::runtime_error(
"TMVA-SOFIE: intermediate tensor with name " + tensor_name +
" already exists \n");
321 throw std::runtime_error(
"TMVA-SOFIE: intermediate tensor with name " + tensor_name +
" already exists \n");
326 for (
auto &
d : shape) {
328 if (
d.dim !=
size_t(-1)) {
360 throw std::runtime_error(
"TMVA-SOFIE: tensor " + tensor_name +
" not found when trying to update it");
369 throw std::runtime_error(
"TMVA-SOFIE: tensor " + tensor_name +
" not found when trying to get its data");
371 return f->second.sharedptr();
378 throw std::runtime_error(
"TMVA-SOFIE: initialized tensor " + tensor_name +
" not found when trying to get its info");
380 t->second.SetNotWritable();
385 std::stringstream code;
388 std::cout <<
"Total chunks allocated\n";
390 std::cout <<
"..... chunk " <<
chunk->first <<
" size " <<
chunk->second.tensor_size <<
" " <<
chunk->second.tensor_name << std::endl;
396 code <<
"\n // Allocating memory for intermediate tensor " <<
name <<
" with size " <<
size <<
" bytes";
398 << typeName <<
"* " <<
TensorMember(
name) <<
" = reinterpret_cast<" << typeName
399 <<
"*>(fIntermediateMemoryPool.data() + " << location <<
");\n";
402 if (
fVerbose) std::cout <<
"*** AllocateIntermediateMemory: Loop on op output tensors\n";
407 auto name = std::string(it);
427 std::string
name = std::string{it.tensor_name};
428 size_t tensor_size = it.tensor_size;
430 std::cout <<
"output tensor " <<
name <<
" size " << tensor_size << std::endl;
435 if (
fVerbose) std::cout <<
".. available chunk " <<
chunk->first <<
" with size = " <<
chunk->second;
437 if (
chunk->second >= tensor_size) {
445 chunk->second -= tensor_size;
451 if (
chunk->second == 0) {
452 if (
fVerbose) std::cout <<
" and deleted since size matches";
455 if (
fVerbose) std::cout << std::endl;
464 if (
fVerbose) std::cout <<
" is extended with a bigger one of size " << tensor_size << std::endl;
468 if (
fVerbose) std::cout << std::endl;
481 if (
fVerbose) std::cout <<
"no chunk available - add in total stack a new chunk with size of tensor and idx : " <<
chunk_idx
489 if (
fVerbose) std::cout <<
"*** CheckAndFlushIntermediateMemory: Loop on input tensors for op " <<
op_idx <<
"\n";
491 if (
fVerbose) std::cout <<
"available chunks before freeing them : \n";
494 if (
fVerbose) std::cout <<
"-- free chunk " <<
chunk->first <<
" size = " <<
chunk->second << std::endl;
498 if (
fVerbose) std::cout <<
".. input tensors : " <<
iv;
505 if (
fVerbose) std::cout <<
" flash condition is met - looping on chunks to find matching one \n";
508 if (
fVerbose) std::cout <<
"--- chunk " <<
chunk->first <<
" , " <<
chunk->second.tensor_name <<
" size " <<
chunk->second.tensor_size;
509 if (
chunk->second.tensor_name == it) {
510 if (
fVerbose) std::cout <<
" -- Found chunk corresponding to input tensor: " <<
chunk->first;
525 if (
fVerbose) std::cout <<
" is adjacent in memory with previous one - merge ";
535 if (
fVerbose) std::cout <<
" merge also with following that is free ";
538 if (
fVerbose) std::cout << std::endl;
543 if (
fVerbose) std::cout <<
" is adjacent in memory with following one - merge \n";
555 if (
fVerbose) std::cout <<
" insert in the available stack the chunk with size " <<
chunk->second.tensor_size << std::endl;
557 chunk->second.tensor_name =
"free";
562 if (
fVerbose) std::cout << std::endl;
583 std::cout <<
"Model is already initialized - skip initialization " << std::endl;
595 if (verbose) std::cout <<
"looking at the tensor " <<
input.first << std::endl;
598 for (
auto &
d :
input.second.shape) {
600 std::string
pname =
d.param;
606 std::cout <<
"Tensor: " <<
input.first <<
" - fix parametric shape " <<
itr->first <<
" to " <<
itr->second << std::endl;
616 if (!shape.empty()) {
628 for (
auto &
d :
input.second.shape) {
654 std::cout <<
"Initializing operator " << i <<
" " <<
typeid(
r).
name() << std::endl;
658 std::string
name = std::string{it};
670 std::string
name = std::string{it};
686 it.second.SetWritable();
688 std::cout <<
"Initialized tensor " << it.first <<
" is flagged as not writable but is used by non constant operators, set it as writable \n";
694 it.second.SetConstant();
702 if (it.second.IsWeightTensor()) {
729 graph->fParentGraph =
this;
730 graph->fIsSubGraph =
true;
739 for (
auto &
e : graph->fNeededBlasRoutines)
742 for (
auto e : graph->fNeededStdLib)
747 graph->fInputTensorNames.emplace_back(
name);
759 std::stringstream
strs;
766 const T *
data = t.second.data<T>();
783 strs <<
"std::vector<" <<
type <<
"> fTensor_" << t.first <<
" = ";
797 fGC +=
"// initialized (weights and constant) tensors\n";
801 if (i.second.IsNotWritable())
continue;
807 const float *
data = i.second.data<
float>();
808 for (
size_t idx = 0; idx <
length; idx++) {
809 if (std::is_floating_point<float>::value) {
810 if (std::isinf(
data[idx]) || std::isnan(
data[idx])) {
835 fGC +=
"std::vector<float> fTensor_" + i.first +
" = std::vector<float>(" + std::to_string(
length) +
");\n";
836 fGC +=
"float * " +
TensorMember(i.first) +
" = fTensor_" + i.first +
".data();\n";
845 fGC +=
"\n//--- Allocating session memory pool to be used for allocating intermediate tensors\n";
851 fGC +=
"std::vector<char> fIntermediateMemoryPool = std::vector<char>(" + std::to_string(
memPoolSize) +
");\n\n";
901 fGC +=
"//--- declare the dynamic tensors\n";
905 fGC +=
"//--- dynamic tensors pool\n";
906 fGC +=
"std::vector<char> fDynamicMemoryPool;\n";
917 fGC +=
"\n//---- operator declarations \n";
929 std::cout <<
"generating code for dynamic tensor management" << std::endl;
933 std::stringstream out;
934 out <<
"// dynamic tensor memory management\n";
935 out <<
SP <<
"std::vector<TMVA::Experimental::SOFIE::TensorLifeInfo> dynamicTensorInfos;\n";
940 std::vector<std::pair<std::string, ETensorType>>
tensors;
944 for (
auto &it :
op->GetOpOutputTensors()) {
947 std::cout <<
"Looping on operator " <<
op_index <<
" " <<
typeid(*op_ptr).name() << std::endl;
950 std::string
name = std::string(it);
966 std::cout <<
"op " <<
op_index <<
"tensor_" <<
name <<
" begin " << begin <<
" " <<
" end " << end << std::endl;
967 throw std::runtime_error(
"TMVA-SOFIE: RModel::GenerateDynamicTensorInfo: tensor_" +
name +
" has end before begin");
971 out <<
SP <<
"dynamicTensorInfos.push_back( {" << begin <<
", " << end <<
", " <<
type_size <<
"* (" << tensor_size <<
") });"
972 <<
" // tensor_" <<
name << std::endl;
978 out <<
"\n" <<
SP <<
"auto memory_result = OrganizeMemory(dynamicTensorInfos);\n\n";
979 out <<
"// allocating now the memory\n";
980 out <<
SP <<
"fDynamicMemoryPool = std::vector<char>(memory_result.total_bytes);\n";
981 out <<
SP <<
"int idx = 0;\n";
983 out <<
SP <<
"tensor_" << it.first <<
" = reinterpret_cast<" <<
ConvertTypeToString(it.second) <<
" *>(fDynamicMemoryPool.data() + memory_result.offsets[idx++]);\n";
991 std::cout <<
"Dynamic tensors " << i.first <<
" is not in list of operator input/output " << std::endl;
996 throw std::runtime_error(
"TMVA-SOFIE: RModel::GenerateDynamicTensorInfo - some tensors are not in input/output list");
1007 for (
auto &
d : shape) {
1022 const std::string
target =
"tensor_";
1024 std::vector<std::string>
result;
1026 for (
size_t i = 0; i <
input.size();) {
1035 std::size_t
j = i +
target.size();
1088 for (
auto &
d : shape) {
1089 std::string
pName =
d.param;
1093 rGC +=
d.param +
",";
1100 if (
type ==
"other")
1101 throw std::runtime_error(
"TMVA-SOFIE: input tensor " +
name +
1102 " is of a data type which is not yet supported.");
1105 rGC +=
"tensor_" +
name +
",";
1124 if (!
name.empty()) {
1125 name[0] = std::toupper(
static_cast<unsigned char>(
name[0]));
1142 if (outputSize == 1) {
1154 for (
size_t i = 0; i < outputSize; i++) {
1156 if (i < outputSize - 1)
1193 fGC +=
SP +
"size_t " + dim.param +
" = 0;\n";
1208 for (
auto &
d : shape) {
1209 std::string
pName =
d.param;
1215 fGC +=
SP +
SP +
"throw std::runtime_error(\"TMVA-SOFIE: dynamic input tensor shape parameter " +
1216 d.param +
" exceeds the initialized maximum allowed shape.\");\n";
1239 fGC +=
SP +
"return {";
1300 std::cout <<
"\n******************\n analyzing input/output operator " <<
op_idx <<
" "
1301 <<
typeid(*op).name() << std::endl;
1326 fGC +=
"\n// dynamic shape parameters\n";
1337 fGC +=
"Session_" + graph->fName +
" fSession_" + graph->fName +
";\n";
1344 for (
size_t id = 0;
id <
fOperators.size();
id++) {
1345 std::string
opName = std::to_string(
id);
1351 std::string fileName =
fName;
1356 fileName +=
".root";
1358 fGC +=
sessionName +
"(std::string filename =\"" + fileName +
"\"";
1387 fGC +=
"\n//--- reading weights from file\n";
1397 for (
size_t id = 0;
id <
fOperators.size();
id++) {
1409 fGC +=
"}; // end of Session\n\n";
1419 std::cout <<
"Generating main inference code for " <<
fName << std::endl;
1422 throw std::runtime_error(
"TMVA-SOFIE: output size=0 are not supported");
1428 std::cout <<
"Generating code for operator .... " <<
op_idx << std::endl;
1441 fGC +=
" auto &" +
name +
" = session." +
name +
";\n";
1453 fGC +=
" " + dim.param +
"_output = " + dim.param +
";\n";
1457 std::string t =
"session.tensor_" +
name;
1459 fGC +=
" std::copy(" + t +
", " + t +
" + " + std::to_string(
length) +
", tensor_" +
name +
");\n";
1467void RModel::Generate(std::underlying_type_t<Options> options,
int batchSize,
long pos,
bool verbose)
1487 throw std::runtime_error(
1488 "TMVA-SOFIE: RModel::Generate: cannot use a separate weight file without generating a Session class");
1491 if (
static_cast<std::underlying_type_t<Options>
>(
Options::kGNN) & options)
1503 std::cout <<
"Warning: Force having a Session since model has dynamic tensors " << std::endl;
1515 std::cout <<
"generate session code for subgraph " << graph->fName << std::endl;
1516 graph->GenerateSessionCode();
1521 std::cout <<
"generate Main session code - model " <<
fName << std::endl;
1527 fGC += (
"} //TMVA_SOFIE_" +
fName +
"\n");
1539 fGC +=
" std::ifstream f;\n";
1540 fGC +=
" f.open(filename);\n";
1541 fGC +=
" if (!f.is_open()) {\n";
1542 fGC +=
" throw std::runtime_error(\"tmva-sofie failed to open file \" + filename + \" for input weights\");\n";
1546 fGC +=
" f.seekg(" + std::to_string(pos) +
");\n";
1549 fGC +=
" using TMVA::Experimental::SOFIE::ReadTensorFromStream;\n";
1554 if (!i.second.IsWeightTensor())
continue;
1555 std::string tensor_name =
"tensor_" + i.first;
1558 fGC +=
" ReadTensorFromStream(f, " + tensor_name +
", \"" + tensor_name +
"\", " +
length +
");\n";
1560 throw std::runtime_error(
"tmva-sofie tensor " + tensor_name +
" with type " +
ConvertTypeToString(i.second.type()) +
" cannot be read from a file");
1563 fGC +=
" f.close();\n";
1568#ifdef SOFIE_SUPPORT_ROOT_BINARY
1570 fGC +=
" std::unique_ptr<TFile> rootFile(TFile::Open(filename.c_str(), \"READ\"));\n";
1571 fGC +=
" if (!rootFile->IsOpen()) {\n";
1572 fGC +=
" throw std::runtime_error(\"tmva-sofie failed to open ROOT file for input weights\");\n";
1576 fGC +=
" if (!rootFile->GetKey(\"" +
dirName +
"\")) {\n";
1577 fGC +=
" throw std::runtime_error(\"tmva-sofie failed to open ROOT directory for input weights\");\n";
1582 if (!i.second.IsWeightTensor())
continue;
1584 std::string tensor_name =
"tensor_" + i.first;
1586 fGC +=
" fTensor_" + i.first +
" = *reinterpret_cast<std::vector<float>*>(rootFile->Get(\"";
1587 fGC +=
dirName +
"/" + tensor_name +
"\"));\n";
1589 fGC +=
" fTensor_" + i.first +
" = *reinterpret_cast<std::vector<double>*>(rootFile->Get(\"";
1590 fGC +=
dirName + +
"/" + tensor_name +
"\"));\n";
1592 fGC +=
" fTensor_" + i.first +
" = *reinterpret_cast<std::vector<int64_t>*>(rootFile->Get(\"";
1593 fGC +=
dirName +
"/" + tensor_name +
"\"));\n";
1595 throw std::runtime_error(
"tmva-sofie tensor " + tensor_name +
" with type " +
ConvertTypeToString(i.second.type()) +
" cannot be read from a ROOT file");
1601 throw std::runtime_error(
"SOFIE was not built with ROOT file support.");
1628#ifdef SOFIE_SUPPORT_ROOT_BINARY
1630 throw std::runtime_error(
"SOFIE-GNN yet not supports writing to a ROOT file.");
1643 if (!
item.second.IsWeightTensor())
continue;
1648 const float*
data =
item.second.data<
float>();
1653 const double*
data =
item.second.data<
double>();
1658 const int64_t*
data =
item.second.data<int64_t>();
1664 " cannot be written to a ROOT file");
1673 throw std::runtime_error(
"SOFIE was not built with ROOT file support.");
1685 std::runtime_error(
"tmva-sofie failed to open file " +
filename +
" for tensor weight data");
1688 if (!i.second.IsWeightTensor()) {
1692 std::string tensor_name =
"tensor_" + i.first;
1693 f << tensor_name <<
" " <<
length <<
"\n";
1695 const float *
data = i.second.data<
float>();
1696 for (
size_t idx = 0; idx <
length; idx++) {
1699 if (
value != 0. && std::abs(
value) < std::numeric_limits<float>::min() )
value = 0;
1701 if (std::isinf(
value))
1702 f << (
value > 0 ?
"inf" :
"-inf");
1703 else if (std::isnan(
value))
1706 f << std::setprecision(std::numeric_limits<float>::max_digits10) <<
value;
1707 f << ( (idx <
length-1) ?
" " :
"\n" );
1711 throw std::runtime_error(
"tmva-sofie tensor " + tensor_name +
" with type " +
ConvertTypeToString(i.second.type()) +
" cannot be written to a file");
1714 throw std::runtime_error(
"tmva-sofie failed to write tensor data to file for " + tensor_name);
1725 std::cout <<
"Summary of model " <<
GetName() << std::endl;
1732 for (
auto &
t_in :
r.GetOpInputTensors()) std::cout <<
t_in <<
" ";
1733 std::cout <<
" ----> ";
1734 for (
auto &
t_out :
r.GetOpOutputTensors()) std::cout <<
t_out <<
" ";
1735 std::cout << std::endl;
1743 fGC +=
"\n// Input tensor dimensions\n";
1744 fGC +=
"using TMVA::Experimental::SOFIE::SingleDim;\n";
1745 fGC +=
"using TMVA::Experimental::SOFIE::TensorDims;\n";
1746 fGC +=
"using TMVA::Experimental::SOFIE::makeDims;\n\n";
1755 fGC +=
"constexpr std::array<SingleDim, " + std::to_string(shape.size()) +
"> dim_" +
name +
"{";
1756 for (std::size_t
iDim = 0;
iDim < shape.size(); ++
iDim) {
1757 auto const &dim = shape[
iDim];
1759 fGC +=
"SingleDim{\"" + dim.GetVal() +
"\"}";
1761 fGC +=
"SingleDim{" + dim.GetVal() +
"}";
1763 if (
iDim != shape.size() - 1) {
1769 fGC +=
"\nconstexpr std::array<TensorDims, " + std::to_string(
fInputTensorNames.size()) +
"> inputTensorDims{\n";
1772 fGC +=
SP +
"makeDims(dim_" +
name +
")";
1782 "\nconstexpr bool hasDynamicInputTensors{" + std::string{
hasDynamicInputTensors ?
"true" :
"false"} +
"};\n\n";
1784 fGC +=
"\n// Output tensor dimensions\n";
1792 fGC +=
"constexpr std::array<SingleDim, " + std::to_string(shape.size()) +
"> dim_" +
name +
"{";
1793 for (std::size_t
iDim = 0;
iDim < shape.size(); ++
iDim) {
1794 auto const &dim = shape[
iDim];
1796 fGC +=
"SingleDim{\"" + dim.GetVal() +
"\"}";
1798 fGC +=
"SingleDim{" + dim.GetVal() +
"}";
1800 if (
iDim != shape.size() - 1) {
1806 fGC +=
"\nconstexpr std::array<TensorDims, " + std::to_string(
fOutputTensorNames.size()) +
"> outputTensorDims{\n";
1809 fGC +=
SP +
"makeDims(dim_" +
name +
")";
1818 "\nconstexpr bool hasDynamicOutputTensors{" + std::string{
hasDynamicOutputTensors ?
"true" :
"false"} +
"};\n\n";
1822 std::cout <<
"Model requires following inputs:\n";
1824 std::cout <<
"Parametrised Tensor name: " <<
inputInfo.first <<
"\t";
1826 std::cout <<
"shape: [";
1827 for (
size_t i = 0; i <
inputInfo.second.shape.size(); i++) {
1828 if (
inputInfo.second.shape[i].isParam) {
1829 std::cout <<
inputInfo.second.shape[i].param;
1831 std::cout <<
inputInfo.second.shape[i].dim ;
1833 if (i <
inputInfo.second.shape.size() - 1) std::cout <<
",";
1835 std::cout <<
"]" << std::endl;
1839 std::cout <<
"Fully Specified Tensor name: " <<
inputInfo.first <<
"\t";
1841 std::cout <<
"shape: [";
1842 for (
size_t i = 0; i <
inputInfo.second.shape.size(); i++) {
1844 if (i <
inputInfo.second.shape.size() - 1) std::cout <<
",";
1846 std::cout <<
"]" << std::endl;
1852 std::cout <<
"Model initialized the following tensors:\n";
1854 std::cout <<
"Tensor name: \"" << it.first <<
"\"\t";
1856 std::cout <<
"shape: [";
1857 for (
size_t i = 0; i < it.second.shape().
size(); i++) {
1858 std::cout << it.second.shape()[i];
1859 if (i < it.second.shape().size() - 1) std::cout <<
",";
1862 if (it.second.IsConstantTensor()) std::cout <<
" (Constant)";
1863 if (it.second.IsNotWritable()) std::cout <<
" (Not Writable)";
1864 std::cout << std::endl;
1870 std::cout <<
"Model specify the following intermediate tensors:\n";
1872 std::cout <<
"Tensor name: \"" << it.first <<
"\"\t";
1874 std::cout <<
"shape: [";
1875 for (
size_t i = 0; i < it.second.shape.size(); i++) {
1876 std::cout << it.second.shape[i];
1877 if (i < it.second.shape.size() - 1) std::cout <<
",";
1879 std::cout <<
"]" << std::endl;
1885 std::cout <<
"Model specify the following dynamic tensors:\n";
1887 std::cout <<
"Tensor name: \"" << it.first <<
"\"\t";
1889 std::cout <<
"shape: [";
1890 for (
size_t i = 0; i < it.second.shape.size(); i++) {
1891 std::cout << it.second.shape[i].GetVal();
1892 if (i < it.second.shape.size() - 1) std::cout <<
",";
1894 std::cout <<
"]" << std::endl;
1900 std::cout <<
"Model specify the following output tensors:\n";
1902 std::cout <<
"Tensor name: \"" << it <<
"\"\t";
1907 std::cout <<
"with shape not yet defined" << std::endl;
1916 std::cout <<
"Tensor " <<
name <<
" not found in model's initialized tensor list" << std::endl;
1920 std::cout <<
"Tensor name: " << it->first <<
"\t";
1923 std::cout <<
"shape: [";
1924 for (
size_t i = 0; i < it->second.shape().
size(); i++) {
1925 std::cout << it->second.shape()[i];
1926 length *= it->second.shape()[i];
1927 if (
i < it->second.shape().size() - 1) std::cout <<
",";
1929 std::cout <<
"]" << std::endl;
1936 std::cout <<
"data: [" << std::endl;
1939 for (
int i =0; i <
n_print; i++) {
1941 if (i <
n_print - 1) std::cout <<
" ,";
1944 if (
ellipsis) std::cout <<
", ...";
1945 std::cout <<
"]" << std::endl;
1956 size_t pos =
filename.find(
".hxx");
1972 if (
R__b.IsReading()) {
1973 RModel::Class()->ReadBuffer(
R__b,
this);
1975 i.second.CastPersistentToShared();
1980 i.second.CastSharedToPersistent();
1982 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