128128// =================================================================================================
129129class qnn_instance ;
130130struct ggml_backend_hexagon_context ;
131- static void ggmlhexagon_probe_dspinfo (ggml_backend_hexagon_context * ctx);
132131
133132#if 0 //def NDEBUG
134133#define GGMLHEXAGON_DEBUG 0
@@ -852,6 +851,7 @@ static void ggmlhexagon_get_timestring(char * p_currenttime) {
852851#endif
853852}
854853
854+ static void ggmlhexagon_probe_dspinfo (ggml_backend_hexagon_context * ctx);
855855static void ggmlhexagon_print_running_timestamp (ggml_backend_hexagon_context * ctx) {
856856 char timestamp[GGMLHEXAGON_TMPBUF_LEN];
857857 memset (timestamp, 0 , GGMLHEXAGON_TMPBUF_LEN);
@@ -1205,7 +1205,7 @@ static size_t ggmlhexagon_get_system_total_memory_in_bytes() {
12051205
12061206 return pages * page_size;
12071207#else
1208- // FIXME : Snapdragon based WoA(Windows on ARM)
1208+ // TODO : Snapdragon based WoA(Windows on ARM)
12091209 MEMORYSTATUSEX statex;
12101210 statex.dwLength = sizeof (statex);
12111211 if (GlobalMemoryStatusEx (&statex)) {
@@ -1228,7 +1228,7 @@ static size_t ggmlhexagon_get_system_free_memory_in_bytes() {
12281228
12291229 return avail_pages * page_size;
12301230#else
1231- // FIXME : Snapdragon based WoA(Windows on ARM)
1231+ // TODO : Snapdragon based WoA(Windows on ARM)
12321232 MEMORYSTATUSEX statex;
12331233 statex.dwLength = sizeof (statex);
12341234 if (GlobalMemoryStatusEx (&statex)) {
@@ -1561,7 +1561,7 @@ static char * ggmlqnn_strndup(const char * source, size_t maxlen) {
15611561#if defined(__ANDROID__) || defined(__linux__)
15621562 return strndup (source, maxlen);
15631563#else
1564- // FIXME :behaviour is not exactly same to Android&Linux
1564+ // TODO :behaviour is not exactly same to Android&Linux
15651565 GGML_UNUSED (maxlen);
15661566 return strdup (source);
15671567#endif
@@ -3163,7 +3163,7 @@ int qnn_instance::htp_init_perfinfra() {
31633163 htp_perfinfra->createPowerConfigId (device_id, core_id, &power_configid);
31643164 _qnn_htp_perfinfra = htp_perfinfra;
31653165 _qnn_htp_powerconfig_id = power_configid;
3166- // FIXME :hardcode to 0 and 0 although it's correct
3166+ // TODO :hardcode to 0 and 0 although it's correct
31673167 _qnn_htp_device_id = device_id;
31683168 _qnn_htp_core_id = core_id;
31693169
@@ -3178,7 +3178,7 @@ void qnn_instance::htp_probe_rpc_meminfo() {
31783178 for (size_t idx = 0 ; idx < probe_counts; idx++) {
31793179 rpc_buffer = static_cast <uint8_t *>(alloc_rpcmem_internal (probe_slots[idx] * SIZE_IN_MB, 4 ));
31803180 if (nullptr == rpc_buffer) {
3181- GGMLHEXAGON_LOG_DEBUG (" alloc rpcmem %d (MB) failure, %s\n " , probe_slots[idx], strerror (errno));
3181+ GGMLHEXAGON_LOG_DEBUG (" alloc rpcmem %d (MB) failure during probe rpc memory info, reason: %s\n " , probe_slots[idx], strerror (errno));
31823182 break ;
31833183 } else {
31843184 candidate_size = probe_slots[idx];
@@ -4694,7 +4694,7 @@ static void ggmlhexagon_init_rpcmempool(ggml_backend_hexagon_context * ctx) {
46944694 for (size_t idx = 0 ; idx < probe_counts; idx++) {
46954695 rpc_buffer = static_cast <uint8_t *>(rpcmem_alloc (RPCMEM_HEAP_ID_SYSTEM, RPCMEM_DEFAULT_FLAGS, (probe_slots[idx] * SIZE_IN_MB)));
46964696 if (nullptr == rpc_buffer) {
4697- GGMLHEXAGON_LOG_DEBUG (" alloc rpcmem %d (MB) failure, %s\n " , probe_slots[idx], strerror (errno));
4697+ GGMLHEXAGON_LOG_DEBUG (" alloc rpcmem %d (MB) failure during probe rpc memory info, reason: %s\n " , probe_slots[idx], strerror (errno));
46984698 break ;
46994699 } else {
47004700 candidate_size = probe_slots[idx];
@@ -4708,13 +4708,13 @@ static void ggmlhexagon_init_rpcmempool(ggml_backend_hexagon_context * ctx) {
47084708 GGMLHEXAGON_LOG_INFO (" capacity of rpc memory %d MB" , ctx->rpc_mempool_capacity / SIZE_IN_MB);
47094709
47104710 if ((g_hexagon_appcfg.hwaccel_approach == HWACCEL_CDSP) && (1 == g_hexagon_appcfg.enable_rpc_ion_mempool )) {
4711- // FIXME: reasonable rpc memory pool size
4711+ // FIXME: reasonable rpc memory pool size through a better approach rather than hardcoded size
47124712 ctx->rpc_mempool_len = 1024 * SIZE_IN_MB;
47134713 if (ctx->rpc_mempool_len > ctx->rpc_mempool_capacity ) {
47144714 GGMLHEXAGON_LOG_WARN (" rpc mempool is too big" );
47154715 return ;
47164716 }
4717- // FIXME: use ion memory pool currently, it seems there is unknown bug with DMA memory pool
4717+ // FIXME: it seems there is unknown issue with DMA memory pool
47184718 ctx->rpc_mempool = rpcmem_alloc (RPCMEM_HEAP_ID_SYSTEM, RPCMEM_DEFAULT_FLAGS,
47194719 ctx->rpc_mempool_len );
47204720 if (nullptr == ctx->rpc_mempool ) {
@@ -4831,11 +4831,11 @@ static int ggmlhexagon_init_dsp(ggml_backend_hexagon_context * ctx) {
48314831 if (nullptr == ctx)
48324832 return 1 ;
48334833 GGMLHEXAGON_LOG_INFO (" init Hexagon DSP with backend %d(%s)" , ctx->device , ggml_backend_hexagon_get_devname (ctx->device ));
4834- if (nullptr != ctx->rpc_mempool ) {
4834+ if (0 != ctx->ggmlop_handle ) {
48354835 GGMLHEXAGON_LOG_DEBUG (" already init Hexagon DSP with backend %d(%s)" , ctx->device , ggml_backend_hexagon_get_devname (ctx->device ));
48364836 return 0 ;
48374837 }
4838- ctx->ggmlop_handle = - 1 ;
4838+ ctx->ggmlop_handle = 0 ;
48394839
48404840 if (-1 == domain_id) {
48414841 if (nullptr != domain_type) {
@@ -4936,10 +4936,11 @@ static int ggmlhexagon_init_dsp(ggml_backend_hexagon_context * ctx) {
49364936 hexagon_error = ggmlop_dsp_open (ggmlop_domain_uri, &ctx->ggmlop_handle );
49374937 if (AEE_SUCCESS == hexagon_error) {
49384938 GGMLHEXAGON_LOG_INFO (" succeed to open domain %d(%s)" , domain_id, ggmlhexagon_get_dsp_name (domain_id));
4939- GGMLHEXAGON_LOG_INFO (" only support offload GGML_OP_ADD and GGML_OP_MUL_MAT to cDSP currently" );
4939+ // FIXME: only support offload fp32 GGML_OP_MUL_MAT to cDSP
4940+ GGMLHEXAGON_LOG_INFO (" only support offload fp32 GGML_OP_ADD and fp32 GGML_OP_MUL_MAT to cDSP currently" );
49404941 ggmlhexagon_probe_dspinfo (ctx);
49414942 ggmlop_dsp_setclocks (ctx->ggmlop_handle , HAP_DCVS_VCORNER_TURBO_PLUS, 40 , 1 );
4942- ggmlhexagon_set_rpc_latency (ctx->ggmlop_handle , RPC_POLL_QOS, 1000 );
4943+ ggmlhexagon_set_rpc_latency (ctx->ggmlop_handle , RPC_POLL_QOS, 100 );
49434944 ggmlhexagon_init_rpcmempool (ctx);
49444945 } else {
49454946 GGMLHEXAGON_LOG_INFO (" error 0x%x: failed to open domain %d(%s)" , hexagon_error, domain_id,
@@ -5455,17 +5456,29 @@ static size_t ggml_backend_hexagon_buffer_type_get_alignment(ggml_backend_buffer
54555456}
54565457
54575458static size_t ggml_backend_hexagon_buffer_type_get_max_size (ggml_backend_buffer_type_t buft) {
5458- GGML_UNUSED (buft);
5459-
5460- return (2 * (1 << 29 ));
5459+ struct ggml_backend_hexagon_context * ctx = static_cast <ggml_backend_hexagon_context *>(buft->context );
5460+ GGML_ASSERT (nullptr != ctx);
5461+ if ((HWACCEL_CDSP == g_hexagon_appcfg.hwaccel_approach ) && (1 == g_hexagon_appcfg.enable_rpc_ion_mempool )) {
5462+ GGML_ASSERT (ctx->rpc_mempool_len > (8 * SIZE_IN_MB));
5463+ return ctx->rpc_mempool_len - (8 * SIZE_IN_MB);
5464+ } else {
5465+ // TODO:this is an experimental value for LLM models
5466+ return (1024 * SIZE_IN_MB);
5467+ }
54615468}
54625469
54635470static bool ggml_backend_buft_is_hexagon (ggml_backend_buffer_type_t buft) {
54645471 return buft->iface .get_name == ggml_backend_hexagon_buffer_type_name;
54655472}
54665473
54675474static bool ggml_backend_hexagon_buffer_is_host (ggml_backend_buffer_type_t buft) {
5468- GGML_UNUSED (buft);
5475+ struct ggml_backend_hexagon_context * ctx = static_cast <ggml_backend_hexagon_context *>(buft->context );
5476+ GGML_ASSERT (nullptr != ctx);
5477+ if ((HWACCEL_CDSP == g_hexagon_appcfg.hwaccel_approach ) && (1 == g_hexagon_appcfg.enable_rpc_ion_mempool )) {
5478+ // FIXME: return false here is make sense in this scenario although this is not key-point at the moment
5479+ // fix it after solving other urgent tasks
5480+ // return false;
5481+ }
54695482 return true ;
54705483}
54715484
0 commit comments