SCIENCE · AI HARDWARE

AMD GPU optimization for training and inference: MI300X, MI325X, MI355X

AUTHOR · XERJ documentation team · REVIEWED BY · XERJ engineering team · PUBLISHED · 2026-11-22 · UPDATED · 2026-11-22
SHORT ANSWER · UPDATED 2026-11-22

Profile first, then optimize the biggest kernel. On MI300X, MI325X and MI355X that means: confirm the gfx target (gfx942 or gfx950), find the top kernels with rocprofv3, decide memory bound or compute bound against the roofline, then fix the kernel (tiles, MFMA shape, LDS, registers) or the library path (hipBLASLt, TunableOp, AITER), and only then tune clocks, partitions and NUMA.

Key number: MI300X needs about 247 FLOPs per byte of HBM traffic to reach its BF16 peak (1,307.4 TFLOPS over 5.3 TB/s). MI355X needs about 313 (2.5 PFLOPS over 8.0 TB/s). Below that, a kernel is memory bound. (as of 2026-11-22 · sources: AMD MI300X, AMD MI355X)

Last checked: 2026-11-22. Commands and environment variables come from ROCm 10.2 documentation and the source repositories. Assembly on this page was compiled with clang 21.1.8, not run on a GPU.

TL;DR AMD Instinct GPUs reward the same discipline as any accelerator: measure, compare with the hardware ceiling, fix the largest gap. The AMD specifics are wave64, MFMA matrix instructions with AGPR accumulators, 64 KiB of LDS per CU on CDNA3 and 160 KiB on CDNA4, eight XCDs with their own L2, and FNUZ FP8 on MI300 versus OCP FP8 and MXFP4 on MI355X. The calculator below gives you the roofline and the decode ceiling before you write a line of code.

Try it: roofline and tokens/s ceiling

AMD Instinct roofline calculator

GPU and GEMM

Presets

Arithmetic intensity
Ridge point (peak ÷ bandwidth)
Attainable
Time floor

LLM decode ceiling
Weights
KV cache read per step
Memory needed
Step time floor
Decode ceiling

Runs in your browser and sends nothing. Peaks are AMD's dense numbers and peak HBM bandwidth from the AMD product pages and the ROCm MI300 and MI350 workload optimization guide (checked 2026-11-22). GEMM bytes assume each matrix crosses HBM once: (M·K + K·N) × input bytes + M·N × output bytes. Decode step reads all weights plus the KV cache (2 × layers × KV heads × head dim × KV bytes per token). Tensor parallel assumes ideal scaling of bandwidth and memory. These are ceilings, not measurements. The default model shape is an example input.
PASTE THIS TO YOUR AI AGENT. IT DOES THE REST Act as a GPU performance engineer. Read https://xerj.org/science/amd-gpu-optimization and https://xerj.org/llms.txt. Install XERJ and index this repository so you can search it with citations. Then profile my workload on the AMD GPU: run rocminfo and amd-smi static, a rocprofv3 kernel trace with --stats, and rocprof-compute on the top kernel. Report the gfx target, the top 5 kernels by time, and whether each one is memory bound or compute bound.

On this page: 1. Profile first · 2. Hardware numbers · 3. Native instructions · 4. How to code · 5. Kernel issues · 6. Push to the limits · Sources. The instruction-level deep dive is in AMD MFMA instructions on CDNA3 and CDNA4.

1. What to do first: profile

Start with the system, then the timeline, then one kernel. Each tool below ships with ROCm under /opt/rocm/bin.

Confirm the GPU and the gfx target

rocminfo | grep -E "Name:|Compute Unit|SIMD|Wavefront Size"
amd-smi static --asic --vram --cache --limit
amd-smi metric --clock --power --temperature --usage
amd-smi monitor -p -u -m -v -w 1        # live power, GFX and memory use, VRAM, 1 s interval
amd-smi partition                       # current compute and memory partition

MI300X and MI325X report gfx942. MI350X and MI355X report gfx950. Build for the target you run on, or for both: --offload-arch=gfx942 --offload-arch=gfx950.

Find the hot kernels: rocprofv3

# kernel timeline plus summary statistics, in CSV
rocprofv3 --kernel-trace --stats --output-format csv -- ./app

