diff --git a/ggml/src/ggml-tsavorite/ggml-tsavorite.cpp b/ggml/src/ggml-tsavorite/ggml-tsavorite.cpp index f6c0977003150..bf24888eb0cc8 100644 --- a/ggml/src/ggml-tsavorite/ggml-tsavorite.cpp +++ b/ggml/src/ggml-tsavorite/ggml-tsavorite.cpp @@ -718,21 +718,26 @@ static void ggml_tsavorite_free(struct ggml_backend_tsavorite_context *ctx) { // delay to allow any file operations to complete for runtime GGML_TSAVORITE_LOG_INFO("Delaying tsi_finalize for 2 sec"); - sleep(2); - tsi_finalize(); - GGML_TSAVORITE_LOG_INFO("End %s\n", __func__); - tsirt::utils::TSIProfiler::finalize(); + if (runtime_initialized == true) { + sleep(2); + runtime_initialized = false; + tsi_finalize(); + tsirt::utils::TSIProfiler::finalize(); + sleep(2); + } std::cout << "\nOPU Profiling Results:" << std::endl; std::cout << tsirt::utils::TSIProfiler::getFormattedResults( /*truncateFuncNames*/ true) << std::endl; - sleep(2); + GGML_TSAVORITE_LOG_INFO("End %s\n", __func__); + return; } void tsi_cleanup() { if (runtime_initialized != true) return; + runtime_initialized = false; tsi_finalize(); GGML_TSAVORITE_LOG_INFO("Start %s\n", __func__); tsirt::utils::TSIProfiler::finalize(); diff --git a/tools/main/main.cpp b/tools/main/main.cpp index 3fbc481dc24ec..7519b9ac9adec 100644 --- a/tools/main/main.cpp +++ b/tools/main/main.cpp @@ -1013,6 +1013,7 @@ int main(int argc, char ** argv) { common_perf_print(ctx, smpl); common_sampler_free(smpl); + ggml_backend_cleanup(); llama_backend_free();