1515 * section-6 implementation of hwaccel approach through QNN: offload ggmlop to QNN
1616 * section-7 cDSP helper function
1717 * section-8 implementation of ggml-hexagon backend according to specification in ggml backend subsystem
18+ * section-9 implementations of various stub methods for libcdsprpc.so
1819 *
1920 * currently provide following ggml op' implementation through QNN:
2021 * - GGML_OP_ADD/GGML_OP_SUB/GGML_OP_MUL/GGML_OP_DIV/GGML_OP_LOG/GGML_OP_SQRT:
@@ -5464,6 +5465,54 @@ static int ggmlhexagon_init_dsp(ggml_backend_hexagon_context * ctx) {
54645465 goto bail;
54655466 }
54665467
5468+ {
5469+ uint32_t dsp_version = 0 ;
5470+ ggmlhexagon_get_hvx_arch_ver (ctx->domain_id , &dsp_version);
5471+
5472+ if (dsp_version == 0x68 || dsp_version == 0x69 || dsp_version == 0x73 ||
5473+ dsp_version == 0x75 || dsp_version == 0x79 ) {
5474+
5475+ // delete the file $(g_hexagon_appcfg.runtime_libpath)/libggmlop-skel.so if it exists
5476+ std::string filepath = std::string (g_hexagon_appcfg.runtime_libpath ) + " /libggmlop-skel.so" ;
5477+ if (std::filesystem::exists (filepath)) {
5478+ std::filesystem::remove (filepath);
5479+ }
5480+
5481+ // detect the htp arch number
5482+ size_t htp_arch = ggmlhexagon_htparch_hex_to_decimal (dsp_version);
5483+
5484+ // find the file $(g_hexagon_appcfg.runtime_libpath)/libggmlop-skelV$(htp_arch).so if it exists
5485+ // copy and rename it to libggmlop-skel.so in the same folder
5486+
5487+ // Construct file paths
5488+ std::string source_filename = std::string (" libggmlop-skelV" ) + std::to_string (htp_arch) + " .so" ;
5489+ std::string source_path = std::string (g_hexagon_appcfg.runtime_libpath ) + " /" + source_filename;
5490+ std::string dest_path = std::string (g_hexagon_appcfg.runtime_libpath ) + " /libggmlop-skel.so" ;
5491+
5492+ // Check if source file exists
5493+ if (std::filesystem::exists (source_path)) {
5494+ // Copy and rename the file
5495+ try {
5496+ std::filesystem::copy_file (
5497+ source_path,
5498+ dest_path,
5499+ std::filesystem::copy_options::overwrite_existing
5500+ );
5501+ } catch (const std::filesystem::filesystem_error& e) {
5502+ // Handle error
5503+ GGMLHEXAGON_LOG_WARN (" Error copying file: %s" , e.what ());
5504+ goto bail;
5505+ }
5506+ } else {
5507+ GGMLHEXAGON_LOG_WARN (" Error finding skel library: %s" , source_path.c_str ());
5508+ goto bail;
5509+ }
5510+ } else {
5511+ GGMLHEXAGON_LOG_WARN (" error: dsp arch version 0x%x is not supported" , dsp_version);
5512+ goto bail;
5513+ }
5514+ }
5515+
54675516 ggmlop_domain_uri_len = strlen (ggmlop_URI) + MAX_DOMAIN_NAMELEN;
54685517 ggmlop_domain_uri = (char *)malloc (ggmlop_domain_uri_len);
54695518 snprintf (ggmlop_domain_uri, ggmlop_domain_uri_len, " %s%s" , ggmlop_URI, uri);
@@ -5473,7 +5522,9 @@ static int ggmlhexagon_init_dsp(ggml_backend_hexagon_context * ctx) {
54735522 GGMLHEXAGON_LOG_INFO (" succeed to open domain %d(%s)" , domain_id, ggmlhexagon_get_dsp_name (domain_id));
54745523 // FIXME: only support offload fp32 GGML_OP_MUL_MAT to cDSP
54755524 GGMLHEXAGON_LOG_INFO (" only support offload fp32 GGML_OP_ADD and fp32 GGML_OP_MUL_MAT to cDSP currently" );
5525+
54765526 ggmlhexagon_probe_dspinfo (ctx);
5527+
54775528 // FIXME: re-use this function to pass thread_counts info to code on cDSP side before fully understand qidl mechanism
54785529 ggmlop_dsp_setclocks (ctx->ggmlop_handle , HAP_DCVS_VCORNER_TURBO_PLUS, 40 , 1 , g_hexagon_appcfg.thread_counts );
54795530 ggmlhexagon_set_rpc_latency (ctx->ggmlop_handle , RPC_POLL_QOS, 100 );
0 commit comments