Skip to content

Commit 461411f

Browse files
authored
Merge pull request #65 from tsisw/FIR-1032
@FIR-1032 - LLama.cpp: wrong model cause crash the llama-cli process
2 parents 22d8b00 + 06fb3df commit 461411f

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

ggml/include/ggml-tsavorite.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ extern void ggml_tsi_log_tensor_data(tensor_log log_data);
214214
// GGML supports tensors with a maximum rank of 4
215215
#define MEM_REF_DESCRIPTOR_RANK 4
216216
#define TSI_TVU_MEM_ALIGN 128
217+
void
218+
ggml_tsi_finalize();
217219

218220
//
219221
// backend API

ggml/src/ggml-tsavorite/ggml-tsavorite.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ namespace tsirt = ::tsi::runtime;
3232
typedef struct _txe_device_t *txe_device_s;
3333
typedef struct _txe_compute_pipeline_state_t *txe_compute_pipeline_state_s;
3434
FILE *tsi_op_log_file;
35+
bool runtime_initialized = false;
3536
uint64_t num_of_op;
3637
// Centralized TSI runtime initialization - called once globally
3738
static 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
693693
static 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 << "\nOPU 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

tools/main/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <sstream>
1515
#include <string>
1616
#include <vector>
17+
#include <ggml-tsavorite.h>
1718

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

154155
if (model == NULL) {
155156
LOG_ERR("%s: error: unable to load model\n", __func__);
157+
ggml_tsi_finalize();
156158
return 1;
157159
}
158160

0 commit comments

Comments
 (0)