Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RModel_Base.hxx
Go to the documentation of this file.
1#ifndef TMVA_SOFIE_RMODEL_BASE
2#define TMVA_SOFIE_RMODEL_BASE
3
4#include <ctime>
5#include <fstream>
6#include <iomanip>
7#include <iostream>
8#include <memory>
9#include <set>
10#include <sstream>
11#include <type_traits>
12#include <unordered_map>
13#include <unordered_set>
14#include <vector>
15
17
18enum class Options {
19 kDefault = 0x0,
20 kNoSession = 0x1,
21 kNoWeightFile = 0x2,
23};
24
25// Optimization levels inspired by ONNXRuntime.
26// We only get Operator Fusion with the Basic, and
27// memory reuse with Extended. kExtended is enabled
28// by default
30 kBasic = 0x0,
31 kExtended = 0x1,
32};
33
35
36std::underlying_type_t<Options> operator|(Options opA, Options opB);
37std::underlying_type_t<Options> operator|(std::underlying_type_t<Options> opA, Options opB);
38
40
41protected:
42 std::string fFileName; // file name of original model file for identification
43 std::string fParseTime; // UTC date and time string at parsing
44
46
47 std::unordered_set<std::string> fNeededBlasRoutines;
48 // Set to true once GenerateHeaderInfo has emitted the extern "C" declaration
49 // of the BLAS sgemm_ routine (from fNeededBlasRoutines). It lets the
50 // standalone Gemm_Call helper skip emitting a second, duplicate declaration.
51 bool fBlasSgemmDeclared = false; //!
52
53 std::unordered_set<std::string> fNeededStdLib = {"vector"};
54 std::unordered_set<std::string> fCustomOpHeaders;
55
56 // Inference helper functions (from SOFIE_common) that the generated code
57 // needs. Their standalone definitions are emitted into the generated header
58 // so that it does not depend on including TMVA/SOFIE_common.hxx.
59 std::set<std::string> fNeededHelperFunctions;
60
61 std::string fName = "UnnamedModel";
62 std::string fGC; // generated code
63 bool fUseWeightFile = true;
64 bool fUseSession = true;
65
66public:
67 /**
68 Default constructor. Needed to allow serialization of ROOT objects. See
69 https://root.cern/manual/io_custom_classes/#restrictions-on-types-root-io-can-handle
70 */
71 RModel_Base() = default;
72
73 RModel_Base(std::string name, std::string parsedtime);
74
75 void AddBlasRoutines(std::vector<std::string> routines)
76 {
77 for (auto &routine : routines) {
79 }
80 }
81 void AddNeededStdLib(std::string libname)
82 {
83 // if the library is already in the set, insert does nothing, so we don't need to check before inserting
84 fNeededStdLib.insert(libname);
85 }
87 {
89 }
90 // Register an inference helper function that the generated code needs. See
91 // GenerateHelperFunctionsCode for the list of recognised keys.
92 void AddNeededHelperFunction(std::string name)
93 {
94 fNeededHelperFunctions.insert(std::move(name));
95 }
96 const std::set<std::string> &GetNeededHelperFunctions() const { return fNeededHelperFunctions; }
97
98 // Placeholder tokens emitted by GenerateHeaderInfo and later replaced by
99 // EmitHelperFunctionsCode with the actual helper includes / definitions.
100 // This two-step approach is needed because the full set of required helpers
101 // is only known once all operators (and sub-graphs) have been generated.
102 static constexpr const char *kHelperIncludesMarker = "//@SOFIE_HELPER_INCLUDES@\n";
103 static constexpr const char *kHelperFunctionsMarker = "//@SOFIE_HELPER_FUNCTIONS@\n";
104
105 void GenerateHeaderInfo(std::string &hgname);
106 // Replace the helper markers in the generated code with the standalone
107 // definitions of the helper functions collected in fNeededHelperFunctions.
109 void PrintGenerated(std::ostream &os=std::cout) { os << fGC; }
110
111 std::string ReturnGenerated() { return fGC; }
112 void OutputGenerated(std::string filename = "", bool append = false);
113 void SetFilename(std::string filename) { fName = filename; }
114 std::string GetFilename() { return fName; }
115 const std::string & GetName() const { return fName;}
116};
117
118} // namespace TMVA::Experimental::SOFIE
119
120#endif // TMVA_SOFIE_RMODEL_BASE
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void 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
char name[80]
Definition TGX11.cxx:142
void GenerateHeaderInfo(std::string &hgname)
RModel_Base()=default
Default constructor.
static constexpr const char * kHelperIncludesMarker
void PrintGenerated(std::ostream &os=std::cout)
std::set< std::string > fNeededHelperFunctions
std::unordered_set< std::string > fNeededBlasRoutines
static constexpr const char * kHelperFunctionsMarker
const std::set< std::string > & GetNeededHelperFunctions() const
void AddNeededHelperFunction(std::string name)
std::unordered_set< std::string > fCustomOpHeaders
void OutputGenerated(std::string filename="", bool append=false)
std::unordered_set< std::string > fNeededStdLib
const std::string & GetName() const
void AddBlasRoutines(std::vector< std::string > routines)
void AddNeededStdLib(std::string libname)
void AddNeededCustomHeader(std::string filename)
void SetFilename(std::string filename)
std::underlying_type_t< Options > operator|(Options opA, Options opB)
Definition RModel.cxx:66