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 ;
@@ -586,7 +596,7 @@ ucp_device_mem_list_create(ucp_ep_h ep,
586596 }
587597
588598 /* Track memory allocator for later release */
589- status = ucp_device_mem_handle_hash_insert (& mem );
599+ status = ucp_device_mem_handle_hash_insert (& mem , params -> num_elements );
590600 if (status != UCS_OK ) {
591601 uct_mem_free (& mem );
592602 } else {
@@ -596,6 +606,24 @@ ucp_device_mem_list_create(ucp_ep_h ep,
596606 return status ;
597607}
598608
609+ uint32_t
610+ ucp_device_get_mem_list_length (const ucp_device_mem_list_handle_h handle )
611+ {
612+ khiter_t iter ;
613+ uint32_t length ;
614+
615+ ucs_assert (handle != NULL );
616+
617+ ucs_spin_lock (& ucp_device_handle_hash_lock );
618+ iter = kh_get (ucp_device_handle_allocs , & ucp_device_handle_hash , handle );
619+ ucs_assertv_always ((iter != kh_end (& ucp_device_handle_hash )), "handle=%p" ,
620+ handle );
621+ length = kh_value (& ucp_device_handle_hash , iter ).mem_list_length ;
622+ ucs_spin_unlock (& ucp_device_handle_hash_lock );
623+
624+ return length ;
625+ }
626+
599627void ucp_device_mem_list_release (ucp_device_mem_list_handle_h handle )
600628{
601629 uct_allocated_memory_t mem = ucp_device_mem_handle_hash_remove (handle );
0 commit comments