Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions flashinfer/experimental/cake_dsa_indexer_det/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,13 @@ that writes the registry verifies the record against them before it is frozen.
* **No host synchronization**: the segment boundaries and offsets are read on
the device only; the host uses `T`, `Tkv`, `S`, `ratio`, `top_k`, the SM
count and the strides. The eager entry point allocates the outputs and the
workspace (unless supplied) through the caching allocator and zeroes the
ticket tail of a supplied workspace once per call (none on a static call:
workspace (unless supplied) through the caching allocator; the scan binding
zeroes the ticket tail of a supplied workspace right before every scan
launch, in the same host call (none on a static call:
where the shape alone bounds the work units by the grid,
`cake_policy.ticket_static_path`, the scan never touches the ticket word);
`cake_policy.ticket_static_path`, the scan never touches the ticket word;
none for a program of the record's `static_scan_kinds`, the sm_107a l6
programs, which keep the static unit enumeration on every call);
the prepared runner (`cake_backend.prepare_dsa_indexer_det_topk`) allocates nothing at launch
and is CUDA-graph capturable.
* **Launch structure**: scan, optional merge, finalize (see above). No
Expand Down
458 changes: 229 additions & 229 deletions flashinfer/experimental/cake_dsa_indexer_det/build.json

Large diffs are not rendered by default.

397 changes: 317 additions & 80 deletions flashinfer/experimental/cake_dsa_indexer_det/cake_backend.py

Large diffs are not rendered by default.