# HIP API, memory copies and kernels together, for overlap problems
rocprofv3 --sys-trace --output-format csv -- ./app

# raw counters, one pass per --pmc group
rocprofv3 --list-avail
rocprofv3 --pmc SQ_WAVES GRBM_GUI_ACTIVE -- ./app

Explain one kernel: rocprof-compute (formerly Omniperf)

rocprof-compute profile --name mywork -k my_gemm_kernel -- ./app
rocprof-compute profile --name mywork --roof-only -- ./app     # roofline data only, faster
rocprof-compute analyze -p workloads/mywork/MI300X            # Speed-of-Light, caches, LDS, wavefronts

Read the System Speed-of-Light block first. It puts VALU FLOPs, MFMA FLOPs, LDS, L2 and HBM use next to their peaks, which tells you which section to open next.

See the whole system: rocprof-sys

rocprof-sys-sample -- ./app                                  # sampling, no rebuild
rocprof-sys-instrument -M sampling -o app.inst -- ./app
rocprof-sys-run -- ./app.inst

Use it when the GPU idles: data loading, CPU launch overhead, host to device copies and collectives show up on one timeline.

2. Getting the hardware numbers

MI300XMI325XMI355X
Architecture, LLVM targetCDNA3, gfx942CDNA3, gfx942CDNA4, gfx950
Compute units (CUs)304 (38 per XCD, 8 XCDs)304 (38 per XCD)256 (32 per XCD)
Peak engine clock2,100 MHz2,100 MHz2,400 MHz
Wavefront size646464
VGPR file per CU / SGPR file512 KiB / 12.5 KiB512 KiB / 12.5 KiB512 KiB / 12.5 KiB
LDS per CU64 KiB64 KiB160 KiB
L1 vector cache per CU32 KiB32 KiB32 KiB
L2 cache4 MiB per XCD (32 MiB)4 MiB per XCD (32 MiB)4 MiB per XCD (32 MiB)
Infinity Cache (L3)256 MiB256 MiB256 MiB
HBM192 GB HBM3256 GB HBM3E288 GB HBM3E
Peak HBM bandwidth5.3 TB/s6.0 TB/s8.0 TB/s
FP64 vector / matrix81.7 / 163.4 TFLOPS81.7 / 163.4 TFLOPS78.6 / 78.6 TFLOPS
FP32 vector / matrix163.4 / 163.4 TFLOPS163.4 / 163.4 TFLOPS157.3 / 157.3 TFLOPS
TF32 matrix653.7 TFLOPS653.7 TFLOPSsoftware, via BF16
FP16 and BF16 matrix (dense)1,307.4 TFLOPS1,307.4 TFLOPS2.5 PFLOPS
FP8 matrix (dense)2,614.9 TFLOPS (FNUZ)2,614.9 TFLOPS (FNUZ)5 PFLOPS (OCP)
MXFP6 and MXFP4 matrixnot in hardwarenot in hardware10.1 PFLOPS
INT8 matrix (dense)2,614.9 TOPS2,614.9 TOPS5 POPS
Board power750 W1,000 W1,400 W

Sources: AMD product pages for MI300X, MI325X and MI355X; the ROCm GPU specifications table; and the ROCm MI300 Series and MI350 Series workload optimization guide. Checked 2026-11-22. AMD also lists structured-sparsity peaks at 2x the dense FP16, BF16, FP8 and INT8 numbers; the table shows dense peaks.

Query them in code

The fields below are in hipDeviceProp_t (hip_runtime_api.h). This host program needs a ROCm install; it was not compiled for this page.

#include <hip/hip_runtime.h>
#include <cstdio>
int main() {
  hipDeviceProp_t p;
  hipGetDeviceProperties(&p, 0);
  printf("arch %s, CUs %d, warpSize %d\n", p.gcnArchName, p.multiProcessorCount, p.warpSize);
  printf("LDS per block %zu, LDS per CU %zu bytes\n", p.sharedMemPerBlock, p.maxSharedMemoryPerMultiProcessor);
  printf("L2 %d bytes, HBM %zu bytes, bus %d bits\n", p.l2CacheSize, p.totalGlobalMem, p.memoryBusWidth);
  printf("clock %d kHz, memory clock %d kHz\n", p.clockRate, p.memoryClockRate);
}

