//Code generated automatically by TMVA for Inference of Model file [sig_back_model] at [Fri Jun 2 22:19:02 2023] #ifndef TMVA_SOFIE_SIG_BACK_MODEL #define TMVA_SOFIE_SIG_BACK_MODEL #include #include #include #include "TMVA/SOFIE_common.hxx" #include namespace TMVA_SOFIE_sig_back_model{ 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 { std::vector fTensor_dense4bias0 = std::vector(2); float * tensor_dense4bias0 = fTensor_dense4bias0.data(); std::vector fTensor_dense3bias0 = std::vector(4); float * tensor_dense3bias0 = fTensor_dense3bias0.data(); std::vector fTensor_dense3kernel0 = std::vector(32); float * tensor_dense3kernel0 = fTensor_dense3kernel0.data(); std::vector fTensor_dense2bias0 = std::vector(8); float * tensor_dense2bias0 = fTensor_dense2bias0.data(); std::vector fTensor_dense4kernel0 = std::vector(8); float * tensor_dense4kernel0 = fTensor_dense4kernel0.data(); std::vector fTensor_dense2kernel0 = std::vector(128); float * tensor_dense2kernel0 = fTensor_dense2kernel0.data(); std::vector fTensor_dense1bias0 = std::vector(16); float * tensor_dense1bias0 = fTensor_dense1bias0.data(); std::vector fTensor_dense1kernel0 = std::vector(80); float * tensor_dense1kernel0 = fTensor_dense1kernel0.data(); std::vector fTensor_densebias0 = std::vector(5); float * tensor_densebias0 = fTensor_densebias0.data(); std::vector fTensor_densekernel0 = std::vector(25); float * tensor_densekernel0 = fTensor_densekernel0.data(); std::vector fTensor_dense4Sigmoid0 = std::vector(2); float * tensor_dense4Sigmoid0 = fTensor_dense4Sigmoid0.data(); std::vector fTensor_densebias0bcast = std::vector(5); float * tensor_densebias0bcast = fTensor_densebias0bcast.data(); std::vector fTensor_dense2bias0bcast = std::vector(8); float * tensor_dense2bias0bcast = fTensor_dense2bias0bcast.data(); std::vector fTensor_dense1Softmax0 = std::vector(16); float * tensor_dense1Softmax0 = fTensor_dense1Softmax0.data(); std::vector fTensor_dense2Softmax0 = std::vector(8); float * tensor_dense2Softmax0 = fTensor_dense2Softmax0.data(); std::vector fTensor_dense2Dense = std::vector(8); float * tensor_dense2Dense = fTensor_dense2Dense.data(); std::vector fTensor_denseBiasAdd0 = std::vector(5); float * tensor_denseBiasAdd0 = fTensor_denseBiasAdd0.data(); std::vector fTensor_dense3bias0bcast = std::vector(4); float * tensor_dense3bias0bcast = fTensor_dense3bias0bcast.data(); std::vector fTensor_dense3Dense = std::vector(4); float * tensor_dense3Dense = fTensor_dense3Dense.data(); std::vector fTensor_dense3Softmax0 = std::vector(4); float * tensor_dense3Softmax0 = fTensor_dense3Softmax0.data(); std::vector fTensor_dense4bias0bcast = std::vector(2); float * tensor_dense4bias0bcast = fTensor_dense4bias0bcast.data(); std::vector fTensor_dense1bias0bcast = std::vector(16); float * tensor_dense1bias0bcast = fTensor_dense1bias0bcast.data(); std::vector fTensor_dense1Dense = std::vector(16); float * tensor_dense1Dense = fTensor_dense1Dense.data(); std::vector fTensor_dense4Dense = std::vector(2); float * tensor_dense4Dense = fTensor_dense4Dense.data(); Session(std::string filename ="") { if (filename.empty()) filename = "sig_back_model.dat"; std::ifstream f; f.open(filename); if (!f.is_open()){ throw std::runtime_error("tmva-sofie failed to open file for input weights"); } std::string tensor_name; int length; f >> tensor_name >> length; if (tensor_name != "tensor_dense4bias0" ) { std::string err_msg = "TMVA-SOFIE failed to read the correct tensor name; expected name is tensor_dense4bias0 , read " + tensor_name; throw std::runtime_error(err_msg); } if (length != 2) { std::string err_msg = "TMVA-SOFIE failed to read the correct tensor size; expected size is 2 , read " + std::to_string(length) ; throw std::runtime_error(err_msg); } for (int i =0; i < length; ++i) f >> tensor_dense4bias0[i]; f >> tensor_name >> length; if (tensor_name != "tensor_dense3bias0" ) { std::string err_msg = "TMVA-SOFIE failed to read the correct tensor name; expected name is tensor_dense3bias0 , read " + tensor_name; throw std::runtime_error(err_msg); } if (length != 4) { std::string err_msg = "TMVA-SOFIE failed to read the correct tensor size; expected size is 4 , read " + std::to_string(length) ; throw std::runtime_error(err_msg); } for (int i =0; i < length; ++i) f >> tensor_dense3bias0[i]; f >> tensor_name >> length; if (tensor_name != "tensor_dense3kernel0" ) { std::string err_msg = "TMVA-SOFIE failed to read the correct tensor name; expected name is tensor_dense3kernel0 , read " + tensor_name; throw std::runtime_error(err_msg); } if (length != 32) { std::string err_msg = "TMVA-SOFIE failed to read the correct tensor size; expected size is 32 , read " + std::to_string(length) ; throw std::runtime_error(err_msg); } for (int i =0; i < length; ++i) f >> tensor_dense3kernel0[i]; f >> tensor_name >> length; if (tensor_name != "tensor_dense2bias0" ) { std::string err_msg = "TMVA-SOFIE failed to read the correct tensor name; expected name is tensor_dense2bias0 , read " + tensor_name; throw std::runtime_error(err_msg); } if (length != 8) { std::string err_msg = "TMVA-SOFIE failed to read the correct tensor size; expected size is 8 , read " + std::to_string(length) ; throw std::runtime_error(err_msg); } for (int i =0; i < length; ++i) f >> tensor_dense2bias0[i]; f >> tensor_name >> length; if (tensor_name != "tensor_dense4kernel0" ) { std::string err_msg = "TMVA-SOFIE failed to read the correct tensor name; expected name is tensor_dense4kernel0 , read " + tensor_name; throw std::runtime_error(err_msg); } if (length != 8) { std::string err_msg = "TMVA-SOFIE failed to read the correct tensor size; expected size is 8 , read " + std::to_string(length) ; throw std::runtime_error(err_msg); } for (int i =0; i < length; ++i) f >> tensor_dense4kernel0[i]; f >> tensor_name >> length; if (tensor_name != "tensor_dense2kernel0" ) { std::string err_msg = "TMVA-SOFIE failed to read the correct tensor name; expected name is tensor_dense2kernel0 , read " + tensor_name; throw std::runtime_error(err_msg); } if (length != 128) { std::string err_msg = "TMVA-SOFIE failed to read the correct tensor size; expected size is 128 , read " + std::to_string(length) ; throw std::runtime_error(err_msg); } for (int i =0; i < length; ++i) f >> tensor_dense2kernel0[i]; f >> tensor_name >> length; if (tensor_name != "tensor_dense1bias0" ) { std::string err_msg = "TMVA-SOFIE failed to read the correct tensor name; expected name is tensor_dense1bias0 , read " + tensor_name; throw std::runtime_error(err_msg); } if (length != 16) { std::string err_msg = "TMVA-SOFIE failed to read the correct tensor size; expected size is 16 , read " + std::to_string(length) ; throw std::runtime_error(err_msg); } for (int i =0; i < length; ++i) f >> tensor_dense1bias0[i]; f >> tensor_name >> length; if (tensor_name != "tensor_dense1kernel0" ) { std::string err_msg = "TMVA-SOFIE failed to read the correct tensor name; expected name is tensor_dense1kernel0 , read " + tensor_name; throw std::runtime_error(err_msg); } if (length != 80) { std::string err_msg = "TMVA-SOFIE failed to read the correct tensor size; expected size is 80 , read " + std::to_string(length) ; throw std::runtime_error(err_msg); } for (int i =0; i < length; ++i) f >> tensor_dense1kernel0[i]; f >> tensor_name >> length; if (tensor_name != "tensor_densebias0" ) { std::string err_msg = "TMVA-SOFIE failed to read the correct tensor name; expected name is tensor_densebias0 , read " + tensor_name; throw std::runtime_error(err_msg); } if (length != 5) { std::string err_msg = "TMVA-SOFIE failed to read the correct tensor size; expected size is 5 , read " + std::to_string(length) ; throw std::runtime_error(err_msg); } for (int i =0; i < length; ++i) f >> tensor_densebias0[i]; f >> tensor_name >> length; if (tensor_name != "tensor_densekernel0" ) { std::string err_msg = "TMVA-SOFIE failed to read the correct tensor name; expected name is tensor_densekernel0 , read " + tensor_name; throw std::runtime_error(err_msg); } if (length != 25) { std::string err_msg = "TMVA-SOFIE failed to read the correct tensor size; expected size is 25 , read " + std::to_string(length) ; throw std::runtime_error(err_msg); } for (int i =0; i < length; ++i) f >> tensor_densekernel0[i]; f.close(); { float * data = TMVA::Experimental::SOFIE::UTILITY::UnidirectionalBroadcast(tensor_densebias0,{ 5 }, { 1 , 5 }); std::copy(data, data + 5, tensor_densebias0bcast); delete [] data; } { float * data = TMVA::Experimental::SOFIE::UTILITY::UnidirectionalBroadcast(tensor_dense1bias0,{ 16 }, { 1 , 16 }); std::copy(data, data + 16, tensor_dense1bias0bcast); delete [] data; } { float * data = TMVA::Experimental::SOFIE::UTILITY::UnidirectionalBroadcast(tensor_dense2bias0,{ 8 }, { 1 , 8 }); std::copy(data, data + 8, tensor_dense2bias0bcast); delete [] data; } { float * data = TMVA::Experimental::SOFIE::UTILITY::UnidirectionalBroadcast(tensor_dense3bias0,{ 4 }, { 1 , 4 }); std::copy(data, data + 4, tensor_dense3bias0bcast); delete [] data; } { float * data = TMVA::Experimental::SOFIE::UTILITY::UnidirectionalBroadcast(tensor_dense4bias0,{ 2 }, { 1 , 2 }); std::copy(data, data + 2, tensor_dense4bias0bcast); delete [] data; } } std::vector infer(float* tensor_denseinput){ //--------- Gemm char op_0_transA = 'n'; char op_0_transB = 'n'; int op_0_m = 1; int op_0_n = 5; int op_0_k = 5; float op_0_alpha = 1; float op_0_beta = 1; int op_0_lda = 5; int op_0_ldb = 5; std::copy(tensor_densebias0bcast, tensor_densebias0bcast + 5, tensor_denseBiasAdd0); BLAS::sgemm_(&op_0_transB, &op_0_transA, &op_0_n, &op_0_m, &op_0_k, &op_0_alpha, tensor_densekernel0, &op_0_ldb, tensor_denseinput, &op_0_lda, &op_0_beta, tensor_denseBiasAdd0, &op_0_n); //--------- Gemm char op_1_transA = 'n'; char op_1_transB = 'n'; int op_1_m = 1; int op_1_n = 16; int op_1_k = 5; float op_1_alpha = 1; float op_1_beta = 1; int op_1_lda = 5; int op_1_ldb = 16; std::copy(tensor_dense1bias0bcast, tensor_dense1bias0bcast + 16, tensor_dense1Dense); BLAS::sgemm_(&op_1_transB, &op_1_transA, &op_1_n, &op_1_m, &op_1_k, &op_1_alpha, tensor_dense1kernel0, &op_1_ldb, tensor_denseBiasAdd0, &op_1_lda, &op_1_beta, tensor_dense1Dense, &op_1_n); //------ SOFTMAX for (size_t n = 0; n < 1 ; n++){ float sum = 0.; size_t index = 0+ n * 16; for (size_t i = 0; i < 16; i++) { tensor_dense1Softmax0[index + i*1] = std::exp(tensor_dense1Dense[index + i*1]); sum += tensor_dense1Softmax0[index + i*1]; } for (size_t i = 0; i < 16; i++) { tensor_dense1Softmax0[index + i*1] /= sum; } } //--------- Gemm char op_3_transA = 'n'; char op_3_transB = 'n'; int op_3_m = 1; int op_3_n = 8; int op_3_k = 16; float op_3_alpha = 1; float op_3_beta = 1; int op_3_lda = 16; int op_3_ldb = 8; std::copy(tensor_dense2bias0bcast, tensor_dense2bias0bcast + 8, tensor_dense2Dense); BLAS::sgemm_(&op_3_transB, &op_3_transA, &op_3_n, &op_3_m, &op_3_k, &op_3_alpha, tensor_dense2kernel0, &op_3_ldb, tensor_dense1Softmax0, &op_3_lda, &op_3_beta, tensor_dense2Dense, &op_3_n); //------ SOFTMAX for (size_t n = 0; n < 1 ; n++){ float sum = 0.; size_t index = 0+ n * 8; for (size_t i = 0; i < 8; i++) { tensor_dense2Softmax0[index + i*1] = std::exp(tensor_dense2Dense[index + i*1]); sum += tensor_dense2Softmax0[index + i*1]; } for (size_t i = 0; i < 8; i++) { tensor_dense2Softmax0[index + i*1] /= sum; } } //--------- Gemm char op_5_transA = 'n'; char op_5_transB = 'n'; int op_5_m = 1; int op_5_n = 4; int op_5_k = 8; float op_5_alpha = 1; float op_5_beta = 1; int op_5_lda = 8; int op_5_ldb = 4; std::copy(tensor_dense3bias0bcast, tensor_dense3bias0bcast + 4, tensor_dense3Dense); BLAS::sgemm_(&op_5_transB, &op_5_transA, &op_5_n, &op_5_m, &op_5_k, &op_5_alpha, tensor_dense3kernel0, &op_5_ldb, tensor_dense2Softmax0, &op_5_lda, &op_5_beta, tensor_dense3Dense, &op_5_n); //------ SOFTMAX for (size_t n = 0; n < 1 ; n++){ float sum = 0.; size_t index = 0+ n * 4; for (size_t i = 0; i < 4; i++) { tensor_dense3Softmax0[index + i*1] = std::exp(tensor_dense3Dense[index + i*1]); sum += tensor_dense3Softmax0[index + i*1]; } for (size_t i = 0; i < 4; i++) { tensor_dense3Softmax0[index + i*1] /= sum; } } //--------- Gemm char op_7_transA = 'n'; char op_7_transB = 'n'; int op_7_m = 1; int op_7_n = 2; int op_7_k = 4; float op_7_alpha = 1; float op_7_beta = 1; int op_7_lda = 4; int op_7_ldb = 2; std::copy(tensor_dense4bias0bcast, tensor_dense4bias0bcast + 2, tensor_dense4Dense); BLAS::sgemm_(&op_7_transB, &op_7_transA, &op_7_n, &op_7_m, &op_7_k, &op_7_alpha, tensor_dense4kernel0, &op_7_ldb, tensor_dense3Softmax0, &op_7_lda, &op_7_beta, tensor_dense4Dense, &op_7_n); for (int id = 0; id < 2 ; id++){ tensor_dense4Sigmoid0[id] = 1 / (1 + std::exp( - tensor_dense4Dense[id])); } std::vector ret (tensor_dense4Sigmoid0, tensor_dense4Sigmoid0 + 2); return ret; } }; } //TMVA_SOFIE_sig_back_model #endif // TMVA_SOFIE_SIG_BACK_MODEL