2121#include "ucp_mm.inl"
2222
2323
24+ typedef struct {
25+ uct_allocated_memory_t mem ;
26+ uint32_t mem_list_length ;
27+ } ucp_device_handle_info_t ;
28+
2429KHASH_TYPE (ucp_device_handle_allocs , ucp_device_mem_list_handle_h ,
25- uct_allocated_memory_t );
30+ ucp_device_handle_info_t );
2631#define ucp_device_handle_hash_key (_handle ) \
2732 kh_int64_hash_func((uintptr_t)(_handle))
2833KHASH_IMPL (ucp_device_handle_allocs , ucp_device_mem_list_handle_h ,
29- uct_allocated_memory_t , 1 , ucp_device_handle_hash_key ,
34+ ucp_device_handle_info_t , 1 , ucp_device_handle_hash_key ,
3035 kh_int64_hash_equal );
3136
3237/* Hash to track handle allocator, used at release time */
@@ -50,11 +55,16 @@ void ucp_device_cleanup(void)
5055}
5156
5257static ucs_status_t
53- ucp_device_mem_handle_hash_insert (uct_allocated_memory_t * mem_handle )
58+ ucp_device_mem_handle_hash_insert (const uct_allocated_memory_t * mem_handle ,
59+ uint32_t mem_list_length )
5460{
5561 ucs_status_t status ;
5662 khiter_t iter ;
5763 int ret ;
64+ ucp_device_handle_info_t info ;
65+
66+ info .mem = * mem_handle ;
67+ info .mem_list_length = mem_list_length ;
5868
5969 ucs_spin_lock (& ucp_device_handle_hash_lock );
6070 iter = kh_put (ucp_device_handle_allocs , & ucp_device_handle_hash ,
@@ -66,7 +76,7 @@ ucp_device_mem_handle_hash_insert(uct_allocated_memory_t *mem_handle)
6676 ucs_error ("handle=%p already found in hash" , mem_handle -> address );
6777 status = UCS_ERR_ALREADY_EXISTS ;
6878 } else {
69- kh_value (& ucp_device_handle_hash , iter ) = * mem_handle ;
79+ kh_value (& ucp_device_handle_hash , iter ) = info ;
7080 status = UCS_OK ;
7181 }
7282
@@ -84,7 +94,7 @@ ucp_device_mem_handle_hash_remove(ucp_device_mem_list_handle_h handle)
8494 iter = kh_get (ucp_device_handle_allocs , & ucp_device_handle_hash , handle );
8595 ucs_assertv_always ((iter != kh_end (& ucp_device_handle_hash )), "handle=%p" ,
8696 handle );
87- mem = kh_value (& ucp_device_handle_hash , iter );
97+ mem = kh_value (& ucp_device_handle_hash , iter ). mem ;
8898 kh_del (ucp_device_handle_allocs , & ucp_device_handle_hash , iter );
8999 ucs_spin_unlock (& ucp_device_handle_hash_lock );
90100 return mem ;
@@ -595,7 +605,7 @@ ucp_device_mem_list_create(ucp_ep_h ep,
595605 }
596606
597607 /* Track memory allocator for later release */
598- status = ucp_device_mem_handle_hash_insert (& mem );
608+ status = ucp_device_mem_handle_hash_insert (& mem , params -> num_elements );
599609 if (status != UCS_OK ) {
600610 uct_mem_free (& mem );
601611 } else {
@@ -605,6 +615,24 @@ ucp_device_mem_list_create(ucp_ep_h ep,
605615 return status ;
606616}
607617
618+ uint32_t
619+ ucp_device_get_mem_list_length (const ucp_device_mem_list_handle_h handle )
620+ {
621+ khiter_t iter ;
622+ uint32_t length ;
623+
624+ ucs_assert (handle != NULL );
625+
626+ ucs_spin_lock (& ucp_device_handle_hash_lock );
627+ iter = kh_get (ucp_device_handle_allocs , & ucp_device_handle_hash , handle );
628+ ucs_assertv_always ((iter != kh_end (& ucp_device_handle_hash )), "handle=%p" ,
629+ handle );
630+ length = kh_value (& ucp_device_handle_hash , iter ).mem_list_length ;
631+ ucs_spin_unlock (& ucp_device_handle_hash_lock );
632+
633+ return length ;
634+ }
635+
608636void ucp_device_mem_list_release (ucp_device_mem_list_handle_h handle )
609637{
610638 uct_allocated_memory_t mem = ucp_device_mem_handle_hash_remove (handle );
0 commit comments