The roofline in one paragraph

Attainable FLOPs = min(peak FLOPs, arithmetic intensity × bandwidth). Arithmetic intensity (AI) is FLOPs divided by bytes moved from HBM. The ridge point is peak ÷ bandwidth. For BF16 it is 1,307.4 ÷ 5.3 ≈ 247 FLOP/byte on MI300X, 1,307.4 ÷ 6.0 ≈ 218 on MI325X and 2,500 ÷ 8.0 ≈ 313 on MI355X. A GEMM of M×N×K does 2·M·N·K FLOPs. At M = 1 (batch-1 decode) the AI of a BF16 GEMV is about 1 FLOP/byte, so it runs at bandwidth speed no matter how fast the matrix cores are. A square 8192 GEMM in BF16 has an AI near 2,700, far right of the ridge, so it is compute bound.

For LLM decode the same logic gives a hard ceiling: tokens/s ≤ batch × bandwidth ÷ (weight bytes + KV bytes read per step). Example arithmetic, not a measurement: 70 billion BF16 parameters are 140 GB. On MI300X, 140 GB ÷ 5.3 TB/s ≈ 26.4 ms per step, so batch 1 stays under about 38 tokens/s. FP8 weights halve the bytes and double that ceiling. Bigger batches reuse each weight read across sequences, which is why serving engines batch.

3. Native instructions

CDNA GPUs do matrix math with MFMA (matrix fused multiply add) instructions, named v_mfma_<out>_<M>x<N>x<K>_<in>. One wavefront of 64 lanes executes one MFMA. The ISA references are the CDNA3 ISA and the CDNA4 ISA. AMD's Matrix Instruction Calculator prints cycles, FLOPs and register layouts per instruction.

git clone https://github.com/ROCm/amd_matrix_instruction_calculator
cd amd_matrix_instruction_calculator && pip install -r requirements.txt
python3 matrix_calculator.py -a CDNA3 -i v_mfma_f32_16x16x16_f16 -d

We ran it for this page. For v_mfma_f32_16x16x16_f16 on CDNA3 it reports 8,192 FLOPs in 16 cycles, 2,048 FLOPs per CU per cycle. Check: 2,048 × 304 CUs × 2.1 GHz = 1,307.4 TFLOPS, exactly AMD's FP16 peak for MI300X. The FP8 instruction v_mfma_f32_16x16x32_fp8_fp8 does 4,096 FLOPs per CU per cycle, which gives the 2,614.9 TFLOPS FP8 peak. The full table, operand layouts and the CDNA4 instructions are on the MFMA page.

Dump the ISA your compiler really emits

hipcc -O3 --offload-arch=gfx942 -save-temps -c kernel.hip     # writes kernel-hip-amdgcn-amd-amdhsa-gfx942.s
hipcc -O3 --offload-arch=gfx942 -Rpass-analysis=kernel-resource-usage -c kernel.hip
llvm-objdump -d --mcpu=gfx942 code_object.co                 # from a saved code object
AMDGCN_ENABLE_DUMP=1 python my_triton_kernel.py               # Triton prints the ISA it generates

In the .s file look for three things: the v_mfma instructions you expect, vector loads (global_load_dwordx4, ds_read_b128 or ds_read2_b64), and the s_waitcnt instructions. vmcnt(n) waits for global memory loads, lgkmcnt(n) for LDS, scalar and message traffic, where n is how many may still be in flight. The comment block at the end lists NumVgprs, NumAgprs, ScratchSize, LDSByteSize and Occupancy.

CPU side: Zen 4 and Zen 5 EPYC and Ryzen

Data loading, tokenization and CPU inference run on the host. GCC 14.2 turns on AVX-512 with AVX512_BF16 and AVX512_VNNI for both -march=znver4 and -march=znver5; znver5 adds AVX-VNNI and AVX512_VP2INTERSECT (checked with gcc -march=znver5 -Q --help=target). The two instructions that matter for ML are vdpbf16ps (BF16 pairs into FP32) and vpdpbusd (u8 × s8 into INT32).

