1#ifndef TMVA_SOFIE_ROPERATOR_TRANSPOSE
2#define TMVA_SOFIE_ROPERATOR_TRANSPOSE
12namespace Experimental{
44 if (
input.size() > 1)
throw std::runtime_error(
"TMVA SOFIE Tranpose Op Shape Inference only need 1 input tensor");
47 throw std::runtime_error(
"TMVA SOFIE Tranpose Op - Invalid axes attributes");
50 for (
size_t i = 0; i <
fAttrPerm.size(); i++){
53 std::vector<std::vector<size_t>>
ret;
73 for (
size_t i = 0; i <
length; i++) {
75 for (
size_t j = 1;
j < dim;
j++) {
80 for (
size_t j = 0;
j < dim;
j++) {
96 std::cout<<
"Input tensor for transpose: "<<
fNX<<
'\n';
97 throw std::runtime_error(
"TMVA SOFIE Tranpose Op Input Tensor is not found in model");
102 for (
int i =
fShapeX.size() - 1; i >= 0; i--){
109 throw std::runtime_error(
"TMVA SOFIE Tranpose Op - Invalid axes attributes");
112 for (
size_t i = 0; i <
fAttrPerm.size(); i++){
132 std::cout <<
"Transpose - no support for initialized tensor of type " <<
ConvertTypeToString(
type) << std::endl;
147 throw std::runtime_error(
"TMVA SOFIE Transpose Op called to Generate without being initialized first");
158 std::stringstream out;
169 out <<
SP <<
SP <<
"// Pre-baked input strides (row-major)\n";
171 for (
size_t i = 0; i <
rank; ++i)
175 out <<
SP <<
SP <<
"// Pre-baked output strides (row-major)\n";
177 for (
size_t i = 0; i <
rank; ++i)
190 <<
"// Fast path: last permuted axis is contiguous in source\n";
192 <<
"// Inner " <<
innerSize <<
" elements copied with pointer arithmetic\n";
198 out <<
SP <<
SP <<
SP <<
"size_t src_off = ";
200 out <<
"idx_" << i <<
" * " <<
opName <<
"_strX["
206 out <<
SP <<
SP <<
SP <<
"size_t dst_off = ";
208 out <<
"idx_" << i <<
" * " <<
opName <<
"_strY[" << i <<
"]";
215 <<
"std::copy(tensor_" <<
fNX <<
" + src_off, "
216 <<
"tensor_" <<
fNX <<
" + src_off + " <<
innerSize <<
", "
217 <<
"tensor_" <<
fNY <<
" + dst_off);\n";
224 out <<
SP <<
SP <<
"// General N-D transpose\n";
229 out <<
SP <<
SP <<
SP <<
"size_t src_idx = ";
230 for (
size_t i = 0; i <
rank; ++i) {
231 out <<
"idx_" << i <<
" * " <<
opName <<
"_strX[" <<
fAttrPerm[i] <<
"]";
232 if (i + 1 <
rank) out <<
" + ";
237 out <<
SP <<
SP <<
SP <<
"size_t dst_idx = ";
238 for (
size_t i = 0; i <
rank; ++i) {
239 out <<
"idx_" << i <<
" * " <<
opName <<
"_strY[" << i <<
"]";
240 if (i + 1 <
rank) out <<
" + ";
245 <<
"tensor_" <<
fNY <<
"[dst_idx] = "
246 <<
"tensor_" <<
fNX <<
"[src_idx];\n";
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 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 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 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
std::vector< Dim > GetDimTensorShape(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 AddConstantTensor(std::string tensor_name, ETensorType type, std::vector< std::size_t > shape, std::shared_ptr< void > data)
bool IsInitializedTensor(const std::string &name) const
std::shared_ptr< void > GetInitializedTensorData(std::string tensor_name)
ETensorType GetTensorType(std::string name) const
std::vector< ETensorType > TypeInference(std::vector< ETensorType > input) override
std::string Generate(std::string opName) override
void Initialize(RModel &model) override
std::vector< Dim > fShapeX
void ProcessInitializedTensor(RModel &model)
ROperator_Transpose(std::vector< int64_t > attr_perm, std::string nameData, std::string nameOutput)
std::vector< std::vector< size_t > > ShapeInference(std::vector< std::vector< size_t > > input) override
std::vector< Dim > fShapeY
std::vector< int64_t > fAttrPerm
std::vector< std::string_view > fInputTensorNames
bool fIsOutputConstant
flag to identify if operator has a constant output (no need to generate code)
const std::string SP
space used to correctly indent the generated C++ code
std::vector< std::string_view > fOutputTensorNames
std::vector< size_t > ComputeStrideFromShape(const std::vector< size_t > &shape)
compute stride of a tensor given its shape (assume layout is row-major)
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< size_t > ConvertShapeToInt(const std::vector< Dim > &shape)
Convert shape based on Dim to integer format.
std::string ConvertTypeToString(ETensorType type)
void EmitNestedLoops(std::stringstream &out, size_t loopRank, const std::vector< Dim > shape)
std::string ConvertShapeToString(const std::vector< size_t > &shape)
void CloseNestedLoops(std::stringstream &out, size_t loopRank)
create variable transformations