Repository navigation
UCT/CUDA_COPY/MD: Don't widen VMM range crossing a handle boundary #12186
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 13 commits
90d1a90
e33ab94
2730801
5fc426a
c12f69b
42a2aa2
2b622d5
9383b84
6fb2d69
350a262
500dc06
9eca2bb
b006d5a
4ed46a1
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 | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -610,9 +610,10 @@ static void uct_cuda_copy_md_sync_memops_get_address_range( | |||||||||||||||||||||||
| ucs_assert(md->config.alloc_whole_reg == UCS_CONFIG_ON); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| /* For multi-handle VMM, the physical allocation may be smaller than the | ||||||||||||||||||||||||
| * mapped virtual range; preserve the caller's requested extent. */ | ||||||||||||||||||||||||
| if (is_vmm && (alloc_length < length)) { | ||||||||||||||||||||||||
| /* For multi-handle VMM, the physical allocation containing the address | ||||||||||||||||||||||||
|
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. minor: the zero-base case is unrelated to multi-handle VMM (and not VMM-specific), pls split it out so each condition carries its own comment:
Suggested change
|
||||||||||||||||||||||||
| * may not cover the whole requested range */ | ||||||||||||||||||||||||
| if ((base_address == 0) || /* host-located VMM reports a zero base */ | ||||||||||||||||||||||||
| (is_vmm && ((base_address + alloc_length) < (address + length)))) { | ||||||||||||||||||||||||
| goto out_ctx_pop; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -660,14 +660,86 @@ UCS_TEST_SKIP_COND_P(test_mem_alloc_device, | |||||||||||||||||||||||||||||
| query_registrable_no_current_context(buffer.ptr(), size); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| UCS_TEST_P(test_mem_alloc_device, vmm_multi_handle_range, | ||||||||||||||||||||||||||||||
| "CUDA_COPY_REG_WHOLE_ALLOC=on") | ||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||
| cuda_vmm_mem_buffer buffer(4 * UCS_MBYTE, UCS_MEMORY_TYPE_CUDA, 3); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| /* The handle containing the address covers only the first chunk, so the | ||||||||||||||||||||||||||||||
| * requested extent must be kept */ | ||||||||||||||||||||||||||||||
| check_mem_query_exact_range(buffer.ptr(), buffer.size()); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| UCS_TEST_P(test_mem_alloc_device, vmm_locality_domain_mem_type) | ||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||
| #if HAVE_DECL_CU_MEM_LOCATION_TYPE_DEVICE_LOCALITY_DOMAIN | ||||||||||||||||||||||||||||||
| ASSERT_EQ(cudaSuccess, cudaSetDevice(0)); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| auto check_domain = [this](unsigned char domain_id, | ||||||||||||||||||||||||||||||
| ucs_sys_device_t &sys_dev) { | ||||||||||||||||||||||||||||||
| cuda_vmm_mem_buffer buffer; | ||||||||||||||||||||||||||||||
| CUresult ret = buffer.alloc(64, 0, | ||||||||||||||||||||||||||||||
| CU_MEM_LOCATION_TYPE_DEVICE_LOCALITY_DOMAIN, | ||||||||||||||||||||||||||||||
| 1, domain_id); | ||||||||||||||||||||||||||||||
| if (ret != CUDA_SUCCESS) { | ||||||||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| uct_md_mem_attr_t mem_attr; | ||||||||||||||||||||||||||||||
| mem_attr.field_mask = UCT_MD_MEM_ATTR_FIELD_MEM_TYPE | | ||||||||||||||||||||||||||||||
| UCT_MD_MEM_ATTR_FIELD_SYS_DEV; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| ASSERT_UCS_OK(uct_md_mem_query(md(), buffer.ptr(), buffer.size(), | ||||||||||||||||||||||||||||||
| &mem_attr)); | ||||||||||||||||||||||||||||||
| EXPECT_EQ(UCS_MEMORY_TYPE_CUDA, mem_attr.mem_type); | ||||||||||||||||||||||||||||||
| EXPECT_NE(UCS_SYS_DEVICE_ID_UNKNOWN, mem_attr.sys_dev); | ||||||||||||||||||||||||||||||
| sys_dev = mem_attr.sys_dev; | ||||||||||||||||||||||||||||||
| return true; | ||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| ucs_sys_device_t sys_dev0, sys_dev1; | ||||||||||||||||||||||||||||||
|
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. pls rebase — master now probes domain 1 first, because domain 0 also succeeds on a single-locality-domain device and this The
Suggested change
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| /* Domain 1 is present only on a device with several locality domains, so | ||||||||||||||||||||||||||||||
| * its absence is what tells a single-domain device apart */ | ||||||||||||||||||||||||||||||
| if (!check_domain(1, sys_dev1)) { | ||||||||||||||||||||||||||||||
| UCS_TEST_SKIP_R("single locality-domain device"); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| if (!check_domain(0, sys_dev0)) { | ||||||||||||||||||||||||||||||
| ADD_FAILURE() << "locality domain 0 allocation failed even though " | ||||||||||||||||||||||||||||||
| "domain 1 succeeded"; | ||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
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 moved copy of Suggested fix:
Suggested change
Please move the current version of this test (test_cuda_ipc_md.cc:790) instead of the older one. |
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| EXPECT_EQ(sys_dev0, sys_dev1); | ||||||||||||||||||||||||||||||
| #else | ||||||||||||||||||||||||||||||
| UCS_TEST_SKIP_R("built without locality-domain support"); | ||||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| UCS_TEST_P(test_mem_alloc_device, vmm_multi_handle_unaligned_range, | ||||||||||||||||||||||||||||||
| "CUDA_COPY_REG_WHOLE_ALLOC=on") | ||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||
| cuda_vmm_mem_buffer buffer(4 * UCS_MBYTE, UCS_MEMORY_TYPE_CUDA, 2); | ||||||||||||||||||||||||||||||
| size_t chunk_size = buffer.size() / 2; | ||||||||||||||||||||||||||||||
| void *address = UCS_PTR_BYTE_OFFSET(buffer.ptr(), chunk_size / 2); | ||||||||||||||||||||||||||||||
| uct_md_mem_attr_t mem_attr; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| /* Contained in the first handle: extended to the whole handle */ | ||||||||||||||||||||||||||||||
| mem_attr.field_mask = UCT_MD_MEM_ATTR_FIELD_BASE_ADDRESS | | ||||||||||||||||||||||||||||||
| UCT_MD_MEM_ATTR_FIELD_ALLOC_LENGTH; | ||||||||||||||||||||||||||||||
| ASSERT_UCS_OK(uct_md_mem_query(md(), address, chunk_size / 2, &mem_attr)); | ||||||||||||||||||||||||||||||
| EXPECT_EQ(buffer.ptr(), mem_attr.base_address); | ||||||||||||||||||||||||||||||
| EXPECT_EQ(chunk_size, mem_attr.alloc_length); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| /* Ends in the second handle, while being shorter than a single handle: | ||||||||||||||||||||||||||||||
| * the requested extent must be kept */ | ||||||||||||||||||||||||||||||
| check_mem_query_exact_range(address, (chunk_size / 2) + 1); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| #if CUDA_VERSION >= 12020 | ||||||||||||||||||||||||||||||
| /* Host-located VMM is not dmabuf-exportable but is registrable by IB. | ||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||
| * TODO: REG_WHOLE_ALLOC=off is needed because of an existing issue with | ||||||||||||||||||||||||||||||
| * base_address being set to 0, causing cache pollution with this type of memory | ||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||
| UCS_TEST_P(test_mem_alloc_device, host_vmm_mem_registrable, | ||||||||||||||||||||||||||||||
| "CUDA_COPY_REG_WHOLE_ALLOC=off") | ||||||||||||||||||||||||||||||
| /* Host-located VMM is not dmabuf-exportable but is registrable by IB */ | ||||||||||||||||||||||||||||||
| UCS_TEST_P(test_mem_alloc_device, host_vmm_mem_registrable) | ||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||
| constexpr size_t size = 4 * UCS_MBYTE; | ||||||||||||||||||||||||||||||
| cuda_host_vmm_mem_buffer buffer(size, UCS_MEMORY_TYPE_CUDA); | ||||||||||||||||||||||||||||||
|
|
@@ -677,14 +749,24 @@ UCS_TEST_P(test_mem_alloc_device, host_vmm_mem_registrable, | |||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| /* Host-located VMM is typed as CUDA memory, but cannot be allocated as | ||||||||||||||||||||||||||||||
| * GPUDirect RDMA capable */ | ||||||||||||||||||||||||||||||
| UCS_TEST_P(test_mem_alloc_device, host_vmm_mem_not_gdr_capable, | ||||||||||||||||||||||||||||||
| "CUDA_COPY_REG_WHOLE_ALLOC=off") | ||||||||||||||||||||||||||||||
| UCS_TEST_P(test_mem_alloc_device, host_vmm_mem_not_gdr_capable) | ||||||||||||||||||||||||||||||
|
d4l3k marked this conversation as resolved.
Resolved
|
||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||
| constexpr size_t size = 4 * UCS_MBYTE; | ||||||||||||||||||||||||||||||
| cuda_host_vmm_mem_buffer buffer(size, UCS_MEMORY_TYPE_CUDA); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| query_registrable_gdr_capable(buffer.ptr(), size, 1, 0); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| /* cuMemGetAddressRange() reports a zero base address for host-located VMM, so | ||||||||||||||||||||||||||||||
| * the registration range must not be extended to it */ | ||||||||||||||||||||||||||||||
| UCS_TEST_P(test_mem_alloc_device, host_vmm_mem_range, | ||||||||||||||||||||||||||||||
|
tvegas1 marked this conversation as resolved.
Resolved
|
||||||||||||||||||||||||||||||
| "CUDA_COPY_REG_WHOLE_ALLOC=on") | ||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||
| constexpr size_t size = 4 * UCS_MBYTE; | ||||||||||||||||||||||||||||||
| cuda_host_vmm_mem_buffer buffer(size, UCS_MEMORY_TYPE_CUDA); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| check_mem_query_exact_range(buffer.ptr(), buffer.size()); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| UCS_TEST_P(test_mem_alloc_device, legacy_cuda_no_memtype_copy_inter_node) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.