diff --git a/src/datadeps/aliasing.jl b/src/datadeps/aliasing.jl index f8de25146..cfce21de5 100644 --- a/src/datadeps/aliasing.jl +++ b/src/datadeps/aliasing.jl @@ -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 diff --git a/test/mpi/cpu.jl b/test/mpi/cpu.jl index 65c2697ea..39731dd91 100644 --- a/test/mpi/cpu.jl +++ b/test/mpi/cpu.jl @@ -146,6 +146,7 @@ end end include("spawn.jl") +include("noaliasing_args.jl") @testset "Datadeps" begin diff --git a/test/mpi/noaliasing_args.jl b/test/mpi/noaliasing_args.jl new file mode 100644 index 000000000..df7077903 --- /dev/null +++ b/test/mpi/noaliasing_args.jl @@ -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