#include <immintrin.h>
#include <stdint.h>
#include <stddef.h>
// 32 bf16 pairs per instruction into 16 fp32 lanes. n multiple of 32.
float dot_bf16(const uint16_t* a, const uint16_t* b, size_t n) {
  __m512 acc = _mm512_setzero_ps();
  for (size_t i = 0; i < n; i += 32)
    acc = _mm512_dpbf16_ps(acc, (__m512bh)_mm512_loadu_si512(a + i),
                                (__m512bh)_mm512_loadu_si512(b + i));
  return _mm512_reduce_add_ps(acc);
}
// 64 u8 x s8 pairs per instruction into 16 int32 lanes. n multiple of 64.
int32_t dot_u8s8(const uint8_t* a, const int8_t* b, size_t n) {
  __m512i acc = _mm512_setzero_si512();
  for (size_t i = 0; i < n; i += 64)
    acc = _mm512_dpbusd_epi32(acc, _mm512_loadu_si512(a + i), _mm512_loadu_si512(b + i));
  return _mm512_reduce_add_epi32(acc);
}
$ gcc -O3 -march=znver5 -ffast-math -S dot.c && grep -E "vdpbf16ps|vpdpbusd" dot.s
    vdpbf16ps   (%rsi,%rax,2), %zmm1, %zmm0
    vpdpbusd    (%rsi,%rax), %zmm1, %zmm0

One detail we saw while compiling: for a plain C FP32 dot product, GCC 14.2 and clang 21.1.8 with -march=znver5 both picked 256-bit ymm FMAs. Clang switched to 512-bit zmm FMAs with -mprefer-vector-width=512; GCC kept ymm for this loop. Always read the assembly, and benchmark both widths on your CPU. For libraries, AMD maintains ZenDNN and a PyTorch plugin for EPYC, and oneDNN also runs on these CPUs. The box that compiled this is an Intel Xeon, so we report no CPU timings here.

4. How to code it

A HIP kernel with MFMA and LDS tiling

Four wavefronts share a 32×32 output tile. Each copies 16 bytes per matrix into LDS, then each wavefront runs four v_mfma_f32_16x16x16_f16 per 64-wide K step. The 8-half pad shifts each LDS row by 4 banks so the 16 lanes reading one column do not collide.

#include <hip/hip_runtime.h>

typedef _Float16 half4 __attribute__((ext_vector_type(4)));
typedef _Float16 half8 __attribute__((ext_vector_type(8)));
typedef float    float4_ __attribute__((ext_vector_type(4)));

// C[M][N] (fp32) = A[M][K] (fp16, row-major) * B (fp16, stored as Bt[N][K]).
// One workgroup = 4 wavefronts of 64 lanes = 256 threads, a 32x32 C tile.
// Each wavefront owns one 16x16 sub-tile and issues v_mfma_f32_16x16x16_f16.
// M, N multiples of 32; K multiple of 64.
constexpr int BM = 32, BN = 32, KT = 64;
constexpr int PAD = 8;                  // 8 halfs = 16 bytes: shifts each LDS row by 4 banks
constexpr int LDS_STRIDE = KT + PAD;    // 72 halfs = 144 bytes, keeps 16-byte alignment

