@@ -32,10 +32,10 @@ namespace tsirt = ::tsi::runtime;
3232typedef struct _txe_device_t *txe_device_s;
3333typedef struct _txe_compute_pipeline_state_t *txe_compute_pipeline_state_s;
3434FILE *tsi_op_log_file;
35+ bool runtime_initialized = false ;
3536uint64_t num_of_op;
3637// Centralized TSI runtime initialization - called once globally
3738static void ensure_tsi_runtime_initialized () {
38- static bool runtime_initialized = false ;
3939 if (!runtime_initialized) {
4040 std::string mainProfilerName = " OPU " ;
4141 tsirt::utils::TSIProfiler::initialize ();
@@ -693,6 +693,8 @@ static struct ggml_backend_tsavorite_context *ggml_tsavorite_init(ggml_backend_d
693693static void ggml_tsavorite_free (struct ggml_backend_tsavorite_context *ctx) {
694694 GGML_TSAVORITE_LOG_INFO (" Start %s\n " , __func__);
695695
696+ if (!ctx)
697+ return ;
696698
697699 for (int i = 0 ; i < GGML_TSAVORITE_KERNEL_TYPE_COUNT; ++i) {
698700 if (ctx->kernels [i].pipeline ) {
@@ -724,6 +726,23 @@ static void ggml_tsavorite_free(struct ggml_backend_tsavorite_context *ctx) {
724726 std::cout << tsirt::utils::TSIProfiler::getFormattedResults (
725727 /* truncateFuncNames*/ true )
726728 << std::endl;
729+ sleep (2 );
730+ }
731+
732+ void
733+ ggml_tsi_finalize () {
734+ if (runtime_initialized != true )
735+ return ;
736+ tsi_finalize ();
737+ GGML_TSAVORITE_LOG_INFO (" Start %s\n " , __func__);
738+ tsirt::utils::TSIProfiler::finalize ();
739+ std::cout << " \n OPU Profiling Results:" << std::endl;
740+ std::cout << tsirt::utils::TSIProfiler::getFormattedResults (
741+ /* truncateFuncNames*/ true )
742+ << std::endl;
743+ sleep (2 );
744+ GGML_TSAVORITE_LOG_INFO (" End %s\n " , __func__);
745+ return ;
727746}
728747
729748#if 0
0 commit comments