Skip to content

DArray: Do not pass Base._InitialValue to partition reductions - #769

Merged
jpsamaroo merged 1 commit into
JuliaParallel:masterfrom
aalquwayfili:mapreduce-gpu-init
Oct 13, 2026
Merged

jpsamaroo merged 1 commit into
JuliaParallel:masterfrom
aalquwayfili:mapreduce-gpu-init

Conversation

@aalquwayfili

Copy link
Copy Markdown
Contributor

Fixes #768.

When the caller gives no init, each partition was reduced with init=Base._InitialValue(). GPU arrays take that for the initial value and the kernel fails to compile, so every reduction on a GPU backed DArray threw. This leaves init out when there is none (_reduce_kwargs), for the partition reductions and for _extrema_inner.

Tested on a Quadro RTX 8000 with CUDA.jl 6.4.2. With the change sum, prod, mapreduce, maximum and extrema match the CPU result, and sum, maximum and extrema also do with dims.

test/runtests.jl --test gpu with CI_USE_CUDA=1 passes, 242 tests. With the source change reverted, 8 of the 9 new tests error. The one that passes is sum(DA; init=0f0).

One of my two runs with the change had 3 errors in the existing Arrays (GPU all) testset (a MethodError from a deserialized generate_thunks closure on a worker). It did not repeat and the run without the change did not have it, so it looks like a flake.

#670 edits the same two @spawn lines (it adds a task name), so one of the two will need a small rebase.

mean/var/std still fail on GPU, for a different reason (mutable OnlineStats accumulators in a CuArray).

@jpsamaroo

Copy link
Copy Markdown
Member

Thanks, this looks great! I'm looking into why GPU CI is suddenly failing, once that's fixed we can merge this.

When the caller gives no `init`, each partition was reduced with
`init=Base._InitialValue()`. `Base`'s own reductions read that as "no
`init`", but GPU arrays take it for the initial value, so the kernel
calls `add_sum(::Base._InitialValue, ::Float32)` and fails to compile:

    InvalidIRError: compiling MethodInstance for
    CUDACore.partial_mapreduce_grid(::typeof(identity), ::typeof(Base.add_sum), ::Base._InitialValue, ...)
    Reason: unsupported call to an unknown function (call to jl_f_throw_methoderror)

`sum`, `prod`, `mapreduce`, `minimum`, `maximum` and `extrema` all
failed this way on a `DArray` of GPU arrays. Leave `init` out when
there is none.
@jpsamaroo
jpsamaroo merged commit d87a730 into JuliaParallel:master Oct 13, 2026
44 of 58 checks passed
@jpsamaroo

Copy link
Copy Markdown
Member

Thanks so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sum, prod, maximum and mapreduce fail on a GPU backed DArray

2 participants