//Code generated automatically by TMVA for Inference of Model file [PyTorchModel.pt] at [Tue May 19 20:23:50 2026] #ifndef ROOT_TMVA_SOFIE_PYTORCHMODEL #define ROOT_TMVA_SOFIE_PYTORCHMODEL #include #include #include "TMVA/SOFIE_common.hxx" #include namespace TMVA_SOFIE_PyTorchModel{ namespace BLAS{ extern "C" void sgemv_(const char * trans, const int * m, const int * n, const float * alpha, const float * A, const int * lda, const float * X, const int * incx, const float * beta, const float * Y, const int * incy); extern "C" void sgemm_(const char * transa, const char * transb, const int * m, const int * n, const int * k, const float * alpha, const float * A, const int * lda, const float * B, const int * ldb, const float * beta, float * C, const int * ldc); }//BLAS struct Session; inline void doInfer(Session const &session, float const* tensor_input1, float *tensor_result3 ); struct Session { // initialized (weights and constant) tensors std::vector fTensor_2bias = std::vector(8); float * tensor_2bias = fTensor_2bias.data(); std::vector fTensor_0weight = std::vector(512); float * tensor_0weight = fTensor_0weight.data(); std::vector fTensor_2weight = std::vector(128); float * tensor_2weight = fTensor_2weight.data(); std::vector fTensor_0bias = std::vector(16); float * tensor_0bias = fTensor_0bias.data(); //--- Allocating session memory pool to be used for allocating intermediate tensors std::vector fIntermediateMemoryPool = std::vector(256); // --- Positioning intermediate tensor memory -- // Allocating memory for intermediate tensor input0 with size 128 bytes float* tensor_input0 = reinterpret_cast(fIntermediateMemoryPool.data() + 0); // Allocating memory for intermediate tensor result with size 128 bytes float* tensor_result = reinterpret_cast(fIntermediateMemoryPool.data() + 128); // Allocating memory for intermediate tensor input2 with size 64 bytes float* tensor_input2 = reinterpret_cast(fIntermediateMemoryPool.data() + 64); // Allocating memory for intermediate tensor result3 with size 64 bytes float* tensor_result3 = reinterpret_cast(fIntermediateMemoryPool.data() + 0); Session(std::string filename ="PyTorchModel.dat") { //--- reading weights from file std::ifstream f; f.open(filename); if (!f.is_open()) { throw std::runtime_error("tmva-sofie failed to open file " + filename + " for input weights"); } using TMVA::Experimental::SOFIE::ReadTensorFromStream; ReadTensorFromStream(f, tensor_2bias, "tensor_2bias", 8); ReadTensorFromStream(f, tensor_0weight, "tensor_0weight", 512); ReadTensorFromStream(f, tensor_2weight, "tensor_2weight", 128); ReadTensorFromStream(f, tensor_0bias, "tensor_0bias", 16); f.close(); } std::vector infer(float const* tensor_input1){ std::vector output_tensor_result3(16); doInfer(*this, tensor_input1, output_tensor_result3.data() ); return {output_tensor_result3}; } }; // end of Session // Input tensor dimensions using TMVA::Experimental::SOFIE::SingleDim; using TMVA::Experimental::SOFIE::TensorDims; using TMVA::Experimental::SOFIE::makeDims; constexpr std::array dim_input1{SingleDim{2}, SingleDim{32}}; constexpr std::array inputTensorDims{ makeDims(dim_input1) }; constexpr bool hasDynamicInputTensors{false}; // Output tensor dimensions constexpr std::array dim_result3{SingleDim{2}, SingleDim{8}}; constexpr std::array outputTensorDims{ makeDims(dim_result3) }; constexpr bool hasDynamicOutputTensors{false}; inline void doInfer(Session const &session, float const* tensor_input1, float *tensor_result3 ) { auto &tensor_0bias = session.tensor_0bias; auto &tensor_0weight = session.tensor_0weight; auto &tensor_2bias = session.tensor_2bias; auto &tensor_2weight = session.tensor_2weight; auto &tensor_input0 = session.tensor_input0; auto &tensor_input2 = session.tensor_input2; auto &tensor_result = session.tensor_result; //--------- Gemm op_0 { 2 , 32 } * { 16 , 32 } -> { 2 , 16 } for (size_t j = 0; j < 2; j++) { size_t y_index = 16 * j; TMVA::Experimental::SOFIE::Copy(tensor_input0 + y_index, tensor_0bias, 16); } TMVA::Experimental::SOFIE::Gemm_Call(tensor_input0, true, false, 16, 2, 32, 1, tensor_0weight, tensor_input1, 1,nullptr); //------ RELU for (int id = 0; id < 32 ; id++){ tensor_result[id] = ((tensor_input0[id] > 0 )? tensor_input0[id] : 0); } //--------- Gemm op_2 { 2 , 16 } * { 8 , 16 } -> { 2 , 8 } for (size_t j = 0; j < 2; j++) { size_t y_index = 8 * j; TMVA::Experimental::SOFIE::Copy(tensor_input2 + y_index, tensor_2bias, 8); } TMVA::Experimental::SOFIE::Gemm_Call(tensor_input2, true, false, 8, 2, 16, 1, tensor_2weight, tensor_result, 1,nullptr); //------ RELU for (int id = 0; id < 16 ; id++){ tensor_result3[id] = ((tensor_input2[id] > 0 )? tensor_input2[id] : 0); } } } //TMVA_SOFIE_PyTorchModel #endif // ROOT_TMVA_SOFIE_PYTORCHMODEL