lib/Rex/GPU/AMD/Setup/RHEL.pm

filter: Statementstmt 95.3% 103 / 108 Branchbran 78.0% 39 / 50 Conditioncond 68.0% 17 / 25 MC/DCmcdc 42.8% 6 / 14 Subroutinesub 95.6% 22 / 23 Podpod 100% 17 / 17 totaltotal 86.0% 204 / 237 CC 40 SCAR 14.5
CC
40
Cov
87%
blocking_holds
8.0
_versionlock_entries
7.0
has_candidate
6.0
CRAP 4.3
« lib/Rex/GPU/NVIDIA/Setup/RHEL.pm ↑ Summary lib/Rex/GPU/NVIDIA/Setup/Rpm.pm »
1 # ABSTRACT: AMD driver setup for RHEL, Rocky Linux and AlmaLinux 8, 9 and 10 (experimental)
2  
3 package Rex::GPU::AMD::Setup::RHEL;
4 40 our $VERSION = '0.006';
5 40 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 40 ▶use Rex::Logger ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 40 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 40 extends 'Rex::GPU::AMD::Setup';
10  
11 # Sources, checked 2026-10-30:
12 # ROCm 10.1 compatibility matrix (Instinct, amdgpu-dkms): RHEL 10.2
13 # 6.12.0-211, 10.0 6.12.0-55, 9.8 5.14.0-687, 9.6 5.14.0-570, 9.4
14 # 5.14.0-427, 8.10 4.18.0-553; Rocky 9 5.14.0-570. Radeon: RHEL 10.2, 9.8.
15 # No Ryzen APU support on RHEL. The Radeon list names the releases only;
16 # %RADEON binds each to the kernel build the Instinct list gives that
17 # release (10.2 6.12.0-211, 9.8 5.14.0-687) -- this distribution's
18 # reading (k82), as strict as the amdgpu-dkms check, for either driver.
19 # Rocky and AlmaLinux with the same VERSION_ID count as RHEL, as they do
20 # for amdgpu-dkms.
21 # amdgpu 31.60 install guide, RHEL: /etc/yum.repos.d/amdgpu.repo, baseurl
22 # https://repo.radeon.com/amdgpu/31.60/el/MAJOR/main/x86_64/, priority=50,
23 # gpgcheck=1; kernel-headers-$K kernel-devel-$K kernel-devel-matched-$K
24 # (8.10: without -matched). The repository ships its own dkms.
25 # Firmware for the inbox amdgpu: amd-gpu-firmware on EL10 (split off
26 # linux-firmware), linux-firmware on EL9 and EL8.
27 40 my %MAJOR = (
28 10 => { kernel => qr/\A6\.12\.0-(?:211|55)\./, kernel_text => '6.12.0-211 or 6.12.0-55',
29 matched => 1, firmware => [qw( amd-gpu-firmware )] },
30 9 => { kernel => qr/\A5\.14\.0-(?:687|570|427)\./, kernel_text => '5.14.0-687, -570 or -427',
31 matched => 1, firmware => [qw( linux-firmware )] },
32 8 => { kernel => qr/\A4\.18\.0-553\./, kernel_text => '4.18.0-553',
33 matched => 0, firmware => [qw( linux-firmware )] },
34 );
35 40 my %RADEON = (
36 '10.2' => { kernel => qr/\A6\.12\.0-211\./, kernel_text => '6.12.0-211' },
37 '9.8' => { kernel => qr/\A5\.14\.0-687\./, kernel_text => '5.14.0-687' },
38 );
39  
40  
41 100 ▶sub major {
Subroutine major: called CC=2 SCAR=7.2
Pod documented
42 100 my ( $self ) = @_;
43 100 ▶ return $self->os_version =~ /\A(\d+)/ ? $1 : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->os_version =~ /\A(\d+)/ ? : 100 0 100
44 }
45  
46 67 ▶sub release_data {
Subroutine release_data: called CC=2 SCAR=7.1
Pod documented
47 67 my ( $self ) = @_;
48 67 ▶ my $major = $self->major // return;
Condition50%1/2
$self->major // (return)
l!l
670
MC/DC0%0/1
$self->major // (return)
$self->major
Truth table50%1/2
A
A= $self->major
Aresult
11
00
49 67 return $MAJOR{$major};
50 }
51  
52 33 ▶sub amdgpu_key_path { '/etc/pki/rpm-gpg/RPM-GPG-KEY-rocm' }
Subroutine amdgpu_key_path: called CC=1 SCAR=0.0
Pod documented
53  
54 33 ▶sub dkms_repo {
Subroutine dkms_repo: called CC=2 SCAR=7.1
Pod documented
55 33 my ( $self ) = @_;
56 33 my $key = $self->amdgpu_key;
57 return {
58 file => '/etc/yum.repos.d/amdgpu.repo',
59 content => join("\n",
60 '[amdgpu]',
61 'name=amdgpu',
62 'baseurl=https://repo.radeon.com/amdgpu/'.$self->amdgpu_release.'/el/'
63 .( $self->major // 'unknown' ).'/main/x86_64/',
64 'enabled=1',
65 'priority=50',
66 'gpgcheck=1',
67 33 ▶ 'gpgkey=file://'.$key->{path}, ''),
Condition50%1/2
$self->major // "unknown"
l!l
330
MC/DC0%0/1
$self->major // "unknown"
$self->major
Truth table50%1/2
A
A= $self->major
Aresult
11
00
68 key => $key,
69 };
70 }
71  
72 34 ▶sub dkms_unsupported {
Subroutine dkms_unsupported: called CC=3 SCAR=11.0
Pod documented
73 34 my ( $self ) = @_;
74 34 ▶ my $row = $self->release_data
Branch: 1 branch
BranchTrueFalseTotal
my $row = $self->release_data or return 'amdgpu-dkms ' . $self->amdgpu_release . ' supports RHEL 8, 9 and 10, not ' . $self->os_label 34 0 34
75 or return 'amdgpu-dkms '.$self->amdgpu_release.' supports RHEL 8, 9 and 10, not '.$self->os_label;
76 34 ▶ return if $self->kernel =~ $row->{kernel};
Branch: 1 branch
BranchTrueFalseTotal
if $self->kernel =~ /$row->{"kernel"}/ 33 1 34
77 return 'amdgpu-dkms '.$self->amdgpu_release.' supports '.$self->os_label.' with kernel '
78 1 .$row->{kernel_text}.'; this host runs '.$self->kernel;
79 }
80  
81 6 ▶sub radeon_unsupported {
Subroutine radeon_unsupported: called CC=3 SCAR=11.0
Pod documented
82 6 my ( $self ) = @_;
83 6 ▶ my $row = $RADEON{ $self->os_version } or return $self->SUPER::radeon_unsupported;
Branch: 1 branch
BranchTrueFalseTotal
my $row = $RADEON{$self->os_version} or return $self->SUPER::radeon_unsupported 4 2 6
84 4 ▶ return if $self->kernel =~ $row->{kernel};
Branch: 1 branch
BranchTrueFalseTotal
if $self->kernel =~ /$row->{"kernel"}/ 2 2 4
85 return 'AMD supports Radeon GPUs on '.$self->os_label.' with kernel '.$row->{kernel_text}
86 2 .' only; this host runs '.$self->kernel;
87 }
88  
89 32 ▶sub kernel_header_packages {
Subroutine kernel_header_packages: called CC=3 SCAR=12.0
Pod documented
90 32 my ( $self ) = @_;
91 32 my $kernel = $self->kernel;
92 32 my $row = $self->release_data;
93 return ( "kernel-headers-$kernel", "kernel-devel-$kernel",
94 32 ▶ ( $row && $row->{matched} ? "kernel-devel-matched-$kernel" : () ) );
Branch: 1 branch
BranchTrueFalseTotal
$row && $row->{'matched'} ? : 32 0 32
Condition33%1/3
$row and $row->{"matched"}
!ll&&!rl&&r
0032
MC/DC0%0/2
$row and $row->{"matched"}
$row $row->{"matched"}
Truth table33%1/3
A and B
A= $rowB= $row->{"matched"}
ABresult
0X0
100
111
95 }
96  
97 1 ▶sub firmware_packages {
Subroutine firmware_packages: called CC=2 SCAR=7.0
Pod documented
98 1 my ( $self ) = @_;
99 1 ▶ my $row = $self->release_data or return;
Branch: 1 branch
BranchTrueFalseTotal
my $row = $self->release_data or return 1 0 1
100 1 return @{ $row->{firmware} };
101 }
102  
103  
104 # repoquery prints one NEVRA per match (name-epoch:version-release.arch, dnf
105 # 4 and 5 alike) and exits 0 also when nothing matches; it exits non-zero
106 # only when it could not run, e.g. metadata that cannot be downloaded --
107 # which must not read as "no candidate". Other output (warnings, with 2>&1)
108 # has spaces and is no NEVRA.
109 111 ▶sub has_candidate {
Subroutine has_candidate: called CC=6 SCAR=18.0
Pod documented
110 111 my ( $self, $package ) = @_;
111 111 ▶ return 1 if $self->package_installed($package);
Branch: 1 branch
BranchTrueFalseTotal
if $self->package_installed($package) 14 97 111
112 97 ▶ my $out = $self->run_cmd("dnf -q repoquery --available $package 2>&1") // '';
Condition50%1/2
$self->run_cmd("dnf -q repoquery --available $package 2>&1") // ""
l!l
970
MC/DC0%0/1
$self->run_cmd("dnf -q repoquery --available $package 2>&1") // ""
$self->run_cmd("dnf -q repoquery --available $package 2>&1")
Truth table50%1/2
A
A= $self->run_cmd("dnf -q repoquery --available $package 2>&1")
Aresult
11
00
113 97 ▶ if ($? != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0) 4 93 97
114 4 my ( $why ) = reverse grep { /\S/ } split /\r?\n/, $out;
115 4 ▶ $why = defined $why ? $why =~ s/\A\s+|\s+\z//gr : 'no output';
Branch: 1 branch
BranchTrueFalseTotal
defined $why ? : 4 0 4
116 4 die "install_driver: looking up $package with dnf failed ($why). No driver package was "
117 ."installed\n";
118 }
119 93 ▶ return ( grep { /\A\s*\S+-\d+:\S+\s*\z/ } split /\r?\n/, $out ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
grep({/\A\s*\S+-\d+:\S+\s*\z/;} split(/\r?\n/, $out, 0)) ? : 91 2 93
120 }
121  
122 219 ▶sub package_installed {
Subroutine package_installed: called CC=2 SCAR=6.9
Pod documented
123 219 my ( $self, $package ) = @_;
124 219 $self->run_cmd("rpm -q $package 2>&1");
125 219 ▶ return $? == 0 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$? == 0 ? : 108 111 219
126 }
127  
128 32 ▶sub install_helpers {
Subroutine install_helpers: called CC=4 SCAR=15.9
Pod documented
129 32 my ( $self ) = @_;
130 32 my @missing;
131 32 for my $helper ([ curl => 'curl' ], [ gpg => 'gnupg2' ]) {
132 64 $self->run_cmd("command -v $helper->[0] >/dev/null 2>&1");
133 64 ▶ push @missing, $helper->[1] if $? != 0;
Branch: 1 branch
BranchTrueFalseTotal
if $? != 0 0 64 64
134 }
135 32 ▶ return unless @missing;
Branch: 1 branch
BranchTrueFalseTotal
unless @missing 32 0 32
136 0 $self->run_cmd('dnf install -y '.join(' ', @missing));
137 0 $self->verify_packages({ packages => \@missing });
138 0 return;
139 }
140  
141 26 ▶sub install_packages {
Subroutine install_packages: called CC=1 SCAR=0.0
Pod documented
142 26 my ( $self, $plan ) = @_;
143 26 Rex::Logger::info(' Installing: '.join(', ', @{ $plan->{packages} }));
144 26 $self->run_cmd('dnf install -y '.join(' ', @{ $plan->{packages} }));
145 26 return;
146 }
147  
148 26 ▶sub verify_packages {
Subroutine verify_packages: called CC=4 SCAR=13.9
Pod documented
149 26 my ( $self, $plan ) = @_;
150 26 for my $package (@{ $plan->{packages} }) {
151 99 ▶ next if $self->package_installed($package);
Branch: 1 branch
BranchTrueFalseTotal
if $self->package_installed($package) 90 9 99
152 9 my $hold = $self->hold_note($plan);
153 9 ▶ die "$package not installed after dnf install -- check the dnf output"
Branch: 1 branch
BranchTrueFalseTotal
length $hold ? : 4 5 9
154 .( length $hold ? "; $hold" : '' )."\n";
155 }
156 17 return;
157 }
158  
159 # k109: the counterpart of the apt hold. A lock (dnf 4 versionlock plugin,
160 # dnf 5 built in) leaves an installed package at its locked version and
161 # keeps every other version out, so `dnf install` of a version it excludes
162 # fails as a whole (strict) -- or does nothing for a package installed at
163 # the locked version. Asked only on a failure path; a dnf without the
164 # plugin, or a list that cannot be read, is no lock (k109: nothing dies,
165 # nothing is installed for it).
166 0 ▶sub package_held {
Subroutine package_held: not called CC=2 SCAR=17.9
Pod documented
167 0 my ( $self, $package ) = @_;
168 0 ▶ return $self->_locked($self->_package_name($package), $self->_versionlock_entries) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->_locked($self->_package_name($package), $self->_versionlock_entries) ? : 0 0 0
169 }
170  
171 19 ▶sub blocking_holds {
Subroutine blocking_holds: called CC=8 SCAR=20.8
Pod documented
172 19 my ( $self, $plan ) = @_;
173 19 ▶ my @entries = $self->_versionlock_entries or return;
Branch: 1 branch
BranchTrueFalseTotal
my(@entries) = $self->_versionlock_entries or return 11 8 19
174 11 ▶ my %asked = map { $_ => 1 } @{ $plan->{packages} || [] };
Condition50%1/2
$plan->{'packages'} || []
l!l
110
MC/DC0%0/1
$plan->{'packages'} || []
$plan->{'packages'}
Truth table50%1/2
A
A= $plan->{'packages'}
Aresult
11
00
175 11 my @held;
176 11 for my $package ($self->_hold_packages($plan)) {
177 55 my $name = $self->_package_name($package);
178 55 ▶ next unless $self->_locked($name, @entries);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_locked($name, @entries) 44 11 55
179 # a spec with the kernel's version is one build, a dependency is required
180 # without a version: installed, the lock kept nothing out
181 push @held, $name
182 11 ▶ if ( $asked{$package} && $package eq $name ) || !$self->package_installed($package);
Branch: 1 branch
BranchTrueFalseTotal
if $asked{$package} and $package eq $name or not $self->package_installed($package) 7 4 11
Condition100%6/6
$asked{$package} and $package eq $name or not $self->package_installed($package)
l!l&&r!l&&!r
344
$asked{$package} and $package eq $name
!ll&&!rl&&r
443
MC/DC100%3/3
$asked{$package} and $package eq $name or not $self->package_installed($package)
$asked{$package} $package eq $name not $self->package_installed($package)
Truth table100%5/5
A and B or not(C)
A= $asked{$package}B= $package eq $nameC= not $self->package_installed($package)
ABCresult
11X1
0X11
1011
0X00
1000
183 }
184 11 return @held;
185 }
186  
187 7 ▶sub hold_advice {
Subroutine hold_advice: called CC=2 SCAR=7.2
Pod documented
188 7 my ( $self, @held ) = @_;
189 7 ▶ return $self->_and_list(@held).( @held > 1 ? ' are' : ' is' ).' version-locked (dnf versionlock), '
Branch: 1 branch
BranchTrueFalseTotal
@held > 1 ? : 0 7 7
190 .'and dnf install leaves a locked package at its locked version (where the install needs another '
191 .'one, it fails). Run dnf versionlock delete '.join(' ', @held).' and install_driver again';
192 }
193  
194 # dnf 4 (python3-dnf-plugin-versionlock) prints the lock list's entries as
195 # they were added, NAME-EPOCH:VERSION-RELEASE.*, "!" in front for an
196 # exclude; dnf 5 prints "Package name: NAME" per entry, then its
197 # conditions ("evr = ..."). Lines with a space or a "#" (conditions,
198 # comments, dnf's own messages) are no entry. Exit status not 0 (no plugin,
199 # an unreadable list): no entries.
200 19 ▶sub _versionlock_entries {
Subroutine _versionlock_entries: called CC=7 SCAR=19.5
201 19 my ( $self ) = @_;
202 19 ▶ my $out = $self->run_cmd('dnf -q versionlock list 2>/dev/null') // '';
Condition50%1/2
$self->run_cmd("dnf -q versionlock list 2>/dev/null") // ""
l!l
190
MC/DC0%0/1
$self->run_cmd("dnf -q versionlock list 2>/dev/null") // ""
$self->run_cmd("dnf -q versionlock list 2>/dev/null")
Truth table50%1/2
A
A= $self->run_cmd("dnf -q versionlock list 2>/dev/null")
Aresult
11
00
203 19 ▶ return if $? != 0;
Branch: 1 branch
BranchTrueFalseTotal
if $? != 0 4 15 19
204 15 my @entries;
205 15 for my $line (split /\r?\n/, $out) {
206 13 $line =~ s/\A\s+|\s+\z//g;
207 13 ▶ if ($line =~ /\APackage name:\s*(\S+)\z/) { push @entries, $1 }
Branch: 2 branches
BranchTrueFalseTotal
if ($line =~ /\APackage name:\s*(\S+)\z/) { } 1 12 13
elsif (length $line and not $line =~ /[\s#]/) { } 10 2 12
208 10 ▶ elsif (length $line && $line !~ /[\s#]/) { push @entries, $line =~ s/\A!//r }
Condition66%2/3
length $line and not $line =~ /[\s#]/
!ll&&!rl&&r
0210
MC/DC50%1/2
length $line and not $line =~ /[\s#]/
length $line not $line =~ /[\s#]/
Truth table66%2/3
A and not(B)
A= length $lineB= not $line =~ /[\s#]/
ABresult
0X0
100
111
209 }
210 15 return @entries;
211 }
212  
213 # An entry is for NAME when it is NAME, or NAME, a dash and an epoch or a
214 # version (a digit, or a glob): kernel-devel-0:5.14.0-570.12.1.el9_6.* is
215 # kernel-devel's, kernel-devel-matched-0:... is not.
216 55 ▶sub _locked {
Subroutine _locked: called CC=2 SCAR=6.9
217 55 my ( $self, $name, @entries ) = @_;
218 55 ▶ return scalar grep { $_ eq $name || /\A\Q$name\E-(?:\d+:)?[\d*]/ } @entries;
Condition100%3/3
$_ eq $name || /\A\Q$name\E-(?:\d+:)?[\d*]/
l!l&&r!l&&!r
11044
MC/DC100%2/2
$_ eq $name || /\A\Q$name\E-(?:\d+:)?[\d*]/
$_ eq $name /\A\Q$name\E-(?:\d+:)?[\d*]/
Truth table100%3/3
A || B
A= $_ eq $nameB= /\A\Q$name\E-(?:\d+:)?[\d*]/
ABresult
1X1
011
000
219 }
220  
221 # The package name of a spec: kernel-devel-$(uname -r) is kernel-devel.
222 55 ▶sub _package_name {
Subroutine _package_name: called CC=1 SCAR=0.0
223 55 my ( $self, $package ) = @_;
224 55 my $kernel = $self->kernel;
225 55 return $package =~ s/-\Q$kernel\E\z//r;
226 }
227  
228 31 ▶sub place_key {
Subroutine place_key: called CC=2 SCAR=7.1
Pod documented
229 31 my ( $self, $dir, $path ) = @_;
230 31 $self->run_cmd("chmod 0644 $dir/key.asc && mv -f $dir/key.asc $path && rpm --import $path");
231 31 ▶ return $? == 0 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$? == 0 ? : 31 0 31
232 }
233  
234 40 1;
235  
236 __END__
« lib/Rex/GPU/NVIDIA/Setup/RHEL.pm ↑ Summary lib/Rex/GPU/NVIDIA/Setup/Rpm.pm »