53 changes: 43 additions & 10 deletions flashinfer/experimental/cake_dsa_indexer_det/cake_jit.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,15 @@
# architecture (see ``cake_policy``), ``POLICY`` the per-architecture host
# dispatch record and ``NUMERICS`` the documented numerics of the programs.
# The launch geometry of a program (block, cluster, dynamic shared memory) is
# fixed in its host binding.
# fixed in its host binding. A scan binding takes ``zero_region`` (slot kind
# ``zero``) right before the grid: a byte range of the workspace it zeroes on
# the launch stream right before the launch, or an empty tensor (nothing).
# Every scan program takes ``TicketWord`` (a 16-byte block) right before it; a
# program's record lists in ``ticket_arg_arches`` the architectures on which it
# draws its work units from that block instead of the workspace's ticket tail.
ARCHES = ("sm_100a", "sm_103a", "sm_107a")
STAGES: list[str] = ["scan", "merge", "finalize", "finalize_rank"]
ABI: str = "dsa_indexer_v2"
ABI: str = "dsa_indexer_v4"
NUMERICS: dict[str, str] = {"zero_sign_policy": "positive_accumulator"}
FFI_ENTRY: str = "run"
ARG_PLANS: dict[str, list[list[str]]] = {
Expand All @@ -80,6 +85,8 @@
["parameter", "grid_ctas"],
["parameter", "softmax_scale"],
["parameter", "n_split"],
["buffer", "TicketWord"],
["zero", "zero_region"],
["grid", "grid_x"],
["grid", "grid_y"],
["grid", "grid_z"],
Expand Down Expand Up @@ -115,14 +122,18 @@
["grid", "grid_z"],
],
}
# The architectures whose scan programs draw every work unit from the workspace's
# ticket tail (``cake_policy.TICKET_TAIL_BYTES``): every sm_100a / sm_103a scan
# program. Every completed scan launch leaves the ticket word at 0; the host
# (``cake_backend``) zeroes the tail once when it prepares a runner on its own
# workspace, and before every run on a caller-owned ``workspace_buffer`` (others
# may write that buffer between runs). sm_107a keeps the static unit
# enumeration and leaves the tail unused.
TICKET_TAIL_ARCHES: tuple[str, ...] = ("sm_100a", "sm_103a")
# The architectures whose scan programs draw every work unit from a ticket word
# (``cake_policy.TICKET_TAIL_BYTES``): every scan program on every architecture
# but the physical kinds of ``POLICY[arch]["static_scan_kinds"]`` (the sm_107a
# l6 programs), which keep the static enumeration. A program whose record lists
# the architecture in ``ticket_arg_arches`` draws from its ``TicketWord`` block
# (``cake_backend`` gives a prepared runner one of its own, zeroed once); every
# other drawing program draws from the workspace's ticket tail. Every completed
# scan launch leaves the ticket word at 0; the host (``cake_backend``) zeroes the
# tail once when it prepares a runner on its own workspace, and on a caller-owned
# ``workspace_buffer`` (others may write that buffer between runs) passes it as
# the scan's ``zero_region``, which the scan binding zeroes before every launch.
TICKET_TAIL_ARCHES: tuple[str, ...] = ("sm_100a", "sm_103a", "sm_107a")
PROGRAMS: dict[str, dict[str, Any]] = {
"cake_dsa_indexer_det_topk_04db38446d526901fed3": {
"role": "scan",
Expand All @@ -138,6 +149,7 @@
"role": "scan",
"library": "cake_dsa_indexer_det_topk_0d38735ee8e81ae6f5e8",
"arches": ["sm_107a"],
"ticket_arg_arches": ["sm_107a"],
},
"cake_dsa_indexer_det_topk_110194b650e766125f9f": {
"role": "scan",
Expand All @@ -148,11 +160,13 @@
"role": "scan",
"library": "cake_dsa_indexer_det_topk_1b6af9940d486a0832d9",
"arches": ["sm_107a"],
"ticket_arg_arches": ["sm_107a"],
},
"cake_dsa_indexer_det_topk_23a4ebeaa3ba23c23c80": {
"role": "scan",
"library": "cake_dsa_indexer_det_topk_23a4ebeaa3ba23c23c80",
"arches": ["sm_103a", "sm_107a"],
"ticket_arg_arches": ["sm_107a"],
},
"cake_dsa_indexer_det_topk_2581ee71bf5e5ecd2556": {
"role": "finalize_rank",
Expand All @@ -168,6 +182,7 @@
"role": "scan",
"library": "cake_dsa_indexer_det_topk_2de9f2d0467668d46463",
"arches": ["sm_107a"],
"ticket_arg_arches": ["sm_107a"],
},
"cake_dsa_indexer_det_topk_31ea61c2c7a160221f01": {
"role": "scan",
Expand All @@ -188,6 +203,7 @@
"role": "scan",
"library": "cake_dsa_indexer_det_topk_3bd43d833b5d53e81dbe",
"arches": ["sm_107a"],
"ticket_arg_arches": ["sm_107a"],
},
"cake_dsa_indexer_det_topk_3c6dc460295ddf3c44de": {
"role": "scan",
Expand Down Expand Up @@ -218,6 +234,7 @@
"role": "scan",
"library": "cake_dsa_indexer_det_topk_506cb2b2c57f0a514cde",
"arches": ["sm_107a"],
"ticket_arg_arches": ["sm_107a"],
},
"cake_dsa_indexer_det_topk_521027e8563a9664acef": {
"role": "scan",
Expand Down Expand Up @@ -248,6 +265,7 @@
"role": "scan",
"library": "cake_dsa_indexer_det_topk_5c6e55c74de033e5f7af",
"arches": ["sm_107a"],
"ticket_arg_arches": ["sm_107a"],
},
"cake_dsa_indexer_det_topk_607b85385dc2e298c030": {
"role": "scan",
Expand Down Expand Up @@ -283,6 +301,7 @@
"role": "scan",
"library": "cake_dsa_indexer_det_topk_74f132250e5e565dfcc9",
"arches": ["sm_107a"],
"ticket_arg_arches": ["sm_107a"],
},
"cake_dsa_indexer_det_topk_75842ae0f80e05addeaa": {
"role": "finalize_rank",
Expand All @@ -293,6 +312,7 @@
"role": "scan",
"library": "cake_dsa_indexer_det_topk_763009af2c0de13ffc29",
"arches": ["sm_107a"],
"ticket_arg_arches": ["sm_107a"],
},
"cake_dsa_indexer_det_topk_7891f3dffb0e0717f725": {
"role": "scan",
Expand Down Expand Up @@ -323,6 +343,7 @@
"role": "scan",
"library": "cake_dsa_indexer_det_topk_81ccb257c7338a468c3b",
"arches": ["sm_107a"],
"ticket_arg_arches": ["sm_107a"],
},
"cake_dsa_indexer_det_topk_88619e22363515835efe": {
"role": "scan",
Expand Down Expand Up @@ -358,6 +379,7 @@
"role": "scan",
"library": "cake_dsa_indexer_det_topk_942797c60bc61df40715",
"arches": ["sm_107a"],
"ticket_arg_arches": ["sm_107a"],
},
"cake_dsa_indexer_det_topk_96c30b1f33d2a094d9b9": {
"role": "finalize_rank",
Expand All @@ -368,6 +390,7 @@
"role": "scan",
"library": "cake_dsa_indexer_det_topk_99af5257f5e28006f79e",
"arches": ["sm_107a"],
"ticket_arg_arches": ["sm_107a"],
},
"cake_dsa_indexer_det_topk_9b89c92489b0e60d8ee7": {
"role": "finalize_rank",
Expand All @@ -378,11 +401,13 @@
"role": "scan",
"library": "cake_dsa_indexer_det_topk_9c823649b35909199596",
"arches": ["sm_107a"],
"ticket_arg_arches": ["sm_107a"],
},
"cake_dsa_indexer_det_topk_9cc421366d6079aa6ca8": {
"role": "scan",
"library": "cake_dsa_indexer_det_topk_9cc421366d6079aa6ca8",
"arches": ["sm_107a"],
"ticket_arg_arches": ["sm_107a"],
},
"cake_dsa_indexer_det_topk_9f4b76cb713088f1285d": {
"role": "scan",
Expand All @@ -403,6 +428,7 @@
"role": "scan",
"library": "cake_dsa_indexer_det_topk_a64563a936f84ea4d9f5",
"arches": ["sm_107a"],
"ticket_arg_arches": ["sm_107a"],
},
"cake_dsa_indexer_det_topk_aa0bedf1a5601a3c55be": {
"role": "finalize_rank",
Expand All @@ -418,11 +444,13 @@
"role": "scan",
"library": "cake_dsa_indexer_det_topk_af8d290aa9010d180ed0",
"arches": ["sm_103a", "sm_107a"],
"ticket_arg_arches": ["sm_107a"],
},
"cake_dsa_indexer_det_topk_afa89b4033e466d158b1": {
"role": "scan",
"library": "cake_dsa_indexer_det_topk_afa89b4033e466d158b1",
"arches": ["sm_107a"],
"ticket_arg_arches": ["sm_107a"],
},
"cake_dsa_indexer_det_topk_b8440d1d1d54917a47d7": {
"role": "merge",
Expand Down Expand Up @@ -493,11 +521,13 @@
"role": "scan",
"library": "cake_dsa_indexer_det_topk_e7860bf225417a2a3b51",
"arches": ["sm_107a"],
"ticket_arg_arches": ["sm_107a"],
},
"cake_dsa_indexer_det_topk_e983ae66ae1ef4d182e5": {
"role": "scan",
"library": "cake_dsa_indexer_det_topk_e983ae66ae1ef4d182e5",
"arches": ["sm_107a"],
"ticket_arg_arches": ["sm_107a"],
},
"cake_dsa_indexer_det_topk_ec8a5e9e791c7fee7261": {
"role": "scan",
Expand Down Expand Up @@ -746,6 +776,7 @@
"sample_shift_rule": None,
"sample_class_rule": [8, 500],
"lsf_programs": True,
"static_scan_kinds": [],
"far_sample": 0,
"check_period_max": 32,
"check_period_knob_max": 64,
Expand Down Expand Up @@ -823,6 +854,7 @@
"sample_shift_rule": [4096, 375],
"sample_class_rule": [8, 500],
"lsf_programs": True,
"static_scan_kinds": [],
"far_sample": 0,
"check_period_max": 32,
"check_period_knob_max": 64,
Expand Down Expand Up @@ -916,6 +948,7 @@
"sample_shift_rule": None,
"sample_class_rule": None,
"lsf_programs": False,
"static_scan_kinds": ["l6", "pair_l6"],
"far_sample": 0,
"check_period_max": 32,
"check_period_knob_max": 64,
Expand Down
22 changes: 20 additions & 2 deletions flashinfer/experimental/cake_dsa_indexer_det/cake_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
"sample_class_rule", # [tiny-unit sample tiles, shift permille] for the wide-unit programs (shift only) and the tiny dispatch class (tiles and shift), or None; explicit knobs override it
"sample_shift_rule", # [min top_k, shift permille] replacing sample_shift_permille from that top_k on, or None (the default shift on every call); an explicit sample_shift_permille knob overrides both
"lsf_programs", # the architecture ships the longest-first segment order copy (scan key suffix :lsf) of every scan program; the host runs it on packed calls whose key segments differ in length (#7549)
"static_scan_kinds", # physical scan kinds whose programs keep the static unit enumeration on a ticket architecture: they never touch the ticket tail, so the host gives their runners none
"far_sample", # 1: the sampled first threshold of the ascending-tile-order programs ranks the far sample tiles only (the tile nearest the diagonal left out); 0: every sample tile
"check_period_max", # cap on the default selection-trigger check period (tiles)
"check_period_knob_max", # cap on an explicit check period (tiles)
Expand Down Expand Up @@ -144,7 +145,8 @@
# ``sample_shift_rule`` shift. Every value gives the same bits; the shift only sets how conservative the sampled first
# threshold is.
SAMPLE_SHIFT_PERMILLE_BOUNDS = (-1000, 10000)
# Global unit tickets (every sm_100a / sm_103a scan program): the CTAs draw every
# Global unit tickets (every scan program but the kinds of a record's
# ``static_scan_kinds``, on ``cake_jit.TICKET_TAIL_ARCHES``): the CTAs draw every
# work unit from the low u32 word of the first int64 behind the candidate buffers
# (and behind the split staging), the first of a tail every plan's workspace
# carries: 16 int64 for the ticket word, then the longest-first segment order the
Expand All @@ -153,7 +155,12 @@
# zeroes the tail once at prepare on a backend-owned workspace and before every
# run on a caller-owned ``workspace_buffer``, which others may write between
# runs -- except where the call always takes the static fast path
# (``ticket_static_path``: the scan never touches the word). sm_107a leaves the tail unused.
# (``ticket_static_path``: the scan never touches the word) or runs a program of
# ``static_scan_kinds``. A scan program whose registry record lists the
# architecture in ``ticket_arg_arches`` draws from its ``TicketWord`` block
# instead and never reads this tail (the eager entry hands it the tail's first
# 16 bytes); every plan still carries the tail, so the size does not depend on
# the program.
TICKET_TAIL_BYTES = 8 * (16 + 1024)


Expand Down Expand Up @@ -299,6 +306,7 @@ class DispatchPolicy:
sample_shift_rule: Optional[list]
sample_class_rule: Optional[list]
lsf_programs: bool
static_scan_kinds: list
far_sample: int
check_period_max: int
check_period_knob_max: int
Expand Down Expand Up @@ -543,6 +551,15 @@ def from_record(cls, raw: Any) -> "DispatchPolicy":
f"policy[{ceiling_name!r}] must be a positive slot count at or above policy[{floor_name!r}]"
f"{' and the floor of policy[' + repr(rule_name) + ']' if rule_name else ''}, got {ceiling!r}"
)
static_kinds = raw["static_scan_kinds"]
if (
not isinstance(static_kinds, (list, tuple))
or not all(isinstance(k, str) and k in PHYSICAL_KINDS for k in static_kinds)
or list(static_kinds) != sorted(set(static_kinds))
):
raise ValueError(
f"policy['static_scan_kinds'] must be an ascending list of physical scan kinds {PHYSICAL_KINDS}, got {static_kinds!r}"
)
fit_kinds = raw["sample_fit_kinds"]
if (
not isinstance(fit_kinds, (list, tuple))
Expand Down Expand Up @@ -598,6 +615,7 @@ def from_record(cls, raw: Any) -> "DispatchPolicy":
]
values["rank_t16_slots"] = [int(v) for v in values["rank_t16_slots"]]
values["sample_fit_kinds"] = [str(k) for k in values["sample_fit_kinds"]]
values["static_scan_kinds"] = [str(k) for k in values["static_scan_kinds"]]
values["pair_units"] = [str(u) for u in values["pair_units"]]
values["split_units"] = [str(u) for u in values["split_units"]]
values["check_period_kind_overrides"] = {
Expand Down
Loading
Loading