Skip to content

Commit 78115a7

Browse files
authored
Add getter for mem list handle num of elements. (#10975)
1 parent a76c086 commit 78115a7

File tree

4 files changed

+59
-12
lines changed

4 files changed

+59
-12
lines changed

src/ucp/api/device/ucp_device_types.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,22 +63,22 @@ typedef struct ucp_device_mem_list_handle {
6363
/**
6464
* Array of local addresses for the device transfer operations.
6565
*/
66-
void **local_addrs;
66+
void **local_addrs;
6767

6868
/**
6969
* Array of remote addresses for the device transfer operations.
7070
*/
71-
uint64_t *remote_addrs;
72-
71+
uint64_t *remote_addrs;
72+
7373
/**
7474
* Array of lengths of the local buffers in bytes.
7575
*/
76-
size_t *lengths;
76+
size_t *lengths;
7777

7878
/**
7979
* Array of UCT memory element objects.
8080
*/
81-
void *uct_mem_elements;
81+
void *uct_mem_elements;
8282

8383
/**
8484
* local address, remote address, and length arrays, are allocated contiguously.

src/ucp/api/device/ucp_host.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ typedef struct ucp_device_mem_list_params {
152152
*
153153
* @param [in] ep Remote endpoint handle.
154154
* @param [in] params Parameters used to create the handle.
155-
* @param [out] handle Created descriptor list handle.
155+
* @param [out] handle Created descriptors list handle.
156156
*
157157
* @return Error code as defined by @ref ucs_status_t.
158158
* @retval UCS_ERR_NOT_CONNECTED if the endpoint is not connected yet.
@@ -164,6 +164,18 @@ ucp_device_mem_list_create(ucp_ep_h ep,
164164
ucp_device_mem_list_handle_h *handle);
165165

166166

167+
/**
168+
* @ingroup UCP_DEVICE
169+
* @brief Return the number of elements in the descriptors mem list handle.
170+
*
171+
* @param [in] handle Descriptors list handle.
172+
*
173+
* @return Descriptors mem list length.
174+
*/
175+
uint32_t
176+
ucp_device_get_mem_list_length(const ucp_device_mem_list_handle_h handle);
177+
178+
167179
/**
168180
* @ingroup UCP_DEVICE
169181
* @brief Release function for a descriptor list handle.

src/ucp/core/ucp_device.c

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,17 @@
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+
2429
KHASH_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))
2833
KHASH_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

5257
static 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+
608636
void 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);

test/gtest/ucp/test_ucp_device.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,13 @@ UCS_TEST_P(test_ucp_device, create_fail)
334334
EXPECT_EQ(nullptr, handle);
335335
}
336336

337+
UCS_TEST_P(test_ucp_device, get_mem_list_length)
338+
{
339+
constexpr unsigned num_elements = 8;
340+
mem_list list(sender(), receiver(), 1 * UCS_KBYTE, num_elements);
341+
EXPECT_EQ(num_elements, ucp_device_get_mem_list_length(list.handle()));
342+
}
343+
337344
UCP_INSTANTIATE_TEST_CASE_TLS_GPU_AWARE(test_ucp_device, rc_gda, "rc,rc_gda")
338345

339346

0 commit comments

Comments
 (0)