sass-machine-code
/sass-machine-code
Czyta kod maszynowy GPU (SASS), wyjaśnia, co wygenerował kompilator, i mapuje zatory z profilera na źródło, by usunąć wąskie gardła kernela. Przydaje się przy optymalizacji kerneli CUDA.
- Autor
- j4flmao ↗
- Repozytorium
- agent-skills ↗
- Licencja
- MIT
- Ostatnia zmiana repozytorium
- 10.11.2026
Ocena i bezpieczeństwo
- Pliki w paczce
- 1
- Skrypty
- 0
- Komentarze HTML
- 0
- Adresy URL w SKILL.md
- 0
Brak sygnałów. Repozytorium zmienione 10.11.2026, bez odwołań do wycofanych modeli i API.
MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.
Co robi i kiedy
Czyta kod maszynowy GPU (SASS), wyjaśnia, co wygenerował kompilator, i mapuje zatory z profilera na źródło, by usunąć wąskie gardła kernela. Przydaje się przy optymalizacji kerneli CUDA.
Wyzwalacze z opisu
Oryginalny opis (EN)
Use this skill when the user says 'sass', 'cuobjdump -sass', 'nvdisasm', 'machine code', 'stall reasons', 'long scoreboard', 'register bank conflict', 'HMMA', 'FFMA', 'instruction mix', 'warp stall'. Reads NVIDIA SASS (native GPU machine code) to explain what the compiler actually generated and maps Nsight Compute per-instruction stall sampling back to source to fix kernel bottlenecks. Do NOT use for: writing PTX or inline asm (ptx-assembly), general kernel design (cuda-programming), Triton kernels (triton-kernels).
Jak działa
- Purpose
- Agent Protocol
- Getting SASS
- Reading Common Instructions
- Scheduling Model (what matters for analysis)
- Nsight Compute Stall Reasons → Fix
- Checklist When Reading a Hot Loop
- Anti-Patterns
- References
Podgląd SKILL.md
---
name: sass-machine-code
description: >
Use this skill when the user says 'sass', 'cuobjdump -sass', 'nvdisasm', 'machine code', 'stall reasons', 'long scoreboard', 'register bank conflict', 'HMMA', 'FFMA', 'instruction mix', 'warp stall'. Reads NVIDIA SASS (native GPU machine code) to explain what the compiler actually generated and maps Nsight Compute per-instruction stall sampling back to source to fix kernel bottlenecks. Do NOT use for: writing PTX or inline asm (ptx-assembly), general kernel design (cuda-programming), Triton kernels (triton-kernels).
version: "1.0.0"
author: "j4flmao"
license: "MIT"
tags: [hardware-acceleration, sass, cuda, nvidia, profiling, gpu-microarchitecture]
---
# SASS Machine Code Analysis
## Purpose
SASS is the architecture-specific machine code that the SM actually executes, produced by `ptxas` from PTX. NVIDIA documents the instruction names per architecture but not the encoding, so SASS is used for reading, not writing: confirming vectorized loads, tensor-core instructions, spills, unrolling and predication, and attributing stalls to exact instructions with Nsight Compute.
## Agent Protocol
### Trigger
"sass", "cuobjdump -sass", "nvdisasm", "machine code", "stall reasons", "long scoreboard", "warp stall", "register bank conflict", "HMMA", "HGMMA", "FFMA", "instruction mix".
### Input Context
- Binary or kernel source + compile flags, target `sm_XX`.
- Nsight Compute report (`--set full`) with source/SASS correlation (`-lineinfo`).
### Output Artifact
Annotated SASS excerpt + root cause + source-level fix. No file unless requested.
### Response Format
```
Hot instruction(s): {SASS line(s)} ← source line {n}
Top stall: {reason} ({% of samples})
Cause: {explanation}
Fix: {source/compile change}
Re-check: {metric}
```
### Completion Criteria
- [ ] Hot spots chosen from sampling data, not by eye.
- [ ] Fix applied at source/flag level, then SASS and metrics re-inspected.
- [ ] Result correctness re-validated.
## Getting SASS
```bash
nvcc -O3 -arch=sm_90 -lineinfo -cubin -o k.cubin k.cu
cuobjdump -sass k.cubin # or on the final executable
nvdisasm -g k.cubin # -g annotates source line info
nvdisasm -cfg k.cubin | dot -Tsvg > cfg.svg # control-flow graph
ncu --set full --import-source yes -o rep ./app # then open the Source page, view "SASS" or "Source and SASS"
```
## Reading Common Instructions
| SASS | Meaning |
|------|---------|
| `LDG.E.128` / `STG.E.128` | 128-bit (vectorized) global load/store. `LDG.E` alone = 32-bit. |
| `LDG.E.CONSTANT` | Read-only (non-coherent) path, from `__ldg` / `const __restrict__`. |
| `LDS` / `STS` | Shared memory load/store. |
| `LDL` / `STL` | Local memory: usually register spills (bad in hot loops). |
| `LDGSTS` | Async global→shared copy (`cp.async`, sm_80+). |
| `UTMALDG` | TMA bulk tensor load (sm_90). |
| `FFMA`, `FADD`, `FMUL` | FP32 fused multiply-add / add / multiply on CUDA cores. |
| `HMMA` / `IMMA` | Warp-level tensor-core MMA (FP16/BF16/TF32 / INT8). |
| `HGMMA` | Hopper warpgroup tensor-core MMA (`wgmma`). |
| `MUFU.EX2`, `MUFU.RCP`, `MUFU.RSQ` | Special function unit: exp2, reciprocal, rsqrt (fast intrinsics). |
| `SHFL.BFLY/DOWN` | Warp shuffle. |
| `BAR.SYNC` | `__syncthreads()`. |
| `ISETP` + `@P0` | Integer compare setting a predicate; `@P0`/`@!P0` predicated execution. |
| `BRA`, `BSSY`/`BSYNC` | Branch; convergence-barrier pairs around divergent regions (Volta+). |
| `S2R SR_TID.X` | Read special register (thread index). |
Matrix-multiply throughput on modern GPUs comes from tensor-core instructions (`HMMA`/`HGMMA`), not `FFMA`. A GEMM kernel full of `FFMA` with FP16/BF16 inputs means tensor cores are not being used.
## Scheduling Model (what matters for analysis)
- Since Maxwell, an SM is split into 4 processing blocks, each with its own warp scheduler that issues at most one instruction per cycle from one eligible warp.
- Each warp issues its instructions in program order; latency is hidden by switching among warps (and by independent instructions within a warp).
- Fixed-latency dependencies are handled by compiler-encoded control information (stall counts, yield hints). Variable-latency results (memory, MUFU) use scoreboards; a dependent instruction waits on that scoreboard.
- Register file is banked; an instruction reading several operands from the same bank can lose cycles. `ptxas` sets `.reuse` flags to serve repeated operands from an operand reuse cache. Bank counts/widths differ per architecture (known from microbenchmark studies, not official docs).
## Nsight Compute Stall Reasons → Fix
| Stall reason | Meaning | Typical fix |
|--------------|---------|-------------|
| Long Scoreboard | Waiting on L1TEX (global/local/texture) data | Coalesce, increase reuse via smem, prefetch/`cp.async` pipelining, more warps/ILP; check for `LDL` spills |
| Short Scoreboard | Waiting on MIO (shared memory, MUFU, shuffles) | Fix bank conflicts, fewer transcendental ops, `-use_fast_math` if accuracy allows |
| MIO Throttle / LG Throttle | Memory instruction queues full | Wider (vectorized) accesses, fewer instructions |
| Math Pipe Throttle | Execution pipe busy | Good if compute-bound; otherwise move work to tensor cores or lower precision |
| Wait | Fixed-latency dependency | More ILP, unrolling |
| Barrier | Waiting at `__syncthreads` | Balance work across warps, fewer barriers |
| Not Selected | Eligible but another warp issued | Not a problem; indicates enough warps |
| No Instruction | Instruction cache miss / branch target | Reduce code size (over-unrolling), avoid huge kernels |
| Branch Resolving | Divergent branches | Make branches warp-uniform, predication |
## Checklist When Reading a Hot Loop
1. Loads vectorized (`.64`/`.128`) where data is contiguous?
2. Any `LDL`/`STL` inside the loop (spills)?
3. Tensor-core instructions present for half/bf16/int8 math?
4. Expected unroll factor visible (repeated instruction blocks)?
5. Address arithmetic (`IMAD`, `LEA`) dominating over useful math? Hoist/strength-reduce in source.
6. Unexpected `F2F`/`I2F` conversions from mixed types (e.g. a stray `double` literal produces `DADD`/`F2F.F64`)?
## Anti-Patterns
- Optimizing without per-instruction sampling; guessing hot spots from SASS length.
- Trying to hand-edit SASS for production (unsupported, architecture-specific, unmaintainable). Change source, flags, or use CUTLASS.
- Treating a high "Not Selected" share as a stall to fix.
- Comparing SASS across architectures as if instruction sets were identical.
## References
- CUDA Binary Utilities documentation (cuobjdump, nvdisasm, instruction set lists per architecture).
- Nsight Compute Kernel Profiling Guide (warp stall reason definitions).
- Jia et al., "Dissecting the NVIDIA Volta GPU Architecture via Microbenchmarking" (arXiv:1804.06826).
- Related: `../ptx-assembly/SKILL.md`, `../cuda-programming/SKILL.md`.
Wersje
W bazie nie ma innych skilli o nazwie sass-machine-code.
Migawka bazy z 13.11.2026 · wersja paczki c15739956c25 (skrót SHA-256 całej paczki)
Pobrania w ostatnich 30 dniach: 0 · ranking
Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.
Podobne skille
- 100ptx-assembly
Czyta i pisze PTX, wirtualny język NVIDIA: generuje i sprawdza kod, asembler inline w CUDA, bariery i diagnozuje presję rejestrów przez ptxas. - 100cuda-programming
Pisze i przegląda jądra CUDA C++: konfigurację uruchomienia, pamięć, koalescencję, tiling w pamięci dzielonej i profilowanie w Nsight. - 90kernel-flow
Prowadzi optymalizację kernela CUDA na GPU NVIDIA: pomiar wąskiego gardła w Nsight Compute i weryfikację poprawności. - 100cuda-profiling
Prowadzi profilowanie kerneli CUDA w Nsight Systems i Nsight Compute: modele roofline, kernele ograniczone pamięcią lub obliczeniami oraz znaczniki NVTX. - 100nsys-optimizer
Optymalizuje kod symulacji CUDA i GPU na podstawie profilowania NVIDIA Nsight Systems, wskazuje wąskie gardła i prowadzi całą pętlę optymalizacji, na przykład gdy jedna scena działa wolniej. - 100css-modules-and-sass
Utrzymuje zakresowe style komponentów, miksiny Sass, zagnieżdżone reguły i zmienne w CSS Modules i Sass/SCSS.