Skip to content
Open
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
4 changes: 4 additions & 0 deletions src/datadeps/aliasing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,10 @@ function set_key_stored!(accel::DistributedAcceleration, cache::AliasedObjectCac
end

function aliased_object!(f, cache::AliasedObjectCache, x; ainfo=aliasing(cache.accel, x, identity))
# `NoAliasing` has no identity: every such value would share one cache key,
# so the second distinct argument would be handed the first one's slot.
# There is no aliasing to preserve, so each value gets its own copy.
(ainfo isa NoAliasing || (ainfo isa AliasingWrapper && ainfo.inner isa NoAliasing)) && return f(x)::Chunk
x_space = memory_space(x)
if !is_key_present(cache, x_space, ainfo)
# Preserve the object's memory-space/processor pairing when inserting
Expand Down
1 change: 1 addition & 0 deletions test/mpi/cpu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ end
end

include("spawn.jl")
include("noaliasing_args.jl")

@testset "Datadeps" begin

Expand Down
23 changes: 23 additions & 0 deletions test/mpi/noaliasing_args.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Datadeps arguments whose aliasing is `NoAliasing` share one aliasing identity; each must still reach its own task
# (app entry 45: with several in flight, writer i received the value of another partition).
struct NoAliasVal; part::Int; v::Vector{Float64}; end
Dagger.aliasing(::NoAliasVal) = Dagger.NoAliasing()
mk_noalias(part::Int) = NoAliasVal(part, fill(Float64(part), 10 + part))
check_noalias!(buf::Vector{Float64}, x::NoAliasVal, expect::Int) = (buf[1] = x.part == expect ? 0.0 : 1.0; buf[2] = x.part; nothing)

@testset "NoAliasing arguments of one Datadeps region keep their own value" begin
nr = MPI.Comm_size(comm)
P = 2 * nr
owner_of(i) = (i - 1) ÷ 2
procs_by_rank = Dict(r => first(filter(p -> p.rank == r, mpi_procs())) for r in 0:nr-1)
bufs = [Dagger.tochunk(zeros(2), procs_by_rank[owner_of(i)], Dagger.memory_space(procs_by_rank[owner_of(i)])) for i in 1:P]
vals = [Dagger.@spawn(scope=Dagger.scope(mpi_rank=owner_of(i)), mk_noalias(i)) for i in 1:P]
Dagger.spawn_datadeps() do
for i in 1:P
Dagger.@spawn scope=Dagger.scope(mpi_rank=owner_of(i)) check_noalias!(Dagger.InOut(bufs[i]), vals[i], i)
end
end
seen = [fetch(Dagger.@spawn(scope=Dagger.scope(mpi_rank=owner_of(i)), copy(bufs[i]))) for i in 1:P]
@test all(s -> s[1] == 0.0, seen)
@test [Int(s[2]) for s in seen] == collect(1:P)
end
Loading