@@ -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,
64026405static 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 }
0 commit comments