Skip to content

Commit f51b53d

Browse files
author
zhouwg
committed
ggml-hexagon: try to make ggml-hexagon backend works fine in a standard Android APP
1 parent 7079528 commit f51b53d

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,21 +1390,18 @@ static void * ggmlhexagon_type_trait(ggml_backend_hexagon_context * ctx, ggml_te
13901390
static void ggmlhexagon_set_runtime_path(size_t device, const std::string & path) {
13911391
#if defined(__ANDROID__)
13921392
if ((HEXAGON_BACKEND_QNNNPU == device) || (HWACCEL_CDSP == g_hexagon_appcfg.hwaccel_approach)) {
1393-
if (0 == setenv("LD_LIBRARY_PATH",
1394-
(path +
1395-
":/vendor/dsp/cdsp:/vendor/lib64:/vendor/dsp/dsp:/vendor/dsp/images").c_str(),
1396-
1)) {
1397-
GGMLHEXAGON_LOG_DEBUG("HEXAGON_BACKEND_QNNNPU / HEXAGON_BACKEND_CDSP setenv successfully");
1393+
std::string lib_runtime_path = path + ":/vendor/dsp/cdsp:/vendor/lib64:/vendor/dsp/dsp:/vendor/dsp/images";
1394+
if (0 == setenv("LD_LIBRARY_PATH", lib_runtime_path.c_str(), 1)) {
1395+
GGMLHEXAGON_LOG_DEBUG("HEXAGON_BACKEND_QNNNPU / HEXAGON_BACKEND_CDSP setenv %s successfully", lib_runtime_path.c_str());
13981396
} else {
1399-
GGMLHEXAGON_LOG_ERROR("HEXAGON_BACKEND_QNNNPU / HEXAGON_BACKEND_CDSP setenv failure");
1397+
GGMLHEXAGON_LOG_ERROR("HEXAGON_BACKEND_QNNNPU / HEXAGON_BACKEND_CDSP setenv %s failure", lib_runtime_path.c_str());
14001398
}
1401-
if (0 == setenv("ADSP_LIBRARY_PATH",
1402-
(path +
1403-
";/vendor/dsp/cdsp;/vendor/lib/rfsa/adsp;/system/lib/rfsa/adsp;/vendor/dsp/dsp;/vendor/dsp/images;/dsp").c_str(),
1404-
1)) {
1405-
GGMLHEXAGON_LOG_DEBUG("HEXAGON_BACKEND_QNNNPU / HEXAGON_BACKEND_CDSP setenv successfully");
1399+
1400+
std::string adsp_runtime_path = path + ";/vendor/dsp/cdsp;/vendor/lib/rfsa/adsp;/system/lib/rfsa/adsp;/vendor/dsp/dsp;/vendor/dsp/images;/dsp";
1401+
if (0 == setenv("ADSP_LIBRARY_PATH", adsp_runtime_path.c_str(), 1)) {
1402+
GGMLHEXAGON_LOG_DEBUG("HEXAGON_BACKEND_QNNNPU / HEXAGON_BACKEND_CDSP setenv %s successfully", adsp_runtime_path.c_str());
14061403
} else {
1407-
GGMLHEXAGON_LOG_ERROR("HEXAGON_BACKEND_QNNNPU / HEXAGON_BACKEND_CDSP setenv failure");
1404+
GGMLHEXAGON_LOG_ERROR("HEXAGON_BACKEND_QNNNPU / HEXAGON_BACKEND_CDSP setenv %s failure", adsp_runtime_path.c_str());
14081405
}
14091406
} else {
14101407
if (0 == setenv("LD_LIBRARY_PATH",
@@ -1469,6 +1466,11 @@ static void ggmlhexagon_load_cfg() {
14691466
} else {
14701467
g_hexagon_appcfg.precision_mode = 0;
14711468
}
1469+
1470+
if (HWACCEL_CDSP == g_hexagon_appcfg.hwaccel_approach) {
1471+
ggmlhexagon_set_runtime_path(HEXAGON_BACKEND_CDSP, g_hexagon_appcfg.runtimelib_path);
1472+
}
1473+
14721474
initialized = true;
14731475
}
14741476

@@ -6070,8 +6072,6 @@ ggml_backend_t ggml_backend_hexagon_init(size_t device, const char * qnn_lib_pat
60706072
return nullptr;
60716073
}
60726074

6073-
std::string path = qnn_lib_path;
6074-
ggmlhexagon_set_runtime_path(device, path);
60756075
if (nullptr != g_hexagon_mgr[device].backend) {
60766076
GGMLHEXAGON_LOG_DEBUG("backend %d(%s) already loaded", device,
60776077
ggml_backend_hexagon_get_devname(device));

0 commit comments

Comments
 (0)