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:

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:

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

Problems specific to AMD are collected in Troubleshooting.