Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions test/integration/MPI/nonblocking_halo.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using MPI
using Enzyme
using Test


function halo(x)
np = MPI.Comm_size(MPI.COMM_WORLD)
rank = MPI.Comm_rank(MPI.COMM_WORLD)
requests = Vector{MPI.Request}()
if rank != 0
buf = @view x[1:1]
push!(requests, MPI.Isend(x[2:2], MPI.COMM_WORLD; dest = rank - 1, tag = 0))
push!(requests, MPI.Irecv!(buf, MPI.COMM_WORLD; source = rank - 1, tag = 0))
end
if rank != np - 1
buf = @view x[end:end]
push!(requests, MPI.Isend(x[(end - 1):(end - 1)], MPI.COMM_WORLD; dest = rank + 1, tag = 0))
push!(requests, MPI.Irecv!(buf, MPI.COMM_WORLD; source = rank + 1, tag = 0))
end
for request in requests
MPI.Wait(request)
end
return nothing
end

MPI.Init()
np = MPI.Comm_size(MPI.COMM_WORLD)
rank = MPI.Comm_rank(MPI.COMM_WORLD)
nl = rank == 0 ? 0 : 2
nr = rank == np - 1 ? 0 : 2
nlocal = nr + nl + 1

x = zeros(nlocal)
fill!(x, Float64(rank))
halo(x)
MPI.Barrier(MPI.COMM_WORLD)

@test x[nl + 1] == Float64(rank) # Local
if rank != 0
@test x[1] == Float64(rank - 1) # Recv
@test x[2] == Float64(rank) # Send
end
if rank != np - 1
@test x[end] == Float64(rank + 1) # Recv
@test x[end - 1] == Float64(rank) # Send
end

dx = zeros(nlocal)
fill!(dx, Float64(rank))
autodiff(Reverse, halo, Duplicated(x, dx))
Copy link
Member

Choose a reason for hiding this comment

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

In 1.10 only: https://github.com/EnzymeAD/Enzyme.jl/actions/runs/19148197862/job/54731298414?pr=518#step:8:31

julia: /workspace/srcdir/Enzyme/enzyme/Enzyme/Utils.cpp:1804: llvm::Function* getOrInsertDifferentialMPI_Wait(llvm::Module&, llvm::ArrayRef<llvm::Type*>, llvm::Type*, llvm::StringRef): Assertion `isendfn' failed.

[1123] signal (6.-6): Aborted
in expression starting at /__w/Enzyme.jl/Enzyme.jl/test/integration/MPI/nonblocking_halo.jl:50
pthread_kill at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
gsignal at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
abort at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
unknown function (ip: 0x7ee131fcb81a)
__assert_fail at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
getOrInsertDifferentialMPI_Wait at /workspace/srcdir/Enzyme/enzyme/Enzyme/Utils.cpp:1804
handleMPI at /workspace/srcdir/Enzyme/enzyme/Enzyme/CallDerivatives.cpp:429
handleKnownCallDerivatives at /workspace/srcdir/Enzyme/enzyme/Enzyme/CallDerivatives.cpp:2254
visitCallInst at /workspace/srcdir/Enzyme/enzyme/Enzyme/AdjointGenerator.h:6405
visit at /opt/x86_64-linux-gnu/x86_64-linux-gnu/sys-root/usr/local/include/llvm/IR/InstVisitor.h:111 [inlined]
CreatePrimalAndGradient at /workspace/srcdir/Enzyme/enzyme/Enzyme/EnzymeLogic.cpp:4505
EnzymeCreatePrimalAndGradient at /workspace/srcdir/Enzyme/enzyme/Enzyme/CApi.cpp:688
EnzymeCreatePrimalAndGradient at /__w/Enzyme.jl/Enzyme.jl/src/api.jl:270
jfptr_EnzymeCreatePrimalAndGradient_24158 at /root/.julia/compiled/v1.10/Enzyme/G1p5n_64aGk.so (unknown line)
_jl_invoke at /cache/build/builder-amdci5-7/julialang/julia-release-1-dot-10/src/gf.c:2895 [inlined]
ijl_apply_generic at /cache/build/builder-amdci5-7/julialang/julia-release-1-dot-10/src/gf.c:3077
macro expansion at /__w/Enzyme.jl/Enzyme.jl/src/compiler.jl:2639 [inlined]
macro expansion at /root/.julia/packages/LLVM/iza6e/src/base.jl:97 [inlined]
enzyme! at /__w/Enzyme.jl/Enzyme.jl/src/compiler.jl:2512

Copy link
Member

Choose a reason for hiding this comment

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

Grrrml

Copy link
Member

Choose a reason for hiding this comment

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

MPI.Barrier(MPI.COMM_WORLD)

@test dx[nl + 1] == Float64(rank) # Local -> no change
if rank != 0
@test dx[1] == 0.0 # Recv -> Send & zero'd
@test dx[2] == Float64(rank + rank - 1) # Send -> += Recv
end
if rank != np - 1
@test dx[end] == 0.0 # Recv -> Send & zero'd
@test dx[end - 1] == Float64(rank + rank + 1) # Send -> += Recv
end

fill!(dx, Float64(rank))
autodiff(Forward, halo, Duplicated(x, dx))
MPI.Barrier(MPI.COMM_WORLD)

@test dx[nl + 1] == Float64(rank)
if rank != 0
@test dx[1] == Float64(rank - 1)
@test dx[2] == Float64(rank)
end
if rank != np - 1
@test dx[end] == Float64(rank + 1)
@test dx[end - 1] == Float64(rank)
end
15 changes: 15 additions & 0 deletions test/integration/MPI/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ using MPI
using Enzyme
using Test

# Current MPI support (needs to be tested from Julia)
# - MPI_Ssend
# - MPI_Waitall
# - MPI_Barrier/MPI_Probe
# - MPI_Allreduce
# - MPI_Bcast
# - MPI_Reduce
# - MPI_Gather/MPI_Scatter
# - MPI_Allgather

# Query functions MPI_Comm_size/MPI_Comm_rank
@testset "queries" for np in (1, 2, 4)
run(`$(mpiexec()) -n $np $(Base.julia_cmd()) --project=$(@__DIR__) $(joinpath(@__DIR__, "queries.jl"))`)
Expand All @@ -11,3 +21,8 @@ end
@testset "blocking_ring" for np in (1, 2, 4)
run(`$(mpiexec()) -n $np $(Base.julia_cmd()) --project=$(@__DIR__) $(joinpath(@__DIR__, "blocking_ring.jl"))`)
end

# Test MPI_Irecv/MPI_Isend/MPI_Wait with a non-blocking halo exchange pattern
VERSION >= v"1.11.0" && @testset "nonblocking_halo" for np in (1, 2, 4)
run(`$(mpiexec()) -n $np $(Base.julia_cmd()) --project=$(@__DIR__) $(joinpath(@__DIR__, "nonblocking_halo.jl"))`)
end