Repository navigation
UCP/API: Endpoint parameter controlling remote key resources. #11870
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
Changes from all commits
f57426f
15c130f
8905f3a
6935920
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -297,14 +297,20 @@ enum ucp_ep_params_flags_field { | |
| send to a particular | ||
| remote endpoint, for | ||
| example stream */ | ||
| UCP_EP_PARAMS_FLAGS_SEND_CLIENT_ID = UCS_BIT(2) /**< Send client id | ||
| UCP_EP_PARAMS_FLAGS_SEND_CLIENT_ID = UCS_BIT(2), /**< Send client id | ||
| when connecting to remote | ||
| socket address as part of the | ||
| connection request payload. | ||
| On the remote side value | ||
| can be obtained from | ||
| @ref ucp_conn_request_h using | ||
| @ref ucp_conn_request_query */ | ||
| /** | ||
| * Resources used by remote keys unpacked (see @ref ucp_ep_rkey_unpack) on | ||
| * this endpoint have their lifetime bound to the remote key, and are | ||
| * released once it is destroyed (see @ref ucp_rkey_destroy). | ||
| */ | ||
| UCP_EP_PARAMS_FLAGS_RKEY_BOUND_LIFETIME = UCS_BIT(3) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AFAIU it is not bound to the rkey. We release it when cache refcount is zero not necessarily when we destroy the rkey. |
||
| }; | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -976,6 +976,10 @@ UCS_PROFILE_FUNC(ucs_status_t, ucp_ep_rkey_unpack_internal, | |
|
|
||
| unpack_params.field_mask = UCT_RKEY_UNPACK_FIELD_SYS_DEVICE; | ||
| unpack_params.sys_device = sys_dev; | ||
| if (ep->ext->flags & UCP_EP_EXT_FLAG_RKEY_BOUND_LIFETIME) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The more I think about it the more I think we should introduce |
||
| unpack_params.field_mask |= UCT_RKEY_UNPACK_FIELD_FLAGS; | ||
| unpack_params.flags = UCT_RKEY_UNPACK_FLAG_BOUND_LIFETIME; | ||
| } | ||
|
|
||
| /* Go over remote MD indices and unpack rkey of each UCT MD */ | ||
| rkey_index = 0; /* Index of the rkey in the array */ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,7 @@ | |
| typedef struct { | ||
| const void *mapped_addr; | ||
| CUdevice cu_dev; | ||
| int cache_enabled; | ||
| } uct_cuda_ipc_rkey_handle_t; | ||
|
|
||
| typedef struct { | ||
|
|
@@ -47,6 +48,7 @@ typedef struct { | |
| uintptr_t d_bptr; | ||
| void *mapped_addr; | ||
| CUdevice cu_dev; | ||
| int cache_enabled; | ||
| } uct_cuda_ipc_mem_elem_release_handle_t; | ||
|
|
||
| static ucs_config_field_t uct_cuda_ipc_md_config_table[] = { | ||
|
|
@@ -493,7 +495,7 @@ static ucs_status_t | |
| uct_cuda_ipc_is_peer_accessible(uct_cuda_ipc_component_t *component, | ||
|
rakhmets marked this conversation as resolved.
Resolved
|
||
| uct_cuda_ipc_unpacked_rkey_t *rkey, | ||
| uct_cuda_ipc_rkey_handle_t *rkey_handle, | ||
| CUdevice cu_dev) | ||
| CUdevice cu_dev, int bound_lifetime) | ||
| { | ||
| ucs_status_t status; | ||
| void *d_mapped; | ||
|
|
@@ -515,8 +517,8 @@ uct_cuda_ipc_is_peer_accessible(uct_cuda_ipc_component_t *component, | |
| * stream sequentialization */ | ||
|
rakhmets marked this conversation as resolved.
Resolved
|
||
| rkey->stream_id = cache->dev_num; | ||
| accessible = &cache->accessible[cu_dev]; | ||
| if (ucs_unlikely(*accessible == UCS_TRY)) { /* unchecked, add to cache */ | ||
|
|
||
| if (ucs_unlikely(*accessible == UCS_TRY) || /* unchecked, add to cache */ | ||
| (bound_lifetime && (*accessible == UCS_YES))) { | ||
| /* Check if peer is reachable by trying to open memory handle. This is | ||
| * necessary when the device is not visible through CUDA_VISIBLE_DEVICES | ||
| * and checking peer accessibility through CUDA driver API is not | ||
|
|
@@ -539,8 +541,12 @@ uct_cuda_ipc_is_peer_accessible(uct_cuda_ipc_component_t *component, | |
| rkey_handle->mapped_addr = d_mapped; | ||
| } | ||
|
|
||
| *accessible = ((status == UCS_OK) || (status == UCS_ERR_ALREADY_EXISTS)) | ||
| ? UCS_YES : UCS_NO; | ||
| if (*accessible == UCS_TRY) { | ||
|
rakhmets marked this conversation as resolved.
Resolved
|
||
| *accessible = ((status == UCS_OK) || | ||
| (status == UCS_ERR_ALREADY_EXISTS)) ? | ||
| UCS_YES : | ||
| UCS_NO; | ||
| } | ||
| } | ||
|
|
||
| status = (*accessible == UCS_YES) ? UCS_OK : UCS_ERR_UNREACHABLE; | ||
|
|
@@ -550,6 +556,13 @@ uct_cuda_ipc_is_peer_accessible(uct_cuda_ipc_component_t *component, | |
| return status; | ||
| } | ||
|
|
||
| static int | ||
| uct_cuda_ipc_rkey_unpack_bound_lifetime(const uct_rkey_unpack_params_t *params) | ||
| { | ||
| return !!(UCS_PARAM_VALUE(UCT_RKEY_UNPACK_FIELD, params, flags, FLAGS, 0) & | ||
| UCT_RKEY_UNPACK_FLAG_BOUND_LIFETIME); | ||
| } | ||
|
|
||
| UCS_PROFILE_FUNC(ucs_status_t, uct_cuda_ipc_rkey_unpack, | ||
| (component, rkey_buffer, params, rkey_p, handle_p), | ||
| uct_component_t *component, const void *rkey_buffer, | ||
|
|
@@ -562,6 +575,7 @@ UCS_PROFILE_FUNC(ucs_status_t, uct_cuda_ipc_rkey_unpack, | |
| uct_cuda_ipc_unpacked_rkey_t *unpacked; | ||
| uct_cuda_ipc_rkey_handle_t *rkey_handle; | ||
| ucs_sys_device_t sys_dev; | ||
| int bound_lifetime; | ||
| CUdevice cuda_device; | ||
| CUdevice avail_cuda_device; | ||
| ucs_status_t status; | ||
|
|
@@ -570,6 +584,8 @@ UCS_PROFILE_FUNC(ucs_status_t, uct_cuda_ipc_rkey_unpack, | |
| sys_dev = UCS_PARAM_VALUE(UCT_RKEY_UNPACK_FIELD, params, sys_device, | ||
| SYS_DEVICE, UCS_SYS_DEVICE_ID_UNKNOWN); | ||
|
|
||
| bound_lifetime = uct_cuda_ipc_rkey_unpack_bound_lifetime(params); | ||
|
|
||
| unpacked = ucs_malloc(sizeof(*unpacked), "uct_cuda_ipc_unpacked_rkey_t"); | ||
| if (NULL == unpacked) { | ||
| ucs_error("failed to allocate memory for uct_cuda_ipc_unpacked_rkey_t"); | ||
|
|
@@ -605,14 +621,17 @@ UCS_PROFILE_FUNC(ucs_status_t, uct_cuda_ipc_rkey_unpack, | |
| /* Check if peer is accessible, and if that check required mapping a memory | ||
| * handle, save it in the rkey handle */ | ||
| status = uct_cuda_ipc_is_peer_accessible(com, unpacked, rkey_handle, | ||
| avail_cuda_device); | ||
| avail_cuda_device, bound_lifetime); | ||
| if (cuda_device != avail_cuda_device) { | ||
| uct_cuda_ctx_primary_pop_and_release(avail_cuda_device); | ||
| } | ||
| if (status != UCS_OK) { | ||
| goto err_free_rkey_handle; | ||
| } | ||
|
|
||
| rkey_handle->cache_enabled = | ||
| bound_lifetime ? 0 : uct_cuda_ipc_component.enable_remote_cache; | ||
|
|
||
| *handle_p = rkey_handle; | ||
| *rkey_p = (uintptr_t) unpacked; | ||
| return UCS_OK; | ||
|
|
@@ -644,7 +663,7 @@ static void uct_cuda_ipc_rkey_release_unmap_memhandle(uct_rkey_t uct_rkey, | |
|
|
||
| uct_cuda_ipc_unmap_memhandle(rkey->pid, extended_rkey->pid_ns, rkey->d_bptr, | ||
| rkey_handle->mapped_addr, rkey_handle->cu_dev, | ||
| uct_cuda_ipc_component.enable_remote_cache); | ||
| rkey_handle->cache_enabled); | ||
| } | ||
|
|
||
| static ucs_status_t uct_cuda_ipc_rkey_release(uct_component_t *component, | ||
|
|
@@ -767,17 +786,23 @@ static void uct_cuda_ipc_md_close(uct_md_h md) | |
|
|
||
| static ucs_status_t | ||
| uct_cuda_ipc_md_mem_elem_pack(uct_md_h md, uct_mem_h memh, uct_rkey_t rkey, | ||
| void *rkey_release_handle, | ||
| uct_device_mem_elem_t *mem_elem, | ||
| void **release_handle_p) | ||
| { | ||
| uct_cuda_ipc_unpacked_rkey_t *key = (uct_cuda_ipc_unpacked_rkey_t*)rkey; | ||
| uct_cuda_ipc_md_device_mem_element_t *cuda_ipc_md_mem_element = | ||
| (uct_cuda_ipc_md_device_mem_element_t*)mem_elem; | ||
| uct_cuda_ipc_rkey_handle_t *cuda_ipc_rkey_handle = rkey_release_handle; | ||
| uct_cuda_ipc_mem_elem_release_handle_t *release_handle; | ||
| ucs_status_t status; | ||
| CUdevice cuda_device; | ||
| void *mapped_addr; | ||
|
|
||
| if ((rkey == UCT_INVALID_RKEY) || (rkey_release_handle == NULL)) { | ||
| return UCS_ERR_INVALID_PARAM; | ||
| } | ||
|
|
||
| if (UCT_CUDADRV_FUNC_LOG_DEBUG(cuCtxGetDevice(&cuda_device)) != UCS_OK) { | ||
| return UCS_ERR_UNREACHABLE; | ||
| } | ||
|
|
@@ -798,12 +823,13 @@ uct_cuda_ipc_md_mem_elem_pack(uct_md_h md, uct_mem_h memh, uct_rkey_t rkey, | |
| cuda_ipc_md_mem_element->mapped_offset = | ||
| UCS_PTR_BYTE_DIFF(key->super.super.d_bptr, mapped_addr); | ||
|
|
||
| release_handle->pid = key->super.super.pid; | ||
| release_handle->pid_ns = key->super.pid_ns; | ||
| release_handle->d_bptr = key->super.super.d_bptr; | ||
| release_handle->mapped_addr = mapped_addr; | ||
| release_handle->cu_dev = cuda_device; | ||
| *release_handle_p = release_handle; | ||
| release_handle->pid = key->super.super.pid; | ||
| release_handle->pid_ns = key->super.pid_ns; | ||
| release_handle->d_bptr = key->super.super.d_bptr; | ||
| release_handle->mapped_addr = mapped_addr; | ||
| release_handle->cu_dev = cuda_device; | ||
| release_handle->cache_enabled = cuda_ipc_rkey_handle->cache_enabled; | ||
| *release_handle_p = release_handle; | ||
|
|
||
| return UCS_OK; | ||
| } | ||
|
|
@@ -814,7 +840,7 @@ static void uct_cuda_ipc_md_mem_elem_release(uct_md_h md, void *release_handle) | |
|
|
||
| uct_cuda_ipc_unmap_memhandle(handle->pid, handle->pid_ns, handle->d_bptr, | ||
| handle->mapped_addr, handle->cu_dev, | ||
| uct_cuda_ipc_component.enable_remote_cache); | ||
| handle->cache_enabled); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lets use |
||
| ucs_free(handle); | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.