rocm
AMD ROCm GPU computing stack for HIP kernel development and GPU-accelerated library usage. Use when: writing HIP kernels (.hip files), using rocBLAS/rocFFT/rocRAND/rocSOLVER/rocSPARSE/hipBLAS/hipBLASLt/hipTensor/hipSPARSELt/rocALUTION compute libraries, profiling with rocProfiler or rocprof, porting CUDA code to HIP, building CMake/Makefile projects targeting AMD GPUs, using HIP Graphs for low-overhead kernel replay, or debugging GPU code with rocGDB.
What this skill does
# ROCm GPU Development
**Version:** rocm-7.2.2
**Language:** C/C++ with HIP (`.hip` or `.cpp` files)
**License:** MIT (examples and most libraries); some components Apache-2.0
**Docs:** https://rocm.docs.amd.com
## Overview
ROCm is AMD's open-source GPU computing stack. HIP (Heterogeneous-compute Interface for Portability) is the primary programming API — it is syntactically close to CUDA and compiles on both AMD and NVIDIA GPUs. ROCm includes optimized compute libraries (BLAS, FFT, RNG, solvers, sparse, tensor contractions, structured sparsity), HIP Graphs for low-overhead kernel replay, and profiling/debugging tools. As of ROCm 7.2, `hipcc` is deprecated in favor of `amdclang++` (same flags, direct invocation recommended).
## Quick Start
```cpp
// minimal.hip
#include <hip/hip_runtime.h>
#include <stdio.h>
__global__ void hello(int n) {
int i = blockIdx.x * blockDim.x + threadIdx.x;
if (i < n) printf("thread %d\n", i);
}
int main() {
hello<<<dim3(4), dim3(8)>>>(32); // 4 blocks × 8 threads
hipDeviceSynchronize();
}
```
```bash
# Compile and run (hipcc still works but is deprecated in 7.2+)
hipcc -O2 -o hello minimal.hip && ./hello
# Preferred: amdclang++ -O2 -x hip -o hello minimal.hip && ./hello
# CMake (preferred for larger projects)
# cmake -S . -B build && cmake --build build
```
**Error-check macro (use throughout your code):**
```cpp
#define HIP_CHECK(expr) do { \
hipError_t err = (expr); \
if (err != hipSuccess) { \
fprintf(stderr, "HIP error: %s at %s:%d\n", \
hipGetErrorString(err), __FILE__, __LINE__); \
exit(EXIT_FAILURE); \
} \
} while(0)
// Usage:
HIP_CHECK(hipMalloc(&d_ptr, bytes));
HIP_CHECK(hipMemcpy(d_ptr, h_ptr, bytes, hipMemcpyHostToDevice));
my_kernel<<<grid, block>>>(args);
HIP_CHECK(hipGetLastError()); // catch launch errors
HIP_CHECK(hipDeviceSynchronize()); // catch runtime errors
```
## Core HIP Concepts
### Device Management
```cpp
int n_devices;
hipGetDeviceCount(&n_devices);
hipSetDevice(0); // select GPU
hipDeviceProp_t props;
hipGetDeviceProperties(&props, 0);
// props.name, .totalGlobalMem, .warpSize (64 on AMD!),
// .maxThreadsPerBlock, .gcnArchName
```
### Memory Pattern
```cpp
float *d_buf;
HIP_CHECK(hipMalloc(&d_buf, N * sizeof(float)));
HIP_CHECK(hipMemcpy(d_buf, h_buf, N*sizeof(float), hipMemcpyHostToDevice));
// ... kernel launches ...
HIP_CHECK(hipMemcpy(h_buf, d_buf, N*sizeof(float), hipMemcpyDeviceToHost));
HIP_CHECK(hipFree(d_buf));
```
For async transfers (overlap with compute), use `hipHostMalloc` + `hipMemcpyAsync` + streams.
### Kernel Launch Syntax
```cpp
// kernel<<<gridDim, blockDim, sharedMemBytes, stream>>>(args)
constexpr int BLOCK = 256;
int grid = (N + BLOCK - 1) / BLOCK; // ceiling division
my_kernel<<<dim3(grid), dim3(BLOCK), 0, hipStreamDefault>>>(d_ptr, N);
```
### Key Device Built-ins
```cpp
// Inside __global__ kernel:
int gid = blockIdx.x * blockDim.x + threadIdx.x; // 1D global index
// 2D:
int x = blockIdx.x * blockDim.x + threadIdx.x;
int y = blockIdx.y * blockDim.y + threadIdx.y;
__syncthreads(); // block-level barrier
__shared__ float smem[BLOCK_SIZE]; // shared memory declaration
atomicAdd(&shared_counter, 1); // atomic operations
// AMD: warpSize = 64 (wavefront), NVIDIA: warpSize = 32
// Always use warpSize built-in, not a hardcoded 32!
```
### Function Qualifiers
| Qualifier | Executes on | Called from |
|-----------|-------------|-------------|
| `__global__` | GPU | host only — kernel entry |
| `__device__` | GPU | GPU only |
| `__host__` | CPU | CPU only (default) |
| `__host__ __device__` | both | both |
## ROCm Installation
```bash
# Default install path
/opt/rocm/ # ROCm root
/opt/rocm/lib/llvm/bin/amdclang++ # AMD Clang (preferred compiler)
/opt/rocm/bin/hipcc # HIP compiler (deprecated, wraps amdclang++)
/opt/rocm/bin/rocm-smi # GPU monitor
/opt/rocm/bin/rocgdb # GPU debugger
# Verify installation
amdclang++ --version # preferred
hipcc --version # still works
rocm-smi # show GPU status
/opt/rocm/bin/rocm_agent_enumerator # list GPU targets (e.g. gfx1100, gfx90a)
# Target architecture flags
amdclang++ --offload-arch=gfx1100 -x hip ... # RX 7900 (Navi31/RDNA3)
amdclang++ --offload-arch=gfx90a -x hip ... # MI200 (CDNA2)
amdclang++ --offload-arch=gfx942 -x hip ... # MI300 (CDNA3)
amdclang++ --offload-arch=gfx1030 -x hip ... # RX 6800 (Navi21/RDNA2)
```
## API Reference
| Domain | Reference File | Key APIs / Purpose |
|--------|---------------|-------------------|
| HIP Runtime | `references/api-hip-core.md` | `hipMalloc`, `hipMemcpy`, `hipMemcpyAsync`, streams, events, HIP Graphs, stream-ordered memory (`hipMallocAsync`/`hipFreeAsync`), occupancy, library API, warp intrinsics, atomics |
| HIP Math | `references/api-hip-math.md` | `sinf/cosf/expf/rsqrtf`, half-precision `__half`, complex math, bit manipulation |
| Compute Libraries | `references/api-libraries.md` | rocBLAS, hipBLAS, hipBLASLt, rocFFT, hipFFT, rocRAND, rocSOLVER, rocSPARSE, hipSPARSE, hipSPARSELt, hipTensor, rocALUTION, rocWMMA, rocPRIM, hipCUB, rocThrust |
| Profiling & Debug | `references/api-profiling.md` | HIP events, rocProfiler-SDK (API tracing, PC sampling, thread trace), `rocprof` CLI, `rocm-smi`, `rocgdb`, ASAN |
| Workflows | `references/workflows.md` | Complete examples: SAXPY, tiled matmul, rocBLAS GEMM, rocFFT, rocRAND, HIP Graphs, multi-GPU, streaming overlap, CUDA→HIP porting, pitfalls |
## Common Workflows
### SAXPY (hello-GPU equivalent)
```cpp
__global__ void saxpy(float a, const float* x, float* y, int n) {
int i = blockIdx.x * blockDim.x + threadIdx.x;
if (i < n) y[i] = a * x[i] + y[i];
}
// See workflows.md for full host setup.
```
### rocBLAS GEMM (matrix multiply)
```cpp
rocblas_handle h; rocblas_create_handle(&h);
rocblas_set_pointer_mode(h, rocblas_pointer_mode_host);
rocblas_sgemm(h, rocblas_operation_none, rocblas_operation_none,
M, N, K, &alpha, d_A, M, d_B, K, &beta, d_C, M);
rocblas_destroy_handle(h);
```
### rocFFT 1D Transform
```cpp
rocfft_setup();
rocfft_plan plan;
size_t len = N;
rocfft_plan_create(&plan, rocfft_placement_inplace,
rocfft_transform_type_complex_forward,
rocfft_precision_double, 1, &len, 1, nullptr);
rocfft_execute(plan, (void**)&d_data, nullptr, nullptr);
rocfft_plan_destroy(plan); rocfft_cleanup();
```
### Kernel Timing
```cpp
hipEvent_t start, stop;
hipEventCreate(&start); hipEventCreate(&stop);
hipEventRecord(start, nullptr);
my_kernel<<<grid, block>>>(args);
hipEventRecord(stop, nullptr);
hipEventSynchronize(stop);
float ms; hipEventElapsedTime(&ms, start, stop);
```
### Occupancy-Based Launch
```cpp
int min_grid, block_size;
hipOccupancyMaxPotentialBlockSize(&min_grid, &block_size, my_kernel, 0, 0);
int grid_size = (N + block_size - 1) / block_size;
my_kernel<<<dim3(grid_size), dim3(block_size)>>>(args);
```
## Build System (CMake)
```cmake
cmake_minimum_required(VERSION 3.21)
project(MyApp LANGUAGES CXX)
enable_language(HIP)
find_package(hip REQUIRED)
find_package(rocblas) # optional
find_package(rocfft) # optional
add_executable(my_app main.hip)
target_link_libraries(my_app PRIVATE hip::host roc::rocblas roc::rocfft)
set_property(TARGET my_app PROPERTY HIP_ARCHITECTURES gfx90a gfx1100)
```
```bash
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build
```
## CUDA to HIP Porting
```bash
# Automated conversion (included with ROCm)
hipify-perl cuda_code.cu > hip_code.hip
hipify-perl -inplace *.cu *.cuh
```
| CUDA | HIP equivalent |
|------|---------------|
| `cudaMalloc / cudaFree` | `hipMalloc / hipFree` |
| `cudaMallocAsync / cudaFreeAsync` | `hipMallocAsync / hipFreeAsync` |
| `cudaMemcpy` | `hipMemcpy` |
| `cudaDeviceSynchronize` | `hipDeviceSynchronize` |
| `cudaStreamCreate` | `hipStrRelated in Writing & Docs
jax-development
IncludedUse this skill when the user is writing, debugging, profiling, refactoring, reviewing, benchmarking, parallelising, exporting, or explaining JAX code, or when they mention JAX, jax.numpy, jit, grad, value_and_grad, vmap, scan, lax, random keys, pytrees, jax.Array, sharding, Mesh, PartitionSpec, NamedSharding, pmap, shard_map, Pallas, XLA, StableHLO, checkify, profiler, or the JAX repo. It helps turn NumPy or PyTorch-style code into pure functional JAX, fix tracer/control-flow/shape/PRNG bugs, remove recompiles and host-device syncs, choose transforms and sharding strategies, inspect jaxpr/lowering/IR, and benchmark compiled code correctly.
nature-article-writer
IncludedDrafts, rewrites, diagnostically critiques, and style-calibrates primary research manuscripts for Nature and Nature Portfolio journals. Use when the user wants a Nature-style title, summary paragraph or abstract, introduction, results, discussion, methods, figure legends, presubmission enquiry, cover letter, reviewer response, or when a scientific draft sounds generic, jargon-heavy, structurally weak, or AI-ish and needs precise, broad-reader-friendly prose without inventing data, analyses, or references. Best for primary research articles and letters rather than reviews or press releases unless explicitly adapting one.
deckrd
IncludedDocument-driven framework that derives requirements, specifications, implementation plans, and executable tasks from goals through structured AI dialogue. Use when user says "write requirements", "create spec", "plan implementation", "derive tasks", "structure this feature", "break down into tasks", or "document this module". Also use for reverse engineering existing code into docs (/deckrd rev). Do NOT use for direct code writing — use /deckrd-coder after tasks are generated. Do NOT use when the user only wants to run or fix existing code without planning.
clinical-decision-support
IncludedGenerate professional clinical decision support (CDS) documents for pharmaceutical and clinical research settings, including patient cohort analyses (biomarker-stratified with outcomes) and treatment recommendation reports (evidence-based guidelines with decision algorithms). Supports GRADE evidence grading, statistical analysis (hazard ratios, survival curves, waterfall plots), biomarker integration, and regulatory compliance. Outputs publication-ready LaTeX/PDF format optimized for drug development, clinical research, and evidence synthesis.
handling-sf-data
IncludedSalesforce data operations with 130-point scoring. Use this skill to create, update, delete, bulk import/export, generate test data, and clean up org records using sf CLI and anonymous Apex. TRIGGER when: user creates test data, performs bulk import/export, uses sf data CLI commands, needs data factory patterns for Apex tests, or needs to seed/clean records in a Salesforce org. DO NOT TRIGGER when: SOQL query writing only (use querying-soql), Apex test execution (use running-apex-tests), or metadata deployment (use deploying-metadata).
accelint-ac-to-playwright
IncludedConvert and validate acceptance criteria for Playwright test automation. Use when user asks to (1) review/evaluate/check if AC are ready for automation, (2) assess if AC can be converted as-is, (3) validate AC quality for Playwright, (4) turn AC into tests, (5) generate tests from acceptance criteria, (6) convert .md bullets or .feature Gherkin files to Playwright specs, (7) create test automation from requirements. Handles both bullet-style markdown and Gherkin syntax with JSON test plan generation and validation.