@@ -5065,11 +5065,15 @@ static int ggmlhexagon_request_status_notifications(int domain_id, void * contex
50655065 return hexagon_error;
50665066}
50675067
5068- static void ggmlhexagon_init_rpcmempool (ggml_backend_hexagon_context * ctx) {
5068+ static int ggmlhexagon_init_rpcmempool (ggml_backend_hexagon_context * ctx) {
50695069 size_t candidate_size = 0 ;
50705070 uint8_t * rpc_buffer = nullptr ;
50715071 size_t probe_slots[] = {1024 , 1536 , 2000 , 2048 };
50725072 size_t probe_counts = sizeof (probe_slots) / sizeof (size_t );
5073+
5074+ if (nullptr == ctx)
5075+ return 1 ;
5076+
50735077 for (size_t idx = 0 ; idx < probe_counts; idx++) {
50745078 rpc_buffer = static_cast <uint8_t *>(rpcmem_alloc (RPCMEM_HEAP_ID_SYSTEM, RPCMEM_DEFAULT_FLAGS, (probe_slots[idx] * SIZE_IN_MB)));
50755079 if (nullptr == rpc_buffer) {
@@ -5087,18 +5091,15 @@ static void ggmlhexagon_init_rpcmempool(ggml_backend_hexagon_context * ctx) {
50875091 GGMLHEXAGON_LOG_INFO (" capacity of rpc memory %d MiB" , ctx->rpc_mempool_capacity / SIZE_IN_MB);
50885092
50895093 if ((g_hexagon_appcfg.hwaccel_approach == HWACCEL_CDSP) && (1 == g_hexagon_appcfg.enable_rpc_ion_mempool )) {
5090- // FIXME: reasonable rpc memory pool size through a better approach rather than hardcoded size
5091- ctx->rpc_mempool_len = 1024 * SIZE_IN_MB;
5092- if (ctx->rpc_mempool_len > ctx->rpc_mempool_capacity ) {
5093- GGMLHEXAGON_LOG_WARN (" rpc mempool is too big" );
5094- return ;
5095- }
5094+ GGML_ASSERT (ctx->rpc_mempool_capacity > (8 * SIZE_IN_MB));
5095+ ctx->rpc_mempool_len = ctx->rpc_mempool_capacity - (8 * SIZE_IN_MB);
5096+
50965097 // FIXME: it seems there is unknown issue with another ION memory pool
50975098 ctx->rpc_mempool = rpcmem_alloc (RPCMEM_HEAP_ID_SYSTEM, RPCMEM_DEFAULT_FLAGS,
50985099 ctx->rpc_mempool_len );
50995100 if (nullptr == ctx->rpc_mempool ) {
51005101 GGMLHEXAGON_LOG_WARN (" alloc rpc memorypool %d failed" , ctx->rpc_mempool_len );
5101- return ;
5102+ return 2 ;
51025103 } else {
51035104 GGMLHEXAGON_LOG_DEBUG (" alloc rpc memorypool %p successfully %ld(%d MiB)" ,
51045105 ctx->rpc_mempool , ctx->rpc_mempool_len ,
@@ -5109,7 +5110,7 @@ static void ggmlhexagon_init_rpcmempool(ggml_backend_hexagon_context * ctx) {
51095110 remote_register_buf (ctx->rpc_mempool , ctx->rpc_mempool_len , ctx->rpc_mempool_handle );
51105111 }
51115112
5112- return ;
5113+ return 0 ;
51135114}
51145115
51155116static void ggmlhexagon_deinit_rpcmempool (ggml_backend_hexagon_context * ctx) {
@@ -5316,7 +5317,11 @@ static int ggmlhexagon_init_dsp(ggml_backend_hexagon_context * ctx) {
53165317 ggmlhexagon_probe_dspinfo (ctx);
53175318 ggmlop_dsp_setclocks (ctx->ggmlop_handle , HAP_DCVS_VCORNER_TURBO_PLUS, 40 , 1 );
53185319 ggmlhexagon_set_rpc_latency (ctx->ggmlop_handle , RPC_POLL_QOS, 100 );
5319- ggmlhexagon_init_rpcmempool (ctx);
5320+ int result = ggmlhexagon_init_rpcmempool (ctx);
5321+ if (0 != result) {
5322+ GGMLHEXAGON_LOG_INFO (" failed to init rpc mempool" );
5323+ goto bail;
5324+ }
53205325 } else {
53215326 GGMLHEXAGON_LOG_INFO (" error 0x%x: failed to open domain %d(%s)" , hexagon_error, domain_id,
53225327 ggmlhexagon_get_dsp_name (domain_id));
0 commit comments