Repository navigation
fix(gpu): re-measure Auto routing and keep unsupported inputs on CPU - #376
Merged
Merged
Conversation
The CUDA routing cells dated from August and sent classic images as small as 256 x 149 to CUDA, which is now slower than the CPU for them. They were re-measured at 0c61cb2 on an RTX 4070 SUPER with Part 1 (openjpeg-data) and Part 15 (T.803) inputs. A single classic image now goes to CUDA only from 2592 x 1944 (RGB8 lossless from 640 x 480), and a region or half-size decode only from a 1296 x 972 output. Batches of one repeated image and the HTJ2K and JPH routes still go to CUDA. CUDA encode stayed slower than the CPU everywhere. Updates xtask/routing-promotion-evidence.json, the generated table, the tests that pin routed shapes, book/performance.md and the corpus recipe in contributor-book/benchmarks.md. Provisional: the measurements predate the performance commits before this one. CUDA and Metal routing still need re-measuring at a commit that includes them, and these cells, tests and numbers redoing. (cherry picked from commit 517b13bc3d13e8e5eb5f1a37746708259eafc197)
…hold The Metal lossy RGB8 encode gate required a nonzero pixel threshold, so a measurement in which no lossy encode was faster on Metal could not be recorded. `metal_lossy_rgb8` may now be `null`; the key stays required, and the generated `auto_lossy_rgb8_encode_qualifies` then returns false. `HOST_OUTPUT_CELLS` is now rendered the way rustfmt lays it out at every length: on one line, wrapped after `=`, or one cell per line. Before, a table of one or two cells failed `cargo fmt --check`. (cherry picked from commit 2b4705392e41bd916d8667d5de22ab4280b3f331)
The Metal cells came from September runs on an M4 Pro, before the CPU speedups and the faster Metal plan cache. They were re-measured at 57779fc2 on a Mac mini (Apple M4, 10 GPU cores) with 49 inputs built from two openjpeg-data photographs: 175 cells, 46 faster on Metal by the verifier's rule. Artifact 6f2b9815, manifest 64178573. - Single images go to Metal from 1024 x 1024 for lossless RGB8 (HTJ2K or Part 1) and at 2048 x 2048 for lossy RGB8 and Gray8 HTJ2K, instead of HTJ2K from 640 x 480, which is now slower on this GPU. - Half-size RGB8 decodes go to Metal from a 1024 x 1024 output for HTJ2K and Part 1 lossless; before, none did. - Repeated RGB8 batches go to Metal from 256 x 256 for every kind. Gray8 HTJ2K batches need 2048 x 2048 and Part 1 lossless 1024 x 1024; Part 1 lossy gray batches stay on the CPU. - Lossless HTJ2K host-output encode goes to Metal only at 2048 x 2048, and no lossy encode does: Metal took 2.5 to 21 times as long. Updates the tests that pin routed shapes, book/performance.md, book/gpu.md, the changelog, and the Metal corpus recipe in contributor-book/benchmarks.md, which now also says how each backend runs the repeated-input batch cell. (cherry picked from commit 1a50c5350cdf7a63d7f1586d2d499d941b84118f)
The CUDA cells from 904c2ed6 were measured at 0c61cb2, before the CPU and Metal performance commits. Re-measured at 533cbba7 on the same RTX 4070 SUPER with the same Part 1 and Part 15 manifests, the verifier reached the same decision for every one of the 58 cells: 28 decode cells go to CUDA and every encode stays on the CPU. Only the artifact hashes change (part1 6e522137, part15 fbca5ff2), so the generated table differs in those two constants and no routed shape or test changes. book/performance.md now quotes the new numbers and says that the CUDA batch cell plans, uploads, and decodes all 16 copies, while the CPU decodes them one after another.
The scheduler test hooks, the cache digest helpers, and the Metal promotion evidence constants are only read by macOS code and macOS-only tests, so gate them on `target_os = "macos"` like the code that uses them. The promotion codegen now writes that gate on the Metal evidence while no lossy RGB8 threshold reads it on other targets.
Auto sends a decode to CUDA when its shape matches a measured routing cell. The decision never looked at component sampling, and CUDA's direct plans decline every component that isn't sampled (1, 1). So an RGB8 image with subsampled chroma that matched a cell, for example a lossless 704x512 one, went to CUDA and failed with the native planner's unsupported error. Auto has no CPU retry after it picks a device, so the caller got an error for an image the CPU decodes. The decoder now records whether any component is subsampled, from the parsed support metadata, and Auto keeps such images on the CPU before any CUDA work, for single decodes and for the repeated tile batch. That also holds for images whose components all share one sampling: no routing measurement covers them. An explicit CUDA request is unchanged. Tests: the_decoder_knows_whether_any_component_is_subsampled runs without a device. auto_keeps_subsampled_images_on_the_cpu decodes a mixed-sampling and a shared-sampling RGB8 image of routed sizes under Auto and expects a CPU surface with the CPU decode's samples, and with a device expects the explicit CUDA request for the mixed image to be an unsupported error; on a machine without CUDA its Auto half passes before and after, so it needs the PC to show the failure this fixes.
jcwal1516
force-pushed
the
stage/14-gpu-auto-routing
branch
2 times, most recently
from
December 2, 2026 19:04
5d7c1c9 to
d92d44a
Compare
jcwal1516
marked this pull request as ready for review
December 2, 2026 19:08
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.
What and why
The CUDA and Metal
Autothresholds predated the current CPU kernels andMetal plan cache. They sent several shapes to a GPU after the CPU had become
faster.
This layer records fresh routing evidence, regenerates the CUDA and Metal
promotion tables, keeps CUDA requests whose components differ in sampling on
the CPU under
Auto, and keeps explicit device requests strict. It also makes amanifest with no qualifying lossy Metal encode representable and gates Metal
evidence constants off non-macOS builds.
This layer is based on the license-packaging PR below it.
Impact
!to the title)Automay choose the CPU for shapes where the GPU is slower or unsupported.The generated routing tables use the measured CUDA and Metal crossover cells.
data, source noted in a README and NOTICES.md)
Testing
Saved evidence covers an RTX 4070 SUPER and an Apple M4. The CUDA confirmation
at
533cbba7kept all 58 route decisions; Metal thresholds were updated forthe newer CPU and cache code.
Generated-table, manifest, routed-shape, and subsampled-
Autotests areincluded.
cargo xtask promotion-codegen, 16 CUDA routing tests, and 37 Metal routingtests passed; two Metal runtime tests remain for hardware validation.
The focused mixed-sampling metadata and
AutoCPU-fallback tests passed.Uniform shared-sampling support remains with the later component-grid layer.
Exact-head CUDA and Metal routing validation: pending.
Bug fix: added tests that fail with stale or unsupported routing
User-visible change: added a
CHANGELOG.mdentry underUnreleased