Support GPUArrays 12 and array-returning `sum(x; dims)` reductions #3957
All Vouch review confidence checks passed
Residual risk 0.20 = Change Risk (0.50) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.50 · 630 lines diff across 7 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.386
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #3957"
general
weight: 0.35
vchuravy
Supersedes #3788 (its commit is cherry-picked here with @vchuravy's authorship), #3784 and #3785.
Before: Enzyme caps GPUArrays at 11. Lifting the cap alone fails: on GPUArrays 12
EnzymeGPUArraysExtdoes not precompile, because its rules nameGPUArrays.mapreducedim!, which 12 removed (reductions go through AcceleratedKernels now). Separately,sum(x; dims)in reverse mode fails on every GPUArrays version with aMethodError(#3808): the_mapreducerules only cover a scalarActivereturn, buthas_rrule_from_sigmatches onType{<:Annotation}, so Enzyme commits to a rule and then finds none.After: Enzyme allows GPUArrays 10, 11 and 12, and
sum(x; dims)differentiates in forward and reverse mode on anyAbstractGPUArray.How:
mapreducedim!rules are defined only@static if isdefined(GPUArrays, :mapreducedim!). The_mapreducerule, which handlessum/mapreduce(identity, add_sum, …)on every backend, is unchanged. GPUArrays 12 passesinit = _NoInit()(notnothing) when noinitis given, so_dinitpasses that marker through.augmented_primal/reversefor_mapreducewith an array (Duplicated/BatchDuplicated) return: the primal runs, a zero shadow of the result goes on the tape, and the reverse pass broadcasts it back along the reduced dims (dA .+= dR).Const-return variants cover an unused result.test/ext/jlarrays.jlgainsdims(1, 2, (1,2)), batched,init, unused-result and forward cases plus a scalarinitcase;test/cuda.jlgainsdimstests (1, 2, (1,2), adot-weighted variant, batched) and, on CUDA ≥ 6.5, a check thatfill!on aFloat32CuArray is no longer ambiguous (#3807). The losses stay off broadcasts on purpose: on CUDA 6.5 + GPUArrays 12 a CuArray broadcast is a KernelAbstractions launch, which CUDACore's Enzyme rules do not cover yet (JuliaGPU/CUDA.jl#3407, see notes).Results
Pkg.test(test_args=["ext/jlarrays"]): resolves JLArrays 0.4.2 / GPUArrays 12.2.0 (LLVM 9.13), all pass.MethodErrorbefore,dx == onesafter.- CUDA 6.4.2 / GPUArrays 11.5.16 (what Buildkite resolves for this PR, up to the 6.4.1 patch level), Julia 1.13: "GPUArrays linalg rules" 14/14 (the
fill!check is skipped below 6.5), "view and reshape keep the shadow buffer alive" 6/6.- CUDA 6.5.1 / GPUArrays 12.2.0 / LLVM.jl 10.4.3, stacked on the LLVM 10 PR: the whole
test/cuda.jlpasses on Julia 1.11; on Julia 1.13 "GPUArrays linalg rules" 15/15 and the refcount test 6/6 (with theCUDA.reclaim()change from the LLVM 10 PR). "Reverse Kernel" fails on 1.13 on this machine only; the same test segfaults here on plain main and passes on 1.11 and in upstream CI.- #3808 MWE on CUDA 6.5.1:
dx == ones.Notes
_mapreduce/mapreducedim!/fill!rules (JuliaGPU/CUDA.jl#3272), so this extension is now the only owner of them; that removes thefill!ambiguity behind #3807 once CUDA 6.5 is reachable. #3807's MWE still does not run on CUDA 6.5.1, though: itsy .+= xis a broadcast, and on GPUArrays 12 broadcasts are KernelAbstractions kernels that CUDACore launches throughKI.launch→kernel_launch→managed_kernel_launch, bypassing theHostKernelcall itsEnzymeCoreExthooks. Enzyme then descends into the managed-memory bookkeeping and fails withIllegalTypeAnalysisExceptioninCUDACore.acquire_managed(::Vector{Managed}, ::CuStream). On CUDA 6.4.1 / GPUArrays 11 broadcasts launched through@cuda, which has a rule, sosum(x .+ y)in reverse mode worked there (JuliaGPU/CUDA.jl#2455). This is the launch-path gap of JuliaGPU/CUDA.jl#3407 and needs a rule in CUDACore'sEnzymeCoreExt. #3807 and #3453 stay open until then._isconsthere testsx.dval === x.valto detect a shadow that aliases its primal. Areshapeof aConstCuArray gets a shadow that is a differentCuArrayobject over the same buffer, so the check misses it and the_mapreducereverse rule accumulates the cotangent into the primal (sum(x)grows by the cotangent). The check needs to compare the underlying buffer, not object identity. Left for a separate PR.identity/add_sumis covered; otherf/oppairs still go through the backend kernel.doton a JLArray fails in reverse mode on GPUArrays 11 (EnzymeNonScalarReturnException) and in forward mode on 12 (runtime-activity error insidemapreduce(dot, +)).Closes #3808.
🤖 Generated with Claude Code
https://claude.ai/code/session_01MsLzHnCigzwjd2ykwJsqYe