Skip to content

Commit 71acbb7

Browse files
authored
Add has_rocm for OpenMPI (#821)
1 parent 5e6557d commit 71acbb7

File tree

5 files changed

+64
-5
lines changed

5 files changed

+64
-5
lines changed

docs/src/knownissues.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ Make sure to:
180180
```
181181
- Then in Julia, upon loading MPI and CUDA modules, you can check
182182
- CUDA version: `CUDA.versioninfo()`
183-
- If MPI has CUDA: `MPI.has_cuda()`
183+
- If MPI has CUDA: [`MPI.has_cuda()`](@ref)
184184
- If you are using correct MPI library: `MPI.libmpi`
185185
186186
After that, it may be preferred to run the Julia MPI script (as suggested [here](https://discourse.julialang.org/t/cuda-aware-mpi-works-on-system-but-not-for-julia/75060/11)) launching it from a shell script (as suggested [here](https://discourse.julialang.org/t/cuda-aware-mpi-works-on-system-but-not-for-julia/75060/4)).
@@ -197,6 +197,7 @@ Make sure to:
197197
```
198198
- Then in Julia, upon loading MPI and CUDA modules, you can check
199199
- AMDGPU version: `AMDGPU.versioninfo()`
200+
- If MPI has ROCm: [`MPI.has_rocm()`](@ref)
200201
- If you are using correct MPI implementation: `MPI.identify_implementation()`
201202
202203
After that, [this script](https://gist.github.com/luraess/c228ec08629737888a18c6a1e397643c) can be used to verify if ROCm-aware MPI is functional (modified after the CUDA-aware version from [here](https://discourse.julialang.org/t/cuda-aware-mpi-works-on-system-but-not-for-julia/75060/11)). It may be preferred to run the Julia ROCm-aware MPI script launching it from a shell script (as suggested [here](https://discourse.julialang.org/t/cuda-aware-mpi-works-on-system-but-not-for-julia/75060/4)).

docs/src/reference/library.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@ MPI.MPI_LIBRARY_VERSION_STRING
1414
```@docs
1515
MPI.versioninfo
1616
MPI.has_cuda
17+
MPI.has_rocm
18+
MPI.has_gpu
1719
MPI.identify_implementation
1820
```

docs/src/usage.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ should confirm your MPI implementation to have the ROCm support (AMDGPU) enabled
9898
[alltoall\_test\_rocm\_multigpu.jl](https://gist.github.com/luraess/a47931d7fb668bd4348a2c730d5489f4) should confirm
9999
your ROCm-aware MPI implementation to use multiple AMD GPUs (one GPU per rank).
100100

101-
The status of ROCm (AMDGPU) support cannot currently be queried.
101+
If using OpenMPI, the status of ROCm support can be checked via the
102+
[`MPI.has_rocm()`](@ref) function.
102103

103104
## Writing MPI tests
104105

src/environment.jl

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,21 +320,23 @@ Wtime() = API.MPI_Wtime()
320320
321321
Check if the MPI implementation is known to have CUDA support. Currently only Open MPI
322322
provides a mechanism to check, so it will return `false` with other implementations
323-
(unless overriden).
323+
(unless overriden). For "IBMSpectrumMPI" it will return `true`.
324324
325325
This can be overriden by setting the `JULIA_MPI_HAS_CUDA` environment variable to `true`
326326
or `false`.
327327
328328
!!! note
329329
For OpenMPI or OpenMPI-based implementations you first need to call [Init()](@ref).
330+
331+
See also [`MPI.has_rocm`](@ref) for ROCm support.
330332
"""
331333
function has_cuda()
332334
flag = get(ENV, "JULIA_MPI_HAS_CUDA", nothing)
333335
if flag === nothing
334336
# Only Open MPI provides a function to check CUDA support
335337
@static if MPI_LIBRARY == "OpenMPI"
336338
# int MPIX_Query_cuda_support(void)
337-
return 0 != ccall((:MPIX_Query_cuda_support, libmpi), Cint, ())
339+
return @ccall libmpi.MPIX_Query_cuda_support()::Bool
338340
elseif MPI_LIBRARY == "IBMSpectrumMPI"
339341
return true
340342
else
@@ -344,3 +346,44 @@ function has_cuda()
344346
return parse(Bool, flag)
345347
end
346348
end
349+
350+
"""
351+
MPI.has_rocm()
352+
353+
Check if the MPI implementation is known to have ROCm support. Currently only Open MPI
354+
provides a mechanism to check, so it will return `false` with other implementations
355+
(unless overriden).
356+
357+
This can be overriden by setting the `JULIA_MPI_HAS_ROCM` environment variable to `true`
358+
or `false`.
359+
360+
See also [`MPI.has_cuda`](@ref) for CUDA support.
361+
"""
362+
function has_rocm()
363+
flag = get(ENV, "JULIA_MPI_HAS_ROCM", nothing)
364+
if flag === nothing
365+
# Only Open MPI provides a function to check ROCm support
366+
@static if MPI_LIBRARY == "OpenMPI" && MPI_LIBRARY_VERSION v"5"
367+
# int MPIX_Query_rocm_support(void)
368+
return @ccall libmpi.MPIX_Query_rocm_support()::Bool
369+
else
370+
return false
371+
end
372+
else
373+
return parse(Bool, flag)
374+
end
375+
end
376+
377+
"""
378+
MPI.has_gpu()
379+
380+
Checks if the MPI implementation is known to have GPU support. Currently this checks for the
381+
following GPUs:
382+
383+
1. CUDA: via [`MPI.has_cuda`](@ref)
384+
2. ROCm: via [`MPI.has_rocm`](@ref)
385+
386+
See also [`MPI.has_cuda`](@ref) and [`MPI.has_rocm`](@ref) for more fine-grained
387+
checks.
388+
"""
389+
has_gpu() = has_cuda() || has_rocm()

test/test_basic.jl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,22 @@ MPI.Init()
88

99
@test MPI.has_cuda() isa Bool
1010

11-
if get(ENV,"JULIA_MPI_TEST_ARRAYTYPE","") == "CuArray"
11+
if get(ENV, "JULIA_MPI_TEST_ARRAYTYPE", "") == "CuArray"
1212
@test MPI.has_cuda()
1313
end
1414

15+
@test MPI.has_rocm() isa Bool
16+
17+
if get(ENV, "JULIA_MPI_TEST_ARRAYTYPE", "") == "ROCArray"
18+
@test MPI.has_rocm()
19+
end
20+
21+
@test MPI.has_gpu() isa Bool
22+
23+
if get(ENV, "JULIA_MPI_TEST_ARRAYTYPE", "") == "CuArray" || get(ENV, "JULIA_MPI_TEST_ARRAYTYPE", "") == "ROCArray"
24+
@test MPI.has_gpu()
25+
end
26+
1527
@test !MPI.Finalized()
1628
MPI.Finalize()
1729
@test MPI.Finalized()

0 commit comments

Comments
 (0)