Repository navigation
UCP/UCT/UCS: Add memory registration flags #11553
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
289e65d
UCP/UCT/UCS: Add memory registration flags
tomerg-nvidia 340465c
UCP/CORE: Fix release build issues
tomerg-nvidia 425cab7
UCP/UCT/UCS: Fix format issues
tomerg-nvidia dbb7009
UCT/CUDA/CUDA_COPY: add dmabuf export based flag detection
tomerg-nvidia 33a94f0
UCP/UCS/UCT: CR fixes
tomerg-nvidia fe4680c
Merge branch 'master' into ucs_mem_flags_pr
tomerg-nvidia 7553779
UCP/UCT/UCS: CR fixes
tomerg-nvidia f2f99ab
UCP/UCT/UCS: Remove the flags from the rcache key
tomerg-nvidia 64954ec
UCP/UCT: Rename mem_info.mem_flags to flags, separate v2 api enum fro…
tomerg-nvidia d07bfdc
UCP/UCT/UCS: CR fixes
tomerg-nvidia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| /** | ||
| * Copyright (c) NVIDIA CORPORATION & AFFILIATES, 2001-2015. ALL RIGHTS RESERVED. | ||
| * Copyright (c) NVIDIA CORPORATION & AFFILIATES, 2001-2026. ALL RIGHTS RESERVED. | ||
| * | ||
| * See file LICENSE for terms. | ||
| */ | ||
|
|
@@ -28,6 +28,7 @@ | |
| /* Context for rcache memory registration callback */ | ||
| typedef struct { | ||
| ucs_memory_type_t mem_type; /* Memory type */ | ||
| uint8_t mem_flags; /* Memory flags (ucp_mem_flags_t) */ | ||
| ucp_md_map_t reg_md_map; /* Map of memory domains to be registered */ | ||
| unsigned uct_flags; /* UCT memory registration flags */ | ||
| const char *alloc_name; /* Memory allocation name */ | ||
|
|
@@ -40,6 +41,7 @@ ucp_mem_dummy_handle_t ucp_mem_dummy_handle = { | |
| .parent = &ucp_mem_dummy_handle.memh, | ||
| .mem_type = UCS_MEMORY_TYPE_HOST, | ||
| .sys_dev = UCS_SYS_DEVICE_ID_UNKNOWN, | ||
| .mem_flags = UCS_MEM_FLAG_REGISTRABLE, | ||
| .md_map = 0, | ||
| .inv_md_map = 0, | ||
| .reg_id = 0, | ||
|
|
@@ -49,7 +51,8 @@ ucp_mem_dummy_handle_t ucp_mem_dummy_handle = { | |
|
|
||
| const ucp_memory_info_t ucp_mem_info_unknown = { | ||
| .type = UCS_MEMORY_TYPE_UNKNOWN, | ||
| .sys_dev = UCS_SYS_DEVICE_ID_UNKNOWN | ||
| .sys_dev = UCS_SYS_DEVICE_ID_UNKNOWN, | ||
| .flags = UCS_MEM_FLAG_REGISTRABLE | ||
| }; | ||
|
|
||
|
|
||
|
|
@@ -561,6 +564,7 @@ ucp_memh_register_internal(ucp_context_h context, ucp_mem_h memh, | |
| uct_md_mem_reg_params_t reg_params; | ||
| uct_md_mem_attr_t mem_attr; | ||
| ucp_md_index_t md_index; | ||
| uint8_t required_mem_flags; | ||
| ucs_status_t status; | ||
| void *reg_address; | ||
| size_t reg_length; | ||
|
|
@@ -575,6 +579,18 @@ ucp_memh_register_internal(ucp_context_h context, ucp_mem_h memh, | |
| } | ||
|
|
||
| reg_md_map = ~memh->md_map & md_map; | ||
| ucs_for_each_bit(md_index, reg_md_map) { | ||
| required_mem_flags = context->tl_mds[md_index].attr.required_mem_flags; | ||
|
|
||
| if (!ucs_test_all_flags(memh->mem_flags, required_mem_flags)) { | ||
| ucs_trace("md[%d]=%s skipped: mem_flags=0x%x do not include " | ||
| "required_mem_flags=0x%x", | ||
| md_index, context->tl_mds[md_index].rsc.md_name, | ||
| memh->mem_flags, required_mem_flags); | ||
| reg_md_map &= ~UCS_BIT(md_index); | ||
| } | ||
| } | ||
|
|
||
| if (reg_md_map == 0) { | ||
| return UCS_OK; | ||
| } | ||
|
|
@@ -715,7 +731,7 @@ void ucp_memh_disable_gva(ucp_mem_h memh, ucp_md_map_t md_map) | |
| static void ucp_memh_init(ucp_mem_h memh, ucp_context_h context, | ||
| uint8_t memh_flags, unsigned uct_flags, | ||
| uct_alloc_method_t method, ucs_memory_type_t mem_type, | ||
| ucs_sys_device_t sys_dev) | ||
| ucs_sys_device_t sys_dev, uint8_t mem_flags) | ||
| { | ||
| memh->md_map = 0; | ||
| memh->inv_md_map = 0; | ||
|
|
@@ -726,6 +742,7 @@ static void ucp_memh_init(ucp_mem_h memh, ucp_context_h context, | |
| memh->alloc_method = method; | ||
| memh->mem_type = mem_type; | ||
| memh->sys_dev = sys_dev; | ||
| memh->mem_flags = mem_flags; | ||
| } | ||
|
|
||
| static ucs_status_t | ||
|
|
@@ -745,7 +762,7 @@ ucp_memh_create(ucp_context_h context, void *address, size_t length, | |
| memh->super.super.end = (uintptr_t)address + length; | ||
| ucp_memory_detect(context, address, length, &info); | ||
| ucp_memh_init(memh, context, memh_flags, uct_flags, method, mem_type, | ||
| info.sys_dev); | ||
| info.sys_dev, info.flags); | ||
|
|
||
| *memh_p = memh; | ||
| return UCS_OK; | ||
|
|
@@ -754,11 +771,13 @@ ucp_memh_create(ucp_context_h context, void *address, size_t length, | |
| static ucs_status_t | ||
| ucp_memh_rcache_get(ucs_rcache_t *rcache, void *address, size_t length, | ||
| size_t alignment, ucs_memory_type_t mem_type, | ||
| ucp_md_map_t reg_md_map, unsigned uct_flags, | ||
| const char *alloc_name, ucp_mem_h *memh_p) | ||
| uint8_t mem_flags, ucp_md_map_t reg_md_map, | ||
| unsigned uct_flags, const char *alloc_name, | ||
| ucp_mem_h *memh_p) | ||
| { | ||
| ucp_mem_rcache_reg_ctx_t reg_ctx = { | ||
| .mem_type = mem_type, | ||
| .mem_flags = mem_flags, | ||
| .reg_md_map = reg_md_map, | ||
| .uct_flags = uct_flags, | ||
| .alloc_name = alloc_name | ||
|
|
@@ -953,7 +972,7 @@ static size_t ucp_memh_reg_align(ucp_context_h context, ucp_md_map_t reg_md_map) | |
|
|
||
| static ucs_status_t | ||
| ucp_memh_find_slow(ucp_context_h context, void *address, size_t length, | ||
| size_t align, ucs_memory_type_t mem_type, | ||
| size_t align, ucs_memory_type_t mem_type, uint8_t mem_flags, | ||
| ucp_md_map_t reg_md_map, unsigned uct_flags, | ||
| const char *alloc_name, ucp_mem_h *memh_p) | ||
| { | ||
|
|
@@ -968,7 +987,7 @@ ucp_memh_find_slow(ucp_context_h context, void *address, size_t length, | |
|
|
||
| for (;;) { | ||
| status = ucp_memh_rcache_get(context->rcache, address, length, align, | ||
| mem_type, reg_md_map, uct_flags, | ||
| mem_type, mem_flags, reg_md_map, uct_flags, | ||
| alloc_name, &memh); | ||
| if (status != UCS_OK) { | ||
| return status; | ||
|
|
@@ -1012,8 +1031,9 @@ ucs_status_t ucp_memh_get_slow(ucp_context_h context, void *address, | |
| size_t reg_length; | ||
| ucp_mem_h memh; | ||
|
|
||
| ucp_memory_detect_internal(context, address, length, &mem_info); | ||
|
|
||
| if (context->config.ext.reg_whole_alloc_bitmap & UCS_BIT(mem_type)) { | ||
| ucp_memory_detect_internal(context, address, length, &mem_info); | ||
| reg_address = mem_info.base_address; | ||
| reg_length = mem_info.alloc_length; | ||
| } else { | ||
|
|
@@ -1023,8 +1043,8 @@ ucs_status_t ucp_memh_get_slow(ucp_context_h context, void *address, | |
|
|
||
| UCP_THREAD_CS_ENTER(&context->mt_lock); | ||
| status = ucp_memh_find_slow(context, reg_address, reg_length, reg_align, | ||
| mem_type, reg_md_map, uct_flags, alloc_name, | ||
| &memh); | ||
| mem_type, mem_info.mem_flags, reg_md_map, | ||
| uct_flags, alloc_name, &memh); | ||
| if (status != UCS_OK) { | ||
| goto out; | ||
| } | ||
|
|
@@ -1680,7 +1700,8 @@ ucp_mem_rcache_mem_reg_cb(void *ctx, ucs_rcache_t *rcache, void *arg, | |
| ucp_mem_h memh = ucs_derived_of(rregion, ucp_mem_t); | ||
|
|
||
| ucp_memh_init(memh, context, 0, reg_ctx->uct_flags, UCT_ALLOC_METHOD_LAST, | ||
| reg_ctx->mem_type, UCS_SYS_DEVICE_ID_UNKNOWN); | ||
| reg_ctx->mem_type, UCS_SYS_DEVICE_ID_UNKNOWN, | ||
| reg_ctx->mem_flags); | ||
| memh->reg_id = context->next_memh_reg_id++; | ||
|
|
||
| if (rcache_mem_reg_flags & UCS_RCACHE_MEM_REG_HIDE_ERRORS) { | ||
|
|
@@ -1713,8 +1734,11 @@ static void ucp_mem_rcache_merge_cb(void *ctx, ucs_rcache_t *rcache, void *arg, | |
| ucp_mem_h memh = ucs_derived_of(rregion, ucp_mem_t); | ||
|
|
||
| ucs_log_indent(+1); | ||
| ucs_trace("merge with memh %p uct_flags 0x%x", memh, memh->uct_flags); | ||
| ucs_trace("merge with memh %p uct_flags 0x%x mem_flags 0x%x/0x%x", memh, | ||
| memh->uct_flags, reg_ctx->mem_flags, memh->mem_flags); | ||
| reg_ctx->uct_flags |= memh->uct_flags; | ||
| /* TODO: The regions shouldn't be merged if they have different mem_flags */ | ||
| reg_ctx->mem_flags &= memh->mem_flags; | ||
| memh->flags &= ~UCP_MEMH_FLAG_MLOCKED; | ||
| ucs_log_indent(-1); | ||
| } | ||
|
|
@@ -1849,14 +1873,16 @@ ucs_status_t ucp_mm_get_alloc_md_index(ucp_context_h context, | |
|
|
||
| context->alloc_md[alloc_mem_type].initialized = 1; | ||
| context->alloc_md[alloc_mem_type].sys_dev = mem_info.sys_dev; | ||
| context->alloc_md[alloc_mem_type].mem_flags = mem_info.flags; | ||
| context->alloc_md[alloc_mem_type].md_index = | ||
| ucp_mem_get_md_index(context, mem.md, mem.method); | ||
|
|
||
| uct_mem_free(&mem); | ||
| } | ||
|
|
||
| *md_idx_p = context->alloc_md[alloc_mem_type].md_index; | ||
| mem_info_p->type = alloc_mem_type; | ||
| *md_idx_p = context->alloc_md[alloc_mem_type].md_index; | ||
| mem_info_p->type = alloc_mem_type; | ||
| mem_info_p->flags = context->alloc_md[alloc_mem_type].mem_flags; | ||
|
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. align
Contributor
Author
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. done |
||
|
|
||
| /* TODO: Extend the cache by alloc sys dev */ | ||
| if (UCP_MEM_IS_HOST(alloc_mem_type) || | ||
|
|
@@ -1973,7 +1999,7 @@ ucp_memh_import_slow(ucp_context_h context, ucs_rcache_t *existing_rcache, | |
|
|
||
| status = ucp_memh_rcache_get(rcache, unpacked->address, | ||
| unpacked->length, UCS_RCACHE_MIN_ALIGNMENT, | ||
| unpacked->mem_type, 0, 0, "", &memh); | ||
| unpacked->mem_type, 0, 0, 0, "", &memh); | ||
| if (status != UCS_OK) { | ||
| goto err_rcache_destroy; | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.