rocm/rocm-libraries/stinkytofu-guide
Claude Code and agent skill by rocm/rocm-libraries
- community
Checking that the SKILL.md file is still in the repository.
Locate where a feature lives in the StinkyTofu codebase, and advise where and how to add a new one, grounded in the actual source. Use when the user asks "where is X", "where should this new feature go", "how do I add a pass / instruction / architecture / scheduling constraint", or types /stinkytofu-guide <topic>.
Install
npx vskill@latest install rocm/rocm-libraries/stinkytofu-guideSKILL.md
The same SKILL.md was published earlier as rocm/rocm-libraries/stinkytofu-guide.
stinkytofu-guide
Answer two kinds of question about the StinkyTofu tree, and nothing else:
- Where does an existing feature live? — find the files/symbols, cite
file:line. - Where and how should a NEW feature go? — recommend the location and the pattern
to follow, grounded in how the codebase already does it.
This skill is read-only and advisory: locate, explain, recommend. Do not implement unless the user separately asks. There is no external wiki — the source tree in this directory is the single source of truth.
0. Verify against CODE, not docs (docs may be stale)
Docs under docs/ and the map in this file are starting points, not authority. Before you assert where something is or how it works, open the actual .cpp/.hpp and confirm. Cite file:line and name stable symbols (pass classes, functions, structs) — line numbers drift. If code and docs disagree, trust the code and tell the user the doc is stale.
1. StinkyTofu is a SCHEDULER, not a code generator (the foundational rule)
StinkyTofu reorders and annotates instructions TensileLite already produced; it does not invent computation from nowhere. This frames every "where should my feature go?" answer. Three consequences to apply, and to raise with the user:
- Correctness must not depend on StinkyTofu. With
ScheduleIterAlg=0(SIA0) in
TensileLite, the generated kernel must already be correct without any StinkyTofu scheduling passes (peephole, DAG scheduler, etc.). StinkyTofu makes correct code faster, it does not make incorrect code correct. If a proposed feature would make the kernel wrong unless a StinkyTofu pass runs, the design is inverted — the correctness piece belongs in TensileLite code gen, not in a scheduler pass.
- **Instruction order chosen in TensileLite code gen is not authoritative — the DAG
scheduler reorders it. So "fixing" behavior by carefully ordering instructions in the TensileLite generator is meaningless for anything the DAG scheduler will touch. Anchor invariant: the DAG scheduler uses WMMA as anchors — the relative order among WMMA instructions is preserved. You can reason about ordering *relative to WMMA*, but not about the absolute order of surrounding instructions. Caution:** this invariant breaks if a pass that reorders WMMA (e.g. a WMMA-reorder pass such as StinkyWmmaVgprReorderPass) runs before the DAG scheduler — then the anchor order itself changed. Check the pass ordering before relying on WMMA order.
- **Ask: does this belong in code gen (TensileLite), the scheduler (StinkyTofu), or
both — split across the two? The analogy is C++ vs. the compiler. The compiler schedules; it does not decide you wanted prefetching. If you need prefetch, either write the prefetch instructions in TensileLite code gen, or build an explicit signal (a pragma / intrinsic / annotation) that tells StinkyTofu what to do. StinkyTofu will not synthesize a feature the input never expressed. Classify the feature, and expect it may split into two halves**:
- The code part (new instructions / new computation / a new signal to emit) ⇒
TensileLite code gen, or a lowering / intrinsic-expansion step in StinkyTofu.
- The scheduling part (how the scheduler should place, order, or hazard-guard
those instructions) ⇒ the DAG scheduler / cost model. Many real features need both: e.g. prefetch emits the load instructions (code part) and teaches the scheduler how far ahead to hoist them (scheduling part). When that's the case, say so explicitly and scope each half to its correct home — don't try to cram the whole thing into one side because it's convenient.
2. Multi-instruction features — don't make the scheduler learn a whole sequence
Some features are not one instruction but a multi-line sequence with internal structure. Exposing that raw sequence to the DAG scheduler (or other passes) forces them to understand relationships they were never designed for, and can break the DAG or other features. This is not a yes/no rule — it's a consideration to raise before adding such a feature. Two established patterns to offer:
- Collapse to a pseudo-instruction, expand after scheduling. If the sequence doesn't
affect performance much, represent it during scheduling as a single pseudo instruction carrying the summed cycles/latency, let the scheduler treat it as one opaque node, then expand it into the real instructions in a post-scheduling pass. This keeps the scheduler's model simple and correct. Example: the cluster barrier is several instructions, not one — see InsertClusterBarrierPass.cpp and docs/developer/cluster-barrier.md; pseudo instructions are recognized via isPseudoInst(...) throughout the passes.
- Do it as a post-scheduling transform when it's just a mechanical copy/edit. If the
feature is essentially duplicating or lightly editing already-scheduled instructions, do it after scheduling rather than in TensileLite code gen — so the scheduler never has to deal with the extra, complicated cases. Example: the InitC feature clones the iter=0 region and rewrites the WMMA src C to zero on the chain heads; it lives in RegionClonePass (initCIterWmma_zeroChainHeads, src/transforms/asm/RegionClonePass.cpp; spec in include/stinkytofu/pipeline/CloneSpec.hpp). Implementing that in code gen would just hand the scheduler more complex input for no benefit.
Weigh this against performance: if the sequence's internal scheduling genuinely matters for perf, then hiding it behind a pseudo may cost too much and it should be modeled properly. Raise the tradeoff; don't decide silently.
3. Don't default to a new pass because it's easier — check the scheduler question
The most common design mistake here: a new feature interacts with instruction scheduling, but the author adds a standalone post-scheduling pass anyway — simply because adding a pass is far easier than touching the DAG scheduler model (src/transforms/asm/dag/CDNA5.hpp and friends). "Easier" is not a design reason.
A post-fix pass is not automatically wrong — LLVM itself implements plenty of features as post-schedule fixups, and StinkyTofu does too. The goal is to make this a conscious decision, not a default driven by effort. So before recommending where a feature goes, surface the scheduling question with the user:
- "Does this feature interact with instruction scheduling — ordering, latencies,
co-issue, hazards, or resource/slot usage?"
- If yes or unsure: "Does the scheduler need to know about it while placing
instructions (so it should be a dependency/hazard/priority in the DAG), or can it be correctly and cheaply applied as a fix-up after scheduling?"
Then weigh it honestly with them:
- Scheduler needs to know — if a correct result requires the scheduler to account
for this while choosing an order (it changes what a good/legal schedule is), encode it in the scheduler: the ready-queue / cost model in src/transforms/asm/dag/CDNA5.hpp, the DAG build in StinkyDAGSchedulerPass (src/transforms/asm/StinkyDAGSchedulerPass.cpp), or dependency construction (StinkyBuildImplicitDependencyPass, BuildDefUseChain.cpp). A later pass can't recover a scheduling decision the scheduler already made wrong.
- A post-fix is genuinely fine — if the transform is local, doesn't change what a
good schedule looks like, and can be applied correctly after scheduling (or is a lowering / standalone analysis / declarative rewrite), then a separate pass or a peephole pattern is the right, simpler choice.
Whichever way it goes, state the tradeoff explicitly so the choice is deliberate — never "a pass is easier, so a pass."
4. The map — where things live (verify before citing)
Paths are relative to this shared/stinkytofu/ directory.
- Scheduler (read before advising on ordering/latency/hazards/co-issue)
- Per-arch model + ready queue:
src/transforms/asm/dag/CDNA5.hpp(CDNA5/Gfx1250:
WMMA–VALU co-issue timeline, latencies, slot fill), plus InFlightQueue.hpp, ReadyQueue.hpp in the same dir.
- The pass:
StinkyDAGSchedulerPass—src/transforms/asm/StinkyDAGSchedulerPass.cpp,
header include/stinkytofu/transforms/asm/StinkyDAGSchedulerPass.hpp. Splits blocks into regions, builds a per-region DAG from physical registers, drains ready nodes.
- Dependencies feeding the DAG:
StinkyBuildImplicitDependencyPass.cpp,
BuildDefUseChain.cpp (inserts pseudo-PHIs), PhiPlacement.cpp.
- IR definitions
- Logical IR (architecture-agnostic):
include/stinkytofu/ir/logical/,src/ir/logical/ - Asm IR (arch-specific:
StinkyInstruction,Function,BasicBlock):
include/stinkytofu/ir/asm/, src/ir/asm/
- Passes — Asm:
src/transforms/asm/; Logical:src/transforms/logical/.
Registry of names usable from stinkytofu-opt: availablePasses in tools/stinkytofu-opt/stinkytofu-opt.hpp.
- Hardware / architectures —
hardware/GfxXXX/.deffiles feed TableGen; a new
arch needs no C++. See docs/developer/adding-architecture.md (verify against tree).
- Peephole / intrinsic patterns —
src/transforms/asm/PeepholePatterns.pattern,
src/transforms/logical/LogicalIRPatterns.pattern; grammar in docs/developer/pattern-grammar.md.
- Wait counts —
StinkyWaitCntInsertionPass.cppandsrc/transforms/asm/waitcnt/. - Tools —
tools/stinkytofu-opt/(standalone pass driver: parses a.stir/.s
asm/IR file and runs passes on it, stinkytofu-opt [options] <ir_file> [--PassName...]; passes run in command-line order — see tools/stinkytofu-opt/README.md), tools/stinkytofu-check/ (FileCheck harness over stinkytofu-opt output), plus stinkytofu-cfg, waitcnt-check, tablegen, intrinsic-compiler.
- Tests — GTest in
tests/, FileCheck.stirintests/filecheck/. - How-to-extend guides —
docs/developer/adding-instructions.md,
adding-architecture.md, adding-intrinsics.md, adding-peephole-patterns.md, architecture.md. Treat as guidance; confirm against code.
5. Design constraints — apply these when advising
Load-bearing invariants. Advice that violates one is wrong.
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingshared/stinkytofu/.claude/skills/stinkytofu-guide/SKILL.md
Popularity
- Repository stars
- 441
- Repository forks
- 420
- 7-day trend score
- 30
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/rocm/rocm-libraries/stinkytofu-guide)