1#ifndef TMVA_SOFIE_ROPERATOR_TRANSPOSE
2#define TMVA_SOFIE_ROPERATOR_TRANSPOSE
12namespace Experimental{
50 auto inputData =
static_cast<T *
>(model.GetInitializedTensorData(
fNX).get());
54 for (
size_t i = 0; i <
length; i++) {
56 for (
size_t j = 1;
j < dim;
j++) {
61 for (
size_t j = 0;
j < dim;
j++) {
69 if (model.Verbose()) {
76 if (model.CheckIfTensorAlreadyExist(
fNX) ==
false){
77 std::cout<<
"Input tensor for transpose: "<<
fNX<<
'\n';
78 throw std::runtime_error(
"TMVA SOFIE Tranpose Op Input Tensor is not found in model");
83 for (
int i =
fShapeX.size() - 1; i >= 0; i--){
90 throw std::runtime_error(
"TMVA SOFIE Tranpose Op - Invalid axes attributes");
93 for (
size_t i = 0; i <
fAttrPerm.size(); i++){
97 if (model.IsInitializedTensor(
fNX) ) {
98 auto type = model.GetTensorType(
fNX);
113 std::cout <<
"Transpose - no support for initialized tensor of type " <<
ConvertTypeToString(
type) << std::endl;
118 model.AddIntermediateTensor(
fNY, model.GetTensorType(
fNX),
fShapeY);
119 if (model.Verbose()) {
128 throw std::runtime_error(
"TMVA SOFIE Transpose Op called to Generate without being initialized first");
139 std::stringstream out;
150 out <<
SP <<
SP <<
"// Pre-baked input strides (row-major)\n";
152 for (
size_t i = 0; i <
rank; ++i)
156 out <<
SP <<
SP <<
"// Pre-baked output strides (row-major)\n";
158 for (
size_t i = 0; i <
rank; ++i)
171 <<
"// Fast path: last permuted axis is contiguous in source\n";
173 <<
"// Inner " <<
innerSize <<
" elements copied with pointer arithmetic\n";
179 out <<
SP <<
SP <<
SP <<
"size_t src_off = ";
181 out <<
"idx_" << i <<
" * " <<
opName <<
"_strX["
187 out <<
SP <<
SP <<
SP <<
"size_t dst_off = ";
189 out <<
"idx_" << i <<
" * " <<
opName <<
"_strY[" << i <<
"]";
196 <<
"std::copy(tensor_" <<
fNX <<
" + src_off, "
197 <<
"tensor_" <<
fNX <<
" + src_off + " <<
innerSize <<
", "
198 <<
"tensor_" <<
fNY <<
" + dst_off);\n";
205 out <<
SP <<
SP <<
"// General N-D transpose\n";
210 out <<
SP <<
SP <<
SP <<
"size_t src_idx = ";
211 for (
size_t i = 0; i <
rank; ++i) {
212 out <<
"idx_" << i <<
" * " <<
opName <<
"_strX[" <<
fAttrPerm[i] <<
"]";
213 if (i + 1 <
rank) out <<
" + ";
218 out <<
SP <<
SP <<
SP <<
"size_t dst_idx = ";
219 for (
size_t i = 0; i <
rank; ++i) {
220 out <<
"idx_" << i <<
" * " <<
opName <<
"_strY[" << i <<
"]";
221 if (i + 1 <
rank) out <<
" + ";
226 <<
"tensor_" <<
fNY <<
"[dst_idx] = "
227 <<
"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 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::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< 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