Repository navigation
perf(minmax): keep the AVX2 float valid kernels out of legacy SSE (#33463) - #33502
Conversation
At 80-90% NULLs the float valid kernels were up to 4.7x slower than the scalar loop. Their visit path, for words with few valid rows, ran scalar float code, which Go encodes as legacy SSE even with GOAMD64=v3, between the 256-bit loops. Each switch between the two costs about 300 cycles: a strict alternation of visit and masked words, which predicts perfectly, took 6.6 us per 8192 rows against 0.4 and 1.0 us for either path alone. int kernels, whose visit path stays in integer registers, do not pay it. On AVX2 the float kernels now visit in integer registers: they read the values' bits, map them to integer keys that order like the floats (a negative value's other bits flip), skip NaN with an integer test, and convert the bounds back after the loop. The keys are set up before any vector code, so no legacy SSE runs while the 256-bit state is live. float32 visits up to 12 valid rows a word, float64 up to 16. arm64 is unchanged. BenchmarkSwitch measures the paths alone and in alternation, and the valid tests gain a mask near the visit thresholds. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
This pull request is merged. |
TestIntegerDifferential and TestFloatDifferential compare Integer, Float, IntegerValid and FloatValid, whichever kernels the build has, with plain loops for every element type and a named one: random lengths up to 700, masks with an exact random count of valid rows per word or whole runs, and values from random bits (every NaN, subnormal and sign pattern) mixed with extremes, -0, signaling and negative NaN. FuzzMinMax runs the same comparisons on fuzzer input. Each of four kernel mutations fails them: no NaN skip, no negative-key flip, a wrong lane-select table, and an off-by-one tail reload. 3 minutes of fuzzing the SIMD build (26.8M runs) found nothing. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ARM64 fuzz and benchmark resultsApple M2 Max, macOS, Go 1.27.1, No float regression on ARM64. This PR does not change the arm64 kernels ( Fuzz
Gap in
So the tests cover the kernels well, but the fuzz target would be stronger with a mask mode that produces full words.
|
| kernel | visit only | masked only | mean of the two | alternate | random 50/50 |
|---|---|---|---|---|---|
| float32 | 860 | 1322 | 1091 | 973 | 898 |
| float64 | 872 | 2504 | 1688 | 1505 | 1516 |
| int32 | 383 | 934 | 658 | 632 | 626 |
Alternate and random are below the mean, so there is no switch cost.
BenchmarkValid, scalar loop → NEON kernel (ns, 8192 rows)
| NULLs | float32 | float64 | ||
|---|---|---|---|---|
| one row | 6031 → 963 | 6.3x | 6035 → 1787 | 3.4x |
| 1% | 9091 → 1112 | 8.2x | 9030 → 2160 | 4.2x |
| 10% | 12828 → 1345 | 9.5x | 12802 → 2516 | 5.1x |
| 50% | 7102 → 1322 | 5.4x | 7049 → 2511 | 2.8x |
| 80% | 2882 → 1342 | 2.1x | 2814 → 2418 | 1.2x |
| 90% | 1368 → 1063 | 1.3x | 1372 → 1346 | 1.02x |
| 95% | 696 → 700 | 0.99x | 693 → 699 | 0.99x |
| 99% | 259 → 260 | 1.0x | 259 → 261 | 0.99x |
At 95–99% almost every word is visited row by row, as in the scalar loop. The integer kernels are at worst equal to scalar (int64 at 80%: 1210 → 1213).
GetMinMaxValue, before #33464 → this PR (ns, 8192 rows)
The old side is this PR's tree with the pre-#33464 vector/minmax.go and vector/utils.go. Runs are interleaved, SIMD build on both sides.
| NULLs | FLOAT | DOUBLE | ||
|---|---|---|---|---|
| none | 5517 → 850 | 6.5x | 5572 → 1660 | 3.4x |
| one row | 14284 → 1245 | 11x | 14256 → 2071 | 6.9x |
| 1% | 14157 → 1413 | 10x | 14155 → 2418 | 5.9x |
| 10% | 13989 → 1622 | 8.6x | 13472 → 2790 | 4.8x |
| 50% | 22532 → 1611 | 14x | 22072 → 2785 | 7.9x |
| 80% | 7354 → 1700 | 4.3x | 7291 → 2622 | 2.8x |
| 90% | 6819 → 1319 | 5.2x | 6774 → 1677 | 4.0x |
| 95% | 6938 → 933 | 7.4x | 6788 → 955 | 7.1x |
| 99% | 6716 → 552 | 12x | 6716 → 553 | 12x |
BenchmarkMinMax without NULLs, scalar → NEON (8192 rows)
int8 23x, int16 14x, int32 6.5x, int64 1.8x, uint8 23x, uint16 14x, uint32 6.5x, uint64 1.8x, float32 6.7x, float64 3.3x.
🤖 Generated with Claude Code
The integer visit path left float64 at 90% NULLs 12-15% slower than before: nearly every word took the old visit path, which never switched and whose float compares were predicted. But at high NULL density the plain scalar loop, which runs no 256-bit code, beats every kernel variant. FloatValid now counts the valid rows, stopping once there are enough, and below a per-architecture threshold takes the scalar loop: on AVX2 25% valid for float32 and 40% for float64, the measured crossovers. arm64 keeps the kernels (0) until it is measured. TestValidKernelsDifferential runs the float valid kernels directly, past the threshold, so they stay tested at every density, and TestSIMDKernelsRun checks the dispatch. Co-Authored-By: Claude Opus 5.5 <[email protected]>
FuzzMinMax never reached the NULL-free-word path of the valid kernels for 8 of the 10 types: an all-valid word needs 8 consecutive 0xff mask bytes. The kind byte now also selects whether even and odd words are all valid. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Measured on an M2 Max: faster than the scalar loop up to 90% NULLs, equal at 95% and 99%. Co-Authored-By: Claude Opus 5.5 <[email protected]>
## What type of PR is this? - [x] Documentation - [x] Test and CI ## Which issue(s) this PR fixes: Related to #30150 for the required check on cancelled producers. The rollout uses the control runner support from #28717 and addresses the queue observed on #33494 and #33501. ## What this PR does / why we need it: On #33501 the old required check waited 7m35s for a hosted runner and ran for four seconds. The replacement workflow was unable to start preflight during that wait. On #33494 the old required check and the cancellation controller also queued together. [Required check from #33501](https://github.com/matrixorigin/matrixone/actions/runs/46374859836/job/141702801415) · [Required check from #33494](https://github.com/matrixorigin/matrixone/actions/runs/46368023504/job/141705095759) The repository setting for preflight, the required check and the cancellation controller now selects the shared CS medium pool. This update records the operational setting and how to restore hosted execution and release a superseded run if a runner label stops serving work. Two simultaneous jobs using the shared label started on MTY and RUH in 7 and 11 seconds. A hosted reference submitted with them waited 61 seconds. JED and MNL2 also ran the same checkout, PR metadata read and required-check verification. [Shared-label comparison](https://github.com/matrixorigin/matrixone/actions/runs/46378188128) · [JED and MNL2](https://github.com/matrixorigin/matrixone/actions/runs/46380046197) In a branch-isolated handoff, cancellation made the old required check fail and the successor reached a runner 50 seconds after its workflow was created. A second exercise held the old required check on a nonexistent label, restored the hosted default for the successor, and used GitHub's force-cancel operation on the obsolete probe. The 65 existing scope and cancellation tests passed locally. [Cancelled producer](https://github.com/matrixorigin/matrixone/actions/runs/46379765379) · [Successful successor](https://github.com/matrixorigin/matrixone/actions/runs/46379836410) · [Hosted recovery](https://github.com/matrixorigin/matrixone/actions/runs/46380130392) After the repository setting changed on November 30 at 08:20 UTC, the production preflight picked up this main PR on RUH in 15 seconds and a 4.2-dev PR on MTY in 5 seconds. The cancellation controller for this PR picked up on RUH in 10 seconds. [Main preflight](https://github.com/matrixorigin/matrixone/actions/runs/46380837572/job/141720723388) · [4.2-dev preflight](https://github.com/matrixorigin/matrixone/actions/runs/46381492276/job/141721422578) · [Cancellation controller](https://github.com/matrixorigin/matrixone/actions/runs/46380847802/job/141719313212) On main PR #33502 the deployed controller picked up on RUH in 11 seconds, waited the existing grace period, and automatically force-cancelled the superseded run while its hosted required check was queued. The successor preflight picked up on MTY in 5 seconds. From the new workflow being created to preflight starting took 2m48s. This documentation PR's required check also passed on MTY after a 6-second queue. [Automatic cancellation](https://github.com/matrixorigin/matrixone/actions/runs/46382877728/job/141725947578) · [Successor preflight](https://github.com/matrixorigin/matrixone/actions/runs/46382871951/job/141727210246) · [Passing required check](https://github.com/matrixorigin/matrixone/actions/runs/46380837572/job/141731647152)
What type of PR is this?
Which issue(s) this PR fixes:
issue #33463
What this PR does / why we need it:
Follow-up to #33464. On amd64, its SIMD float valid kernels (
FloatValid, used byGetMinMaxValueon columns with NULLs) were slower than the scalar loop at high NULL density: float32 at 90% NULLs took 2.3 µs per 8192 rows against 0.49 µs scalar.Cause. A kernel visits words with few valid rows row by row (the visit path) and masks the others with 256-bit vectors. In the float kernels the visit path ran scalar float code, which Go encodes as legacy SSE even with
GOAMD64=v3. Each switch between that code and the 256-bit loops costs about 300 cycles. The evidence:math.Float64bits(rows[i])and register spills in the setup code.Fix (AVX2 only, in
mkminmax.go):vzeroupper, the kernels now contain no legacy-SSE instruction (checked with binutilsobjdump).FloatValidnow counts the valid rows, stopping as soon as there are enough, and takes the scalar loop below a per-architecture threshold. On AVX2 that is 25% valid rows for float32 and 40% for float64, the measured crossovers (float64 vectors hold half as many lanes, so the scalar loop wins sooner).Benchmarks
Intel Core Ultra 9 275HX (AVX2),
GOEXPERIMENT=simd GOAMD64=v3, pinned to one performance core, median of 8 interleaved runs, main → this PR.BenchmarkSwitch(new), 128 words, each with 4 valid rows (visit) or 32 (masked), ns:BenchmarkValid, 8192 rows with random NULLs, ns. "scalar" is the plain scalar loop:BenchmarkGetMinMaxValueNulls(8192 rows, main → PR): DOUBLE at 90% NULLs 754 → 721 ns (−4%), at 99% 409 → 370 ns (−9%), and at 0–50% +0.6% to +2.2%. BIGINT and everyBenchmarkGetMinMaxValueByTypecase are within ±1%.Costs: counting the valid rows adds about 20 ns per 8192 rows on float32 columns that have some NULLs but are mostly valid (+1.7% to +3.6%); float64 pays about 1%. It stops after a quarter (float32) or two fifths (float64) of the words of a dense column. Columns without NULLs never reach it. At 80–99% NULLs the PR stays 10–30 ns above the scalar loop: that's the count plus the call.
arm64 thresholds
arm64 has not been measured, so its thresholds are 0. To set them, run the crossover on an arm64 machine:
For each type, find the NULL percentage where the
scalarrow starts beatingdefault. Then setscalarBelow["NEON"]inmkminmax.goto 100 minus that percentage, rungo generate ./pkg/common/minmax, and checkTestSIMDKernelsRun.Tests
TestValidKernelsDifferentialcalls the float valid kernels directly, past the density threshold, so they stay tested at every NULL density.TestSIMDKernelsRunchecks that a mostly NULL column takes the scalar loop where the threshold is set, and the kernel where it isn't.TestIntegerDifferentialandTestFloatDifferentialcompareInteger,Float,IntegerValidandFloatValid(whichever kernels the build has) with plain loops. They cover every element type and a named type, with random lengths up to 700 rows.FuzzMinMaxruns the same comparisons on fuzzer input. 3 minutes of fuzzing in the SIMD build (26.8M executions) found nothing.TestFloatValidandTestIntegerValidgain a "sparse words" mask, about 13 valid rows per word, which lands on both sides of the visit thresholds.pkg/common/minmaxpasses in the scalar build and in the SIMD build with-race; arm64 SIMD vets.make static-check-changedreports 0 issues.🤖 Generated with Claude Code