| name | ptx-optimization |
|---|---|
| description | Inspect, patch, assemble, and validate generated NVIDIA PTX using exact cubin identity and profiler evidence. Use for direct PTX optimization, ptxas experiments, or mapping NCU/SASS hotspots back to emitted code; not for generic CUDA source tuning or unsupported SASS binary patching. |
PTX Optimization
Optimize the actual generated program, not a similarly named source prototype. Diagnosis alone does not authorize edits; optimization does not authorize changing precision, clocks, device state, or the deployed solution without the applicable task scope and qualification.
Workflow
Read the experiment procedure before patching or compiling. It covers artifact identity, NCU attribution, reassembly controls, native validation, and timing gates.
- Freeze the deployed cubin, matching PTX, launch ABI, input contract, and original assembler/options. Record evaluator conditions separately from verified local operating state.
- Reassemble unmodified PTX first. Compare executable bytes and resource/ metadata differences, not just disassembly text or whole-file hashes.
- Use exact-binary hotspot evidence to identify the dependency or limiting resource. A waiting instruction is not necessarily an expensive operation. Read optimization patterns when choosing a memory, epilogue, synchronization or address-decoding experiment.
- Patch one mechanism, preserve the original, and inspect resulting SASS. PTX order is not a promise about final instruction scheduling.
- Numerically screen the substituted native cubin, run relevant native safety checks, then benchmark uninstrumented through the same runtime.
- Retain only repeatable improvements exceeding the declared materiality threshold at the requested metric. Fewer instructions are not a speedup. Compare follow-ups against the latest qualified artifact, preserving prior wins; keep historical comparisons explicitly tied to their baseline hashes.
Reusable tools and evidence
scripts/ptx_artifact.py: CPU-only standalone-cubin inventories, executable-byte comparisons, and explicit-toolchain assembly records. Run with--help. It never launches kernels or changes GPU settings.scripts/rank_ncu_samples.py: rank a single kernel's NCU SASS CSV by non-issued stall samples; refuse missing or mixed-kernel data.- Worked experiment and failure modes: bounded empirical lessons and synthetic counterexamples, not tuning defaults.
Preserve generated compiler ownership/layout semantics when editing code from a block language. Do not introduce hidden lane-varying source scalars, alter participation, or remove async waits/fences based only on sampled stalls. Raw SASS encoding edits are a different, architecture-specific task and are not implied by permission to patch PTX.
