Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UCT/CUDA_IPC: Use buffer id to detect VA recylcing #10405

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions src/uct/cuda/cuda_ipc/cuda_ipc_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ static ucs_status_t uct_cuda_ipc_close_memhandle(uct_cuda_ipc_cache_region_t *re
(CUdeviceptr)region->mapped_addr, region->key.b_len));
}
} else if (region->key.ph.handle_type == UCT_CUDA_IPC_KEY_HANDLE_TYPE_MEMPOOL) {
return UCT_CUDADRV_FUNC_LOG_WARN(cuMemPoolDestroy(region->key.ph.pool));
return UCT_CUDADRV_FUNC_LOG_WARN(cuMemFree((CUdeviceptr)region->mapped_addr));
} else
#endif
{
Expand Down Expand Up @@ -480,14 +480,9 @@ UCS_PROFILE_FUNC(ucs_status_t, uct_cuda_ipc_map_memhandle, (key, mapped_addr),
ucs_pgt_region_t *pgt_region;
uct_cuda_ipc_cache_region_t *region;
int ret;
const void *arg1, *arg2;
size_t cmp_size;

#if HAVE_CUDA_FABRIC
cmp_size = sizeof(key->ph.handle);
#else
cmp_size = sizeof(key->ph);
#endif

status = uct_cuda_ipc_get_remote_cache(key->pid, &cache);
if (status != UCS_OK) {
return status;
Expand All @@ -497,9 +492,17 @@ UCS_PROFILE_FUNC(ucs_status_t, uct_cuda_ipc_map_memhandle, (key, mapped_addr),
pgt_region = UCS_PROFILE_CALL(ucs_pgtable_lookup,
&cache->pgtable, key->d_bptr);
if (ucs_likely(pgt_region != NULL)) {
region = ucs_derived_of(pgt_region, uct_cuda_ipc_cache_region_t);
if (memcmp((const void *)&key->ph, (const void *)&region->key.ph,
cmp_size) == 0) {
region = ucs_derived_of(pgt_region, uct_cuda_ipc_cache_region_t);
#if HAVE_CUDA_FABRIC
cmp_size = sizeof(key->ph.buffer_id);
arg1 = (const void*)&key->ph.buffer_id;
arg2 = (const void*)&region->key.ph.buffer_id;
#else
cmp_size = sizeof(key->ph);
arg1 = (const void*)&key->ph;
arg2 = (const void*)&region->key.ph;
#endif
if (memcmp(arg1, arg2, cmp_size) == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it makes sense to update the test to cover this behavior?

/*cache hit */
ucs_trace("%s: cuda_ipc cache hit addr:%p size:%lu region:"
UCS_PGT_REGION_FMT, cache->name, (void *)key->d_bptr,
Expand Down
10 changes: 6 additions & 4 deletions src/uct/cuda/cuda_ipc/cuda_ipc_md.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ uct_cuda_ipc_mem_add_reg(void *addr, uct_cuda_ipc_memh_t *memh,
uct_cuda_ipc_lkey_t *key;
ucs_status_t status;
#if HAVE_CUDA_FABRIC
#define UCT_CUDA_IPC_QUERY_NUM_ATTRS 2
#define UCT_CUDA_IPC_QUERY_NUM_ATTRS 4
CUmemGenericAllocationHandle handle;
CUmemoryPool mempool;
CUpointer_attribute attr_type[UCT_CUDA_IPC_QUERY_NUM_ATTRS];
Expand All @@ -143,6 +143,10 @@ uct_cuda_ipc_mem_add_reg(void *addr, uct_cuda_ipc_memh_t *memh,
attr_data[0] = &legacy_capable;
attr_type[1] = CU_POINTER_ATTRIBUTE_ALLOWED_HANDLE_TYPES;
attr_data[1] = &allowed_handle_types;
attr_type[2] = CU_POINTER_ATTRIBUTE_MEMPOOL_HANDLE;
attr_data[2] = &mempool;
attr_type[3] = CU_POINTER_ATTRIBUTE_BUFFER_ID;
attr_data[3] = &key->ph.buffer_id;

status = UCT_CUDADRV_FUNC_LOG_ERR(
cuPointerGetAttributes(ucs_static_array_size(attr_data), attr_type,
Expand Down Expand Up @@ -185,9 +189,7 @@ uct_cuda_ipc_mem_add_reg(void *addr, uct_cuda_ipc_memh_t *memh,
goto common_path;
}

status = UCT_CUDADRV_FUNC_LOG_ERR(cuPointerGetAttribute(&mempool,
CU_POINTER_ATTRIBUTE_MEMPOOL_HANDLE, (CUdeviceptr)addr));
if ((status != UCS_OK) || (mempool == 0)) {
if (mempool == 0) {
/* cuda_ipc can only handle UCS_MEMORY_TYPE_CUDA, which has to be either
* legacy type, or VMM type, or mempool type. Return error if memory
* does not belong to any of the three types */
Expand Down
1 change: 1 addition & 0 deletions src/uct/cuda/cuda_ipc/cuda_ipc_md.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ typedef struct uct_cuda_ipc_md_handle {
} handle;
CUmemPoolPtrExportData ptr;
CUmemoryPool pool;
unsigned long long buffer_id;
iyastreb marked this conversation as resolved.
Show resolved Hide resolved
} uct_cuda_ipc_md_handle_t;
#else
typedef CUipcMemHandle uct_cuda_ipc_md_handle_t;
Expand Down
Loading