lib/Rex/GPU/NVIDIA/Setup/Ubuntu.pm

filter: Statementstmt 100% 62 / 62 Branchbran 80.7% 21 / 26 Conditioncond 70.5% 12 / 17 MC/DCmcdc 12.5% 1 / 8 Subroutinesub 100% 12 / 12 Podpod 100% 7 / 7 totaltotal 87.1% 115 / 132 CC 21 SCAR 17.2
CC
21
Cov
90%
resolve_source
10.1
_nvlsm_repo
6.2
nvlink_fabric_unavailable
4.2
CRAP 5.6
« blib/lib/Rex/GPU/Detect.pm ↑ Summary lib/Rex/GPU/NVIDIA/VGPU.pm »
1 # ABSTRACT: NVIDIA driver setup for Ubuntu (experimental)
2  
3 package Rex::GPU::NVIDIA::Setup::Ubuntu;
4 36 our $VERSION = '0.005';
5 36 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 36 ▶use Rex::Logger ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 36 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 36 extends 'Rex::GPU::NVIDIA::Setup::Apt';
10  
11  
12 # 580 is published for jammy and noble (Launchpad, source
13 # nvidia-graphics-drivers-580-server, checked 2026-09-23: 580.178.04 on both,
14 # next to 590 and 595). The apt-cache search runs in resolve_source, after
15 # `apt-get update` -- before it, a fresh image's index is stale or empty
16 # (karr #35).
17 #
18 # Fabric Manager (karr #23): Ubuntu's archive builds nvidia-fabricmanager-NNN
19 # (source fabric-manager-NNN) for each -server branch, one package for the
20 # proprietary and the -open driver; it Depends on the virtual
21 # nvidia-kernel-common-NNN-server-<exact upstream version>, and on noble and
22 # jammy it carries exactly the version string of nvidia-driver-NNN-server
23 # (packages.ubuntu.com, 580.178.04-0ubuntu0.24.04.1 / 22.04.1, checked
24 # 2026-09-24).
25 140 ▶sub sources {
Subroutine sources: called CC=1 SCAR=0.0
Pod documented
26 140 my ( $self ) = @_;
27 140 my %fm = ( fabric_manager => 'nvidia-fabricmanager-%s' );
28 return (
29 {
30 140 name => 'ubuntu-server',
31 kernel_module => 'proprietary',
32 branch_at_least => 580,
33 search => '^nvidia-driver-[0-9].*-server$',
34 %fm,
35 fabric_manager_match => 'nvidia-driver-%s-server'
36 },
37 {
38 name => 'ubuntu-server-open',
39 kernel_module => 'open',
40 branch_at_least => 580,
41 search => '^nvidia-driver-[0-9].*-server-open$',
42 %fm,
43 fabric_manager_match => 'nvidia-driver-%s-server-open'
44 },
45 {
46 name => 'ubuntu-server-580',
47 kernel_module => 'proprietary',
48 branch => 580,
49 packages => [ 'nvidia-driver-580-server' ],
50 verify => [ 'nvidia-driver-580-server' ],
51 check_candidate => 'nvidia-driver-580-server',
52 %fm,
53 fabric_manager_match => 'nvidia-driver-580-server'
54 }
55 );
56 }
57  
58  
59 10 ▶sub nvlink_fabric_packages {
Subroutine nvlink_fabric_packages: called CC=1 SCAR=0.0
Pod documented
60 10 my ( $self ) = @_;
61 # ib_umad.ko is in linux-modules-extra-<kver> (research 2026-09-24,
62 # checked for 6.8.0-142-generic); the running kernel's own package.
63 10 return ( $self->SUPER::nvlink_fabric_packages, 'linux-modules-extra-'.$self->kernel );
64 }
65  
66 # nvlsm verified in repos/ubuntu2204 and repos/ubuntu2404 (x86_64), research
67 # of 2026-09-24; not in Ubuntu's archive, not in DOCA.
68 36 my %NVLSM_REPO = ( '22.04' => 'ubuntu2204', '24.04' => 'ubuntu2404' );
69  
70 22 ▶sub _nvlsm_repo {
Subroutine _nvlsm_repo: called CC=6 SCAR=18.3
71 22 my ( $self ) = @_;
72 22 ▶ my ($release) = ( $self->release // '' ) =~ /^(\d+\.\d+)/;
Condition50%1/2
$self->release // ""
l!l
220
MC/DC0%0/1
$self->release // ""
$self->release
Truth table50%1/2
A
A= $self->release
Aresult
11
00
73 22 ▶ my $distro = defined $release ? $NVLSM_REPO{$release} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $release ? : 22 0 22
74 22 ▶ return unless defined $distro && ( $self->arch // '' ) eq 'amd64';
Branch: 1 branch
BranchTrueFalseTotal
unless defined $distro and ($self->arch // "") eq "amd64" 2 20 22
Condition80%4/5
defined $distro and ($self->arch // "") eq "amd64"
!ll&&!rl&&r
1120
$self->arch // ""
l!l
210
MC/DC50%1/2
defined $distro and ($self->arch // "") eq "amd64"
defined $distro $self->arch
Truth table66%2/3
A and B
A= defined $distroB= $self->arch
ABresult
0X0
100
111
75 return {
76 20 distro => $distro,
77 arch => 'x86_64',
78 url => "https://developer.download.nvidia.com/compute/cuda/repos/$distro/x86_64/",
79 keyring_url => "https://developer.download.nvidia.com/compute/cuda/repos/$distro/x86_64/cuda-keyring_1.1-1_all.deb"
80 };
81 }
82  
83 14 ▶sub nvlink_fabric_unavailable {
Subroutine nvlink_fabric_unavailable: called CC=4 SCAR=14.3
Pod documented
84 14 my ( $self ) = @_;
85 14 ▶ return if $self->_nvlsm_repo;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_nvlsm_repo 12 2 14
86 2 ▶ return "nvlsm is only in NVIDIA's CUDA repository, which Rex::GPU uses for it on Ubuntu "
Condition50%2/4
$self->release // ""
l!l
20
$self->arch // ""
l!l
20
MC/DC0%0/1
$self->release // ""
$self->release
MC/DC0%0/1
$self->arch // ""
$self->arch
Truth table50%1/2
A
A= $self->release
Aresult
11
00
Truth table50%1/2
A
A= $self->arch
Aresult
11
00
87 ."22.04 and 24.04 (amd64) only, not on release '".( $self->release // '' )."' ("
88 .( $self->arch // '' ).')';
89 }
90  
91 6 ▶sub nvlsm_pin_file { '/etc/apt/preferences.d/rex-gpu-nvlsm.pref' }
Subroutine nvlsm_pin_file: called CC=1 SCAR=0.0
Pod documented
92 6 ▶sub nvlsm_source_file { '/etc/apt/sources.list.d/rex-gpu-nvlsm.list' }
Subroutine nvlsm_source_file: called CC=1 SCAR=0.0
Pod documented
93  
94 8 ▶sub prepare_nvlink_fabric_source {
Subroutine prepare_nvlink_fabric_source: called CC=4 SCAR=13.9
Pod documented
95 8 my ( $self, $plan ) = @_;
96 8 ▶ my $repo = $self->_nvlsm_repo
Branch: 1 branch
BranchTrueFalseTotal
my $repo = $self->_nvlsm_repo or die "No NVIDIA CUDA repository for nvlsm on this Ubuntu host; the driver and Fabric Manager are installed, nvlsm is not\n" 8 0 8
97 or die 'No NVIDIA CUDA repository for nvlsm on this Ubuntu host; the driver and '
98 ."Fabric Manager are installed, nvlsm is not\n";
99 8 $self->run_cmd("dpkg -l cuda-keyring 2>/dev/null | grep -q '^ii'", auto_die => 0);
100 8 ▶ if ($? == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? == 0) 1 7 8
101 1 Rex::Logger::info(' cuda-keyring is installed: NVIDIA\'s CUDA repository is already '
102 .'configured (with its own apt pin), nothing is added');
103 1 $self->refresh_package_index;
104 1 return;
105 }
106 7 Rex::Logger::info(" Adding NVIDIA's CUDA repository ($repo->{distro}/$repo->{arch}) for nvlsm "
107 .'only, every other package of it pinned out');
108 7 my $keyring = '/usr/share/keyrings/cuda-archive-keyring.gpg';
109 7 $self->run_cmd('DEBIAN_FRONTEND=noninteractive '.$self->apt_get.' install -y --no-upgrade curl',
110 auto_die => 0);
111 7 $self->verify_packages({ verify => [ 'curl' ] });
112 $self->run_cmd(q{t=$(mktemp -d) && curl -fsSL -o "$t/cuda-keyring.deb" }.$repo->{keyring_url}
113 7 .q{ && dpkg-deb --fsys-tarfile "$t/cuda-keyring.deb" | tar -xO ./usr/share/keyrings/cuda-archive-keyring.gpg > "$t/key.gpg"}
114 .q{ && test -s "$t/key.gpg" && install -m 0644 "$t/key.gpg" }.$keyring
115 .q{; rc=$?; rm -rf "$t"; exit $rc},
116 auto_die => 0);
117 7 ▶ die "Could not fetch the signing key of NVIDIA's CUDA repository ($repo->{keyring_url}) "
Branch: 1 branch
BranchTrueFalseTotal
if $? != 0 1 6 7
118 ."into $keyring; the driver and Fabric Manager are installed, nvlsm is not\n" if $? != 0;
119 6 $self->file_cmd($self->nvlsm_pin_file, content => $self->_nvlsm_pin, mode => 644);
120 $self->file_cmd($self->nvlsm_source_file,
121 6 content => 'deb [signed-by='.$keyring.'] '.$repo->{url}." /\n", mode => 644);
122 6 $self->refresh_package_index;
123 6 return;
124 }
125  
126 # apt_preferences(5): the first specific-form record (Package: nvlsm) decides
127 # nvlsm's priority; every other package of that origin gets the general
128 # record's -1, "prevents the version from being installed". cuda-keyring's
129 # own pin (Package: * / release l=NVIDIA CUDA / 600) is NOT installed: a
130 # general record, it would win the maximum over -1.
131 6 ▶sub _nvlsm_pin {
Subroutine _nvlsm_pin: called CC=1 SCAR=0.0
132 6 return join("\n",
133 'Explanation: Rex::GPU (HGX B200/B300): NVIDIA\'s CUDA repository is here for nvlsm only.',
134 'Explanation: Nothing else is installed or upgraded from it; the NVIDIA driver stays Ubuntu\'s.',
135 'Package: *',
136 'Pin: origin developer.download.nvidia.com',
137 'Pin-Priority: -1',
138 '',
139 'Package: nvlsm',
140 'Pin: origin developer.download.nvidia.com',
141 'Pin-Priority: 500',
142 '');
143 }
144  
145  
146 93 ▶sub resolve_source {
Subroutine resolve_source: called CC=10 SCAR=23.2
Pod documented
147 93 my ( $self, $source ) = @_;
148 93 ▶ if (defined $source->{search}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $source->{"search"}) 70 23 93
149 70 my $latest = $self->run_cmd("apt-cache search '$source->{search}' 2>/dev/null | sort -t- -k3 -n | tail -1 | awk '{print \$1}'",
150 auto_die => 0);
151 70 ▶ chomp $latest if $latest;
Branch: 1 branch
BranchTrueFalseTotal
if $latest 67 3 70
152 # Filter out *-open variants from auto-detect (use regular server driver)
153 70 ▶ $latest = undef if $latest && $source->{kernel_module} ne 'open' && $latest =~ /-open$/;
Branch: 1 branch
BranchTrueFalseTotal
if $latest and $source->{"kernel_module"} ne "open" and $latest =~ /-open$/ 0 70 70
Condition83%5/6
$latest and $source->{"kernel_module"} ne "open" and $latest =~ /-open$/
!ll&&!rl&&r
35350
$latest and $source->{"kernel_module"} ne "open"
!ll&&!rl&&r
33235
MC/DC0%0/3
$latest and $source->{"kernel_module"} ne "open" and $latest =~ /-open$/
$latest $source->{"kernel_module"} ne "open" $latest =~ /-open$/
Truth table75%3/4
A and B and C
A= $latestB= $source->{"kernel_module"} ne "open"C= $latest =~ /-open$/
ABCresult
0XX0
10X0
1100
1111
154 70 ▶ return { %$source, unavailable => "apt-cache search '".$source->{search}."' finds no "
Branch: 1 branch
BranchTrueFalseTotal
unless $latest 3 67 70
155 .'package after apt-get update (did the update fail, or is the restricted '
156 .'component missing from the apt sources?)' }
157 unless $latest;
158 67 my ($branch) = $latest =~ /^nvidia-driver-(\d+)-server/;
159 67 ▶ return { %$source, unavailable => 'no driver branch in the package name '.$latest }
Branch: 1 branch
BranchTrueFalseTotal
unless defined $branch 0 67 67
160 unless defined $branch;
161 67 my %resolved = ( %$source, packages => [ $latest ], verify => [ $latest ], branch => $branch );
162 67 delete $resolved{branch_at_least};
163 67 return \%resolved;
164 }
165 23 ▶ if (defined $source->{check_candidate}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $source->{"check_candidate"}) 23 0 23
166 23 my $pinned = $source->{check_candidate};
167 23 my $policy = $self->run_cmd("LC_ALL=C apt-cache policy $pinned 2>/dev/null", auto_die => 0);
168 23 ▶ return { %$source, unavailable => $pinned.' has no installation candidate after '
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_apt_candidate_present($policy) 1 22 23
169 .'apt-get update, and no other package is substituted' }
170 unless $self->_apt_candidate_present($policy);
171 }
172 22 return $source;
173 }
174  
175 36 1;
176  
177 __END__
« blib/lib/Rex/GPU/Detect.pm ↑ Summary lib/Rex/GPU/NVIDIA/VGPU.pm »