__global__ __launch_bounds__(256)
void gemm_f16_mfma(const _Float16* __restrict__ A, const _Float16* __restrict__ Bt,
                   float* __restrict__ C, int M, int N, int K) {
  __shared__ _Float16 As[BM * LDS_STRIDE];
  __shared__ _Float16 Bs[BN * LDS_STRIDE];

  const int t = threadIdx.x;
  const int lane = t & 63, wave = t >> 6;          // wave64: 64 lanes, not 32
  const int m0 = blockIdx.y * BM, n0 = blockIdx.x * BN;
  const int wm = (wave >> 1) * 16, wn = (wave & 1) * 16;
  const int i = lane & 15, kq = (lane >> 4) * 4;   // MFMA 16x16x16 operand layout

  const int lr = t >> 3, lc = (t & 7) * 8;         // each thread copies 8 halfs = 16 bytes
  float4_ acc = {0.f, 0.f, 0.f, 0.f};

  for (int k0 = 0; k0 < K; k0 += KT) {
    // global -> LDS, 16-byte vector loads (global_load_dwordx4, ds_write_b128)
    *(half8*)&As[lr * LDS_STRIDE + lc] = *(const half8*)&A [(size_t)(m0 + lr) * K + k0 + lc];
    *(half8*)&Bs[lr * LDS_STRIDE + lc] = *(const half8*)&Bt[(size_t)(n0 + lr) * K + k0 + lc];
    __syncthreads();
#pragma unroll
    for (int kk = 0; kk < KT; kk += 16) {
      half4 a = *(const half4*)&As[(wm + i) * LDS_STRIDE + kk + kq];
      half4 b = *(const half4*)&Bs[(wn + i) * LDS_STRIDE + kk + kq];
      acc = __builtin_amdgcn_mfma_f32_16x16x16f16(a, b, acc, 0, 0, 0);
    }
    __syncthreads();
  }
  // D layout: lane holds column i, rows kq..kq+3
#pragma unroll
  for (int r = 0; r < 4; ++r)
    C[(size_t)(m0 + wm + kq + r) * N + n0 + wn + i] = acc[r];
}

Compiled for gfx942 with clang 21.1.8 (-O3 --offload-arch=gfx942, a minimal stand-in for hip_runtime.h because the box has no ROCm install). This is the real inner loop. It was compiled, not run:

    global_load_dwordx4 v[12:15], v[0:1], off
    global_load_dwordx4 v[16:19], v[2:3], off
    s_add_i32 s8, s8, 64
    v_lshl_add_u64 v[2:3], v[2:3], 0, s[0:1]
    v_lshl_add_u64 v[0:1], v[0:1], 0, s[0:1]
    s_cmp_ge_i32 s8, s5
    s_waitcnt vmcnt(1)
    ds_write_b128 v8, v[12:15]
    s_waitcnt vmcnt(0)
    ds_write_b128 v9, v[16:19]
    s_waitcnt lgkmcnt(0)
    s_barrier
    ds_read2_b64 v[12:15], v10 offset1:4
    ds_read2_b64 v[16:19], v11 offset1:4
    s_waitcnt lgkmcnt(0)
    v_mfma_f32_16x16x16_f16 a[0:3], v[12:13], v[16:17], a[0:3]
    ds_read2_b64 v[20:23], v10 offset0:8 offset1:12
    v_mfma_f32_16x16x16_f16 a[0:3], v[14:15], v[18:19], a[0:3]
    ds_read2_b64 v[12:15], v11 offset0:8 offset1:12
    s_waitcnt lgkmcnt(0)
    s_barrier
    v_mfma_f32_16x16x16_f16 a[0:3], v[20:21], v[12:13], a[0:3]
    v_mfma_f32_16x16x16_f16 a[0:3], v[22:23], v[14:15], a[0:3]
    s_cbranch_scc0 .LBB0_2

What to read from it: the 16-byte global loads became global_load_dwordx4; LDS writes are ds_write_b128; the compiler merged the two 8-byte LDS reads into ds_read2_b64; the accumulators live in AGPRs a[0:3]. Resource summary from the same build: 24 VGPRs, 4 AGPRs, 0 bytes scratch, 9,216 bytes LDS per workgroup, occupancy 7 waves per SIMD on gfx942 and 8 on gfx950. The difference is LDS: 64 KiB ÷ 9,216 bytes fits 7 workgroups per CU on gfx942, while gfx950's 160 KiB fits 17. The s_waitcnt lgkmcnt(0) before the first MFMA is the next thing to remove, with double-buffered LDS.

Triton on ROCm

Triton's AMD backend accepts these options per kernel config (from HIPOptions in triton-lang/triton, third_party/amd/backend/compiler.py): num_warps, num_stages, waves_per_eu, matrix_instr_nonkdim and kpack. AMD's guidance: num_stages = 2 for a single GEMM, 1 for two fused GEMMs such as attention; matrix_instr_nonkdim = 16 picks the 16×16 MFMA and usually beats 32 on MI300X; waves_per_eu asks the compiler to cut VGPRs to reach that occupancy. kpack is deprecated on gfx950 and forced to 1.

