//Code generated automatically by TMVA for Inference of Model file [gnn_decoder] at [Tue May 19 20:23:38 2026] #ifndef ROOT_TMVA_SOFIE_GNN_DECODER #define ROOT_TMVA_SOFIE_GNN_DECODER #include #include #include #include "TMVA/SOFIE_common.hxx" #include namespace TMVA_SOFIE_gnn_decoder{ namespace BLAS{ 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 namespace Edge_Update{ struct Session { //--------- GNN_Update_Function---edge_update // initialized (weights and constant) tensors std::vector fTensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentedge_modelmlplinear_3w0 = std::vector(10000); float * tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentedge_modelmlplinear_3w0 = fTensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentedge_modelmlplinear_3w0.data(); std::vector fTensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentedge_modelmlplinear_3b0 = std::vector(100); float * tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentedge_modelmlplinear_3b0 = fTensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentedge_modelmlplinear_3b0.data(); std::vector fTensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentedge_modelmlplinear_2w0 = std::vector(10000); float * tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentedge_modelmlplinear_2w0 = fTensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentedge_modelmlplinear_2w0.data(); std::vector fTensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentedge_modelmlplinear_2b0 = std::vector(100); float * tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentedge_modelmlplinear_2b0 = fTensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentedge_modelmlplinear_2b0.data(); std::vector fTensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentedge_modelmlplinear_1w0 = std::vector(10000); float * tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentedge_modelmlplinear_1w0 = fTensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentedge_modelmlplinear_1w0.data(); std::vector fTensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentedge_modelmlplinear_1b0 = std::vector(100); float * tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentedge_modelmlplinear_1b0 = fTensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentedge_modelmlplinear_1b0.data(); std::vector fTensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentedge_modelmlplinear_0w0 = std::vector(10000); float * tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentedge_modelmlplinear_0w0 = fTensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentedge_modelmlplinear_0w0.data(); std::vector fTensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentedge_modelmlplinear_0b0 = std::vector(100); float * tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentedge_modelmlplinear_0b0 = fTensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentedge_modelmlplinear_0b0.data(); // --- Positioning intermediate tensor memory --//--- declare the dynamic tensors float * tensor_edge_updateRelu4 = nullptr; float * tensor_edge_updateGemm2 = nullptr; float * tensor_edge_updateRelu1 = nullptr; float * tensor_edge_updateGemm1 = nullptr; float * tensor_edge_updateGemm4 = nullptr; float * tensor_edge_updateRelu2 = nullptr; float * tensor_edge_updateRelu0 = nullptr; float * tensor_edge_updateGemm0 = nullptr; //--- dynamic tensors pool std::vector fDynamicMemoryPool; // dynamic shape parameters size_t fNum_edges; Session(std::string filename ="gnn_decoder.dat", size_t num_edges = 20) { fNum_edges = num_edges; //--- 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"); } f.seekg(0); using TMVA::Experimental::SOFIE::ReadTensorFromStream; ReadTensorFromStream(f, tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentedge_modelmlplinear_3w0, "tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentedge_modelmlplinear_3w0", 10000); ReadTensorFromStream(f, tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentedge_modelmlplinear_3b0, "tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentedge_modelmlplinear_3b0", 100); ReadTensorFromStream(f, tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentedge_modelmlplinear_2w0, "tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentedge_modelmlplinear_2w0", 10000); ReadTensorFromStream(f, tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentedge_modelmlplinear_2b0, "tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentedge_modelmlplinear_2b0", 100); ReadTensorFromStream(f, tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentedge_modelmlplinear_1w0, "tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentedge_modelmlplinear_1w0", 10000); ReadTensorFromStream(f, tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentedge_modelmlplinear_1b0, "tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentedge_modelmlplinear_1b0", 100); ReadTensorFromStream(f, tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentedge_modelmlplinear_0w0, "tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentedge_modelmlplinear_0w0", 10000); ReadTensorFromStream(f, tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentedge_modelmlplinear_0b0, "tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentedge_modelmlplinear_0b0", 100); f.close(); // dynamic tensor memory management std::vector dynamicTensorInfos; dynamicTensorInfos.reserve(8); dynamicTensorInfos.push_back( {0, 2, 4* (num_edges * 100) }); // tensor_edge_updateGemm0 dynamicTensorInfos.push_back( {1, 3, 4* (num_edges * 100) }); // tensor_edge_updateRelu0 dynamicTensorInfos.push_back( {2, 4, 4* (num_edges * 100) }); // tensor_edge_updateGemm1 dynamicTensorInfos.push_back( {3, 5, 4* (num_edges * 100) }); // tensor_edge_updateRelu1 dynamicTensorInfos.push_back( {4, 6, 4* (num_edges * 100) }); // tensor_edge_updateGemm2 dynamicTensorInfos.push_back( {5, 7, 4* (num_edges * 100) }); // tensor_edge_updateRelu2 dynamicTensorInfos.push_back( {6, 8, 4* (num_edges * 100) }); // tensor_edge_updateGemm4 auto memory_result = OrganizeMemory(dynamicTensorInfos); // allocating now the memory fDynamicMemoryPool = std::vector(memory_result.total_bytes); int idx = 0; tensor_edge_updateGemm0 = reinterpret_cast(fDynamicMemoryPool.data() + memory_result.offsets[idx++]); tensor_edge_updateRelu0 = reinterpret_cast(fDynamicMemoryPool.data() + memory_result.offsets[idx++]); tensor_edge_updateGemm1 = reinterpret_cast(fDynamicMemoryPool.data() + memory_result.offsets[idx++]); tensor_edge_updateRelu1 = reinterpret_cast(fDynamicMemoryPool.data() + memory_result.offsets[idx++]); tensor_edge_updateGemm2 = reinterpret_cast(fDynamicMemoryPool.data() + memory_result.offsets[idx++]); tensor_edge_updateRelu2 = reinterpret_cast(fDynamicMemoryPool.data() + memory_result.offsets[idx++]); tensor_edge_updateGemm4 = reinterpret_cast(fDynamicMemoryPool.data() + memory_result.offsets[idx++]); } std::vector infer(size_t num_edges,float const* tensor_edge){ std::vector output_tensor_edge_updateRelu4(num_edges * 100); if (num_edges > fNum_edges) { throw std::runtime_error("TMVA-SOFIE: dynamic input tensor shape parameter num_edges exceeds the initialized maximum allowed shape."); } doInfer(*this, num_edges,tensor_edge, output_tensor_edge_updateRelu4.data() ); output_tensor_edge_updateRelu4.resize(num_edges * 100); return {output_tensor_edge_updateRelu4}; } inline void doInfer(Session const &session, size_t num_edges,float const* tensor_edge, float *tensor_edge_updateRelu4 ) { //--------- Gemm op_0 { num_edges , 100 } * { 100 , 100 } -> { num_edges , 100 } for (size_t j = 0; j < num_edges; j++) { size_t y_index = 100 * j; TMVA::Experimental::SOFIE::Copy(tensor_edge_updateGemm0 + y_index, tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentedge_modelmlplinear_0b0, 100); } TMVA::Experimental::SOFIE::Gemm_Call(tensor_edge_updateGemm0, false, false, 100, num_edges, 100, 1, tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentedge_modelmlplinear_0w0, tensor_edge, 1,nullptr); //------ RELU for (int id = 0; id < num_edges * 100 ; id++){ tensor_edge_updateRelu0[id] = ((tensor_edge_updateGemm0[id] > 0 )? tensor_edge_updateGemm0[id] : 0); } //--------- Gemm op_2 { num_edges , 100 } * { 100 , 100 } -> { num_edges , 100 } for (size_t j = 0; j < num_edges; j++) { size_t y_index = 100 * j; TMVA::Experimental::SOFIE::Copy(tensor_edge_updateGemm1 + y_index, tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentedge_modelmlplinear_1b0, 100); } TMVA::Experimental::SOFIE::Gemm_Call(tensor_edge_updateGemm1, false, false, 100, num_edges, 100, 1, tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentedge_modelmlplinear_1w0, tensor_edge_updateRelu0, 1,nullptr); //------ RELU for (int id = 0; id < num_edges * 100 ; id++){ tensor_edge_updateRelu1[id] = ((tensor_edge_updateGemm1[id] > 0 )? tensor_edge_updateGemm1[id] : 0); } //--------- Gemm op_4 { num_edges , 100 } * { 100 , 100 } -> { num_edges , 100 } for (size_t j = 0; j < num_edges; j++) { size_t y_index = 100 * j; TMVA::Experimental::SOFIE::Copy(tensor_edge_updateGemm2 + y_index, tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentedge_modelmlplinear_2b0, 100); } TMVA::Experimental::SOFIE::Gemm_Call(tensor_edge_updateGemm2, false, false, 100, num_edges, 100, 1, tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentedge_modelmlplinear_2w0, tensor_edge_updateRelu1, 1,nullptr); //------ RELU for (int id = 0; id < num_edges * 100 ; id++){ tensor_edge_updateRelu2[id] = ((tensor_edge_updateGemm2[id] > 0 )? tensor_edge_updateGemm2[id] : 0); } //--------- Gemm op_6 { num_edges , 100 } * { 100 , 100 } -> { num_edges , 100 } for (size_t j = 0; j < num_edges; j++) { size_t y_index = 100 * j; TMVA::Experimental::SOFIE::Copy(tensor_edge_updateGemm4 + y_index, tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentedge_modelmlplinear_3b0, 100); } TMVA::Experimental::SOFIE::Gemm_Call(tensor_edge_updateGemm4, false, false, 100, num_edges, 100, 1, tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentedge_modelmlplinear_3w0, tensor_edge_updateRelu2, 1,nullptr); //------ RELU for (int id = 0; id < num_edges * 100 ; id++){ tensor_edge_updateRelu4[id] = ((tensor_edge_updateGemm4[id] > 0 )? tensor_edge_updateGemm4[id] : 0); } } }; } namespace Node_Update{ struct Session { //--------- GNN_Update_Function---node_update // initialized (weights and constant) tensors std::vector fTensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentnode_modelmlplinear_3w0 = std::vector(10000); float * tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentnode_modelmlplinear_3w0 = fTensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentnode_modelmlplinear_3w0.data(); std::vector fTensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentnode_modelmlplinear_3b0 = std::vector(100); float * tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentnode_modelmlplinear_3b0 = fTensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentnode_modelmlplinear_3b0.data(); std::vector fTensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentnode_modelmlplinear_2w0 = std::vector(10000); float * tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentnode_modelmlplinear_2w0 = fTensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentnode_modelmlplinear_2w0.data(); std::vector fTensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentnode_modelmlplinear_1w0 = std::vector(10000); float * tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentnode_modelmlplinear_1w0 = fTensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentnode_modelmlplinear_1w0.data(); std::vector fTensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentnode_modelmlplinear_2b0 = std::vector(100); float * tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentnode_modelmlplinear_2b0 = fTensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentnode_modelmlplinear_2b0.data(); std::vector fTensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentnode_modelmlplinear_1b0 = std::vector(100); float * tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentnode_modelmlplinear_1b0 = fTensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentnode_modelmlplinear_1b0.data(); std::vector fTensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentnode_modelmlplinear_0w0 = std::vector(10000); float * tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentnode_modelmlplinear_0w0 = fTensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentnode_modelmlplinear_0w0.data(); std::vector fTensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentnode_modelmlplinear_0b0 = std::vector(100); float * tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentnode_modelmlplinear_0b0 = fTensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentnode_modelmlplinear_0b0.data(); // --- Positioning intermediate tensor memory --//--- declare the dynamic tensors float * tensor_node_updateRelu4 = nullptr; float * tensor_node_updateGemm4 = nullptr; float * tensor_node_updateRelu2 = nullptr; float * tensor_node_updateGemm2 = nullptr; float * tensor_node_updateGemm1 = nullptr; float * tensor_node_updateRelu0 = nullptr; float * tensor_node_updateRelu1 = nullptr; float * tensor_node_updateGemm0 = nullptr; //--- dynamic tensors pool std::vector fDynamicMemoryPool; // dynamic shape parameters size_t fNum_nodes; Session(std::string filename ="gnn_decoder.dat", size_t num_nodes = 5) { fNum_nodes = num_nodes; //--- 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"); } f.seekg(529495); using TMVA::Experimental::SOFIE::ReadTensorFromStream; ReadTensorFromStream(f, tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentnode_modelmlplinear_3w0, "tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentnode_modelmlplinear_3w0", 10000); ReadTensorFromStream(f, tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentnode_modelmlplinear_3b0, "tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentnode_modelmlplinear_3b0", 100); ReadTensorFromStream(f, tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentnode_modelmlplinear_2w0, "tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentnode_modelmlplinear_2w0", 10000); ReadTensorFromStream(f, tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentnode_modelmlplinear_1w0, "tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentnode_modelmlplinear_1w0", 10000); ReadTensorFromStream(f, tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentnode_modelmlplinear_2b0, "tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentnode_modelmlplinear_2b0", 100); ReadTensorFromStream(f, tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentnode_modelmlplinear_1b0, "tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentnode_modelmlplinear_1b0", 100); ReadTensorFromStream(f, tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentnode_modelmlplinear_0w0, "tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentnode_modelmlplinear_0w0", 10000); ReadTensorFromStream(f, tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentnode_modelmlplinear_0b0, "tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentnode_modelmlplinear_0b0", 100); f.close(); // dynamic tensor memory management std::vector dynamicTensorInfos; dynamicTensorInfos.reserve(8); dynamicTensorInfos.push_back( {0, 2, 4* (num_nodes * 100) }); // tensor_node_updateGemm0 dynamicTensorInfos.push_back( {1, 3, 4* (num_nodes * 100) }); // tensor_node_updateRelu0 dynamicTensorInfos.push_back( {2, 4, 4* (num_nodes * 100) }); // tensor_node_updateGemm1 dynamicTensorInfos.push_back( {3, 5, 4* (num_nodes * 100) }); // tensor_node_updateRelu1 dynamicTensorInfos.push_back( {4, 6, 4* (num_nodes * 100) }); // tensor_node_updateGemm2 dynamicTensorInfos.push_back( {5, 7, 4* (num_nodes * 100) }); // tensor_node_updateRelu2 dynamicTensorInfos.push_back( {6, 8, 4* (num_nodes * 100) }); // tensor_node_updateGemm4 auto memory_result = OrganizeMemory(dynamicTensorInfos); // allocating now the memory fDynamicMemoryPool = std::vector(memory_result.total_bytes); int idx = 0; tensor_node_updateGemm0 = reinterpret_cast(fDynamicMemoryPool.data() + memory_result.offsets[idx++]); tensor_node_updateRelu0 = reinterpret_cast(fDynamicMemoryPool.data() + memory_result.offsets[idx++]); tensor_node_updateGemm1 = reinterpret_cast(fDynamicMemoryPool.data() + memory_result.offsets[idx++]); tensor_node_updateRelu1 = reinterpret_cast(fDynamicMemoryPool.data() + memory_result.offsets[idx++]); tensor_node_updateGemm2 = reinterpret_cast(fDynamicMemoryPool.data() + memory_result.offsets[idx++]); tensor_node_updateRelu2 = reinterpret_cast(fDynamicMemoryPool.data() + memory_result.offsets[idx++]); tensor_node_updateGemm4 = reinterpret_cast(fDynamicMemoryPool.data() + memory_result.offsets[idx++]); } std::vector infer(size_t num_nodes,float const* tensor_node){ std::vector output_tensor_node_updateRelu4(num_nodes * 100); if (num_nodes > fNum_nodes) { throw std::runtime_error("TMVA-SOFIE: dynamic input tensor shape parameter num_nodes exceeds the initialized maximum allowed shape."); } doInfer(*this, num_nodes,tensor_node, output_tensor_node_updateRelu4.data() ); output_tensor_node_updateRelu4.resize(num_nodes * 100); return {output_tensor_node_updateRelu4}; } inline void doInfer(Session const &session, size_t num_nodes,float const* tensor_node, float *tensor_node_updateRelu4 ) { //--------- Gemm op_0 { num_nodes , 100 } * { 100 , 100 } -> { num_nodes , 100 } for (size_t j = 0; j < num_nodes; j++) { size_t y_index = 100 * j; TMVA::Experimental::SOFIE::Copy(tensor_node_updateGemm0 + y_index, tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentnode_modelmlplinear_0b0, 100); } TMVA::Experimental::SOFIE::Gemm_Call(tensor_node_updateGemm0, false, false, 100, num_nodes, 100, 1, tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentnode_modelmlplinear_0w0, tensor_node, 1,nullptr); //------ RELU for (int id = 0; id < num_nodes * 100 ; id++){ tensor_node_updateRelu0[id] = ((tensor_node_updateGemm0[id] > 0 )? tensor_node_updateGemm0[id] : 0); } //--------- Gemm op_2 { num_nodes , 100 } * { 100 , 100 } -> { num_nodes , 100 } for (size_t j = 0; j < num_nodes; j++) { size_t y_index = 100 * j; TMVA::Experimental::SOFIE::Copy(tensor_node_updateGemm1 + y_index, tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentnode_modelmlplinear_1b0, 100); } TMVA::Experimental::SOFIE::Gemm_Call(tensor_node_updateGemm1, false, false, 100, num_nodes, 100, 1, tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentnode_modelmlplinear_1w0, tensor_node_updateRelu0, 1,nullptr); //------ RELU for (int id = 0; id < num_nodes * 100 ; id++){ tensor_node_updateRelu1[id] = ((tensor_node_updateGemm1[id] > 0 )? tensor_node_updateGemm1[id] : 0); } //--------- Gemm op_4 { num_nodes , 100 } * { 100 , 100 } -> { num_nodes , 100 } for (size_t j = 0; j < num_nodes; j++) { size_t y_index = 100 * j; TMVA::Experimental::SOFIE::Copy(tensor_node_updateGemm2 + y_index, tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentnode_modelmlplinear_2b0, 100); } TMVA::Experimental::SOFIE::Gemm_Call(tensor_node_updateGemm2, false, false, 100, num_nodes, 100, 1, tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentnode_modelmlplinear_2w0, tensor_node_updateRelu1, 1,nullptr); //------ RELU for (int id = 0; id < num_nodes * 100 ; id++){ tensor_node_updateRelu2[id] = ((tensor_node_updateGemm2[id] > 0 )? tensor_node_updateGemm2[id] : 0); } //--------- Gemm op_6 { num_nodes , 100 } * { 100 , 100 } -> { num_nodes , 100 } for (size_t j = 0; j < num_nodes; j++) { size_t y_index = 100 * j; TMVA::Experimental::SOFIE::Copy(tensor_node_updateGemm4 + y_index, tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentnode_modelmlplinear_3b0, 100); } TMVA::Experimental::SOFIE::Gemm_Call(tensor_node_updateGemm4, false, false, 100, num_nodes, 100, 1, tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentnode_modelmlplinear_3w0, tensor_node_updateRelu2, 1,nullptr); //------ RELU for (int id = 0; id < num_nodes * 100 ; id++){ tensor_node_updateRelu4[id] = ((tensor_node_updateGemm4[id] > 0 )? tensor_node_updateGemm4[id] : 0); } } }; } namespace Global_Update{ struct Session { //--------- GNN_Update_Function---global_update // initialized (weights and constant) tensors std::vector fTensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentglobal_modelmlplinear_2w0 = std::vector(10000); float * tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentglobal_modelmlplinear_2w0 = fTensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentglobal_modelmlplinear_2w0.data(); std::vector fTensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentglobal_modelmlplinear_3w0 = std::vector(10000); float * tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentglobal_modelmlplinear_3w0 = fTensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentglobal_modelmlplinear_3w0.data(); std::vector fTensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentglobal_modelmlplinear_2b0 = std::vector(100); float * tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentglobal_modelmlplinear_2b0 = fTensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentglobal_modelmlplinear_2b0.data(); std::vector fTensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentglobal_modelmlplinear_1w0 = std::vector(10000); float * tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentglobal_modelmlplinear_1w0 = fTensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentglobal_modelmlplinear_1w0.data(); std::vector fTensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentglobal_modelmlplinear_1b0 = std::vector(100); float * tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentglobal_modelmlplinear_1b0 = fTensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentglobal_modelmlplinear_1b0.data(); std::vector fTensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentglobal_modelmlplinear_3b0 = std::vector(100); float * tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentglobal_modelmlplinear_3b0 = fTensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentglobal_modelmlplinear_3b0.data(); std::vector fTensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentglobal_modelmlplinear_0w0 = std::vector(10000); float * tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentglobal_modelmlplinear_0w0 = fTensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentglobal_modelmlplinear_0w0.data(); std::vector fTensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentglobal_modelmlplinear_0b0 = std::vector(100); float * tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentglobal_modelmlplinear_0b0 = fTensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentglobal_modelmlplinear_0b0.data(); //--- Allocating session memory pool to be used for allocating intermediate tensors std::vector fIntermediateMemoryPool = std::vector(800); // --- Positioning intermediate tensor memory -- // Allocating memory for intermediate tensor global_updateGemm0 with size 400 bytes float* tensor_global_updateGemm0 = reinterpret_cast(fIntermediateMemoryPool.data() + 0); // Allocating memory for intermediate tensor global_updateRelu0 with size 400 bytes float* tensor_global_updateRelu0 = reinterpret_cast(fIntermediateMemoryPool.data() + 400); // Allocating memory for intermediate tensor global_updateGemm1 with size 400 bytes float* tensor_global_updateGemm1 = reinterpret_cast(fIntermediateMemoryPool.data() + 0); // Allocating memory for intermediate tensor global_updateRelu1 with size 400 bytes float* tensor_global_updateRelu1 = reinterpret_cast(fIntermediateMemoryPool.data() + 400); // Allocating memory for intermediate tensor global_updateGemm2 with size 400 bytes float* tensor_global_updateGemm2 = reinterpret_cast(fIntermediateMemoryPool.data() + 0); // Allocating memory for intermediate tensor global_updateRelu2 with size 400 bytes float* tensor_global_updateRelu2 = reinterpret_cast(fIntermediateMemoryPool.data() + 400); // Allocating memory for intermediate tensor global_updateGemm4 with size 400 bytes float* tensor_global_updateGemm4 = reinterpret_cast(fIntermediateMemoryPool.data() + 0); // Allocating memory for intermediate tensor global_updateRelu4 with size 400 bytes float* tensor_global_updateRelu4 = reinterpret_cast(fIntermediateMemoryPool.data() + 400); Session(std::string filename ="gnn_decoder.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"); } f.seekg(1058911); using TMVA::Experimental::SOFIE::ReadTensorFromStream; ReadTensorFromStream(f, tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentglobal_modelmlplinear_2w0, "tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentglobal_modelmlplinear_2w0", 10000); ReadTensorFromStream(f, tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentglobal_modelmlplinear_3w0, "tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentglobal_modelmlplinear_3w0", 10000); ReadTensorFromStream(f, tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentglobal_modelmlplinear_2b0, "tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentglobal_modelmlplinear_2b0", 100); ReadTensorFromStream(f, tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentglobal_modelmlplinear_1w0, "tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentglobal_modelmlplinear_1w0", 10000); ReadTensorFromStream(f, tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentglobal_modelmlplinear_1b0, "tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentglobal_modelmlplinear_1b0", 100); ReadTensorFromStream(f, tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentglobal_modelmlplinear_3b0, "tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentglobal_modelmlplinear_3b0", 100); ReadTensorFromStream(f, tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentglobal_modelmlplinear_0w0, "tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentglobal_modelmlplinear_0w0", 10000); ReadTensorFromStream(f, tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentglobal_modelmlplinear_0b0, "tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentglobal_modelmlplinear_0b0", 100); f.close(); } std::vector infer(float const* tensor_global){ std::vector output_tensor_global_updateRelu4(100); doInfer(*this, tensor_global, output_tensor_global_updateRelu4.data() ); return {output_tensor_global_updateRelu4}; } inline void doInfer(Session const &session, float const* tensor_global, float *tensor_global_updateRelu4 ) { //--------- Gemm op_0 { 1 , 100 } * { 100 , 100 } -> { 1 , 100 } for (size_t j = 0; j < 1; j++) { size_t y_index = 100 * j; TMVA::Experimental::SOFIE::Copy(tensor_global_updateGemm0 + y_index, tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentglobal_modelmlplinear_0b0, 100); } TMVA::Experimental::SOFIE::Gemm_Call(tensor_global_updateGemm0, false, false, 100, 1, 100, 1, tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentglobal_modelmlplinear_0w0, tensor_global, 1,nullptr); //------ RELU for (int id = 0; id < 100 ; id++){ tensor_global_updateRelu0[id] = ((tensor_global_updateGemm0[id] > 0 )? tensor_global_updateGemm0[id] : 0); } //--------- Gemm op_2 { 1 , 100 } * { 100 , 100 } -> { 1 , 100 } for (size_t j = 0; j < 1; j++) { size_t y_index = 100 * j; TMVA::Experimental::SOFIE::Copy(tensor_global_updateGemm1 + y_index, tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentglobal_modelmlplinear_1b0, 100); } TMVA::Experimental::SOFIE::Gemm_Call(tensor_global_updateGemm1, false, false, 100, 1, 100, 1, tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentglobal_modelmlplinear_1w0, tensor_global_updateRelu0, 1,nullptr); //------ RELU for (int id = 0; id < 100 ; id++){ tensor_global_updateRelu1[id] = ((tensor_global_updateGemm1[id] > 0 )? tensor_global_updateGemm1[id] : 0); } //--------- Gemm op_4 { 1 , 100 } * { 100 , 100 } -> { 1 , 100 } for (size_t j = 0; j < 1; j++) { size_t y_index = 100 * j; TMVA::Experimental::SOFIE::Copy(tensor_global_updateGemm2 + y_index, tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentglobal_modelmlplinear_2b0, 100); } TMVA::Experimental::SOFIE::Gemm_Call(tensor_global_updateGemm2, false, false, 100, 1, 100, 1, tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentglobal_modelmlplinear_2w0, tensor_global_updateRelu1, 1,nullptr); //------ RELU for (int id = 0; id < 100 ; id++){ tensor_global_updateRelu2[id] = ((tensor_global_updateGemm2[id] > 0 )? tensor_global_updateGemm2[id] : 0); } //--------- Gemm op_6 { 1 , 100 } * { 100 , 100 } -> { 1 , 100 } for (size_t j = 0; j < 1; j++) { size_t y_index = 100 * j; TMVA::Experimental::SOFIE::Copy(tensor_global_updateGemm4 + y_index, tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentglobal_modelmlplinear_3b0, 100); } TMVA::Experimental::SOFIE::Gemm_Call(tensor_global_updateGemm4, false, false, 100, 1, 100, 1, tensor_EncodeProcessDecodeMLPGraphIndependentgraph_independentglobal_modelmlplinear_3w0, tensor_global_updateRelu2, 1,nullptr); //------ RELU for (int id = 0; id < 100 ; id++){ tensor_global_updateRelu4[id] = ((tensor_global_updateGemm4[id] > 0 )? tensor_global_updateGemm4[id] : 0); } } }; } struct Session { // Instantiating session objects for graph components Edge_Update::Session edge_update; std::vector fEdgeInputs = std::vector(20*100); Node_Update::Session node_update; std::vector fNodeInputs = std::vector(5*100); Global_Update::Session global_update; void infer(TMVA::Experimental::SOFIE::GNN_Data& input_graph){ // --- Edge Update --- size_t n_edges = input_graph.edge_data.GetShape()[0]; for (size_t k = 0; k < n_edges; k++) { std::copy(input_graph.edge_data.GetData() + k * 100, input_graph.edge_data.GetData() + (k + 1) * 100, fEdgeInputs.begin() + k * 100); } auto edgeUpdates = edge_update.infer(n_edges,fEdgeInputs.data()); for (size_t k = 0; k < n_edges; k++) { std::copy(edgeUpdates.begin()+ k * 100, edgeUpdates.begin()+ (k+1) * 100,input_graph.edge_data.GetData() + k * 100); } // --- Node Update --- size_t n_nodes = input_graph.node_data.GetShape()[0]; for (size_t k = 0; k < n_nodes; k++) { std::copy(input_graph.node_data.GetData() + k * 100, input_graph.node_data.GetData() + (k + 1) * 100, fNodeInputs.begin() + k * 100); } auto nodeUpdates = node_update.infer(n_nodes,fNodeInputs.data()); for (size_t k = 0; k < n_nodes; k++) { std::copy(nodeUpdates.begin()+ k * 100, nodeUpdates.begin() + (k+1) * 100,input_graph.node_data.GetData() + k * 100); } // --- Global Update --- std::vector Global_Data = global_update.infer(input_graph.global_data.GetData()); std::copy(Global_Data.begin(), Global_Data.end(), input_graph.global_data.GetData()); } }; } //TMVA_SOFIE_gnn_decoder #endif // TMVA_SOFIE_ROOT_TMVA_SOFIE_GNN_DECODER