Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ggml/include/ggml-tsavorite.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ extern void ggml_tsi_log_tensor_data(tensor_log log_data);
// GGML supports tensors with a maximum rank of 4
#define MEM_REF_DESCRIPTOR_RANK 4
#define TSI_TVU_MEM_ALIGN 128
void
ggml_tsi_finalize();

//
// backend API
Expand Down
21 changes: 20 additions & 1 deletion ggml/src/ggml-tsavorite/ggml-tsavorite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ namespace tsirt = ::tsi::runtime;
typedef struct _txe_device_t *txe_device_s;
typedef struct _txe_compute_pipeline_state_t *txe_compute_pipeline_state_s;
FILE *tsi_op_log_file;
bool runtime_initialized = false;
uint64_t num_of_op;
// Centralized TSI runtime initialization - called once globally
static void ensure_tsi_runtime_initialized() {
static bool runtime_initialized = false;
if (!runtime_initialized) {
std::string mainProfilerName = "OPU ";
tsirt::utils::TSIProfiler::initialize();
Expand Down Expand Up @@ -693,6 +693,8 @@ static struct ggml_backend_tsavorite_context *ggml_tsavorite_init(ggml_backend_d
static void ggml_tsavorite_free(struct ggml_backend_tsavorite_context *ctx) {
GGML_TSAVORITE_LOG_INFO("Start %s\n", __func__);

if (!ctx)
return;

for (int i = 0; i < GGML_TSAVORITE_KERNEL_TYPE_COUNT; ++i) {
if (ctx->kernels[i].pipeline) {
Expand Down Expand Up @@ -724,6 +726,23 @@ static void ggml_tsavorite_free(struct ggml_backend_tsavorite_context *ctx) {
std::cout << tsirt::utils::TSIProfiler::getFormattedResults(
/*truncateFuncNames*/ true)
<< std::endl;
sleep(2);
}

void
ggml_tsi_finalize() {
if (runtime_initialized != true)
return;
tsi_finalize();
GGML_TSAVORITE_LOG_INFO("Start %s\n", __func__);
tsirt::utils::TSIProfiler::finalize();
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;
}

#if 0
Expand Down
2 changes: 2 additions & 0 deletions tools/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <sstream>
#include <string>
#include <vector>
#include <ggml-tsavorite.h>

#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
#include <signal.h>
Expand Down Expand Up @@ -153,6 +154,7 @@ int main(int argc, char ** argv) {

if (model == NULL) {
LOG_ERR("%s: error: unable to load model\n", __func__);
ggml_tsi_finalize();
return 1;
}

Expand Down