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
25 changes: 25 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -1279,3 +1279,28 @@ this section verbatim). Each entry is one bullet starting with `- `.
Honor that flag before raising a positive pivot error, and retain the
global singular-column metadata. Check the public distributed LU call
on the older runtime: modern-runtime tests only exercise the other branch.

116. **A backend's generic scan and native product scan may initialize
differently.** AMDGPU and oneAPI default generic `accumulate` to a zero
initializer, even for multiplication; their native `cumprod` supplies the
product initialization. Lowering every product partition to generic
`accumulate(Base.mul_prod, ...)` therefore turns it into zeros. Use the
native product operation for partitions without an explicit initializer,
retaining the explicit initializer only on the first partition and the
existing carry combination afterwards. Preserve small-integer promotion
when choosing the native operation: generic `*` and `Base.mul_prod` are
different contracts. This does not supply a generic scan initializer:
without one, every independent scan lane starts from its own first value.

117. **Validate the private GPU compilation cache before blaming a change.**
With an incomplete private cache, `--compiled-modules=existing` produced
`LLVM.Interop.pointerset` InvalidIR errors even for a tiny broadcast in a
pinned Julia 1.11.9 / AMDGPU 2.1.0 environment. Allowing normal precompilation
into that private depot made the unchanged scan probe run: three controls
passed and three genuine numerical scan failures became visible. Package
sources and versions were unchanged. This does not make existing-only mode
universally invalid; it means a clean backend copy/kernel preflight and a
coherent private cache are prerequisites for interpreting a compiler error.
Never repair this by modifying installed package caches or disabling GPU
validation, and keep backend-only preflight and Dagger integration in
separate processes to isolate process-level state during diagnosis.
12 changes: 11 additions & 1 deletion src/array/map-reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,17 @@ std(f::Function, x::DArray; dims=nothing) =
# cannot do. Scan each partition on its own instead, then combine the running
# last slice of the partitions before it along `dims` into it. Like `reduce`,
# this assumes `op` is associative.
_accumulate_part(op, x, RT, dims, kw) = accumulate(op, _widen(x, RT); dims, kw...)
function _accumulate_part(op, x, RT, dims, kw)
part = _widen(x, RT)
# Some array backends default generic accumulate to a zero initializer,
# including for multiplication. Their native product scan supplies the
# correct operation-specific initialization. An explicit init still belongs
# to the first partition; later partitions use the ordinary product scan.
if op === Base.mul_prod && isempty(kw)
return cumprod(part; dims)
end
return accumulate(op, part; dims, kw...)
end
# Only the first partition along `dims` starts from `init`. When `init` widens
# the eltype, the others would scan in the narrower one and could overflow or
# lose precision before the carry reaches them, so widen the partitions first.
Expand Down
12 changes: 12 additions & 0 deletions test/array/mapreduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,18 @@ end
w8 = fill(Int8(100), 10, 4)
@test collect(accumulate(+, distribute(w8, Blocks(3, 2)); dims=1, init=0)) == accumulate(+, w8; dims=1, init=0)
@test collect(accumulate(+, distribute(w8[:, 1], Blocks(3)); init=0)) == accumulate(+, w8[:, 1]; init=0)
p8 = fill(Int8(2), 10, 4)
Dp = distribute(p8, Blocks(3, 2))
for dims in (1, 2)
expected = cumprod(p8; dims)
R = cumprod(Dp; dims)
@test eltype(R) == eltype(expected)
@test collect(R) == expected
expected_init = accumulate(Base.mul_prod, p8; dims, init=Int16(2))
Rinit = accumulate(Base.mul_prod, Dp; dims, init=Int16(2))
@test eltype(Rinit) == eltype(expected_init)
@test collect(Rinit) == expected_init
end
@test_throws ArgumentError cumsum(Dv; dims=0)
@test_throws ArgumentError accumulate(+, Dv; foo=1)
end
2 changes: 2 additions & 0 deletions test/gpu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ end
return
end
@test collect(cumsum(DA; dims=1)) ≈ cumsum(A; dims=1)
@test collect(cumprod(DA; dims=1)) ≈ cumprod(A; dims=1)
@test collect(cumprod(DA; dims=2)) ≈ cumprod(A; dims=2)
@test collect(accumulate(Base.mul_prod, DA; dims=2, init=2f0)) ≈ accumulate(Base.mul_prod, A; dims=2, init=2f0)
@test collect(accumulate(max, DA; dims=1)) == accumulate(max, A; dims=1)
@test collect(accumulate(+, DA; dims=2, init=1f0)) ≈ accumulate(+, A; dims=2, init=1f0)
# Metal has no Float64
Expand Down
Loading