@@ -391,7 +391,7 @@ static struct hexagon_appcfg_t g_hexagon_appcfg = {
391391 #if defined(STANDARD_ANDROID_APP)
392392 .runtime_libpath = " /data/data/com.kantvai.kantvplayer/" ,
393393 #else
394- .runtime_libpath = " /data/local/tmp /" ,
394+ .runtime_libpath = " /data/data/com.layla/files/app-data/qnn-inference /" ,
395395 #endif
396396#elif defined(__linux__)
397397 .qnn_runtimelib_path = " /tmp/" ,
@@ -1829,24 +1829,31 @@ static void ggmlhexagon_set_runtime_path(size_t device, const std::string & path
18291829 if ((HEXAGON_BACKEND_QNNNPU == device) || (HWACCEL_CDSP == g_hexagon_appcfg.hwaccel_approach )) {
18301830 std::string lib_runtime_path = path + " :/vendor/dsp/cdsp:/vendor/lib64:/vendor/dsp/dsp:/vendor/dsp/images" ;
18311831 if (0 == setenv (" LD_LIBRARY_PATH" , lib_runtime_path.c_str (), 1 )) {
1832- GGMLHEXAGON_LOG_DEBUG (" setenv LD_LIBRARY_PATH %s successfully" , lib_runtime_path.c_str ());
1832+ GGMLHEXAGON_LOG_INFO (" setenv LD_LIBRARY_PATH %s successfully" , lib_runtime_path.c_str ());
18331833 } else {
18341834 GGMLHEXAGON_LOG_ERROR (" setenv LD_LIBRARY_PATH %s failure" , lib_runtime_path.c_str ());
18351835 }
18361836
18371837 std::string adsp_runtime_path = path + " ;/vendor/dsp/cdsp;/vendor/lib/rfsa/adsp;/system/lib/rfsa/adsp;/vendor/dsp/dsp;/vendor/dsp/images;/dsp" ;
18381838 if (0 == setenv (" ADSP_LIBRARY_PATH" , adsp_runtime_path.c_str (), 1 )) {
1839- GGMLHEXAGON_LOG_DEBUG (" setenv ADSP_LIBRARY_PATH %s successfully" , adsp_runtime_path.c_str ());
1839+ GGMLHEXAGON_LOG_INFO (" setenv ADSP_LIBRARY_PATH %s successfully" , adsp_runtime_path.c_str ());
18401840 } else {
18411841 GGMLHEXAGON_LOG_ERROR (" setenv ADSP_LIBRARY_PATH %s failure" , adsp_runtime_path.c_str ());
18421842 }
1843+
1844+ std::string dsp_runtime_path = path;
1845+ if (0 == setenv (" DSP_LIBRARY_PATH" , dsp_runtime_path.c_str (), 1 )) {
1846+ GGMLHEXAGON_LOG_INFO (" setenv DSP_LIBRARY_PATH %s successfully" , dsp_runtime_path.c_str ());
1847+ } else {
1848+ GGMLHEXAGON_LOG_ERROR (" setenv DSP_LIBRARY_PATH %s failure" , dsp_runtime_path.c_str ());
1849+ }
18431850 } else {
18441851 if (0 == setenv (" LD_LIBRARY_PATH" ,
18451852 (path +
18461853 " :/vendor/dsp/cdsp:/vendor/lib64:/vendor/dsp/dsp:/vendor/dsp/images" ).c_str (),
18471854 1 )) {
18481855 GGMLHEXAGON_LOG_DEBUG (" %s backend setenv successfully\n " ,
1849- ggml_backend_hexagon_get_devname (device));
1856+ ggml_backend_hexagon_get_devname (device));
18501857 } else {
18511858 GGMLHEXAGON_LOG_ERROR (" %s backend setenv failure\n " ,
18521859 ggml_backend_hexagon_get_devname (device));
@@ -3375,10 +3382,10 @@ int qnn_instance::qnn_init(const QnnSaver_Config_t ** saver_config) {
33753382
33763383#if defined(__ANDROID__) || defined(__linux__)
33773384 std::filesystem::path full_path (std::string (g_hexagon_appcfg.runtime_libpath ) + " libcdsprpc.so" );
3378- full_path /= std::filesystem::path (" libcdsprpc.so" ).filename ();
3385+ // full_path /= std::filesystem::path("libcdsprpc.so").filename();
33793386 _rpc_lib_handle = dlopen (full_path.string ().c_str (), RTLD_NOW | RTLD_LOCAL);
33803387 if (nullptr == _rpc_lib_handle) {
3381- GGMLHEXAGON_LOG_WARN (" failed to load %s\n " , full_path.c_str ());
3388+ GGMLHEXAGON_LOG_WARN (" failed to load %s from local file, trying to find in system libraries \n " , full_path.c_str ());
33823389 _rpc_lib_handle = dlopen (" libcdsprpc.so" , RTLD_NOW | RTLD_LOCAL);
33833390 }
33843391#else
@@ -5185,6 +5192,8 @@ static int ggmlhexagon_request_status_notifications(int domain_id, void * contex
51855192}
51865193
51875194static int ggmlhexagon_init_rpcmempool (ggml_backend_hexagon_context * ctx) {
5195+ throw std::runtime_error (" Not implemented. Directly initialising RPC memory pool is not supported right now." );
5196+
51885197 size_t candidate_size = 0 ;
51895198 uint8_t * rpc_buffer = nullptr ;
51905199 size_t probe_slots[] = {1024 , 1536 , 2000 , 2048 };
@@ -5232,6 +5241,8 @@ static int ggmlhexagon_init_rpcmempool(ggml_backend_hexagon_context * ctx) {
52325241}
52335242
52345243static void ggmlhexagon_deinit_rpcmempool (ggml_backend_hexagon_context * ctx) {
5244+ throw std::runtime_error (" Not implemented. Directly initialising RPC memory pool is not supported right now." );
5245+
52355246 if ((g_hexagon_appcfg.hwaccel_approach == HWACCEL_CDSP) && (1 == g_hexagon_appcfg.enable_rpc_ion_mempool )) {
52365247 if (ctx->rpc_mempool ) {
52375248 // deregister rpc memory pool
@@ -6233,7 +6244,11 @@ static ggml_backend_buffer_type_t ggml_backend_hexagon_buffer_type(size_t device
62336244 // cover following special case:
62346245 // toggle backend and forth between cDSP and ggml in a standard Android APP or in
62356246 // a same running process
6236- g_hexagon_appcfg.hexagon_backend = device_index;
6247+
6248+ // TODO: not sure why we need to update the global setting here in the original code
6249+ // it seems this code is reached when we allocate buffers for all devices (including the qnn-cpu device)
6250+ // so if it reaches this code, then it won't use the NPU anymore since the backend config will be updated to use the cpu device
6251+ // g_hexagon_appcfg.hexagon_backend = device_index;
62376252 }
62386253
62396254 static struct ggml_backend_buffer_type ggml_backend_hexagon_buffer_types[GGML_HEXAGON_MAX_DEVICES];
@@ -6284,6 +6299,10 @@ static const char * ggml_backend_hexagon_host_buffer_name(ggml_backend_buffer_t
62846299}
62856300
62866301static void ggml_backend_hexagon_host_buffer_free (ggml_backend_buffer_t buffer) {
6302+ // always use ggml memory management for now
6303+ ggml_aligned_free (buffer->context , 0 );
6304+ return ;
6305+
62876306 if (0 == g_hexagon_appcfg.enable_pinned_memory ) {
62886307 ggml_aligned_free (buffer->context , 0 );
62896308 } else {
@@ -6292,6 +6311,9 @@ static void ggml_backend_hexagon_host_buffer_free(ggml_backend_buffer_t buffer)
62926311}
62936312
62946313static void * ggml_hexagon_host_malloc (ggml_backend_buffer_type_t buft, size_t size) {
6314+ // we always use ggml malloc right now
6315+ return ggml_aligned_malloc (size);
6316+
62956317 if (0 == g_hexagon_appcfg.enable_pinned_memory ) {
62966318 return ggml_aligned_malloc (size);
62976319 } else {
@@ -6664,6 +6686,9 @@ ggml_backend_t ggml_backend_hexagon_init(size_t device, const char * runtime_lib
66646686 ggmlhexagon_set_runtime_path (device, runtime_libpath);
66656687 }
66666688
6689+ // the condition above never be true because our hardcoded runtime_libpath is always the same as the config, so we manually set the library paths here
6690+ ggmlhexagon_set_runtime_path (g_hexagon_appcfg.hexagon_backend , g_hexagon_appcfg.runtime_libpath );
6691+
66676692 if (nullptr != g_hexagon_mgr[device].backend ) {
66686693 GGMLHEXAGON_LOG_DEBUG (" backend %d(%s) already loaded" , device,
66696694 ggml_backend_hexagon_get_devname (device));
0 commit comments