First occurrence config print with set memo
Skill kjuhwa/skills-hub/skills/jit-compilation/first-occurrence-config-print-with-set-memo
Print a JIT-selected config the first time a given shape/desc is encountered, memoizing with `std::unordered_set<std::string>` keyed on the stringified descriptor — so each unique workload prints exactly once.From its SKILL.md
npx -y skills add kjuhwa/skills-hub --skill first-occurrence-config-print-with-set-memoAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
3.4 KB, 685 tokens by cl100k_base, as published. Nobody here has run it
First-Occurrence Config Print Memoized On Descriptor String
When to use
Your JIT picks a config (block size, stages, cluster dims) for each unique GEMM/MoE shape. You want debug visibility — "which config got picked for M=128, N=4096, K=7168?" — without flooding the log with the same line 10,000 times per iteration.
The right cadence is "log once per unique input", keyed on the full descriptor string (not just M/N/K — that would miss cases where dtype or layout differs).
Steps
- Stringify the descriptor via
operator<<. Definefriend std::ostream& operator<<(std::ostream&, const Desc&)on yourDescstruct so every field is serialized. This makes the key unique per input combination and the log line human-readable. - Inside the config-picking function, after computing the config:
if (get_env<int>("DG_JIT_DEBUG") or get_env<int>("DG_PRINT_CONFIGS")) { std::stringstream ss; ss << desc; const auto key = ss.str(); static std::unordered_set<std::string> printed; if (printed.count(key) == 0) { std::cout << desc << ": " << gemm_config << ", " << layout_info << std::endl; printed.insert(key); } } staticscope means the memo persists across calls but doesn't leak across processes. That's the right semantics for a dev-debug flag.- Gate by env var.
DG_JIT_DEBUG(uber) orDG_PRINT_CONFIGS(targeted). Zero overhead when off — the string build and set lookup are inside the guard. - Apply the same pattern wherever dispatch happens.
mega_moeuses a separateprintedset with a separate key format (descriptor formatted withfmt::format), because the MoE descriptor isn't a struct — it's N separate ints.
Evidence (from DeepGEMM)
csrc/jit_kernels/heuristics/common.hpp:40-50: the GEMM-side implementation, usingoperator<<ofGemmDesc.csrc/jit_kernels/heuristics/mega_moe.hpp:198-207: the MoE-side variant, usingfmt::formatto build the key because the inputs don't form a struct.
Counter / Caveats
- Memo grows unbounded. For long-running inference servers with millions of distinct shapes the set never stops growing. Mitigation: bound the set size (LRU) or gate the print behind a "recent only" policy. In practice, a training run has ~hundreds of distinct shapes, so unbounded is fine.
static unordered_setis not thread-safe. If multiple host threads call the dispatch concurrently, you need a mutex or accept rare duplicate prints. DeepGEMM assumes single-threaded dispatch.stringstream ss; ss << deschappens on every call when debug is enabled, even on a memoized hit. If theoperator<<is expensive, hash the key separately.
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.