feat(cutile): support scalar specialization overrides - #227
Open
lucifer1004 wants to merge 1 commit into
Open
lucifer1004 wants to merge 1 commit into
lucifer1004 wants to merge 1 commit into
Conversation
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.
Motivation
The launcher infers divisibility hints (
DivHint) for integer scalar and raw-pointer kernel parameters from their runtime values, and those hints feed the JIT specialization key. For truly dynamic scalars this backfires: a value that happens to be divisible by 4/8/16 on some launches (e.g. a decode batch sizemthat varies per step) silently produces multiple JIT specializations for the same kernel, each triggering a recompile.What this adds
A
scalar_hint(name, hint)builder method on the generated kernel launcher (declared on theTileKerneltrait) that replaces the inferred hint for a named parameter — or adds one — before hints are consumed:.scalar_hint("m", DivHint::default())(divisor 1) disables specialization for a genuinely dynamic scalar, so incidental runtime divisibility no longer creates extra JIT variants..scalar_hint("n", hint)can also pin a stronger hint than the inferred one when the caller knows a contract the runtime value doesn't reveal.The override drain runs on both the launch path and the specialization path (the shared statement is pushed into
launcher_methodandspecialization_method), so the two stay consistent.Example
Tests
Added two GPU launch tests in
cutile/tests/specialization_bits.rsthat dump the generated MLIR and assert:n=12infersdiv_by<4>; overriding withdiv_by<8>emitsassume div_by<8>and nodiv_by<4>);assumeentirely while the raw-pointer assume is untouched.All 4
raw_pointer_launch*tests in that file pass locally on an SM120 GPU.