Skip to content

btl/self: add accelerator-aware memory copy for put/get - #13746

Merged
bosilca merged 1 commit into
open-mpi:mainfrom
Gonzalosilvalde:12230
Apr 30, 2026
Merged

btl/self: add accelerator-aware memory copy for put/get#13746
bosilca merged 1 commit into
open-mpi:mainfrom
Gonzalosilvalde:12230

Conversation

@Gonzalosilvalde

Copy link
Copy Markdown
Contributor

The btl/self component was not accelerator aware. Send-to-self operations involving GPU memory would copy data through the host instead of performing a direct device memory copy.

Add mca_btl_self_memcpy() which checks whether src/dst buffers reside in accelerator memory via opal_accelerator.check_addr() and dispatches to opal_accelerator.mem_copy() accordingly, falling back to memcpy() when both buffers are in host memory.

Fixes #12230

Comment thread opal/mca/btl/self/btl_self.c Outdated
@janjust

janjust commented Apr 21, 2026

Copy link
Copy Markdown
Contributor

@edgargabriel will have a deeper look before signoff, mostly correct
LGTM

@bosilca bosilca left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You need to set the BTL flags to reflect this new capability and avoid the PML staging the transfers through CPU memory. Add MCA_BTL_FLAGS_ACCELERATOR_RDMA.

I would have expected to have to define a btl_register_mem function or the RDMCA cuda will skip the optimized path.

You need to call the provided callback even in an error case and pass the appropriate error to it. We didn't do it before because memcpy could not fail (or really bad things were happening), but now there are more opportunities for badness.

Comment thread opal/mca/btl/self/btl_self.c Outdated
Comment thread opal/mca/btl/self/btl_self.c Outdated
Comment thread opal/mca/btl/self/btl_self.c Outdated
Comment thread opal/mca/btl/self/btl_self.c Outdated
The btl/self component was not accelerator aware. Send-to-self
operations involving GPU memory would copy data through the host
instead of performing a direct device memory copy.

Add mca_btl_self_memcpy() which checks whether src/dst buffers
reside in accelerator memory via opal_accelerator.check_addr()
and dispatches to opal_accelerator.mem_copy() accordingly, falling
back to memcpy() when both buffers are in host memory.

Signed-off-by: Gonzalosilvalde <gonzalo.silvalde@gmail.com>
@Gonzalosilvalde

Copy link
Copy Markdown
Contributor Author

Hi, thanks for the review.
About the dst_flags/src_flags thing, I just merged them into a single flags variable but I'm not sure if that's the right way. If you had something else in mind let me know.
On btl_register_mem I'm less sure. I tried adding register_mem and deregister_mem as no-ops but they never get called in any of the paths I tried, plain send/recv with GPU buffers up to 64MB, RMA Put/Get/atomics, Win_allocate, with osc rdma and osc sm. I ended up leaving them out to avoid adding unused code but happy to try more things if you know of a path I might be missing.

@bosilca
bosilca merged commit 98e1ee0 into open-mpi:main Apr 30, 2026
18 checks passed
@edgargabriel

Copy link
Copy Markdown
Member

@Gonzalosilvalde @bosilca thank you both for this PR, can we cherry-pick that to the 6.0.x branch?

@Gonzalosilvalde

Copy link
Copy Markdown
Contributor Author

@Gonzalosilvalde @bosilca thank you both for this PR, can we cherry-pick that to the 6.0.x branch?

Sure, go ahead! No objections from my side.

@bosilca

bosilca commented May 4, 2026

Copy link
Copy Markdown
Member

/backport v5.0.x
/backport v6.0.x

@bosilca

bosilca commented May 4, 2026

Copy link
Copy Markdown
Member

/backport v5.0.x

@bosilca

bosilca commented May 4, 2026

Copy link
Copy Markdown
Member

/backport v6.0.x

@edgargabriel

Copy link
Copy Markdown
Member

Hm, please wait with merging this to 5.0.x and 6.0.x. I have tested the patch and I do not see the accelerator path ever be invoked, something is still missing.

@Gonzalosilvalde

Copy link
Copy Markdown
Contributor Author

Hm, please wait with merging this to 5.0.x and 6.0.x. I have tested the patch and I do not see the accelerator path ever be invoked, something is still missing.

Hi, I've been looking at the commit again since I didn't understand why you were seeing it not work. I think I got mixed up at some point while undoing changes or something like that. I'm pretty sure the line bool inline_send = !(opal_convertor_need_buffers(convertor) || opal_convertor_on_device(convertor)) shouldn't have the second part. I'm not entirely sure though, and I can't run tests right now. I'll re-test as soon as I have access to a machine with a GPU. Sorry for the inconvenience.

@Gonzalosilvalde

Copy link
Copy Markdown
Contributor Author

Should be enough now, sorry for the trouble.
Gonzalosilvalde@866353a

@edgargabriel

Copy link
Copy Markdown
Member

@Gonzalosilvalde sorry, where is this patch? Did you file a new PR with the modification?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

btl/self is not accelerator aware

4 participants