@@ -2250,8 +2250,8 @@ class qnn_instance {
22502250 pfn_rpc_mem_deinit _pfn_rpc_mem_deinit;
22512251 std::unordered_map<void *, void *> _rpcmem_store_map;
22522252 std::unordered_map<void *, size_t > _rpcmem_usage_map;
2253- size_t _rpcmem_usage = 0 ; // mempool usage in Mbytes
2254- size_t _rpcmem_capacity = 512 ; // mempool size in Mbytes
2253+ size_t _rpcmem_usage = 0 ; // mempool usage in bytes
2254+ size_t _rpcmem_capacity = 0 ; // mempool size in bytes
22552255
22562256 std::string _graph_name;
22572257 HEXAGONBackend _device_id;
@@ -2289,8 +2289,8 @@ void * qnn_instance::alloc_rpcmem_internal(size_t bytes, size_t alignment) {
22892289}
22902290
22912291void * qnn_instance::alloc_rpcmem (size_t bytes, size_t alignment) {
2292- if (_rpcmem_usage > (_rpcmem_capacity - 8 )) { // reserve 8Mbytes in rpc mempool
2293- GGMLHEXAGON_LOG_WARN (" rpc mempool capcaity : %d MB, usage: %d MB" , _rpcmem_capacity, _rpcmem_usage);
2292+ if (_rpcmem_usage > (_rpcmem_capacity - ( 8 * SIZE_IN_MB) )) { // reserve 8Mbytes in rpc mempool
2293+ GGMLHEXAGON_LOG_WARN (" rpc mempool capacity : %d MB, usage: %d MB" , _rpcmem_capacity / SIZE_IN_MB , _rpcmem_usage / SIZE_IN_MB );
22942294 return nullptr ;
22952295 }
22962296
@@ -2299,9 +2299,7 @@ void * qnn_instance::alloc_rpcmem(size_t bytes, size_t alignment) {
22992299 return nullptr ;
23002300 _rpcmem_usage_map.insert (std::pair<void *, size_t >(aligned_buf, bytes));
23012301
2302- size_t rpcmem_usage_in_bytes = _rpcmem_usage * (1 << 20 );
2303- rpcmem_usage_in_bytes += bytes;
2304- _rpcmem_usage = rpcmem_usage_in_bytes / ( 1 << 20 );
2302+ _rpcmem_usage += bytes;
23052303 return aligned_buf;
23062304}
23072305
@@ -2319,9 +2317,7 @@ void qnn_instance::free_rpcmem(void * buf) {
23192317 void * rpcbuffer = it->first ;
23202318 if (buf == rpcbuffer) {
23212319 rpcbuffer_size = it->second ;
2322- size_t rpcmem_usage_in_bytes = _rpcmem_usage * (1 << 20 );
2323- rpcmem_usage_in_bytes -= rpcbuffer_size;
2324- _rpcmem_usage = rpcmem_usage_in_bytes / ( 1 << 20 );
2320+ _rpcmem_usage -= rpcbuffer_size;
23252321 }
23262322 }
23272323 if (rpcbuffer_size != 0 ) {
@@ -3191,11 +3187,11 @@ void qnn_instance::htp_probe_rpc_meminfo() {
31913187 }
31923188 }
31933189 if (candidate_size > _rpcmem_capacity)
3194- _rpcmem_capacity = candidate_size;
3190+ _rpcmem_capacity = candidate_size * SIZE_IN_MB ;
31953191
31963192 free_rpcmem ();
31973193 _rpcmem_usage = 0 ;
3198- GGMLHEXAGON_LOG_INFO (" capacity of rpc ion memory %d MB\n " , _rpcmem_capacity);
3194+ GGMLHEXAGON_LOG_INFO (" capacity of rpc ion memory %d MB\n " , _rpcmem_capacity / SIZE_IN_MB );
31993195}
32003196
32013197void qnn_instance::htp_print_info () {
@@ -5579,21 +5575,16 @@ static void ggml_backend_hexagon_device_get_memory(ggml_backend_dev_t dev, size_
55795575 size_t rpc_ion_memsize = 0 ;
55805576 size_t rpc_ion_usage = 0 ;
55815577 if (HWACCEL_CDSP != g_hexagon_appcfg.hwaccel_approach ) {
5582- // TODO: uniform rpc_ion_memsize and rpc_ion_usage between HWACCEL_CDSP and HWACCEL_QNN
55835578 rpc_ion_memsize = ctx->instance ->get_rpcmem_capacity ();
55845579 rpc_ion_usage = ctx->instance ->get_rpcmem_usage ();
5585- *total = rpc_ion_memsize * SIZE_IN_MB;
5586- *free = (rpc_ion_memsize - rpc_ion_usage) * SIZE_IN_MB;
5587- GGMLHEXAGON_LOG_DEBUG (" rpc memsize %d M" , rpc_ion_memsize);
5588- GGMLHEXAGON_LOG_DEBUG (" rpc usage %d M\n\n " , rpc_ion_usage);
55895580 } else {
55905581 rpc_ion_memsize = ctx->rpc_mempool_capacity ;
5591- rpc_ion_usage = ctx->rpc_mempool_usage ;
5592- *total = rpc_ion_memsize;
5593- *free = (rpc_ion_memsize - rpc_ion_usage);
5594- GGMLHEXAGON_LOG_DEBUG (" rpc memsize %d M" , rpc_ion_memsize / SIZE_IN_MB);
5595- GGMLHEXAGON_LOG_DEBUG (" rpc usage %d M\n\n " , rpc_ion_usage / SIZE_IN_MB);
5582+ rpc_ion_usage = ctx->rpc_mempool_usage ;
55965583 }
5584+ *total = rpc_ion_memsize;
5585+ *free = (rpc_ion_memsize - rpc_ion_usage);
5586+ GGMLHEXAGON_LOG_DEBUG (" rpc memsize %d M" , rpc_ion_memsize / SIZE_IN_MB);
5587+ GGMLHEXAGON_LOG_DEBUG (" rpc usage %d M\n\n " , rpc_ion_usage / SIZE_IN_MB);
55975588 }
55985589}
55995590
0 commit comments