Skip to content

Commit

Permalink
update to CUDA v1.0+ (#401)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebolewski authored Jun 23, 2020
1 parent 393543b commit 1fd7c09
Show file tree
Hide file tree
Showing 28 changed files with 62 additions and 69 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ Requires = "~0.5, 1.0"
julia = "1"

[extras]
CuArrays = "3a865a2d-5b23-5a0f-bc46-62713ec82fae"
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
DoubleFloats = "497a8b3b-efae-58df-a0af-a86822472b78"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["CuArrays", "DoubleFloats", "Pkg", "Test"]
test = ["CUDA", "DoubleFloats", "Pkg", "Test"]
2 changes: 1 addition & 1 deletion docs/src/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ The test suite can also be modified by the following variables:

- `JULIA_MPIEXEC_TEST_ARGS`: Additional arguments to be passed to the MPI launcher for the tests only.
- `JULIA_MPI_TEST_ARRAYTYPE`: Set to `CuArray` to test the CUDA-aware interface with
[`CuArray`s](https://github.com/JuliaGPU/CuArrays.jl) buffers.
[`CUDA.CuArray](https://github.com/JuliaGPU/CUDA.jl) buffers.

## Julia wrapper for `mpiexec`

Expand Down
4 changes: 2 additions & 2 deletions docs/src/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ The [`mpiexec`](@ref) function is provided for launching MPI programs from Julia

## CUDA-aware MPI support

If your MPI implementation has been compiled with CUDA support, then `CuArray`s (from the
[CuArrays.jl](https://github.com/JuliaGPU/CuArrays.jl) package) can be passed directly as
If your MPI implementation has been compiled with CUDA support, then `CUDA.CuArray`s (from the
[CUDA.jl](https://github.com/JuliaGPU/CUDA.jl) package) can be passed directly as
send and receive buffers for point-to-point and collective operations (they may also work
with one-sided operations, but these are not often supported).

Expand Down
2 changes: 1 addition & 1 deletion src/MPI.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function __init__()
ENV["UCX_ERROR_SIGNALS"] = "SIGILL,SIGBUS,SIGFPE"
end

@require CuArrays="3a865a2d-5b23-5a0f-bc46-62713ec82fae" include("cuda.jl")
@require CUDA="052768ef-5323-5732-b1bb-66c8b64840ba" include("cuda.jl")
end

end
6 changes: 3 additions & 3 deletions src/buffers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Currently supported are:
- `Ref`
- `Array`
- `SubArray`
- `CuArray` if CuArrays.jl is loaded.
- `CUDA.CuArray` if CUDA.jl is loaded.
Additionally, certain sentinel values can be used, e.g. `MPI_IN_PLACE` or `MPI_BOTTOM`.
"""
Expand Down Expand Up @@ -79,8 +79,8 @@ and `datatype`. Methods are provided for
- `Ref`
- `Array`
- `CuArray` if CuArrays.jl is loaded
- `SubArray`s of an `Array` or `CuArray` where the layout is contiguous, sequential or
- `CUDA.CuArray` if CUDA.jl is loaded
- `SubArray`s of an `Array` or `CUDA.CuArray` where the layout is contiguous, sequential or
blocked.
"""
Expand Down
25 changes: 9 additions & 16 deletions src/cuda.jl
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
import .CuArrays: CuArray
import .CuArrays.CUDAdrv: CuPtr, synchronize
import .CuArrays.CUDAdrv.Mem: DeviceBuffer
import .CUDA


function Base.cconvert(::Type{MPIPtr}, buf::CuArray{T}) where T
Base.cconvert(CuPtr{T}, buf) # returns DeviceBuffer
function Base.cconvert(::Type{MPIPtr}, buf::CUDA.CuArray{T}) where T
Base.cconvert(CUDA.CuPtr{T}, buf) # returns DeviceBuffer
end

# CuArrays <= v1.3
function Base.unsafe_convert(::Type{MPIPtr}, buf::DeviceBuffer)
reinterpret(MPIPtr, buf.ptr)
end
# CuArrays > v1.3
function Base.unsafe_convert(::Type{MPIPtr}, X::CuArray{T}) where T
reinterpret(MPIPtr, Base.unsafe_convert(CuPtr{T}, X))
function Base.unsafe_convert(::Type{MPIPtr}, X::CUDA.CuArray{T}) where T
reinterpret(MPIPtr, Base.unsafe_convert(CUDA.CuPtr{T}, X))
end

# only need to define this for strided arrays: all others can be handled by generic machinery
function Base.unsafe_convert(::Type{MPIPtr}, V::SubArray{T,N,P,I,true}) where {T,N,P<:CuArray,I}
function Base.unsafe_convert(::Type{MPIPtr}, V::SubArray{T,N,P,I,true}) where {T,N,P<:CUDA.CuArray,I}
X = parent(V)
pX = Base.unsafe_convert(CuPtr{T}, X)
pX = Base.unsafe_convert(CUDA.CuPtr{T}, X)
pV = pX + ((V.offset1 + V.stride1) - first(LinearIndices(X)))*sizeof(T)
return reinterpret(MPIPtr, pV)
end

function Buffer(arr::CuArray)
function Buffer(arr::CUDA.CuArray)
Buffer(arr, Cint(length(arr)), Datatype(eltype(arr)))
end
4 changes: 2 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ using Test, MPI
# load test packages to trigger precompilation
using DoubleFloats
if get(ENV,"JULIA_MPI_TEST_ARRAYTYPE","") == "CuArray"
using CuArrays
ArrayType = CuArray
import CUDA
ArrayType = CUDA.CuArray
else
ArrayType = Array
end
Expand Down
4 changes: 2 additions & 2 deletions test/test_allgather.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ using Test
using MPI

if get(ENV,"JULIA_MPI_TEST_ARRAYTYPE","") == "CuArray"
using CuArrays
ArrayType = CuArray
import CUDA
ArrayType = CUDA.CuArray
else
ArrayType = Array
end
Expand Down
4 changes: 2 additions & 2 deletions test/test_allgatherv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ using Test
using MPI

if get(ENV,"JULIA_MPI_TEST_ARRAYTYPE","") == "CuArray"
using CuArrays
ArrayType = CuArray
import CUDA
ArrayType = CUDA.CuArray
else
ArrayType = Array
end
Expand Down
4 changes: 2 additions & 2 deletions test/test_allreduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ using Test
using MPI

if get(ENV,"JULIA_MPI_TEST_ARRAYTYPE","") == "CuArray"
using CuArrays
ArrayType = CuArray
import CUDA
ArrayType = CUDA.CuArray
else
ArrayType = Array
end
Expand Down
4 changes: 2 additions & 2 deletions test/test_alltoall.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ using Test
using MPI

if get(ENV,"JULIA_MPI_TEST_ARRAYTYPE","") == "CuArray"
using CuArrays
ArrayType = CuArray
import CUDA
ArrayType = CUDA.CuArray
else
ArrayType = Array
end
Expand Down
4 changes: 2 additions & 2 deletions test/test_alltoallv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ using Test
using MPI

if get(ENV,"JULIA_MPI_TEST_ARRAYTYPE","") == "CuArray"
using CuArrays
ArrayType = CuArray
import CUDA
ArrayType = CUDA.CuArray
else
ArrayType = Array
end
Expand Down
4 changes: 2 additions & 2 deletions test/test_basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ using Test
using MPI

if get(ENV,"JULIA_MPI_TEST_ARRAYTYPE","") == "CuArray"
using CuArrays
ArrayType = CuArray
import CUDA
ArrayType = CUDA.CuArray
else
ArrayType = Array
end
Expand Down
4 changes: 2 additions & 2 deletions test/test_bcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ using MPI
using Random

if get(ENV,"JULIA_MPI_TEST_ARRAYTYPE","") == "CuArray"
using CuArrays
ArrayType = CuArray
import CUDA
ArrayType = CUDA.CuArray
else
ArrayType = Array
end
Expand Down
4 changes: 2 additions & 2 deletions test/test_exscan.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ using Test
using MPI

if get(ENV,"JULIA_MPI_TEST_ARRAYTYPE","") == "CuArray"
using CuArrays
ArrayType = CuArray
import CUDA
ArrayType = CUDA.CuArray
else
ArrayType = Array
end
Expand Down
4 changes: 2 additions & 2 deletions test/test_gather.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ using Test
using MPI

if get(ENV,"JULIA_MPI_TEST_ARRAYTYPE","") == "CuArray"
using CuArrays
ArrayType = CuArray
import CUDA
ArrayType = CUDA.CuArray
else
ArrayType = Array
end
Expand Down
4 changes: 2 additions & 2 deletions test/test_gatherv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ using Test
using MPI

if get(ENV,"JULIA_MPI_TEST_ARRAYTYPE","") == "CuArray"
using CuArrays
ArrayType = CuArray
import CUDA
ArrayType = CUDA.CuArray
else
ArrayType = Array
end
Expand Down
4 changes: 2 additions & 2 deletions test/test_io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ using MPI
using Random

if get(ENV,"JULIA_MPI_TEST_ARRAYTYPE","") == "CuArray"
using CuArrays
ArrayType = CuArray
import CUDA
ArrayType = CUDA.CuArray
else
ArrayType = Array
end
Expand Down
4 changes: 2 additions & 2 deletions test/test_io_shared.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ using MPI
using Random

if get(ENV,"JULIA_MPI_TEST_ARRAYTYPE","") == "CuArray"
using CuArrays
ArrayType = CuArray
import CUDA
ArrayType = CUDA.CuArray
else
ArrayType = Array
end
Expand Down
4 changes: 2 additions & 2 deletions test/test_reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ using Test
using MPI

if get(ENV,"JULIA_MPI_TEST_ARRAYTYPE","") == "CuArray"
using CuArrays
ArrayType = CuArray
import CUDA
ArrayType = CUDA.CuArray
else
ArrayType = Array
end
Expand Down
4 changes: 2 additions & 2 deletions test/test_scan.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ using Test
using MPI

if get(ENV,"JULIA_MPI_TEST_ARRAYTYPE","") == "CuArray"
using CuArrays
ArrayType = CuArray
import CUDA
ArrayType = CUDA.CuArray
else
ArrayType = Array
end
Expand Down
4 changes: 2 additions & 2 deletions test/test_scatter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ using Test
using MPI

if get(ENV,"JULIA_MPI_TEST_ARRAYTYPE","") == "CuArray"
using CuArrays
ArrayType = CuArray
import CUDA
ArrayType = CUDA.CuArray
else
ArrayType = Array
end
Expand Down
4 changes: 2 additions & 2 deletions test/test_scatterv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ using Test
using MPI

if get(ENV,"JULIA_MPI_TEST_ARRAYTYPE","") == "CuArray"
using CuArrays
ArrayType = CuArray
import CUDA
ArrayType = CUDA.CuArray
else
ArrayType = Array
end
Expand Down
4 changes: 2 additions & 2 deletions test/test_sendrecv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ using Test
using MPI

if get(ENV,"JULIA_MPI_TEST_ARRAYTYPE","") == "CuArray"
using CuArrays
ArrayType = CuArray
import CUDA
ArrayType = CUDA.CuArray
else
ArrayType = Array
end
Expand Down
4 changes: 2 additions & 2 deletions test/test_subarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ using Test
using MPI

if get(ENV,"JULIA_MPI_TEST_ARRAYTYPE","") == "CuArray"
using CuArrays
ArrayType = CuArray
import CUDA
ArrayType = CUDA.CuArray
else
ArrayType = Array
end
Expand Down
4 changes: 2 additions & 2 deletions test/test_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ using Test
using MPI

if get(ENV,"JULIA_MPI_TEST_ARRAYTYPE","") == "CuArray"
using CuArrays
ArrayType = CuArray
import CUDA
ArrayType = CUDA.CuArray
else
ArrayType = Array
end
Expand Down
4 changes: 2 additions & 2 deletions test/test_threads.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ using Test
using MPI

if get(ENV,"JULIA_MPI_TEST_ARRAYTYPE","") == "CuArray"
using CuArrays
ArrayType = CuArray
import CUDA
ArrayType = CUDA.CuArray
else
ArrayType = Array
end
Expand Down
4 changes: 2 additions & 2 deletions test/test_wait.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ using Test
using MPI

if get(ENV,"JULIA_MPI_TEST_ARRAYTYPE","") == "CuArray"
using CuArrays
ArrayType = CuArray
import CUDA
ArrayType = CUDA.CuArray
else
ArrayType = Array
end
Expand Down

0 comments on commit 1fd7c09

Please sign in to comment.