1#ifndef TMVA_SOFIE_ROPERATOR_GEMM 
    2#define TMVA_SOFIE_ROPERATOR_GEMM 
   17namespace Experimental{
 
   54         static_assert(std::is_same_v<T, float>,
 
   55                  "TMVA::SOFIE - Unsupported type parsing a Gemm operator");
 
 
   77         if (
input.size() > 3) 
throw std::runtime_error(
"TMVA SOFIE Gemm Op Shape Inference only need 2 or 3 input tensor");
 
   82               throw std::runtime_error(
"TMVA SOFIE Gemm Op Shape Inference only accept input tensor with >=2 dimensions");
 
   86         std::vector<std::vector<U>> 
ret;
 
   88         if (
input.size() == 3){
 
  109            for (
size_t i = 0; i < 
input[0].size()-2; i++) {
 
  113                  if (
valueB.GetVal() == 
"1")
 
  115                  else if (
valueA.GetVal() == 
"1")
 
  118                     throw std::runtime_error(
"TMVA SOFIE Gemm Op - invalid input shapes " + 
valueA.GetVal() + 
" and " 
 
  144            throw std::runtime_error(
"TMVA SOFIE Gemm Op Input Tensor " + 
fNA + 
" or " + 
fNB + 
" is not found in model");
 
  148               throw std::runtime_error(
"TMVA SOFIE Gemm Op Input Tensor" + 
fNC + 
" is not found in model");
 
  191         std::vector<size_t> 
shapeY;
 
  203               throw std::runtime_error(
"TMVA SOFIE Gemm Op Input Tensor" + 
fNC + 
" is dynamic and is not supported");
 
  217                      throw std::runtime_error(
"TMVA SOFIE Gemm Op:  dynamic tensors not supported without a session");
 
  221                  if (
fType == 
"float") {
 
  222                     std::shared_ptr<void> 
new_data_ptr(UTILITY::UnidirectionalBroadcast<float>(
 
  224                        std::default_delete<
float[]>());
 
  262            std::cout << 
"Gemm (or MatMul) " << 
" ---> " << 
fNY << 
" shape ";
 
 
  273         std::stringstream out;
 
  281            out << 
"//--- broadcast bias tensor " << 
fNC << 
"for Gemm op\n";
 
  283            out << 
"      float * data = TMVA::Experimental::SOFIE::UTILITY::UnidirectionalBroadcast<float>(tensor_" 
  286            out << 
SP << 
SP << 
"std::copy(data, data + " << 
length << 
", tensor_" << 
fNC2 << 
");\n";
 
  287            out << 
SP << 
SP << 
"delete [] data;\n";
 
 
  297            throw std::runtime_error(
"TMVA SOFIE Gemm Op called to Generate without being initialized first");
 
  299         std::stringstream out;
 
  300         out << 
"\n//--------- Gemm\n";
 
  306             throw std::runtime_error(
"TMVA SOFIE Gemm(MatMul) has invalid shape for inputs or output");
 
  314         for (int64_t i = 0; i < 
dimY-2; i++) {
 
  327                     throw std::runtime_error(
"TMVA SOFIE Gemm Op " + 
opName + 
" Bias tensor has not correct size " 
  338               throw std::runtime_error(
"TMVA SOFIE Gemm Op " + 
opName + 
" Bias tensor is not present but beta value in Gemm is not zero");
 
  346            out << 
SP << 
"size_t " << 
opName << 
"_yoffset = 0;\n"; 
 
  347            out << 
SP << 
"for (int i = 0; i < " << 
lengthExtra << 
"; i++){\n";
 
  351         if (
fType == 
"float"){
 
  353            out << 
SP << 
"TMVA::Experimental::SOFIE::Gemm_Call(" 
  359             << 
n << 
", " << 
m << 
", " << k << 
", ";
 
  360            out << std::setprecision(std::numeric_limits<float>::max_digits10) << 
fAttrAlpha << 
",";
 
  361            out << 
"tensor_" << 
fNB << 
", " << 
"tensor_" << 
fNA << 
", ";
 
  362            out << std::setprecision(std::numeric_limits<float>::max_digits10) << 
fAttrBeta << 
",";
 
  365               out << 
"tensor_" << 
fNC2;
 
  372               out << 
SP << 
SP << 
"tensor_" << 
fNY << 
"[id] = ((tensor_" << 
fNY << 
"[id] > 0 )? tensor_" << 
fNY << 
"[id] : 0);\n";
 
 
  385      std::vector<std::string> 
GetBlasRoutines()
 override { 
return { std::string(
"Gemm"), std::string(
"Gemv") }; }
 
 
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.
 
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 Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h length
 
const_iterator begin() const
 
const_iterator end() const
 
void AddNeededStdLib(std::string libname)
 
bool IsDynamicTensor(const std::string &name) const
 
void AddIntermediateTensor(std::string tensor_name, ETensorType type, std::vector< Dim > dim_shape)
 
bool CheckIfTensorAlreadyExist(std::string tensor_name)
 
void AddDynamicTensor(std::string tensor_name, ETensorType type, std::vector< Dim > shape)
 
const ETensorType & GetTensorType(std::string name) const
 
bool IsDimInputTensor(const std::string &name) const
 
const std::vector< size_t > & GetTensorShape(std::string name) const
 
std::shared_ptr< void > GetInitializedTensorData(std::string tensor_name)
 
std::vector< Dim > GetDynamicTensorShape(std::string name) const
 
void UpdateInitializedTensor(std::string tensor_name, ETensorType type, std::vector< std::size_t > shape, std::shared_ptr< void > data)
 
ROperator_Gemm(float alpha, float beta, int_t transA, int_t transB, std::string nameA, std::string nameB, std::string nameC, std::string nameY, EActivationType activation=EActivationType::UNDEFINED)
 
std::vector< std::vector< U > > DoShapeInference(const std::vector< std::vector< U > > &input)
 
std::vector< Dim > fShapeY
 
std::vector< ETensorType > TypeInference(std::vector< ETensorType > input) override
 
ROperator_Gemm(float alpha, float beta, int_t transA, int_t transB, std::string nameA, std::string nameB, std::string nameY, EActivationType activation=EActivationType::UNDEFINED)
 
std::vector< std::vector< size_t > > ShapeInference(std::vector< std::vector< size_t > > input) override
 
std::vector< Dim > fShapeA
 
std::vector< Dim > fShapeB
 
std::vector< size_t > fShapeC
 
std::string Generate(std::string opName) override
 
void Initialize(RModel &model) override
 
std::vector< std::vector< Dim > > DynamicShapeInference(const std::vector< std::vector< Dim > > &input)
 
EActivationType fActivation
 
std::vector< std::string > GetBlasRoutines() override
 
std::string GenerateInitCode() override
 
std::vector< std::string_view > fInputTensorNames
 
const std::string SP
space used to correctly indent the generated C++ code
 
std::vector< std::string_view > fOutputTensorNames
 
std::vector< size_t > UnidirectionalBroadcastShape(std::vector< size_t >, std::vector< size_t >)
 
std::vector< Dim > ConvertShapeToDim(std::vector< size_t > shape)
Convert shape from integer format to dynamic one (based on Dim)
 
std::string ConvertDynamicShapeToLength(std::vector< Dim > shape)
 
std::string ConvertShapeToString(std::vector< size_t > shape)
 
std::string ConvertDynamicShapeToString(std::vector< Dim > shape)
 
std::vector< size_t > ConvertShapeToInt(std::vector< Dim > shape)
Convert shape based on Dim to integer format.
 
std::size_t ConvertShapeToLength(std::vector< size_t > shape)
 
create variable transformations