AMD GPUs (ROCm)
flodl trains on AMD GPUs through ROCm, on Linux. The same code runs on an
AMD card as on an NVIDIA one: a ROCm libtorch presents its devices as
Device::CUDA(n), so nothing in a model or a training loop names the
vendor. The vendor is chosen when the binary is built, with the rocm
cargo feature in place of cuda.
This page gathers what is specific to AMD. It was written from runs on real hardware by contributors (#80), on three chips:
| Chip | Target | Kind |
|---|---|---|
| Strix Halo APU | gfx1151 | integrated, shared memory |
| Radeon AI PRO R9700 | gfx1201 | discrete |
| Radeon RX 7900 XTX | gfx1100 | discrete |
flodl’s own CI builds and lints the ROCm variant on every change, but has no AMD card to run on. What is stated here as measured was measured on the chips above.
Setup
fdl setup detects AMD cards from the kernel’s KFD topology and installs
the ROCm libtorch when the card is one it ships kernels for:
fdl setup # detects the card, picks the variant
fdl libtorch download --rocm 7.0 # or explicitly
Covered targets: gfx908, gfx90a, gfx942, gfx950, gfx1030, gfx1100, gfx1101, gfx1102, gfx1150, gfx1151, gfx1200, gfx1201. A card outside that list has no pre-built kernels, and setup says so and stays on CPU.
Then the GPU commands build with the right feature on their own:
fdl gpu-test # the GPU test suite, on the AMD card
fdl probe # what fdl sees, and anything missing
In your own project, cargo add flodl --features rocm.
Two things worth knowing:
- Docker is enough. A box with Docker and no ROCm installed on the
host is provisioned for its AMD cards: the
rocmcontainer image carries the runtime. - One vendor per build. A libtorch build serves CUDA or ROCm, never both in one process. On a box with NVIDIA and AMD cards, setup provisions the NVIDIA ones and leaves AMD to an explicit download.
The ROCm runtime version
The libtorch archive is built against ROCm 7.0, and the container runs
ROCm 10.2 by default. In the rocm image the image’s runtime is loaded
ahead of the copy libtorch bundles, so the image’s version is the one
that governs. On the chips above the older runtime segfaulted on gfx1151
and was about five times slower on gfx1201 with the same libtorch.
To run another runtime for one command:
ROCM_VERSION=<x.y> fdl gpu-test
A variant records its runtime in its .arch file (rocm_runtime=), and
fdl derives the image tag from it.
Integrated GPUs
On an APU such as Strix Halo the GPU shares the host’s memory. flodl accounts for it:
- Batches upload synchronously. The page-locked staging copy and the separate copy stream that a discrete card uses buy nothing on shared memory.
- The data loader’s memory budgets subtract what the GPU has taken from the same pool.
Mixed precision
bf16-mixed and f16-mixed both run on AMD cards. Which one is faster
depends on the chip and the model, so measure. From the runs above,
training time against f32:
| Chip | Model | bf16-mixed |
f16-mixed |
|---|---|---|---|
| Strix Halo | transformer (OLMo) | 3.4x faster | 3.2x faster |
| Strix Halo | convolutional (ResNet-20) | 1.3x slower | 1.6x faster |
| R9700 | transformer (OLMo) | 1.9x faster | 1.8x faster |
| R9700 | convolutional (ResNet-20) | 1.9x faster | 2.4x faster |
See Mixed Precision Training for the setting.
Transformers and TunableOp
A matrix multiply on ROCm can go through several routines, and the default is not always the fastest. PyTorch’s TunableOp times them once and records the winner. It roughly halved a transformer run on gfx1151 and changed nothing on gfx1201. The recipe is in Troubleshooting.
Multi-GPU
RCCL, AMD’s implementation of the NCCL interface, ships inside the ROCm libtorch, so there is no separate build step. A join window refuses a cohort that mixes CUDA and ROCm ranks under the NCCL modes; the CPU averaging modes mix vendors legally.
Monitoring
Utilisation, temperature and power are read from the kernel’s amdgpu
sysfs files, with no ROCm SMI install. Inside a container this needs
--device=/dev/kfd, which ROCm itself requires and the rocm service
already passes.
What is still NVIDIA-only
fdl --gpus allresolves throughnvidia-smi. Name the devices instead (--gpus 0,1), which works on AMD.fdl libtorch build(source builds for custom architectures) andfdl nccl build.- A cluster roster’s
local_devices: allon a remote host.
Problems specific to AMD are collected in Troubleshooting.