Skip to content

Commit 047b200

Browse files
committed
ggml-hexagon: fix issue which introduced by test-thread-safety in the upstream
1 parent c7c5797 commit 047b200

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

ggml/src/ggml-hexagon/ggml-hexagon.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,7 +1323,10 @@ class hexagon_perf {
13231323
if (g_hexagon_profiler.profiler_get_frame_index() <= g_hexagon_profiler.profiler_get_threshold_count()) {
13241324
const char * devname = ggml_backend_hexagon_get_devname(g_hexagon_appcfg.hexagon_backend);
13251325
if (g_hexagon_appcfg.hexagon_backend != HEXAGON_BACKEND_GGML) {
1326-
devname += 16;
1326+
//add this check for a special scenario: a invalid value passed from user's program
1327+
if (0 != memcmp(devname, "unknown", strlen("unknown"))) {
1328+
devname += 16;
1329+
}
13271330
}
13281331
GGMLHEXAGON_LOG_VERBOSE("inference duration of %s through %s: %lld microseconds",
13291332
_perf_name.c_str(), devname, _duration);
@@ -6402,7 +6405,7 @@ static void ggml_backend_hexagon_device_get_props(ggml_backend_dev_t dev,
64026405
static ggml_backend_t ggml_backend_hexagon_device_init_backend(ggml_backend_dev_t dev, const char * params) {
64036406
GGML_UNUSED(dev);
64046407
GGMLHEXAGON_LOG_DEBUG("enter %s\n", __func__);
6405-
size_t dev_index = 0;
6408+
int dev_index = 0;
64066409

64076410
//case-1: test-backend-ops or other similar scenario: calling ggml_backend_dev_init(dev, reinterpret_cast<const char *>(i)) directly in user's code
64086411
ggmlhexagon_load_cfg();
@@ -6421,6 +6424,11 @@ static ggml_backend_t ggml_backend_hexagon_device_init_backend(ggml_backend_dev_
64216424
GGMLHEXAGON_LOG_VERBOSE("program specified param is not nullptr");
64226425
//user's program calling ggml_backend_hexagon_device_init_backend directly
64236426
dev_index = (int)(intptr_t)params;
6427+
if (dev_index < 0) {
6428+
GGMLHEXAGON_LOG_VERBOSE("it shouldn't happend\n");
6429+
//test-thread-safety might-be running at the moment or a invalid value passed from user's program
6430+
dev_index = 0;
6431+
}
64246432
g_hexagon_appcfg.hexagon_backend = dev_index;
64256433
GGMLHEXAGON_LOG_VERBOSE("program specified dev_index %d\n", dev_index);
64266434
}

scripts/build-run-android.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,9 +469,10 @@ function run_threadsafety()
469469
{
470470
prepare_run_on_phone test-thread-safety
471471

472+
echo "${REMOTE_PATH}/test-thread-safety -np 2 -mg $qnnbackend -m ${GGUF_MODEL_NAME} -p \"hello,world\" -n 256 -ngl 99 "
472473
adb shell "cd ${REMOTE_PATH} \
473474
&& export LD_LIBRARY_PATH=${REMOTE_PATH} \
474-
&& ${REMOTE_PATH}/test-thread-safety -np 2 -mg $qnnbackend -m ${GGUF_MODEL_NAME}"
475+
&& ${REMOTE_PATH}/test-thread-safety -np 1 -mg $qnnbackend -m ${GGUF_MODEL_NAME} -p \"hello,world\" -n 256 -ngl 99 "
475476

476477
}
477478

0 commit comments

Comments
 (0)