| name | cuda-hip-kernel-optimization |
| description | Map CUDA kernel optimization strategies to HIP/ROCm implementations with performance-focused rewrites. Use when a CUDA kernel has already been translated (or partially translated) and needs optimization parity on AMD GPUs, especially for tiling, pipelining, shared-memory/LDS staging, warp-to-wavefront adaptation, vectorized loads/stores, and tensor-op path selection. |
CUDA HIP Kernel Optimization
Use this skill after mechanical porting to recover performance and architecture fit on ROCm.
Workflow
- Extract the CUDA kernel optimization intent (tile sizes, stages, tensor op path, memory movement).
- Map each CUDA optimization mechanism to a ROCm/CK equivalent.
- Re-tune for wavefront and vectorization constraints.
- Re-validate correctness and performance.
Step 1: Identify CUDA Intent
Capture these parameters from CUDA code:
- Threadblock/warp/instruction tile hierarchy.
- Pipeline stage count and async copy model.
- Shared-memory layout and synchronization pattern.
- Warp-level reductions/collectives.
Step 2: Map to CK/ROCm Building Blocks
Use references/cutlass-ck-patterns.md to map:
- CUDA multistage
cp.async pipelines -> CK blockwise pipelines with prefetch/scheduling choices.
- CUDA warp-centric logic -> wave-aware logic (
warpSize-aware or explicit wave assumptions).
- CUDA tensor op specialization -> CK XDL/MFMA or WMMA/XDL variants based on target architecture.
- CUDA vectorized global/shared transfers -> CK vector-load/store constraints.
Step 3: Re-tune for Wavefront and Memory
Prioritize:
- Wave mapping: ensure reductions/shuffles do not assume 32 lanes.
- LDS scheduling: evaluate
Intrawave vs Interwave.
- Pipeline buffering: tune prefetch/stage depth.
- Vector width/alignment: satisfy CK vector access validity constraints.
Step 4: Guardrails
- Do not mimic CUDA inline PTX behavior with unstable hacks; use native ROCm constructs.
- Keep architecture-specific specializations explicit and selectable.
- Preserve a correctness-first fallback path when introducing aggressive optimizations.
Output Contract
When finishing an optimization task with this skill, return:
- The CUDA optimization mechanism identified.
- The HIP/CK equivalent chosen.
- Tuning parameters changed (tile/stage/scheduler/vector width).
- Performance result and correctness status.
References