Skip to content

Add JACC.transfer!#357

Merged
williamfgc merged 2 commits into
JuliaGPU:mainfrom
nhz2:nz/inplace-transfer
Apr 24, 2026
Merged

Add JACC.transfer!#357
williamfgc merged 2 commits into
JuliaGPU:mainfrom
nhz2:nz/inplace-transfer

Conversation

@nhz2

@nhz2 nhz2 commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

This PR adds a new function transfer! as an in-place version of to_host or to_device. Fixes #356

Unlike copy! or copyto!, transfer! checks that the source and destination arrays have the same axes and element type.

The tests currently fail because copyto! doesn't work with views when using CUDA.jl. I think it is important to be able to handle basic contiguous views of host and device arrays, especially since the function has strict axes checks. But should this be fixed in JACC.jl, CUDA.jl, or somewhere else?

Also looking for feedback on the function name. I had originally thought of using to_host! and to_device!, but it turns out a single transfer! function can do both.

@PhilipFackler

Copy link
Copy Markdown
Collaborator

Test this please

@PhilipFackler

Copy link
Copy Markdown
Collaborator

@nhz2 the above comment is only to trigger our local GPU runners. :)

@PhilipFackler

Copy link
Copy Markdown
Collaborator

Test this please

@PhilipFackler

Copy link
Copy Markdown
Collaborator

@nhz2 , I pushed to your branch, but feel free to update as you see fit. I added tests for 2D arrays to test strided views, and I think my updates should handle the relevant use-cases.

See the issue here. Using a SubArray of a Base.Array results in calling the base implementation of copyto! for two AbstractArrays, since the GPUArrays (and CUDA, etc) versions of copyto! accept strictly Array input.

My addition here is an attempt to work around that. Hope that makes sense. Let me know what you think.

@PhilipFackler PhilipFackler added the enhancement New feature or request label Apr 15, 2026
@PhilipFackler

Copy link
Copy Markdown
Collaborator

@nhz2 , @williamfgc any further comments before I merge this?

@williamfgc

williamfgc commented Apr 24, 2026

Copy link
Copy Markdown
Collaborator

LGTM, thanks a lot to @nhz2 for the contribution. Please feel free to move it out of the "draft" stage.

@PhilipFackler PhilipFackler marked this pull request as ready for review April 24, 2026 16:10
Comment thread docs/src/api_usage.md
- **`JACC.fill`**: create a new array on the device filled with a specified value.
- **`JACC.to_device`**: transfer an existing Julia array from host to device.
- **`JACC.to_host`**: transfer an existing JACC array from device to host.
- **`JACC.transfer!`**: in-place version of `to_device` or `to_host`.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for adding docs!

Comment thread src/array.jl

See also [`copyto!`](@ref).
"""
function transfer!(dst::AbstractArray{T, N}, src::AbstractArray{

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for adding API docs

@williamfgc williamfgc left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@williamfgc williamfgc merged commit 5847b84 into JuliaGPU:main Apr 24, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Memory allocation docs section missing inplace copy

3 participants