@triton.autotune(configs=[
    triton.Config({"BLOCK_M": 256, "BLOCK_N": 256, "BLOCK_K": 64, "GROUP_SIZE_M": 8,
                   "waves_per_eu": 2, "matrix_instr_nonkdim": 16, "kpack": 2},
                  num_warps=8, num_stages=2),
    triton.Config({"BLOCK_M": 128, "BLOCK_N": 128, "BLOCK_K": 64, "GROUP_SIZE_M": 8,
                   "waves_per_eu": 0, "matrix_instr_nonkdim": 16, "kpack": 1},
                  num_warps=4, num_stages=2),
], key=["M", "N", "K"])
@triton.jit
def matmul_kernel(...): ...

To see what Triton built: AMDGCN_ENABLE_DUMP=1 prints ISA, MLIR_ENABLE_DUMP=1 prints the IR passes.

Libraries before hand-written kernels

For GEMMs, PyTorch on ROCm chooses between hipBLASLt and rocBLAS by heuristics; TORCH_BLAS_PREFER_HIPBLASLT=1 prefers hipBLASLt. Benchmark a shape directly with hipBLASLt's tool:

HIP_FORCE_DEV_KERNARG=1 hipblaslt-bench --alpha 1 --beta 0 -r f16_r \
  --a_type f16_r --b_type f8_r --compute_type f32_f16_r \
  --initialization trig_float --cold_iters 100 --iters 1000 --rotating 256

PyTorch TunableOp tries the GEMM algorithms in rocBLAS and hipBLASLt for each shape and records the winner:

# pass 1: tune and write tunableop_results.csv (slow)
PYTORCH_TUNABLEOP_ENABLED=1 PYTORCH_TUNABLEOP_VERBOSE=1 python train.py
# pass 2: reuse the results, no tuning
PYTORCH_TUNABLEOP_ENABLED=1 PYTORCH_TUNABLEOP_TUNING=0 python train.py

For compiled models, torch.compile(mode="max-autotune") benchmarks Triton GEMM configs (including matrix_instr_nonkdim) and turns on HIP graphs. TORCHINDUCTOR_MAX_AUTOTUNE_GEMM_BACKENDS can add CK for Composable Kernel candidates; for inference, TORCHINDUCTOR_FREEZING=1 folds weights as constants.

FP8 on MI300 and MI355X

MI300X and MI325X implement the FNUZ FP8 variants (e4m3fnuz, e5m2fnuz). MI350X and MI355X implement the OCP variants (e4m3fn, e5m2) plus MXFP8, MXFP6 and MXFP4 with a shared exponent per 32 elements. A checkpoint quantized for one family may need conversion for the other, so check the dtype names in your stack.

Attention kernels

AITER (AI Tensor Engine for ROCm) provides fused attention, MoE and GEMM kernels that vLLM uses on ROCm. ROCm/flash-attention is AMD's FlashAttention port, and Composable Kernel (now in ROCm/rocm-libraries) supplies attention and GEMM building blocks.

Inference with vLLM

export HIP_FORCE_DEV_KERNARG=1            # set in vLLM ROCm images; set it on bare metal
export SAFETENSORS_FAST_GPU=1
export TORCH_BLAS_PREFER_HIPBLASLT=1
export VLLM_ROCM_USE_AITER=1              # master switch for AITER kernels
export NCCL_MIN_NCHANNELS=112             # multi-GPU only, MI300X and MI325X

vllm serve meta-llama/Llama-3.1-8B-Instruct \
  --kv-cache-dtype fp8 --calculate-kv-scales \
  --gpu-memory-utilization 0.90 \
  --max-num-batched-tokens 16384

AMD's vLLM guide adds: --attention-backend overrides the auto-selected kernel but keep VLLM_ROCM_USE_AITER=1 set; FP8 KV cache cuts KV memory by about half; sweep --max-num-batched-tokens between about 8k and 64k for the latency and throughput balance; CUDA graph capture is set with --compilation-config '{"cudagraph_mode": "FULL_AND_PIECEWISE"}', which is the V1 default.

Training

PyTorch's nccl backend runs on RCCL on ROCm. For FSDP across nodes, AMD recommends high-priority RCCL streams so communication overlaps compute, and at most 4 HIP streams:

