Skip to content
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

Implement 3D async copy #447

Merged
merged 5 commits into from
Jul 20, 2023
Merged

Implement 3D async copy #447

merged 5 commits into from
Jul 20, 2023

Conversation

pxl-th
Copy link
Collaborator

@pxl-th pxl-th commented Jul 19, 2023

No description provided.

@pxl-th pxl-th added enhancement New feature or request hip labels Jul 19, 2023
src/runtime/memory/hip.jl Outdated Show resolved Hide resolved
src/runtime/memory/hip.jl Outdated Show resolved Hide resolved
@luraess
Copy link
Collaborator

luraess commented Jul 19, 2023

Suggesting this minor change to be able to pass a tuple as [src/dst]Pos

@luraess
Copy link
Collaborator

luraess commented Jul 19, 2023

Having an issue with the following MWE for dim=1

using AMDGPU

dim = 2  # works for 2 and 3, but not 1

P = zeros(Int32, 2, 3, 4)
P .= [iz*1e2 + iy*1e1 + ix for ix=1:size(P,1), iy=1:size(P,2), iz=1:size(P,3)];
P = ROCArray(P)

if dim==1
    ranges = [2:2, 1:size(P,2), 1:size(P,3)]
    buf = zeros(Int32, size(P,2), size(P,3))
elseif dim==2
    ranges = [1:size(P,1), 3:3, 1:size(P,3)]
    buf = zeros(Int32, size(P,1), size(P,3))
elseif dim==3
    ranges = [1:size(P,1), 1:size(P,2), 3:3]
    buf = zeros(Int32, size(P,1), size(P,2))
end

# device to host
AMDGPU.Mem.unsafe_copy3d!(
        pointer(buf), AMDGPU.Mem.HostBuffer,
        pointer(P), typeof(P.buf),
        length(ranges[1]), length(ranges[2]), length(ranges[3]);
        srcPos=AMDGPU.ROCDim3(ranges[1][1], ranges[2][1], ranges[3][1]),
        srcPitch=sizeof(Int32)*size(P,1), srcHeight=size(P,2),
        dstPitch=sizeof(Int32)*length(ranges[1]), dstHeight=length(ranges[2])
);

if dim==1
    @assert buf[:]  Array(P[2,:,:])[:]
elseif dim==2
    @assert buf[:]  Array(P[:,3,:])[:]
elseif dim==3
    @assert buf[:]  Array(P[:,:,3])[:]
end

# host to device
P2 = similar(P)

AMDGPU.Mem.unsafe_copy3d!(
        pointer(P2), typeof(P2.buf),
        pointer(buf), AMDGPU.Mem.HostBuffer,
        length(ranges[1]), length(ranges[2]), length(ranges[3]);
        dstPos=AMDGPU.ROCDim3(ranges[1][1], ranges[2][1], ranges[3][1]),
        srcPitch=sizeof(Int32)*length(ranges[1]), srcHeight=length(ranges[2]),
        dstPitch=sizeof(Int32)*size(P,1), dstHeight=size(P,2)
);

if dim==1
    @assert Array(P2[2,:,:])[:]  Array(P[2,:,:])[:]
elseif dim==2
    @assert Array(P2[:,3,:])[:]  Array(P[:,3,:])[:]
elseif dim==3
    @assert Array(P2[:,:,3])[:]  Array(P[:,:,3])[:]
end

@pxl-th pxl-th merged commit 0c511c6 into master Jul 20, 2023
5 checks passed
@pxl-th pxl-th deleted the pxl-th/copy-3d branch July 20, 2023 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request hip
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants