gcnasm -- GCN Assembly & HIP Programming Examples

February 13, 2026 ยท View on GitHub

A collection of AMD GPU programming examples targeting CDNA / RDNA architectures (primarily gfx942 / MI300), covering hand-written GCN assembly kernels, HIP C++ device code, and PyTorch/Triton extensions.

Legend

TagMeaning
[A]Hand-written GCN assembly kernel (.s)
[H]HIP / C++ / CUDA device code
[A/H]Both hand-written assembly and HIP host code
+Has Python / PyTorch / Triton interface (can run from Python directly)

Highlighted Examples

bandwidth_memread/ [H] -- The go-to memory bandwidth microbenchmark. Measures peak read-only and read+write GPU memory bandwidth using float4 vectorized, non-temporal, persistent kernels. Supports both ROCm and CUDA. Sweeps from ~78 KB to ~1.7 GB and reports GB/s per size. Peak observed: ~4.56 TB/s read-only on MI308X (gfx942). See the detailed README.

vector_add_asm/ [A/H] -- A minimal but complete hand-written GCN assembly kernel for C[i] = A[i] + B[i] on gfx942, demonstrating persistent kernel launch, double LDS buffering with deep pipeline fill, buffer_load_dword ... offen lds (async load to LDS), OOB-based control flow (no exec mask), and vmcnt(3) pipelining. See the detailed README.

Examples

Vector / Element-wise

TagFolderDescription
[H]vector_addBasic HIP vector add C[i] = A[i] + B[i]
[A/H]vector_add_asmHand-written asm vector add with buffer_load...lds, double LDS buffering, OOB control flow, vmcnt(3) pipelining (gfx942)
[H]absdiffSAD 8x8 absolute difference using __builtin_amdgcn_sad_u16

Matrix Multiply (GEMM)

TagFolderDescription
[A/H]hgemmHalf-precision GEMM 128x128 with hand-written MFMA asm
[H+]hgemm_mfmaHalf-precision GEMM with MFMA; Python codegen helpers
[A/H]sgemmSGEMM 128x128 with hand-written asm (VEGA64)
[H]sgemm_reductionSGEMM with warp reduction for large K, small M/N

Matrix Core / MFMA

TagFolderDescription
[H]matrix_coreMatrix core MFMA demo (32x32x16 f16, gfx942)
[H]matrix_core_aAlternate matrix core MFMA demo
[A/H]matrix_core_asmHand-written GCN matrix core kernel
[H]matrix_core_gfx950Matrix core MFMA for gfx950
[H]matrix_core_opusMatrix core via opus library

Memory Bandwidth / Memcpy

TagFolderDescription
[A/H]bandwidthMemory bandwidth memcpy with hand-written asm kernel
[H]bandwidth_cMemory bandwidth benchmark (CUDA/HIP memcpy kernel)
[H]bandwidth_hip_jitJIT HIP bandwidth -- kernel compiled and loaded at runtime
[H]bandwidth_memreadMemory bandwidth microbenchmark -- read-only & read+write, float4, non-temporal, persistent kernels (ROCm / CUDA)
[H]bandwidth_memread_2d2D memory read bandwidth benchmark
[H+]membenchMemory bandwidth test suite with JSON config
[H]memcpy_asyncAsync memcpy via shared memory (global -> LDS -> global)
[A/H]memcpy_exampleMemcpy kernel with hand-written asm
[A/H]memcpy_example_gfx1030Memcpy kernels for gfx1030 (RDNA2)
[+]triton_memreadTriton memory read kernel
[H]smidMemcpy throughput benchmark (buffer load, swizzled)

Warp / Wave Primitives

TagFolderDescription
[H]wave_reduce_dppWave-level reduction using DPP
[H]warp_sortWarp-level sort using DPP
[H+]warp_sort_bitonicBitonic merge sort (med3 + DPP/SHFL) with Python wrapper
[H+]warp_histogramPyTorch extension for warp-level histogram
[H]ds_permuteLDS ds_permute via __builtin_amdgcn_ds_permute
[A/H]transpose-ldsMatrix transpose via LDS with hand-written asm

Reduction

TagFolderDescription
[H]nbuf_reductionN-buffer reduction kernel
[H]nbuf_reduction_asyncAsync N-buffer reduction
[H]nbuf_reduction_wN-buffer reduction variant

Atomics / Synchronization

TagFolderDescription
[H]cmpswap_atomicAtomic compare-swap with bf16x2 reduction
[H]cmpswap_atomic_benchBenchmark for atomic compare-swap reduction
[H]cross-wg-syncCross-workgroup synchronization

Type Conversion

TagFolderDescription
[H]cvt_fp8FP8 (E4M3) conversion test using builtins
[H]cvt_i4Int4 conversion / IPS test
[H]pk_cvtFP8 packed conversion
[H]opus_castFast tanh via opus (ROCm / CUDA)
[H]mix_loadMixed-load kernel (bf16x2, gfx942)
[H]lqqLQQ quantization: i8 -> i4 with scale/zero

Integer Arithmetic

TagFolderDescription
[A/H]int_divide_modInteger division / modulus via hand-written asm
[A/H]int_divide_mod_2Integer division / modulus variant
[A/H]magic_integer_divisionMagic-number integer division via GCN asm

Instruction Throughput / HW Probing

TagFolderDescription
[A/H]measure_ipsInstruction throughput (IPS) measurement
[A/H+]measure_ips_benchIPS benchmark for many instructions; Python generates asm
[H]hwregHW_ID register readout for wave layout
[H]hwreg_maskHW_ID register access with masking

Buffer / LDS / Async

TagFolderDescription
[H]buffer_ld_oobBuffer load out-of-bounds behavior test
[H]async_copyMatrix transpose with HIP async copy
[H]test_lds_instLDS instruction test

Math Functions / Compiler Tests

TagFolderDescription
[H]test_exp2Device-side exp2f() test
[H]test_tanhDevice tanh test (ROCm / CUDA)
[H]test_compilerCompiler builtin tests (ds_permute)

PyTorch Extensions / Python Tools

TagFolderDescription
[H+]opus_fmmPyTorch extension for opus flat matrix multiply
[+]hadmard_rotateHadamard / orthogonal matrix (PyTorch)
[+]merge_w_kv_oMerge K/KV/O utility (Python)
[+]co-execPython tool: compile + run asm/HIP kernels via HSA