Repository navigation
Fix MPI/count_eltype regressions and route large 2D histograms to global atomics - #35
Merged
Merged
Conversation
…, now pivoting towards algorithm optimization
…d and 2D batch paths
jbphyswx
force-pushed
the
gpu-sp2d-routing-and-count-eltype-fixes
branch
from
August 20, 2026 06:40
41cc22b to
b019a1e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-on to the
b4da818checkpoint: three bug fixes, two measured speedups, and the test coveragethat would have caught two of the bugs.
Bugs
count_eltypepositional/keyword mismatches (4b05764) — regression from makingcount_eltypepositional in the 1D chain. Four sites were missed:
SFC._dispatch_execution_backenddeclaredcount_eltypeas akeyword while the core passes it as the 7th positional argument, so no method matched and every
call fell through to the
(::AbstractMPIBackend, args...)stub — which reports "MPI backend isunavailable. Load MPI". A signature mismatch disguised as a missing package.
test_mpireportedBroken(itsmpiexeclaunch failed) rather than failing, so this was invisible.Now:
MPI_PARITY_OK np=2 nthreads=2 cases=20.count_eltypeand hardcodedzeros(UInt32, …), returningwrong-typed counts instead of erroring; it also forwarded the keyword into
auxiliary_joint2d!,which takes already-allocated buffers, so Distributed batched calls raised
MethodError.batch.jlused a hardcodedUInt32per-slice buffer, which overflows above N≈92k when widercounts were requested.
Single-pass 2D threw for any
n_dist > 128(5b963df) — above the tiled cap the only route isthe naive global-atomic kernel, which digitizes the value axis by binary search and demanded
workspace.value_edges_sp2d_dev. With no workspace (the default) every large-bin call raisedArgumentError. Now reconstructs the edge vector from the linear plan, matching theallocate-on-demand pattern the general-bins routes already use.
Performance
Four accumulators instead of six (
2473352) —T2 = S2 − L2andL1T2 = S3 − L3hold per pair,and a histogram bin is a sum, so two of the six moments are recovered exactly at flush instead of
costing a per-pair atomic. Applied to the CPU and KA sp1d kernels (the CUDA path landed in the
checkpoint). The derive runs at the end of each kernel and uses
=, never+=, so it isidempotent and correct under threaded/partial reduction — which avoids threading it through 20+
accumulator assembly points, several of which are sp2d where the identity does not hold.
sf1dalso drops a per-ilocal histogram (fill!two buffers, branchlessclampinto guardcells, merge
nbbins, everyi) for a direct scatter —clamp(bin, 0, nb+1)+1with cells 1 andnb+2dropped is exactlyif 1 <= bin <= nb.Large 2D histograms go to global atomics (
5b963df) —:directabandons the on-chip histogramfor block-private global partitions plus a merge, so its cost grows with cells × tile-blocks, while
plain global atomics get cheaper as more cells spread the contention. Above a measured 340 KB of
histogram bytes the naive kernel wins:
The threshold (rather than an unconditional skip) keeps
:directreachable below the crossover,where Float32 measured it still ~11% ahead — an unconditional skip would also have orphaned the
63-kernel template in
kernels_2d_direct.jland overfit one GPU.Tests
Nothing in the suite exercised 2D bin counts past 60×60, and no test asserted which kernel ran
— which is why both the routing cliff and the outright failure went unnoticed. Adds 100×100 and
200×200 cases plus direct assertions on the byte crossover.
It caught a real hole in this PR's own routing fix on the first run: the change handled
GPUValueLinearSharedbut not the per-momentGPUValueLinearColsplan, which has no global-atomicmethod above 128 bins. Root cause was the rule living in two places (the value-plan builder and the
launcher) that could disagree; both now consult one
_sp2d_prefers_global_atomicspredicate.Float64 is used for the large-bin assertions deliberately: Float32 carries ~7 digits and a histogram
this sparse disagrees with a Float64 reference by percent even on the CPU, so a Float32 assertion
there would be testing arithmetic, not the kernel.
Verification
gpu/SPEED_OF_LIGHT.mdrecords the analysis with every claim tagged measured / derived /inherited-unverified / hypothesis, including the levers that were measured dead (registers and
occupancy ≤3%, constant memory, textures 8.6% slower, a CUDA typeplane mode that was implemented and
then reverted for being ~2× slower than this routing change, larger tiles,
rsqrt) so they are notre-derived.
CI
benchmark/Project.tomlcarried a machine-specific absolute[sources]path — the only one of sixsuch files that was not relative (
docs/,docs/generate_assets/,examples/,gpu/all use".."). It was introduced in theb4da818checkpoint as a side effect of runningjulia --project=benchmark, and it brokePkg.update()on any other machine:Also stops tracking
.dev/Manifest.tomland removes theUpDepsworkflow..gitignorehas ignoredManifest.tomlfor a long time, but that has no effect on an already-tracked file, so this was theone committed manifest in the repo; there are now none. The workflow existed to assert that tracked
manifests were current (
update_depsthengit diff --exit-code), which is vacuous with nonetracked — and
UPDATE_PLAN.md:443already recorded the decision to remove it..dev/up_deps.jliskept: it refreshes the local, untracked manifests in one step.