export TORCH_NCCL_HIGH_PRIORITY=1   # all RCCL streams high priority
export GPU_MAX_HW_QUEUES=2          # two compute streams plus two RCCL streams

On MI300X, AMD advises running collectives on 1 GPU or all 8 rather than 2 or 4, because of how the GPUs are linked. Train in BF16 with FP32 master weights by default; for FP8 training on ROCm, AMD maintains a TransformerEngine port. Use TunableOp or hipBLASLt tuning for the GEMM shapes your model actually runs.

5. Avoiding kernel issues

IssueSymptomHow to detect itFix
VGPR spillsKernel slower than expected, scratch traffic-Rpass-analysis=kernel-resource-usage shows VGPRs Spill above 0; .vgpr_spill_count in the ISA metadataSmaller tiles, fewer live accumulators, or a lower waves_per_eu target so the compiler gets more registers
Scratch from private arraysscratch_store and scratch_load in the ISA, ScratchSize above 0 with zero spillsSame remark; search the .s file for scratch_; rocprofv3 --scratch-memory-traceIndex per-thread arrays with compile-time constants, fully unroll, or move the array to LDS
Low occupancyFew waves per SIMD, latency not hiddenThe Occupancy line in the .s file or remark; rocprof-compute wavefront sectionCheck which limit wins (registers or LDS) with the occupancy calculator
LDS bank conflictsLDS time high in rocprof-computerocprofv3 --pmc SQ_LDS_BANK_CONFLICT (cycles LDS is stalled by bank conflicts) or the LDSBankConflict metric; rocprof-compute LDS sectionPad rows or swizzle. CDNA3 LDS has 32 banks of 4 bytes, CDNA4 has 64 banks
s_waitcnt stallsMFMA idle between LDS readsRead the ISA: an s_waitcnt lgkmcnt(0) right before each v_mfmaSoftware pipelining: double-buffer LDS and issue the next loads before the current MFMAs
wave64 porting bugsWrong results only on AMDgrep for hard-coded 32, 0xffffffff masks and 32-bit ballot resultsUse warpSize, 64-bit masks and 64-bit ballot results
Managed memory not migratingPage faults or slow first touch with hipMallocManagedCheck HSA_XNACK and whether the kernel driver supports HMMSet HSA_XNACK=1 on supported GPUs with an HMM driver, or use explicit hipMalloc and copies
Memory access faultProcess aborts with a GPU memory faultHSA_TOOLS_LIB=/opt/rocm/lib/librocm-debug-agent.so.2 HSA_ENABLE_DEBUG=1 ./app prints the faulting kernelAdd PYTORCH_NO_HIP_MEMORY_CACHING=1 and HSA_DISABLE_FRAGMENT_ALLOCATOR=1 while debugging so the fault shows where it starts
Async errors hard to placeError reported at a later API callRun with AMD_SERIALIZE_KERNEL=3 or HIP_LAUNCH_BLOCKING=1, and AMD_LOG_LEVEL for runtime logsFix the first failing launch, then remove the serialization
GEMM stride hot spots on MI300Large drop for some leading dimensions, mostly TNLeading dimension in bytes is a multiple of 512Pad: for TN FP16 GEMM, AMD suggests lda = ldb = K + 128 when K % 256 == 0
Version mismatchKernels missing for your GPU, or tools that disagreeamd-smi version, rocminfo, and the framework's ROCm buildMatch ROCm, driver and framework builds using the ROCm compatibility matrix, and build for your exact gfx target

Two of these were reproduced at compile time for this page. A per-thread float buf[64] indexed with a runtime value compiled to 272 bytes of scratch with 0 spills (the array lives in scratch, not registers). A wavefront holding a 4×4 grid of 32×32 MFMA accumulators needed 24 VGPRs plus 256 AGPRs and ran at occupancy 1; forcing amdgpu_waves_per_eu(2) gave occupancy 2 but spilled 66 VGPRs. Details on the MFMA page.

Porting from CUDA: HIP keeps the CUDA programming model, and hipify tools translate most API calls. The usual surprises are wave64 (warpSize is 64), 64-bit ballot and lane masks, and tile shapes chosen for 32-thread warps. Grep for literal 32 and 0xffffffff in warp-level code first.

