-
Notifications
You must be signed in to change notification settings - Fork 457
prov/efa: dmabuf try / fallback logic #11465
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
Open
nmazzilli3
wants to merge
2
commits into
ofiwg:main
Choose a base branch
from
nmazzilli3:Subspace-2834
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+215
−98
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,34 @@ | |
|
|
||
| struct efa_hmem_info g_efa_hmem_info[OFI_HMEM_MAX]; | ||
|
|
||
| /** | ||
| * @brief Check if DMABUF is enabled for a specific HMEM interface | ||
| * | ||
| * This function checks the environment variables to determine if DMABUF | ||
| * should be used for the specified HMEM interface. It respects both | ||
| * EFA-specific and core libfabric environment variables. | ||
| * | ||
| * @param[in] iface The HMEM interface to check | ||
| * @return true if DMABUF is enabled for the interface, false otherwise | ||
| */ | ||
| bool efa_hmem_is_dmabuf_env_var_enabled(enum fi_hmem_iface iface) | ||
| { | ||
| switch (iface) { | ||
| case FI_HMEM_SYSTEM: | ||
| return false; | ||
| case FI_HMEM_CUDA: | ||
| return cuda_is_dmabuf_requested(); | ||
| case FI_HMEM_NEURON: | ||
| return neuron_is_dmabuf_requested(); | ||
| case FI_HMEM_SYNAPSEAI: | ||
| return synapseai_is_dmabuf_requested(); | ||
| case FI_HMEM_ROCR: | ||
| return rocr_is_dmabuf_requested(); | ||
| default: | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| #if HAVE_CUDA || HAVE_NEURON | ||
| static size_t efa_max_eager_msg_size_with_largest_header() { | ||
| int mtu_size; | ||
|
|
@@ -134,21 +162,28 @@ static inline void efa_hmem_info_check_p2p_support_cuda(struct efa_hmem_info *in | |
| } | ||
|
|
||
| #if HAVE_EFA_DMABUF_MR | ||
| ret = cuda_get_dmabuf_fd(ptr, len, &dmabuf_fd, &dmabuf_offset); | ||
| if (ret == FI_SUCCESS) { | ||
| ibv_mr = ibv_reg_dmabuf_mr(ibv_pd, dmabuf_offset, | ||
| len, (uint64_t)ptr, dmabuf_fd, ibv_access); | ||
| (void)cuda_put_dmabuf_fd(dmabuf_fd); | ||
| if (!ibv_mr) { | ||
| if (efa_hmem_is_dmabuf_env_var_enabled(FI_HMEM_CUDA)) { | ||
| ret = ofi_hmem_get_dmabuf_fd(FI_HMEM_CUDA, ptr, len, &dmabuf_fd, &dmabuf_offset); | ||
| if (ret == FI_SUCCESS) { | ||
| ibv_mr = ibv_reg_dmabuf_mr(ibv_pd, dmabuf_offset, | ||
| len, (uint64_t)ptr, dmabuf_fd, ibv_access); | ||
| (void)ofi_hmem_put_dmabuf_fd(FI_HMEM_CUDA, dmabuf_fd); | ||
| if (!ibv_mr) { | ||
| EFA_INFO(FI_LOG_CORE, | ||
| "Unable to register CUDA device buffer via dmabuf: %s. " | ||
| "Fall back to ibv_reg_mr\n", fi_strerror(-errno)); | ||
| ibv_mr = ibv_reg_mr(ibv_pd, ptr, len, ibv_access); | ||
| } else { | ||
| info->dmabuf_supported_by_device_b = true; | ||
| } | ||
| } else { | ||
| EFA_INFO(FI_LOG_CORE, | ||
| "Unable to register CUDA device buffer via dmabuf: %s. " | ||
| "Fall back to ibv_reg_mr\n", fi_strerror(-errno)); | ||
| "Unable to retrieve dmabuf fd of CUDA device buffer: %d. " | ||
| "Fall back to ibv_reg_mr\n", ret); | ||
| ibv_mr = ibv_reg_mr(ibv_pd, ptr, len, ibv_access); | ||
| } | ||
| } else { | ||
| EFA_INFO(FI_LOG_CORE, | ||
| "Unable to retrieve dmabuf fd of CUDA device buffer: %d. " | ||
| "Fall back to ibv_reg_mr\n", ret); | ||
| EFA_INFO(FI_LOG_CORE, "FI_HMEM_CUDA DMABUF disabled by environment variable\n"); | ||
| ibv_mr = ibv_reg_mr(ibv_pd, ptr, len, ibv_access); | ||
| } | ||
| #else | ||
|
|
@@ -217,15 +252,29 @@ static inline void efa_hmem_info_check_p2p_support_neuron(struct efa_hmem_info * | |
| } | ||
|
|
||
| #if HAVE_EFA_DMABUF_MR | ||
| ret = neuron_get_dmabuf_fd(ptr, (uint64_t)len, &dmabuf_fd, &offset); | ||
| if (ret == FI_SUCCESS) { | ||
| ibv_mr = ibv_reg_dmabuf_mr( | ||
| ibv_pd, offset, | ||
| len, (uint64_t)ptr, dmabuf_fd, ibv_access); | ||
| } else if (ret == -FI_EOPNOTSUPP) { | ||
| EFA_INFO(FI_LOG_MR, | ||
| "Unable to retrieve dmabuf fd of Neuron device buffer, " | ||
| "Fall back to ibv_reg_mr\n"); | ||
| if (efa_hmem_is_dmabuf_env_var_enabled(FI_HMEM_NEURON)) { | ||
| ret = ofi_hmem_get_dmabuf_fd(FI_HMEM_NEURON, ptr, (uint64_t)len, &dmabuf_fd, &offset); | ||
| if (ret == FI_SUCCESS) { | ||
| ibv_mr = ibv_reg_dmabuf_mr( | ||
| ibv_pd, offset, | ||
| len, (uint64_t)ptr, dmabuf_fd, ibv_access); | ||
| (void)ofi_hmem_put_dmabuf_fd(FI_HMEM_NEURON, dmabuf_fd); | ||
| if (!ibv_mr) { | ||
| EFA_INFO(FI_LOG_CORE, | ||
| "Unable to register Neuron device buffer via dmabuf: %s. " | ||
| "Fall back to ibv_reg_mr\n", fi_strerror(-errno)); | ||
| ibv_mr = ibv_reg_mr(ibv_pd, ptr, len, ibv_access); | ||
| } else { | ||
| info->dmabuf_supported_by_device_b = true; | ||
| } | ||
| } else { | ||
| EFA_INFO(FI_LOG_MR, | ||
| "Unable to retrieve dmabuf fd of Neuron device buffer: %d. " | ||
| "Fall back to ibv_reg_mr\n", ret); | ||
| ibv_mr = ibv_reg_mr(ibv_pd, ptr, len, ibv_access); | ||
| } | ||
| } else { | ||
| EFA_INFO(FI_LOG_CORE, "FI_HMEM_NEURON DMABUF disabled by environment variable\n"); | ||
| ibv_mr = ibv_reg_mr(ibv_pd, ptr, len, ibv_access); | ||
| } | ||
| #else | ||
|
|
@@ -284,9 +333,23 @@ efa_hmem_info_init_iface(enum fi_hmem_iface iface) | |
| } | ||
|
|
||
| info->initialized = true; | ||
| info->max_medium_msg_size = 0; | ||
| info->runt_size = 0; | ||
| info->min_read_msg_size = 0; | ||
| info->min_read_write_size = 0; | ||
|
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. These are default to 0 and set in efa_domain_hmem_info_init_protocol_thresholds. |
||
| info->dmabuf_supported_by_device_b = false; | ||
|
|
||
| if (iface == FI_HMEM_SYNAPSEAI || iface == FI_HMEM_SYSTEM) { | ||
| if (iface == FI_HMEM_SYNAPSEAI) { | ||
| info->p2p_supported_by_device = true; | ||
| if (efa_hmem_is_dmabuf_env_var_enabled(FI_HMEM_SYNAPSEAI)) { | ||
| info->dmabuf_supported_by_device_b = true; | ||
| } else { | ||
| EFA_INFO(FI_LOG_CORE, "FI_HMEM_SYNAPSEAI DMABUF disabled by environment variable\n"); | ||
| info->dmabuf_supported_by_device_b = false; | ||
|
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. You don't need to set it again here |
||
| } | ||
| } else if(iface == FI_HMEM_SYSTEM) { | ||
| info->p2p_supported_by_device = true; | ||
| info->dmabuf_supported_by_device_b = false; | ||
| } else if (ofi_hmem_p2p_disabled()) { | ||
| info->p2p_supported_by_device = false; | ||
| } else { | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should add a method to the common hmem interface and define an
ofi_hmem_is_dmabuf_requestedfunction insrc/hmem.c. That make the code reusable for other providers. Also need to add the function forFI_HMEM_ZEis going this route.