NAME
Rex::GPU::AMD - AMD GPU driver (amdgpu) and ROCm management (experimental)
VERSION
version 0.006
SYNOPSIS
use Rex -feature => ['1.4'];
use Rex::GPU;
use Rex::GPU::AMD;
task 'setup', sub {
# detect + driver; an integrated GPU (APU) only with amd_integrated => 1
gpu_setup(containerd_config => 'none', amd_integrated => 1, reboot => 1);
};
task 'amd', sub {
my @amd = grep { $_->{compute} } @{ gpu_detect()->{amd} };
return unless @amd; # gpus => [] dies; no gpus at all means every AMD GPU
Rex::GPU::AMD::install_driver(gpus => \@amd, reboot => 1); # 'present', 'inbox', 'dkms'
my $check = Rex::GPU::AMD::verify_amd(gpus => \@amd);
die "AMD driver not usable\n" unless $check->{ok};
Rex::GPU::AMD::install_rocm(release => '10.1', gpus => \@amd);
};
DESCRIPTION
Experimental. The AMD half of Rex::GPU: the amdgpu kernel driver -- the distribution kernel's own (inbox) or AMD's amdgpu-dkms -- and, separately, AMD's ROCm Core SDK. Which driver AMD supports for a GPU comes from Rex::GPU::AMD::Hardware (by gfx target), which OS, release and kernel from the setup classes (Rex::GPU::AMD::Setup and its per-OS subclasses).
Kubernetes needs nothing else from the host: the AMD device plugin finds the GPUs through /dev/kfd and /dev/dri/renderD*; there is no container runtime hook and no CDI step as for NVIDIA.
Every host command goes through "host_run", and the checks ("read_state", "verify_amd", install_driver's present path) are read-only: install_driver on a host with a working driver runs exactly one command, the "state_script".
FUNCTIONS
Experimental. Each function is also a class method: Rex::GPU::AMD->install_driver(...) or My::GPU::AMD->... for a subclass, with the same arguments. Called as a function (Rex::GPU::AMD::install_driver(...)) it runs as the class "configured_class" names (set gpu_amd_class, or Rex::GPU::AMD). Nothing is exported: call them fully qualified.
install_driver
my $how = Rex::GPU::AMD::install_driver(
gpus => \@amd, # optional: AMD GPU hashrefs, e.g. from Rex::GPU::Detect
method => 'auto', # 'auto' (default), 'inbox' or 'dkms'
reboot => 1, # optional: reboot when the driver cannot take effect otherwise
);
# 'present', 'inbox' or 'dkms'
Experimental. Makes the AMD kernel driver amdgpu usable for ROCm on the given GPUs and returns how:
present-- it already was:/sys/module/amdgpuexists,/dev/kfdis a character device, and every GPU has a KFD topology node with agfx_target_versionother than0and a/sys/class/drm/renderD*node of vendor0x1002at its PCI address. That check is one read-only command ("read_state"); nothing else runs, and nothing is changed. A working driver is never replaced, whatever themethod: an explicitinboxordkmsthat is not the working driver's kind is answered withpresentand a warning (the two read-only commandsuname -randmodinfo -n amdgputell the kinds apart).inbox-- the distribution kernel's ownamdgpuwas made usable: only what is missing is installed (the firmware package if none of "firmware_packages" in Rex::GPU::AMD::Setup is installed, the module package if the running kernel has noamdgpu.ko-- where "inbox_module_packages" in Rex::GPU::AMD::Setup has none, as on Debian, it dies before any change), nothing if nothing is missing. On Debian only on 12 and 13 with the release's ownamd64kernel, asdkms.dkms-- AMD'samdgpu-dkms31.60 was installed fromrepo.radeon.comwith the running kernel's headers, its signing key checked against a pinned fingerprint, and its module verified to be built for the running kernel (dkms statusandmodinfo -n amdgpu).
gpus is an arrayref of hashrefs, each with a slot (PCI address, 95:00.0 or 0000:95:00.0) or a device_id (four hex digits) or both; name is used in messages, a vendor other than amd is refused, every other key is ignored. The elements "detect" in Rex::GPU::Detect returns under amd fit as they are. Without gpus every AMD GPU of the host is meant: vendor 1002, PCI class 03xx or 1200, as read from /sys/bus/pci/devices. An empty gpus => [] is refused: omit gpus to mean every AMD GPU.
method => 'auto' follows Rex::GPU::AMD::Hardware: the driver of each GPU's gfx target row (inbox for the Ryzen APUs, which AMD supports only with the inbox driver). GPUs whose rows disagree make it die (one amdgpu drives every GPU of a host), naming the way out: method => 'inbox' only where the inbox driver is supported for all of them on this host (neither "inbox_only_unsupported" in Rex::GPU::AMD::Setup nor "inbox_unsupported" in Rex::GPU::AMD::Setup gives a reason), else that reason and gpus with only the amdgpu-dkms ones -- on a Proxmox VE host the Proxmox reason instead, and for a Radeon GPU AMD's matrix does not list on this host ("check_radeon" in Rex::GPU::AMD::Setup) the Radeon reason, naming no way out: both would include it. Called from "gpu_setup" in Rex::GPU, which takes neither method nor gpus, the message names its ways out instead: leaving out its amd_integrated (where that skips every GPU AMD supports only with the inbox driver), or calling install_driver directly, with the advice above. For GPUs without a row it takes inbox if the running kernel has an amdgpu.ko or can get one from the host's package sources, else dkms. method => 'dkms' for a GPU AMD supports only with the inbox driver dies, also where the driver already works; method => 'inbox' for one whose row says dkms warns and goes ahead. install_driver never removes or replaces a driver.
Then -- also when nothing had to be installed -- amdgpu is loaded with modprobe amdgpu if it was not loaded before. If it was, or if the GPUs are still not usable, only a reboot can activate the driver: with reboot => 1 the host is rebooted and waited for (20 seconds, then up to 60 reconnects 5 seconds apart, over 5 minutes in all, until echo ok answers from the new boot -- a changed boot_id, where it was readable before; it dies if the host does not come back, see "reboot_and_wait"), and the driver must then be usable or it dies; without it a warning says so and the method is returned.
Dies -- before anything is changed on the host -- for an unknown option, a malformed or empty gpus, a GPU that is not on the host, a host without an AMD GPU, a state that could not be read; and, unless the driver already works (present), for an unsupported OS, a Proxmox VE host (pve-firmware installed; whatever the method), an unsupported release or kernel for dkms, for a GPU AMD supports only with the inbox driver, for a Radeon GPU (hardware row matrix => 'radeon') outside the releases and kernels AMD's matrix lists for Radeon ("radeon_supported" in Rex::GPU::AMD::Setup: none on Debian, Ubuntu 26.04 GA 7.0, 24.04 HWE 7.0, 22.04 HWE 6.8, RHEL 10.2 and 9.8 with their kernel build) whatever the method (this distribution's reading of the matrix), and on Debian for inbox too (the per-OS matrix is in Rex::GPU::AMD::Setup::Ubuntu, Rex::GPU::AMD::Setup::Debian and Rex::GPU::AMD::Setup::RHEL; on Ubuntu and RHEL inbox for any GPU but these two kinds checks neither the release nor the kernel series; a GPU whose row has no matrix is not taken for a Radeon), a kernel command line with nomodeset, amdgpu.modeset=0 or a module blacklist naming amdgpu, an amdgpu blacklist in modprobe.d, a GPU bound to another driver (vfio-pci, radeon), and, for dkms, a non-x86_64 host, Secure Boot enabled (the DKMS module would need a MOK enrolled at the console), or an existing repository file of other content. These messages end with Nothing was changed on the host; called from "gpu_setup" in Rex::GPU, whose earlier steps may have changed the host (pciutils, the NVIDIA steps), they end with Nothing was changed for the AMD GPU (GPUs for several) instead. For dkms it dies before any driver package is installed, but after the apt timers are stopped (apt), in "prepare_source" in Rex::GPU::AMD::Setup, which puts AMD's repository in place: when a missing curl or gpg is not installed after its install (apt: after an apt-get update; the other one may be installed by then); after that, when AMD's signing key cannot be downloaded or is not the pinned one (the key file is left as it was; only its directory is created if it was missing), or cannot be put in place (on RHEL the key file may then be there, not rpm --imported); and, with the key in place, when the repository file cannot be written. Dies before any driver package is installed, but after the apt timers are stopped and apt-get update ran (apt) and, for dkms, with curl and gpg installed where they were missing and AMD's signing key and repository file in place (a re-run accepts them), when a package the install needs has no candidate -- neither installed nor offered by the host's package sources: for dkms the running kernel's headers (the message then says to upgrade the kernel and reboot: usually the mirror has moved on to a newer kernel than the running one) and amdgpu-dkms; for inbox the module package or every firmware package; on RHEL also when dnf repoquery itself fails (metadata that cannot be downloaded). These messages say No driver package was installed (dkms, and the failed dnf repoquery) or Nothing was installed (inbox); called from "gpu_setup" in Rex::GPU, whose NVIDIA steps may have installed their driver, they say it for the AMD GPU (GPUs for several). Dies after the install when a package is not installed afterwards (a failed DKMS build leaves amdgpu-dkms half-configured, so dpkg -l does not show it ii; an RPM whose %post build failed is caught by the dkms status check). For dkms that message and the one for no module built name a hold in the way of the install as the cause, with the way out ("hold_note" in Rex::GPU::AMD::Setup). On Debian and Ubuntu (apt-mark hold; apt-get install -y does not change a held package, and aborts the whole install where it would have to; way out apt-mark unhold): a held package of the install that is not installed or not at its candidate version (apt-cache policy), or a held amdgpu-dkms-firmware that is not installed; a hold at the candidate is not named. On RHEL (dnf versionlock; way out dnf versionlock delete): a lock on amdgpu-dkms, or on a kernel header package or amdgpu-dkms-firmware that is not installed; without the versionlock plugin, or when its list cannot be read, no lock is named. Asked only then: an install that went through runs no extra command.
verify_amd
my $result = Rex::GPU::AMD::verify_amd(gpus => \@amd); # gpus optional
# { ok => 1,
# gpus => [ { slot => '0000:95:00.0',
# device_id => '1586',
# gfx_target => 'gfx1151',
# vram_bytes => '137438953472',
# gtt_bytes => '33535848448',
# kfd_node => 1, # the lowest KFD node of the GPU
# kfd_nodes => [ 1 ] } ] }
Experimental. Checks, with the one read-only command of "read_state", that the AMD driver is usable for ROCm on the given GPUs (all AMD GPUs of the host without gpus): /sys/module/amdgpu, /dev/kfd a character device, and per GPU a KFD node with a gfx_target_version other than 0 and a /sys/class/drm/renderD* node of vendor 0x1002 at the GPU's PCI address. gpus as for "install_driver".
ok is 1 only if all of that holds. One entry per GPU, in the order given (or of the PCI address): slot with its domain, device_id four lowercase hex digits, gfx_target from the GPU's lowest KFD node (the device table without one), vram_bytes and gtt_bytes from the GPU's mem_info_vram_total / mem_info_gtt_total (decimal strings), kfd_node the lowest KFD node ID and kfd_nodes all of them (a partitioned MI300 has several); undef or [] for what is not there. A GPU that is not on the host has undef everywhere but the slot or device_id it was given.
Never dies: every problem is logged as a warning and makes ok 0, also an unreadable state or a malformed gpus. An empty gpus => [] warns and returns { ok => 0, gpus => [] } -- omit gpus to check every AMD GPU.
install_rocm
my $how = Rex::GPU::AMD::install_rocm(release => '10.1', gpus => \@amd);
my $how = Rex::GPU::AMD::install_rocm(release => '10.1', targets => [ 'gfx1151' ]);
my $how = Rex::GPU::AMD::install_rocm(release => '10.1'); # targets from the running driver
# 'present' or 'installed'
Experimental. Installs AMD's ROCm Core SDK of release (required; known: see "rocm_releases") for the given gfx targets from stable.repo.amd.com: per target the package amdrocm10.1-gfxNNNN, plus libatomic1 and libquadmath0 (AMD: some ROCm tools need them). The targets come from targets (gfx target names), else from each of gpus' gfx_target (as Rex::GPU::Detect sets it), else from the KFD nodes of the running driver. Returns present if every target's package is already installed at that release (one read of dpkg-query, nothing else changed), installed after the install. The repository key is checked against a pinned fingerprint before apt trusts it.
apt hosts only: Ubuntu 22.04, 24.04, 26.04 and Debian 12, 13 on amd64. Dies before anything is changed on the host for anything else, for a release or target AMD ships no package for, for both gpus and targets, for an empty gpus, for a GPU without gfx_target, when the old ROCm line is installed (rocm-core: AMD requires removing ROCm 7.2.4 or older first; install_rocm never uninstalls), for a Radeon or Ryzen APU target AMD's matrix does not list for the host's release and kernel (below), and when /etc/apt/sources.list.d/amdrocm-stable.sources exists with other content. Dies after the install if a package is not installed, or not at release.
AMD's compatibility matrix binds the Radeon GPUs and the Ryzen APUs to releases and kernels, and install_rocm follows it as "install_driver" does. Unless every package is already installed (present, checked first), it dies before any change for a target whose "hardware_class" row says matrix => 'radeon' outside the releases and kernels of "radeon_unsupported" in Rex::GPU::AMD::Setup (Ubuntu 26.04 GA kernel 7.0, 24.04 HWE kernel 7.0, 22.04 HWE kernel 6.8, all -generic; no Debian release), then for one with matrix => 'ryzen' outside those of "inbox_only_unsupported" in Rex::GPU::AMD::Setup (Ubuntu 26.04 GA kernel 7.0 and 24.04 HWE kernel 7.0, -generic; not 22.04, no Debian release), reading the running kernel for it. The row is looked up by gfx target, whether the targets came from targets, gpus or the KFD nodes. A matrix => 'instinct' target needs nothing beyond the OS list above; a target without matrix -- no row (gfx1250), a compute => 0 target (gfx1010-gfx1012, gfx1031-gfx1036), a row of your own written without the field -- is not checked ("check_rocm_matrix" in Rex::GPU::AMD::Setup).
The driver is not part of it: run "install_driver" first. On Proxmox VE (pve-firmware installed) that installs no driver -- only a working amdgpu passes it, as present -- but install_rocm is not refused there and runs as on the Debian release the host reports itself as (so not for a Radeon or Ryzen APU target, above): neither its packages nor what apt pulls in with them include a firmware package, so nothing conflicts with pve-firmware.
rocm_releases
my $releases = Rex::GPU::AMD->rocm_releases; # { '10.1' => { ... } }
Experimental. The ROCm releases "install_rocm" knows, by release: the gfx targets AMD ships a package for (amdrocm10.1-gfxNNNN, read from the repository's Packages files of every supported OS on 2026-10-30), the extra packages, the repository base URL and its signing key with the pinned primary key fingerprint. Override it in a subclass to add a release.
read_state
my $state = Rex::GPU::AMD->read_state; # hashref, or undef if unreadable
Experimental. Runs "state_script" (one read-only command) and returns "parse_state" of its output.
state_script
The read-only shell command behind "read_state": shell builtins over /sys/module/amdgpu, /dev/kfd, the vendor 0x1002 display and accelerator devices under /sys/bus/pci/devices (bound driver, mem_info_vram_total, mem_info_gtt_total), /sys/class/drm/renderD* and the KFD topology under /sys/class/kfd/kfd/topology/nodes. Rex::GPU::Detect runs it too, on hosts with an AMD GPU.
parse_state
my $state = Rex::GPU::AMD->parse_state($output);
Experimental. The output of "state_script" as
{ amdgpu => 1, kfd => 1,
pci => [ { slot => '0000:95:00.0', class => '0380', device_id => '1586',
bound_driver => 'amdgpu', vram_bytes => '...', gtt_bytes => '...' } ],
render => [ { name => 'renderD128', vendor => '1002', slot => '0000:95:00.0' } ],
nodes => [ { id => 1, gfx_target_version => 110501, gfx_target => 'gfx1151',
vendor => '1002', device_id => '1586', slot => '0000:95:00.0',
drm_render_minor => 128 } ] }
or undef when the output does not end with the end line (the read did not complete). Lines it does not know are ignored; it never dies.
state_problems
my @problems = Rex::GPU::AMD->state_problems($state, \@gpus);
Experimental. What keeps the driver from being usable for @gpus (GPUs as "install_driver" resolves them; all AMD GPUs of $state without), one message each; empty when it is usable. The check "install_driver" calls present and "verify_amd" ok.
kfd_nodes
my @nodes = Rex::GPU::AMD->kfd_nodes($state, $gpu);
Experimental. The KFD GPU nodes (gfx_target_version not 0) of one GPU, lowest ID first: matched by PCI address (slot), or by device_id for a node whose topology has no location_id.
gpu_label
Rex::GPU::AMD->gpu_label($gpu); # 'AMD GPU 0000:95:00.0 [1002:1586] (gfx1151)'
Experimental. How messages name a GPU hashref.
module_source
my $source = Rex::GPU::AMD->module_source(kernel => '7.0.0-42-generic');
Experimental. Where modinfo -n amdgpu resolves the module for the running kernel (uname -r unless kernel is given): inbox under /lib/modules/KERNEL/kernel/, dkms under updates/ or extra/, other elsewhere, undef without a module. Read-only.
host_run
my $out = $class->host_run($command, %run_options);
Experimental. The one place every host command of Rex::GPU::AMD and its setup classes goes through: Rex::Commands::Run::run($command, auto_die => 0, %run_options) in scalar context; $? is left as run set it. Override it in a subclass to log, dry-run or refuse commands.
read_os_release
my $os = Rex::GPU::AMD->read_os_release; # { ID => 'ubuntu', VERSION_ID => '24.04', ... }
Experimental. /etc/os-release as a hashref of its keys, quotes removed; {} when it cannot be read.
setup_class_for_os
my $setup = Rex::GPU::AMD->setup_class_for_os($os); # class name or undef
Experimental. The setup class for an "read_os_release" hashref: ID ubuntu Rex::GPU::AMD::Setup::Ubuntu, debian Rex::GPU::AMD::Setup::Debian, rhel, rocky or almalinux Rex::GPU::AMD::Setup::RHEL; undef for anything else. Override it in a subclass to use a setup class of your own.
setup_for
my $setup = Rex::GPU::AMD->setup_for(gpus => \@targets, state => $state);
Experimental. Reads /etc/os-release and returns a new object of "setup_class_for_os". Dies, before anything is changed on the host, for an OS without a setup class.
hardware_class
Experimental. The class "install_driver" and "verify_amd" ask for a GPU's gfx target, compute, integrated, supported driver and AMD matrix table, and "install_rocm" for each target's matrix: Rex::GPU::AMD::Hardware. Override it in a subclass to use your own rows.
normalize_slot
Rex::GPU::AMD->normalize_slot('95:00.0'); # '0000:95:00.0'
Experimental. A PCI address with its domain, lowercase; undef for anything that is not one -- always exactly one value, also in a list.
reboot_and_wait
Experimental. Reboots the host (shutdown -r now, two seconds after the command returns) and waits for it: 20 seconds, then up to 60 times every 5 seconds a reconnect and echo ok, and the kernel's boot_id must differ from the one before (when it was readable). Dies Host did not come back after reboot after that. Every command through "host_run".
configured_class
my $class = Rex::GPU::AMD->configured_class($amd_option);
Experimental. The class a function call of "install_driver", "verify_amd" or "install_rocm" is passed on to as a method: $amd_option ("gpu_setup" in Rex::GPU's amd option) if defined, else set gpu_amd_class => 'My::GPU::AMD' in the Rexfile, else Rex::GPU::AMD. Loaded by "load_user_class" in Rex::GPU::NVIDIA; croaks, before anything touches the host, for a class that is not a package name, cannot be loaded or is not a subclass of Rex::GPU::AMD.
SEE ALSO
Rex::GPU, Rex::GPU::AMD::Hardware, Rex::GPU::AMD::Setup, https://rocm.docs.amd.com/en/latest/compatibility/compatibility-matrix.html, https://instinct.docs.amd.com/projects/amdgpu-docs/en/latest/
SUPPORT
Issues
Please report bugs and feature requests at https://github.com/Getty/rex-gpu/issues.
CONTRIBUTING
Contributions are welcome! Please fork the repository and submit a pull request.
AUTHOR
Torsten Raudssus <getty@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2026 by Torsten Raudssus <torsten@raudssus.de> https://raudssus.de/.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.