6. Pushing to the limits

Power and clocks

sudo amd-smi set -l DETERMINISM      # performance determinism level
sudo amd-smi set -d 1900             # determinism mode with a GFXCLK soft max, in MHz (example value)
sudo amd-smi set -o 700              # power cap in watts (example value)
amd-smi metric -v                    # throttle accumulators (MI300 and newer)

Determinism trades a little peak clock for steady clocks, which makes benchmarks repeatable. AMD notes 3% to 10% clock variation between XCDs on MI300X, with XCD0 usually fastest; use the slowest XCD's clock when you compute efficiency.

Partitions: SPX, DPX, QPX, CPX and NPS

ModeMI300XMI325XMI355X
SPX8 XCDs, 192 GB, NPS18 XCDs, 256 GB, NPS18 XCDs, 288 GB, NPS1
DPX4 XCDs, 96 GB4 XCDs, 128 GB4 XCDs, 144 GB, NPS2
QPX2 XCDs, 48 GB2 XCDs, 64 GB2 XCDs, 72 GB, NPS2
CPX1 XCD, 24 GB1 XCD, 32 GB1 XCD, 36 GB, NPS2

Source: ROCm MI300 and MI350 workload optimization guide, partitioning table.

sudo amd-smi partition --accelerator    # list valid compute partitions
sudo amd-smi set -C CPX                 # compute partition
sudo amd-smi set -M NPS4                # memory partition (NPS1, NPS2, NPS4, NPS8 where supported)

Partitions help when many small jobs or model replicas each fit in one partition. A single large job usually runs in SPX, where one GPU exposes all 8 XCDs.

NUMA and host settings

cat /proc/sys/kernel/numa_balancing     # 1 means on
sudo sysctl kernel.numa_balancing=0

AMD recommends turning NUMA auto-balancing off on MI300X systems. Pin each rank's CPU threads and memory to the socket nearest its GPU, for example with numactl.

GEMM and graph tuning

Batch, KV cache and quantization

Use the calculator above: fit weights plus KV cache in HBM, then raise the batch until decode moves from bandwidth bound toward compute bound. MI325X and MI355X's larger HBM holds more KV cache per GPU. FP8 weights halve weight traffic on both families; MXFP4 on MI355X cuts it to a quarter of BF16. FP8 KV cache halves KV bytes. Validate accuracy on your own evaluation set after each quantization step.

What we compiled and what we cite

How XERJ fits

XERJ is a new way for AI to search for data. Index your kernel repository and the ROCm docs you keep locally, and your coding agent can find the right flag, counter or kernel with a file and line to cite instead of guessing. The prompt above sets that up.

FAQ

What is the first step to optimize code on an AMD GPU?

Profile before you change anything. Confirm the gfx target with rocminfo, check clocks and power with amd-smi, find the top kernels with rocprofv3 --kernel-trace --stats, then run rocprof-compute on the top kernel to see if it is memory bound or compute bound.

What is the gfx target of MI300X, MI325X and MI355X?

MI300X and MI325X are CDNA3 and use gfx942. MI350X and MI355X are CDNA4 and use gfx950. Compile with --offload-arch=gfx942 or --offload-arch=gfx950.

What is the wavefront size on AMD Instinct GPUs?

64 lanes on all CDNA GPUs, including MI300X and MI355X. CUDA warps are 32 threads, so code that assumes 32 lanes in shuffles, ballots or masks needs to be checked when porting.

Is my LLM decode on MI300X memory bound or compute bound?

At small batch sizes decode is memory bound. Each step reads all weights and the KV cache, so the ceiling is HBM bandwidth divided by bytes read per step: 5.3 TB/s on MI300X, 6.0 TB/s on MI325X and 8.0 TB/s on MI355X.

Which environment variables help vLLM on MI300X and MI355X?

AMD's ROCm guide lists VLLM_ROCM_USE_AITER=1 for AITER kernels, HIP_FORCE_DEV_KERNARG=1, TORCH_BLAS_PREFER_HIPBLASLT=1, SAFETENSORS_FAST_GPU=1, and NCCL_MIN_NCHANNELS=112 for multi-GPU runs on MI300X and MI325X.

Evidence

Related