NAME

Rex::GPU::AMD::Setup - Base class of the AMD driver setups: preflight, install flow, signing keys, repository files (experimental)

VERSION

version 0.006

SYNOPSIS

# lib/My/AMD/Setup.pm, next to the Rexfile: a site mirror for amdgpu-dkms
package My::AMD::Setup;
use Moo;
extends 'Rex::GPU::AMD::Setup::Ubuntu';
around dkms_repo => sub {
  my ( $orig, $self ) = @_;
  my $repo = $self->$orig;
  $repo->{content} =~ s{https://repo\.radeon\.com}{https://mirror.example.com};
  return $repo;
};
1;

# lib/My/GPU/AMD.pm
package My::GPU::AMD;
use parent 'Rex::GPU::AMD';
sub setup_class_for_os {
  my ( $class, $os ) = @_;
  return 'My::AMD::Setup' if ( $os->{ID} // '' ) eq 'ubuntu';
  return $class->SUPER::setup_class_for_os($os);
}
1;

# Rexfile
set gpu_amd_class => 'My::GPU::AMD';

DESCRIPTION

Experimental. The base class of the setups "install_driver" in Rex::GPU::AMD runs, one per OS family: Rex::GPU::AMD::Setup::Ubuntu and Rex::GPU::AMD::Setup::Debian on the apt layer Rex::GPU::AMD::Setup::Apt, and Rex::GPU::AMD::Setup::RHEL. Which one: "setup_class_for_os" in Rex::GPU::AMD.

This class holds the flow ("install"), the checks every OS shares ("preflight", the DKMS checks, "post_install"), the signing-key and file helpers, and the per-OS data methods a subclass fills. Driver packages are installed directly through the packaging layer and verified afterwards, never through Rex::Commands::Pkg: a DKMS post-install that exits non-zero makes pkg report a failure on a host where the driver works, or the other way round.

amd

The Rex::GPU::AMD class (or subclass) the setup works for, required. Every host command goes through its "host_run" in Rex::GPU::AMD.

gpus

The GPUs to install for, as "install_driver" in Rex::GPU::AMD resolved them (slot, device_id, gfx_target, driver, matrix, integrated, bound_driver, ...). Default [].

state

The "read_state" in Rex::GPU::AMD the install started from, or undef.

os_release

"read_os_release" in Rex::GPU::AMD, read when first needed.

kernel

The running kernel, uname -r, read when first needed.

arch

The architecture as the packaging names it: uname -m here, dpkg --print-architecture in Rex::GPU::AMD::Setup::Apt.

run_cmd

my $out = $setup->run_cmd($command, %run_options);

"host_run" in Rex::GPU::AMD of "amd": auto_die => 0, $? as run left it.

os_version

VERSION_ID of "os_release" (24.04, 13, 9.6), '' without.

os_label

The OS for messages: PRETTY_NAME, else ID VERSION_ID.

install

my $installed = $setup->install($method);   # 'inbox' or 'dkms'

The fixed sequence, each step a method a subclass can override:

plan_inbox / plan_dkms -> host-read-only; dies before any change
-- returns 0 here when the plan needs nothing --
prepare_host($plan)
prepare_source($plan)   -> signing key and repository file (dkms), index refresh
resolve_plan($plan)     -> packages that need a candidate (dkms: the kernel
                           headers, amdgpu-dkms); dies before any install
install_packages($plan)
verify_packages($plan)
post_install($plan)     -> the module must be there (dkms: built for the kernel)

Returns 1 after an install, 0 if nothing was missing. Loading the module or rebooting is "install_driver" in Rex::GPU::AMD's, after this.

plan_inbox

Host-read-only. Dies for a "host_unsupported" reason first, then "preflight", then "check_radeon"; for GPUs whose hardware row says driver => 'inbox' (AMD supports them with the inbox driver only) dies unless "inbox_only_unsupported" is empty, then for any GPU unless "inbox_unsupported" is; then what is missing: the "inbox_module_packages" when the running kernel has no amdgpu.ko (dies if there are none), the first of "firmware_packages" when none of them is installed. needed is 0 when nothing is.

plan_dkms

Host-read-only. Dies for a "host_unsupported" reason first, then "preflight", then "check_radeon", then dies for an architecture other than "supported_arch", a "dkms_unsupported" reason, Secure Boot ("secure_boot_enabled") and an existing "dkms_repo" file of other content. needed is 0 when dkms status already shows amdgpu installed for the running kernel; else the plan requires "kernel_header_packages" (also listed under headers, for "resolve_plan"'s message) and amdgpu-dkms -- neither is looked up yet: AMD's repository and a fresh index exist only after "prepare_source" -- plus those of "optional_packages" that have a candidate.

preflight

Host-read-only; dies before any change when amdgpu could not work after the install either: /proc/cmdline with nomodeset, amdgpu.modeset=0 or a modprobe.blacklist=/module_blacklist= naming amdgpu; a blacklist amdgpu or install amdgpu /bin/false line in a *.conf under /etc/modprobe.d, /run/modprobe.d, /usr/lib/modprobe.d or /lib/modprobe.d; a GPU bound to a driver other than amdgpu (vfio-pci, radeon, ...: it is not unbound).

check_radeon

Host-read-only: dies, naming them, for the GPUs of "gpus" whose hardware row says matrix => 'radeon' (the Radeon table of AMD's ROCm compatibility matrix) unless "radeon_unsupported" is empty -- whatever the method, since the matrix lists operating systems and kernels per GPU table, not per driver. A GPU without matrix -- no row, a compute => 0 target, a row of your own written without the field -- is not checked: it is not guessed from family. Asked by "plan_inbox" and "plan_dkms" after "preflight", and by "install_driver" in Rex::GPU::AMD before it names a way out for GPUs whose hardware rows disagree.

check_rocm_matrix

$setup->check_rocm_matrix(\@targets);   # gfx target names, lowercase

Host-read-only: dies, naming them, for the gfx targets whose "hardware_class" in Rex::GPU::AMD row says matrix => 'radeon' unless "radeon_unsupported" is empty, then for those whose row says matrix => 'ryzen' (the Ryzen APUs) unless "inbox_only_unsupported" is -- the releases and kernels "install_driver" in Rex::GPU::AMD binds these GPUs to. A matrix => 'instinct' target and a target without matrix -- no row, a compute => 0 target, a row of your own written without the field -- are not checked. The running kernel is read only for a radeon or ryzen target. Asked by "install_rocm" in Rex::GPU::AMD::Setup::Apt after its present check, before any change.

fallback_method

For GPUs without a hardware row ("install_driver" in Rex::GPU::AMD with method => 'auto'): inbox if the running kernel has an amdgpu.ko or one of "inbox_module_packages" has a candidate, else dkms. Host-read-only.

prepare_host

Nothing here; Rex::GPU::AMD::Setup::Apt stops the apt timers.

prepare_source

With a repository in the plan (dkms): "install_helpers", the signing key ("install_key") and the repository file ("write_file", unless it is already there as needed); then "refresh_index".

resolve_plan

Adds to the plan's packages the required ones (dies, before any install, for one without a candidate), the optional ones that have a candidate, and the first firmware package with a candidate (dies if none has).

A required package of the plan's headers without a candidate dies with its own message: the package sources do not (or no longer) carry the running kernel's headers -- usually they have moved on to a newer kernel the host was not upgraded to or rebooted into (Ubuntu after a kernel update without a reboot, Debian after an ABI bump, a RHEL-family mirror past the running build): upgrade the kernel, reboot into it, run again. With a repository in the plan (dkms) every one of these messages says that no driver package was installed and that the repository file and its signing key are in place (a re-run accepts them); else Nothing was installed. "gpu_setup" in Rex::GPU adds for the AMD GPU to either. "has_candidate" may die by itself before that ("has_candidate" in Rex::GPU::AMD::Setup::RHEL: dnf could not run).

post_install

inbox: modinfo -n amdgpu must now find a module for the running kernel. dkms: dkms status must show amdgpu installed for the running kernel and modinfo -n amdgpu resolve the DKMS module -- an RPM whose %post build failed is still installed for rpm -q, so the package check alone proves nothing. Dies otherwise. When no module is built and "hold_note" finds a hold in the way of the install (apt: apt-mark hold, RHEL: dnf versionlock), the message names it and the way out before the build log; asked only then, so a host where the module is there runs no extra command.

dkms_built

True if dkms status -m amdgpu -k KERNEL lists amdgpu as installed for the running kernel. Read-only.

secure_boot_enabled

True if the SecureBoot EFI variable's value byte is 1 (od of /sys/firmware/efi/efivars/SecureBoot-8be4df61-...); false on a BIOS host or when it cannot be read. Read-only.

file_content

my $text = $setup->file_content($path);   # '' if missing

cat PATH over the exec channel. Read-only.

write_file

$setup->write_file($path, $content);

Writes $content (mode 0644) through printf into PATH.tmp and mv -f over PATH, over the exec channel -- no SFTP. Dies if that fails.

install_key

$setup->install_key(url => $url, fingerprint => $fpr, path => $path);

Downloads an armored OpenPGP key (curl -fsSL --proto =https) into a temporary directory next to path, reads it with gpg --show-keys into a throwaway GNUPGHOME and requires exactly one primary key whose fingerprint is fingerprint; only then "place_key" puts it at path. The temporary directory is removed in every case. Dies, leaving path as it was, when the download fails or the key is not the pinned one -- an expired or rotated AMD key stops here, loudly.

place_key

my $ok = $setup->place_key($tmpdir, $path);

Moves the checked $tmpdir/key.asc into place: dearmored for apt in Rex::GPU::AMD::Setup::Apt, armored and rpm --imported in Rex::GPU::AMD::Setup::RHEL. Returns true on success.

supported_arch

The architecture amdgpu-dkms is built for, as "arch" names it: x86_64 (amd64 in Rex::GPU::AMD::Setup::Apt).

refresh_index

Refreshes the package index, so that "has_candidate" sees what the package sources carry now; "prepare_source" ends with it. Nothing here, and so in Rex::GPU::AMD::Setup::RHEL (dnf fetches the metadata it lacks itself); "refresh_index" in Rex::GPU::AMD::Setup::Apt: apt-get update -q.

has_candidate

$setup->has_candidate($package);

True if $package has an installation candidate -- already installed, or installable from the host's package sources. Here: always true, without a host command; "has_candidate" in Rex::GPU::AMD::Setup::Apt and "has_candidate" in Rex::GPU::AMD::Setup::RHEL ask the package manager.

package_installed

$setup->package_installed($package);

True if $package is installed. Here: always false, without a host command; "package_installed" in Rex::GPU::AMD::Setup::Apt (dpkg -l) and "package_installed" in Rex::GPU::AMD::Setup::RHEL (rpm -q) ask the package database.

package_held

$setup->package_held($package);

True if $package is on hold, so that the package manager does not change it (apt: apt-mark hold, RHEL: dnf versionlock). Here: always false, without a host command; "package_held" in Rex::GPU::AMD::Setup::Apt reads dpkg's selection, "package_held" in Rex::GPU::AMD::Setup::RHEL dnf's lock list. Asked by "blocking_holds" here; the packaging layers answer that one themselves, with one command for all packages.

dkms_dependencies

Packages amdgpu-dkms depends on without a version, whose hold "blocking_holds" asks next to the plan's packages: amdgpu-dkms-firmware (a dependency of amdgpu-dkms 31.60 in AMD's Ubuntu 24.04 and RHEL 9 repositories). A hold on one of them is in the way only while it is not installed: any installed version satisfies the dependency.

blocking_holds

my @held = $setup->blocking_holds($plan);

The packages of the plan -- its packages, then the "dkms_dependencies" it does not list -- that are on hold in a way that stops the install, by name. Here: those "package_held" says are held, one question per package (none: no host command). "blocking_holds" in Rex::GPU::AMD::Setup::Apt and "blocking_holds" in Rex::GPU::AMD::Setup::RHEL leave out a hold the install did not have to get past.

hold_note

my $note = $setup->hold_note($plan);   # '' when no hold is in the way

For a dkms plan with "blocking_holds": "hold_advice" for them, the words "post_install" and the packaging layers' verify_packages put into their message. '' for any other plan (inbox, ROCm, the helpers), without a host command. Asked only on those failure paths, once the module or a package is missing.

hold_advice

my $text = $setup->hold_advice(@held);

The sentence that names the held packages, what the package manager does with them and the way out, ending in ... and install_driver again without a full stop. Here a generic one; "hold_advice" in Rex::GPU::AMD::Setup::Apt (apt-mark unhold) and "hold_advice" in Rex::GPU::AMD::Setup::RHEL (dnf versionlock delete) name their package manager's.

install_helpers

Installs curl and gpg when they are missing -- "install_key" needs both; "prepare_source" runs it before the signing key of a repository. Nothing here; "install_helpers" in Rex::GPU::AMD::Setup::Apt and "install_helpers" in Rex::GPU::AMD::Setup::RHEL install them.

install_packages

$setup->install_packages($plan);

Installs the plan's packages directly, never through Rex::Commands::Pkg; whether they went in is for "verify_packages", which "install" runs next. Dies here: the base class has no packaging layer ("install_packages" in Rex::GPU::AMD::Setup::Apt: apt-get install, "install_packages" in Rex::GPU::AMD::Setup::RHEL: dnf install).

verify_packages

$setup->verify_packages($plan);

Dies unless every one of the plan's packages is installed, as the package database reports it -- not the installer's exit status. Dies here, whatever the plan: the base class has no packaging layer ("verify_packages" in Rex::GPU::AMD::Setup::Apt: dpkg -l, "verify_packages" in Rex::GPU::AMD::Setup::RHEL: rpm -q).

amdgpu_release

The amdgpu driver release of the amdgpu-dkms repository: 31.60.

amdgpu_key

{ url => 'https://repo.radeon.com/rocm/rocm.gpg.key',
  fingerprint => 'CA8BB4727A47B4D09B4EE8969386B48A1A693C5C', path => ... }

The signing key of repo.radeon.com (primary key valid until 2028-08-21), with path from "amdgpu_key_path".

amdgpu_key_path

Where "install_key" puts "amdgpu_key" and the "dkms_repo" file points to it. Per OS class: /etc/apt/keyrings/rocm.gpg here, and so for Rex::GPU::AMD::Setup::Ubuntu and Rex::GPU::AMD::Setup::Debian; /etc/pki/rpm-gpg/RPM-GPG-KEY-rocm in Rex::GPU::AMD::Setup::RHEL.

dkms_repo

{ file => ..., content => ..., key => amdgpu_key }

The amdgpu-dkms repository for this OS. Per OS class.

host_unsupported

Why no AMD driver may be installed on this host at all, whatever the method, or undef: "plan_inbox" and "plan_dkms" ask it before any other check, "install_driver" in Rex::GPU::AMD before it names a way out for GPUs whose hardware rows disagree; "install_rocm" does not. Here: undef, without a host command; Rex::GPU::AMD::Setup::Debian refuses a Proxmox VE host. Host-read-only.

dkms_unsupported

Why amdgpu-dkms is not supported on this OS release and kernel, or undef when it is. Here: always a reason.

inbox_unsupported

Why the inbox driver is not supported on this OS release and kernel, or undef when it is -- for every GPU, asked by "plan_inbox" after "inbox_only_unsupported", and so by "install_driver" in Rex::GPU::AMD before it names method => 'inbox' as the way out for GPUs whose hardware rows disagree. Host-read-only. Here: undef, nothing checked; Rex::GPU::AMD::Setup::Debian binds it to Debian 12 and 13 with Debian's own amd64 kernel.

inbox_only_unsupported

Why a GPU AMD supports only with the inbox driver (the Ryzen APUs) is not supported on this OS release and kernel, or undef. Asked by "plan_inbox", by "install_driver" in Rex::GPU::AMD for GPUs whose hardware rows disagree and by "check_rocm_matrix" for their gfx targets; host-read-only. Here: always a reason -- AMD supports them only on Ubuntu ("inbox_only_supported").

inbox_only_supported

Where AMD supports the inbox-only GPUs, for messages: Ubuntu 26.04 with the GA kernel 7.0 and Ubuntu 24.04 with the HWE kernel 7.0 (ROCm 10.1 compatibility matrix).

radeon_unsupported

Why a GPU of the Radeon table of AMD's ROCm compatibility matrix (matrix => 'radeon') is not supported on this OS release and kernel, or undef when it is -- for inbox and amdgpu-dkms alike. Asked by "check_radeon" and, for their gfx targets, by "check_rocm_matrix"; host-read-only. Here: always a reason -- AMD lists the Radeon GPUs only on Ubuntu and RHEL ("radeon_supported"); Rex::GPU::AMD::Setup::Debian inherits it (no Radeon on Debian), Rex::GPU::AMD::Setup::Ubuntu and Rex::GPU::AMD::Setup::RHEL bind it to the releases and kernels the matrix lists for them.

radeon_supported

Where AMD supports the Radeon GPUs, for messages: Ubuntu 26.04 (GA kernel 7.0), Ubuntu 24.04 (HWE kernel 7.0), Ubuntu 22.04 (HWE kernel 6.8), RHEL 10.2 (kernel 6.12.0-211) and RHEL 9.8 (kernel 5.14.0-687), per the ROCm 10.1 compatibility matrix.

kernel_header_packages

The running kernel's header packages, which amdgpu-dkms is built against: "plan_dkms" requires them. None here; linux-headers-KERNEL in Rex::GPU::AMD::Setup::Ubuntu and Rex::GPU::AMD::Setup::Debian, kernel-headers-KERNEL, kernel-devel-KERNEL and (9, 10) kernel-devel-matched-KERNEL in Rex::GPU::AMD::Setup::RHEL.

optional_packages

Packages installed with amdgpu-dkms only if they have a candidate: "plan_dkms" lists them, "resolve_plan" keeps those that have one. None here, and so in Rex::GPU::AMD::Setup::Debian and Rex::GPU::AMD::Setup::RHEL; linux-modules-extra-KERNEL on Ubuntu 24.04 and 22.04.

firmware_packages

The amdgpu firmware packages for the inbox driver, alternatives: none is needed if one of them is installed ("plan_inbox"), else the first with a candidate is installed ("resolve_plan"; it dies if none has one). None here, so no firmware package is checked or installed; Rex::GPU::AMD::Setup::Ubuntu, Rex::GPU::AMD::Setup::Debian and Rex::GPU::AMD::Setup::RHEL name theirs in their DESCRIPTION.

inbox_module_packages

The packages that bring amdgpu.ko to a running kernel without it: "plan_inbox" requires them then (and dies if there are none), "fallback_method" picks inbox when one of them has a candidate. None here, and so in Rex::GPU::AMD::Setup::Debian and Rex::GPU::AMD::Setup::RHEL; in Rex::GPU::AMD::Setup::Ubuntu its "optional_packages" (linux-modules-extra-KERNEL on 24.04 and 22.04).

rocm_repo_dir

The directory of AMD's ROCm repository for this OS release (ubuntu2404, debian13, ...), for "install_rocm" in Rex::GPU::AMD: "install_rocm" in Rex::GPU::AMD::Setup::Apt builds the repository's URIs from it and dies without one. undef where there is none: here, and so in Rex::GPU::AMD::Setup::RHEL; Rex::GPU::AMD::Setup::Ubuntu and Rex::GPU::AMD::Setup::Debian take it from their release_data.

install_rocm

my $how = $setup->install_rocm($rocm, \@targets);   # 'present' or 'installed'

"install_rocm" in Rex::GPU::AMD's host part; dies here (apt only, see "install_rocm" in Rex::GPU::AMD::Setup::Apt).

SEE ALSO

Rex::GPU::AMD, Rex::GPU::AMD::Setup::Apt, Rex::GPU::AMD::Setup::RHEL

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.