lib/Rex/GPU/NVIDIA/Setup.pm

filter: Statementstmt 97.0% 454 / 468 Branchbran 89.0% 196 / 220 Conditioncond 76.4% 130 / 170 MC/DCmcdc 59.3% 57 / 96 Subroutinesub 87.0% 74 / 85 Podpod 97.9% 48 / 49 totaltotal 88.1% 959 / 1088 CC 189 SCAR 19.5
CC
189
Cov
91%
adopt
17.0
retrofit_fabric_manager
16.0
resolve_plan
11.6
CRAP 7.0
« blib/lib/Rex/GPU/Detect.pm ↑ Summary lib/Rex/GPU/AMD/Setup/Apt.pm »
1 # ABSTRACT: Base class of the per-distro NVIDIA driver setups (experimental)
2  
3 package Rex::GPU::NVIDIA::Setup;
4 49 our $VERSION = '0.006';
5 49 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 49 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 49 ▶use Rex::Commands::File ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 49 ▶use Rex::Commands::Gather ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 49 ▶use Rex::Commands::Pkg ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 49 ▶use Rex::Commands::Run ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 49 ▶use Rex::Logger ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 49 ▶use Rex::GPU::NVIDIA::Requirement ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 49 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 49 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 # No `use utf8` here, on purpose: the die messages carry UTF-8 em dashes as
17 # byte strings exactly like Rex::GPU::NVIDIA always emitted them.
18  
19  
20 49 has gpu => ( is => 'ro' );
21 49 has gpus => ( is => 'lazy', writer => '_set_gpus' );
22  
23 120 ▶sub _build_gpus {
Subroutine _build_gpus: called CC=2 SCAR=6.9
24 120 my ( $self ) = @_;
25 120 ▶ return defined $self->gpu ? [ $self->gpu ] : [];
Branch: 1 branch
BranchTrueFalseTotal
defined $self->gpu ? : 92 28 120
26 }
27  
28 826 ▶sub BUILD {
Subroutine BUILD: called CC=9 SCAR=22.0
Pod undocumented
29 826 my ( $self, $args ) = @_;
30 croak __PACKAGE__.'->new: pass gpu or gpus, not both'
31 826 ▶ if defined $args->{gpu} && defined $args->{gpus};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args->{"gpu"} and defined $args->{"gpus"} 1 825 826
Condition100%3/3
defined $args->{"gpu"} and defined $args->{"gpus"}
!ll&&!rl&&r
732931
MC/DC100%2/2
defined $args->{"gpu"} and defined $args->{"gpus"}
defined $args->{"gpu"} defined $args->{"gpus"}
Truth table100%3/3
A and B
A= defined $args->{"gpu"}B= defined $args->{"gpus"}
ABresult
0X0
100
111
32 croak __PACKAGE__.'->new: gpus must be an arrayref of GPU hashrefs'
33 825 ▶ if defined $args->{gpus} && ref $args->{gpus} ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if defined $args->{"gpus"} and ref $args->{"gpus"} ne "ARRAY" 1 824 825
Condition100%3/3
defined $args->{"gpus"} and ref $args->{"gpus"} ne "ARRAY"
!ll&&!rl&&r
2046201
MC/DC100%2/2
defined $args->{"gpus"} and ref $args->{"gpus"} ne "ARRAY"
defined $args->{"gpus"} ref $args->{"gpus"} ne "ARRAY"
Truth table100%3/3
A and B
A= defined $args->{"gpus"}B= ref $args->{"gpus"} ne "ARRAY"
ABresult
0X0
100
111
34 croak __PACKAGE__.'->new: nvswitches must be an arrayref'
35 824 ▶ if defined $args->{nvswitches} && ref $args->{nvswitches} ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if defined $args->{"nvswitches"} and ref $args->{"nvswitches"} ne "ARRAY" 1 823 824
Condition100%3/3
defined $args->{"nvswitches"} and ref $args->{"nvswitches"} ne "ARRAY"
!ll&&!rl&&r
785381
MC/DC100%2/2
defined $args->{"nvswitches"} and ref $args->{"nvswitches"} ne "ARRAY"
defined $args->{"nvswitches"} ref $args->{"nvswitches"} ne "ARRAY"
Truth table100%3/3
A and B
A= defined $args->{"nvswitches"}B= ref $args->{"nvswitches"} ne "ARRAY"
ABresult
0X0
100
111
36 823 ▶ $self->_check_gpus($args->{gpus} // [ defined $args->{gpu} ? $args->{gpu} : () ]);
Branch: 1 branch
BranchTrueFalseTotal
defined $args->{'gpu'} ? : 93 110 203
Condition100%2/2
$args->{"gpus"} // [defined $args->{"gpu"} ? $args->{"gpu"} : ()]
l!l
620203
MC/DC100%1/1
$args->{"gpus"} // [defined $args->{"gpu"} ? $args->{"gpu"} : ()]
$args->{"gpus"}
Truth table100%2/2
A
A= $args->{"gpus"}
Aresult
11
00
37 }
38  
39 # A device_id that is there but not four hex digits ("0x2b85" from sysfs,
40 # "2b85\n" from a cat) would make Requirement->from_gpu see an unknown GPU:
41 # no Kepler refusal, no open module for Blackwell. Croak instead (karr #42).
42 834 ▶sub _check_gpus {
Subroutine _check_gpus: called CC=5 SCAR=16.1
43 834 my ( $self, $gpus ) = @_;
44 834 for my $gpu (grep { ref $_ eq 'HASH' } @$gpus) {
45 955 my $id = $gpu->{device_id};
46 955 ▶ next if !defined $id || $id =~ /\A[0-9a-f]{4}\z/i;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $id or $id =~ /\A[0-9a-f]{4}\z/i 947 8 955
Condition100%3/3
not defined $id or $id =~ /\A[0-9a-f]{4}\z/i
l!l&&r!l&&!r
49438
MC/DC100%2/2
not defined $id or $id =~ /\A[0-9a-f]{4}\z/i
not defined $id $id =~ /\A[0-9a-f]{4}\z/i
Truth table100%3/3
not(A) or B
A= not defined $idB= $id =~ /\A[0-9a-f]{4}\z/i
ABresult
1X1
011
000
47 8 ▶ croak "NVIDIA GPU '".( $gpu->{name} // 'unknown' )."': device_id '".$id."' is not "
Condition100%2/2
$gpu->{"name"} // "unknown"
l!l
62
MC/DC100%1/1
$gpu->{"name"} // "unknown"
$gpu->{"name"}
Truth table100%2/2
A
A= $gpu->{"name"}
Aresult
11
00
48 .'a PCI device ID of four hex digits, e.g. 2b85 (no 0x, no newline). No driver '
49 .'package was installed and no package source was added';
50 }
51 826 return;
52 }
53  
54  
55 49 has nvswitches => ( is => 'lazy', writer => '_set_nvswitches' );
56  
57 545 ▶sub _build_nvswitches { [] }
Subroutine _build_nvswitches: called CC=1 SCAR=0.0
58  
59 2346 ▶sub fabric_manager_needed {
Subroutine fabric_manager_needed: called CC=2 SCAR=6.9
Pod documented
60 2346 my ( $self ) = @_;
61 2346 ▶ return 1 if grep { ref $_ eq 'HASH' } @{ $self->nvswitches };
Branch: 1 branch
BranchTrueFalseTotal
if grep {ref $_ eq "HASH";} @{$self->nvswitches;} 98 2248 2346
62 2248 return $self->nvlink_fabric_needed;
63 }
64  
65 86 ▶sub fabric_label {
Subroutine fabric_label: called CC=2 SCAR=6.9
Pod documented
66 86 my ( $self ) = @_;
67 86 ▶ return ( grep { ref $_ eq 'HASH' } @{ $self->nvswitches } )
Branch: 1 branch
BranchTrueFalseTotal
grep({ref $_ eq 'HASH';} @{$self->nvswitches;}) ? : 60 26 86
68 ? 'NVSwitch' : 'HGX B200/B300 NVLink fabric';
69 }
70  
71  
72 4011 ▶sub nvlink_platform_ids {
Subroutine nvlink_platform_ids: called CC=1 SCAR=0.0
Pod documented
73 return (
74 4011 '2901' => 'hgx-nvlink5', # B200
75 '2909' => 'hgx-nvlink5', # B200
76 '3182' => 'hgx-nvlink5', # B300 SXM6 AC
77 '2941' => 'nvl72', # GB200
78 '31c2' => 'nvl72', # GB300
79 '31c3' => 'nvl72' # GB300
80 );
81 }
82  
83 4013 ▶sub nvlink_platforms {
Subroutine nvlink_platforms: called CC=2 SCAR=6.9
Pod documented
84 4013 my ( $self ) = @_;
85 4013 my %platform = $self->nvlink_platform_ids;
86 1075 my %seen = map { $_ => 1 }
87 5347 grep { defined }
88 5347 ▶ map { $platform{ lc( $_->{device_id} // '' ) } }
Condition100%2/2
$_->{"device_id"} // ""
l!l
533314
MC/DC100%1/1
$_->{"device_id"} // ""
$_->{"device_id"}
Truth table100%2/2
A
A= $_->{"device_id"}
Aresult
11
00
89 4013 grep { ref $_ eq 'HASH' } @{ $self->gpus };
90 4013 return sort keys %seen;
91 }
92  
93 3568 ▶sub nvlink_fabric_needed {
Subroutine nvlink_fabric_needed: called CC=2 SCAR=6.9
Pod documented
94 3568 my ( $self ) = @_;
95 3568 ▶ return ( grep { $_ eq 'hgx-nvlink5' } $self->nvlink_platforms ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
grep({$_ eq 'hgx-nvlink5';} $self->nvlink_platforms) ? : 136 3432 3568
96 }
97  
98 # extra_requirement may be given as a plain hashref; it becomes an object of
99 # the class's requirement_class here, so a typo croaks at construction -- on
100 # every host, not only on one that gets as far as plan.
101 830 ▶around BUILDARGS => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
102 830 my ( $orig, $class, @args ) = @_;
103 830 my $args = $class->$orig(@args);
104 $args->{extra_requirement} = $class->_coerce_requirement($args->{extra_requirement})
105 830 ▶ if defined $args->{extra_requirement};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args->{"extra_requirement"} 15 815 830
106 826 return $args;
107 49 };
108  
109  
110 49 has requirement => ( is => 'lazy', predicate => '_has_requirement' );
111  
112 49 has extra_requirement => ( is => 'ro', writer => '_set_extra_requirement' );
113  
114 1395 ▶sub requirement_class { 'Rex::GPU::NVIDIA::Requirement' }
Subroutine requirement_class: called CC=1 SCAR=0.0
Pod documented
115  
116 566 ▶sub _build_requirement {
Subroutine _build_requirement: called CC=6 SCAR=17.9
117 566 my ( $self ) = @_;
118 566 my $class = $self->requirement_class;
119 566 my $extra = $self->extra_requirement;
120 566 my @gpus = grep { ref $_ eq 'HASH' } @{ $self->gpus };
121 566 ▶ return $extra // $class->new unless @gpus;
Branch: 1 branch
BranchTrueFalseTotal
unless @gpus 37 529 566
Condition66%2/3
$extra // $class->new
l!l&&r!l&&!r
2350
MC/DC0%0/2
$extra // $class->new
$extra $class->new
Truth table66%2/3
A // B
A= $extraB= $class->new
ABresult
1X1
011
000
122 529 my @reqs = map { $class->from_gpu($_) } @gpus;
123 529 ▶ if ( my @conflicts = $class->conflicts(@reqs) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@conflicts) = $class->conflicts(@reqs)) 24 505 529
124 24 die 'No single NVIDIA driver supports all GPUs on this host: '
125 .join('; ', @conflicts).'. No driver package was installed and no package '
126 .'source was added. Install the '
127 ."driver yourself; once `nvidia-smi -L` lists the GPUs and libcuda.so.1 is in "
128 ."the linker cache, install_driver skips the driver step\n";
129 }
130 505 my $gpu_req = $class->intersect(@reqs);
131 505 ▶ return $gpu_req unless $extra;
Branch: 1 branch
BranchTrueFalseTotal
unless $extra 497 8 505
132 # The user's requirement only tightens (karr #34): a conflict with what the
133 # GPUs need dies here, in plan, before anything on the host is changed.
134 8 ▶ if ( my @conflicts = $class->conflicts($gpu_req, $extra) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@conflicts) = $class->conflicts($gpu_req, $extra)) 2 6 8
135 2 die 'No NVIDIA driver meets both what the GPUs need and '.$extra->who.' ('
136 .$extra->describe.'): '.join('; ', @conflicts).'. No driver package was '
137 .'installed and no package source was added. '
138 ."Loosen the requirement, or install the driver yourself\n";
139 }
140 6 return $class->intersect($gpu_req, $extra);
141 }
142  
143 49 my %REQUIREMENT_KEY = map { $_ => 1 } qw( kernel_module min_branch max_branch name );
144  
145 # A hashref or requirement object -> requirement object. Callable on the class
146 # (BUILDARGS) and on an object (adopt).
147 17 ▶sub _coerce_requirement {
Subroutine _coerce_requirement: called CC=7 SCAR=19.7
148 17 my ( $self, $req ) = @_;
149 17 my $base = $self->requirement_class;
150 17 ▶ return $req if blessed($req) && $req->isa($base);
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($req) and $req->isa($base) 1 16 17
Condition66%2/3
builtin::blessed($req) and $req->isa($base)
!ll&&!rl&&r
1601
MC/DC50%1/2
builtin::blessed($req) and $req->isa($base)
builtin::blessed($req) $req->isa($base)
Truth table66%2/3
A and B
A= builtin::blessed($req)B= $req->isa($base)
ABresult
0X0
100
111
151 16 ▶ croak __PACKAGE__.': a requirement is a hashref or a '.$base.' object, not '
Branch: 2 branches
BranchTrueFalseTotal
unless ref $req eq "HASH" 1 15 16
defined $req ? : 1 0 1
152 .( defined $req ? "'".$req."'" : 'undef' )
153 unless ref $req eq 'HASH';
154 15 my @unknown = sort grep { !$REQUIREMENT_KEY{$_} } keys %$req;
155 15 ▶ croak __PACKAGE__.': unknown requirement key'.( @unknown == 1 ? '' : 's' ).' '
Branch: 2 branches
BranchTrueFalseTotal
if @unknown 2 13 15
@unknown == 1 ? : 2 0 2
156 .join(', ', @unknown).' -- known: kernel_module, min_branch, max_branch, name'
157 if @unknown;
158 13 return $self->requirement_class->new(name => 'the requirement option', %$req);
159 }
160  
161  
162 12 ▶sub adopt {
Subroutine adopt: called CC=17 SCAR=28.4
Pod documented
163 12 my ( $self, %arg ) = @_;
164 12 ▶ my $gpus = $arg{gpus} // [];
Condition100%2/2
$arg{"gpus"} // []
l!l
111
MC/DC100%1/1
$arg{"gpus"} // []
$arg{"gpus"}
Truth table100%2/2
A
A= $arg{"gpus"}
Aresult
11
00
165 12 ▶ croak __PACKAGE__.'->adopt: gpus must be an arrayref of GPU hashrefs'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $gpus eq "ARRAY" 0 12 12
166 unless ref $gpus eq 'ARRAY';
167 12 ▶ croak ref($self).' object passed as setup => has already run install -- it '
Branch: 1 branch
BranchTrueFalseTotal
if $self->_installed 1 11 12
168 .'holds that host\'s facts and GPUs. Build a new object per host, or pass a '
169 .'class name. No driver package was installed and no package source was added'
170 if $self->_installed;
171 my $extra = defined $arg{extra_requirement}
172 11 ▶ ? $self->_coerce_requirement($arg{extra_requirement}) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $arg{'extra_requirement'} ? : 2 9 11
173 11 $self->_check_gpus($gpus);
174 10 ▶ my $nvswitches = $arg{nvswitches} // [];
Condition100%2/2
$arg{"nvswitches"} // []
l!l
19
MC/DC100%1/1
$arg{"nvswitches"} // []
$arg{"nvswitches"}
Truth table100%2/2
A
A= $arg{"nvswitches"}
Aresult
11
00
175 10 ▶ croak __PACKAGE__.'->adopt: nvswitches must be an arrayref'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $nvswitches eq "ARRAY" 0 10 10
176 unless ref $nvswitches eq 'ARRAY';
177 # NVSwitches add the Fabric Manager step and a source filter plan applies;
178 # they do not touch the requirement, so no fixed-requirement check for them.
179 10 ▶ $self->_set_nvswitches($nvswitches) if @$nvswitches && !@{ $self->nvswitches };
Branch: 1 branch
BranchTrueFalseTotal
if @$nvswitches and not @{$self->nvswitches;} 1 9 10
Condition66%2/3
@$nvswitches and not @{$self->nvswitches;}
!ll&&!rl&&r
901
MC/DC50%1/2
@$nvswitches and not @{$self->nvswitches;}
@$nvswitches not @{$self->nvswitches;}
Truth table66%2/3
A and not(B)
A= @$nvswitchesB= not @{$self->nvswitches;}
ABresult
0X0
100
111
180 10 ▶ my $take_gpus = @$gpus && !@{ $self->gpus };
Condition100%3/3
@$gpus && !@{$self->gpus;}
!ll&&!rl&&r
415
MC/DC100%2/2
@$gpus && !@{$self->gpus;}
@$gpus !@{$self->gpus;}
Truth table100%3/3
A && not(B)
A= @$gpusB= !@{$self->gpus;}
ABresult
0X0
100
111
181 10 ▶ return $self unless $take_gpus || $extra;
Branch: 1 branch
BranchTrueFalseTotal
unless $take_gpus or $extra 3 7 10
Condition100%3/3
$take_gpus or $extra
l!l&&r!l&&!r
523
MC/DC100%2/2
$take_gpus or $extra
$take_gpus $extra
Truth table100%3/3
A or B
A= $take_gpusB= $extra
ABresult
1X1
011
000
182 7 ▶ croak ref($self).' object passed as setup => already has a fixed requirement '
Branch: 1 branch
BranchTrueFalseTotal
if $self->_has_requirement 1 6 7
183 .'(given to new or built by plan), so the detected GPUs or the requirement '
184 .'option could not be checked. Build it without requirement =>, or pass a '
185 .'class name. No driver package was installed and no package source was added'
186 if $self->_has_requirement;
187 6 ▶ croak ref($self).' object passed as setup => has an extra_requirement of its '
Branch: 1 branch
BranchTrueFalseTotal
if $extra and $self->extra_requirement 1 5 6
Condition100%3/3
$extra and $self->extra_requirement
!ll&&!rl&&r
411
MC/DC100%2/2
$extra and $self->extra_requirement
$extra $self->extra_requirement
Truth table100%3/3
A and B
A= $extraB= $self->extra_requirement
ABresult
0X0
100
111
188 .'own and the requirement option was given too; pass one of them. No driver '
189 .'package was installed and no package source was added'
190 if $extra && $self->extra_requirement;
191 5 ▶ $self->_set_gpus($gpus) if $take_gpus;
Branch: 1 branch
BranchTrueFalseTotal
if $take_gpus 4 1 5
192 5 ▶ $self->_set_extra_requirement($extra) if $extra;
Branch: 1 branch
BranchTrueFalseTotal
if $extra 1 4 5
193 5 return $self;
194 }
195  
196  
197 49 has os => ( is => 'lazy' );
198 49 has release => ( is => 'lazy' );
199 49 has arch => ( is => 'lazy' );
200 49 has kernel => ( is => 'lazy' );
201  
202 472 ▶sub _build_os { Rex::Commands::Gather::operating_system() }
Subroutine _build_os: called CC=1 SCAR=0.0
203 385 ▶sub _build_release { Rex::Commands::Gather::operating_system_release() }
Subroutine _build_release: called CC=1 SCAR=0.0
204  
205 162 ▶sub _build_arch {
Subroutine _build_arch: called CC=2 SCAR=7.0
206 162 my ( $self ) = @_;
207 162 my $arch = $self->run_cmd('uname -m', auto_die => 0);
208 162 ▶ chomp $arch if defined $arch;
Branch: 1 branch
BranchTrueFalseTotal
if defined $arch 162 0 162
209 162 return $arch;
210 }
211  
212 473 ▶sub _build_kernel {
Subroutine _build_kernel: called CC=1 SCAR=0.0
213 473 my ( $self ) = @_;
214 # auto_die left to Rex's default, as install_driver always read it
215 473 my $kernel = $self->run_cmd('uname -r');
216 473 chomp $kernel;
217 473 return $kernel;
218 }
219  
220 #### The host seam ############################################################
221  
222  
223 5773 ▶sub run_cmd { my ( $self, @args ) = @_; return Rex::Commands::Run::run(@args) }
Subroutine run_cmd: called CC=1 SCAR=0.0
Pod documented
224 121 ▶sub pkg_cmd { my ( $self, @args ) = @_; return Rex::Commands::Pkg::pkg(@args) }
Subroutine pkg_cmd: called CC=1 SCAR=0.0
Pod documented
225 476 ▶sub file_cmd { my ( $self, @args ) = @_; return Rex::Commands::File::file(@args) }
Subroutine file_cmd: called CC=1 SCAR=0.0
Pod documented
226  
227 #### The flow #################################################################
228  
229  
230 # Set once install starts: the object has read (and cached) one host's facts
231 # and GPUs, so adopt refuses to hand it to another host.
232 49 has _installed => ( is => 'rwp', init_arg => undef );
233  
234 594 ▶sub install {
Subroutine install: called CC=4 SCAR=13.9
Pod documented
235 594 my ( $self ) = @_;
236 594 $self->_set__installed(1);
237 594 ▶ return 0 if $self->already_installed;
Branch: 1 branch
BranchTrueFalseTotal
if $self->already_installed 62 532 594
238 532 my $plan = $self->plan;
239 426 $self->prepare_host($plan);
240 424 $self->prepare_source($plan);
241 412 $self->resolve_plan($plan);
242 404 $self->install_packages($plan);
243 404 $self->verify_packages($plan);
244 399 $self->verify_driver_branch($plan);
245 389 ▶ $self->install_fabric_manager($plan) if $self->fabric_manager_needed;
Branch: 1 branch
BranchTrueFalseTotal
if $self->fabric_manager_needed 21 368 389
246 385 ▶ $self->install_nvlink_fabric($plan) if $self->nvlink_fabric_needed;
Branch: 1 branch
BranchTrueFalseTotal
if $self->nvlink_fabric_needed 12 373 385
247 383 $self->post_install($plan);
248 383 return 1;
249 }
250  
251  
252 596 ▶sub already_installed {
Subroutine already_installed: called CC=4 SCAR=13.9
Pod documented
253 596 my ( $self ) = @_;
254 # nvidia-smi -L lists a "GPU N:" device only when the module is loaded and
255 # functional, so it is the safe, OS-neutral signal. Distro-neutral and
256 # BEFORE package selection: a host set up from NVIDIA's CUDA repo would
257 # otherwise get a different (possibly lower) driver whose libs conflict.
258 596 my $smi = $self->run_cmd('nvidia-smi -L 2>&1', auto_die => 0);
259 596 ▶ chomp $smi if defined $smi;
Branch: 1 branch
BranchTrueFalseTotal
if defined $smi 596 0 596
260 596 ▶ return 0 unless $self->_driver_present($smi);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_driver_present($smi) 511 85 596
261 # ... and libcuda (karr #42): a module without the CUDA user-space library
262 # cannot run a CUDA workload, so it is not "installed". Probed only after
263 # nvidia-smi passed: a fresh host runs no more than the one probe.
264 85 ▶ unless ($self->_libcuda_present) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_libcuda_present) 23 62 85
265 23 Rex::Logger::info("nvidia-smi lists a GPU ($smi) but libcuda.so.1 is not in the "
266 .'linker cache (ldconfig -p) — installing the driver packages', 'warn');
267 23 return 0;
268 }
269 62 Rex::Logger::info("NVIDIA driver already present and working — skipping driver install ($smi)");
270 62 return 1;
271 }
272  
273 462 ▶sub libcuda_command { q{/sbin/ldconfig -p 2>/dev/null | grep -q '^[[:space:]]*libcuda\.so\.1 '} }
Subroutine libcuda_command: called CC=1 SCAR=0.0
Pod documented
274  
275 # Runs libcuda_command; 1 if it exited 0.
276 85 ▶sub _libcuda_present {
Subroutine _libcuda_present: called CC=2 SCAR=6.9
277 85 my ( $self ) = @_;
278 85 $self->run_cmd($self->libcuda_command, auto_die => 0);
279 85 ▶ return $? == 0 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$? == 0 ? : 62 23 85
280 }
281  
282  
283 633 ▶sub plan {
Subroutine plan: called CC=10 SCAR=23.0
Pod documented
284 633 my ( $self ) = @_;
285 # vGPU guest (karr #24): after already_installed (a guest whose vGPU
286 # driver runs passes there) and before anything on the host is changed.
287 633 $self->_reject_vgpu_guest;
288 # Kepler or older (karr #26), on any GPU in the list: die here, after
289 # already_installed (a host whose operator installed 470 by hand still
290 # passes) and before anything on the host is changed or even read.
291 607 $self->_reject_unsupported_gpu($_) for @{ $self->gpus };
292 # Multi-GPU (karr #33): one driver for all of them, or die untouched.
293 559 my $requirement = $self->requirement;
294 535 Rex::Logger::info('Installing NVIDIA drivers on '.$self->os.' (kernel '.$self->kernel.')');
295 Rex::Logger::info(' Driver requirement: '.$requirement->who.': '.$requirement->describe)
296 535 ▶ if @{ $self->gpus } || $self->extra_requirement;
Branch: 1 branch
BranchTrueFalseTotal
if @{$self->gpus;} or $self->extra_requirement 500 35 535
Condition66%2/3
@{$self->gpus;} or $self->extra_requirement
l!l&&r!l&&!r
500035
MC/DC50%1/2
@{$self->gpus;} or $self->extra_requirement
@{$self->gpus;} $self->extra_requirement
Truth table66%2/3
A or B
A= @{$self->gpus;}B= $self->extra_requirement
ABresult
1X1
011
000
297  
298 535 my $plan = { packages => [ $self->kernel_packages ], verify => [] };
299 535 my @sources = $self->sources;
300 535 ▶ return $plan unless @sources;
Branch: 1 branch
BranchTrueFalseTotal
unless @sources 1 534 535
301 534 my $source = $self->select_source(@sources);
302 # HGX B200/B300 (karr #56): nvlsm must have a source too, known before any
303 # change -- a driver without it cannot run CUDA there either.
304 511 ▶ if ($self->nvlink_fabric_needed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->nvlink_fabric_needed) 26 485 511
305 26 my $why = $self->nvlink_fabric_unavailable($source);
306 26 ▶ die 'HGX B200/B300 on this '.$self->os.' '.( $self->release // '' ).' host: '.$why
Branch: 1 branch
BranchTrueFalseTotal
if defined $why 3 23 26
Condition50%1/2
$self->release // ""
l!l
30
MC/DC0%0/1
$self->release // ""
$self->release
Truth table50%1/2
A
A= $self->release
Aresult
11
00
307 .'. Without nvlsm and Fabric Manager CUDA fails with cudaErrorSystemNotReady, so '
308 .'no driver package was installed and no package source was added. Install the '
309 ."driver, Fabric Manager and nvlsm yourself\n" if defined $why;
310 }
311 508 $plan->{source} = $source;
312 508 ▶ push @{ $plan->{packages} }, @{ $source->{packages} // [] };
Condition100%2/2
$source->{"packages"} // []
l!l
408100
MC/DC100%1/1
$source->{"packages"} // []
$source->{"packages"}
Truth table100%2/2
A
A= $source->{"packages"}
Aresult
11
00
313 508 ▶ $plan->{verify} = [ @{ $source->{verify} // [] } ];
Condition100%2/2
$source->{"verify"} // []
l!l
408100
MC/DC100%1/1
$source->{"verify"} // []
$source->{"verify"}
Truth table100%2/2
A
A= $source->{"verify"}
Aresult
11
00
314 508 return $plan;
315 }
316  
317 81 ▶sub kernel_packages { () }
Subroutine kernel_packages: called CC=1 SCAR=0.0
Pod documented
318 1 ▶sub sources { () }
Subroutine sources: called CC=1 SCAR=0.0
Pod documented
319  
320 312 ▶sub resolve_source {
Subroutine resolve_source: called CC=1 SCAR=0.0
Pod documented
321 312 my ( $self, $source ) = @_;
322 312 return $source;
323 }
324  
325 534 ▶sub select_source {
Subroutine select_source: called CC=6 SCAR=17.9
Pod documented
326 534 my ( $self, @candidates ) = @_;
327 534 my $requirement = $self->requirement;
328 534 my @rejected;
329 534 for my $candidate (@candidates) {
330 775 ▶ my $why = $candidate->{unavailable} // $requirement->why_not($candidate)
Condition100%6/6
($candidate->{"unavailable"} // $requirement->why_not($candidate)) // $self->_fabric_manager_why_not($candidate)
l!l&&r!l&&!r
2586511
$candidate->{"unavailable"} // $requirement->why_not($candidate)
l!l&&r!l&&!r
18240517
MC/DC100%3/3
($candidate->{"unavailable"} // $requirement->why_not($candidate)) // $self->_fabric_manager_why_not($candidate)
$candidate->{"unavailable"} $requirement->why_not($candidate) $self->_fabric_manager_why_not($candidate)
Truth table100%4/4
A // B // C
A= $candidate->{"unavailable"}B= $requirement->why_not($candidate)C= $self->_fabric_manager_why_not($candidate)
ABCresult
1XX1
01X1
0011
0000
331 // $self->_fabric_manager_why_not($candidate);
332 775 ▶ unless (defined $why) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $why) 511 264 775
333 511 Rex::Logger::info(' Driver source: '.$candidate->{name});
334 511 return $candidate;
335 }
336 264 push @rejected, $candidate->{name}.': '.$why;
337 }
338 23 ▶ die 'No NVIDIA driver source on this '.$self->os.' '.( $self->release // '' ).' host fits '
Condition100%2/2
$self->release // ""
l!l
221
MC/DC100%1/1
$self->release // ""
$self->release
Truth table100%2/2
A
A= $self->release
Aresult
11
00
339 .$requirement->who.' ('.$requirement->describe.') -- '.join('; ', @rejected)
340 .'. No driver package was installed and no package source was added. Install '
341 .'the driver yourself; once '
342 ."`nvidia-smi -L` lists the GPU and libcuda.so.1 is in the linker cache, "
343 ."install_driver skips the driver step\n";
344 }
345  
346 418 ▶sub resolve_plan {
Subroutine resolve_plan: called CC=11 SCAR=24.5
Pod documented
347 418 my ( $self, $plan ) = @_;
348 418 ▶ my $source = $plan->{source} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $source = $plan->{"source"} or return 418 0 418
349 # After prepare_source (karr #35): the package index is fresh now, so a
350 # source that picks its package from it (Ubuntu's apt-cache search) sees
351 # what the repository carries, not a fresh image's stale or empty lists.
352 418 my $resolved = $self->resolve_source($source);
353 418 my $requirement = $self->requirement;
354 418 ▶ my $why = $resolved->{unavailable} // $requirement->why_not($resolved);
Condition100%3/3
$resolved->{"unavailable"} // $requirement->why_not($resolved)
l!l&&r!l&&!r
73408
MC/DC100%2/2
$resolved->{"unavailable"} // $requirement->why_not($resolved)
$resolved->{"unavailable"} $requirement->why_not($resolved)
Truth table100%3/3
A // B
A= $resolved->{"unavailable"}B= $requirement->why_not($resolved)
ABresult
1X1
011
000
355 418 ▶ die 'The NVIDIA driver source '.$source->{name}.' chosen for '.$requirement->who
Branch: 1 branch
BranchTrueFalseTotal
if defined $why 10 408 418
Condition50%1/2
$self->release // ""
l!l
100
MC/DC0%0/1
$self->release // ""
$self->release
Truth table50%1/2
A
A= $self->release
Aresult
11
00
356 .' ('.$requirement->describe.') has nothing to install on this '.$self->os.' '
357 .( $self->release // '' ).' host: '.$why.'. No driver package was installed, '
358 .'only the package sources were prepared. Install the driver yourself; once '
359 ."`nvidia-smi -L` lists the GPU and libcuda.so.1 is in the linker cache, "
360 ."install_driver skips the driver step\n"
361 if defined $why;
362 408 ▶ $self->_check_fabric_manager_source($resolved) if $self->fabric_manager_needed;
Branch: 1 branch
BranchTrueFalseTotal
if $self->fabric_manager_needed 25 383 408
363 407 ▶ return if $resolved == $source;
Branch: 1 branch
BranchTrueFalseTotal
if $resolved == $source 337 70 407
364 0 ▶ my %old = map { $_ => 1 } @{ $source->{packages} // [] };
Condition50%1/2
$source->{"packages"} // []
l!l
070
MC/DC0%0/1
$source->{"packages"} // []
$source->{"packages"}
Truth table50%1/2
A
A= $source->{"packages"}
Aresult
11
00
365 70 $plan->{source} = $resolved;
366 70 $plan->{packages} = [ ( grep { !$old{$_} } @{ $plan->{packages} } ),
367 70 ▶ @{ $resolved->{packages} // [] } ];
Condition50%1/2
$resolved->{"packages"} // []
l!l
700
MC/DC0%0/1
$resolved->{"packages"} // []
$resolved->{"packages"}
Truth table50%1/2
A
A= $resolved->{"packages"}
Aresult
11
00
368 70 ▶ $plan->{verify} = [ @{ $resolved->{verify} // [] } ];
Condition50%1/2
$resolved->{"verify"} // []
l!l
700
MC/DC0%0/1
$resolved->{"verify"} // []
$resolved->{"verify"}
Truth table50%1/2
A
A= $resolved->{"verify"}
Aresult
11
00
369 70 ▶ Rex::Logger::info(' Driver packages: '.join(', ', @{ $resolved->{packages} // [] }));
Condition50%1/2
$resolved->{"packages"} // []
l!l
700
MC/DC0%0/1
$resolved->{"packages"} // []
$resolved->{"packages"}
Truth table50%1/2
A
A= $resolved->{"packages"}
Aresult
11
00
370 70 return;
371 }
372  
373 # NVSwitch host (karr #23): a source that names no Fabric Manager package
374 # cannot make the GPUs usable -- without Fabric Manager CUDA init fails with
375 # cudaErrorSystemNotReady -- so it does not fit, like a wrong branch.
376 517 ▶sub _fabric_manager_why_not {
Subroutine _fabric_manager_why_not: called CC=3 SCAR=11.0
377 517 my ( $self, $source ) = @_;
378 517 ▶ return unless $self->fabric_manager_needed;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->fabric_manager_needed 474 43 517
379 43 ▶ return if defined $source->{fabric_manager};
Branch: 1 branch
BranchTrueFalseTotal
if defined $source->{"fabric_manager"} 37 6 43
380 6 return 'no NVIDIA Fabric Manager package for the '.$self->fabric_label.' on this host';
381 }
382  
383 # After resolve (the branch is exact now): the package name must be complete
384 # and the repository must carry it -- dies before any driver package goes in.
385 25 ▶sub _check_fabric_manager_source {
Subroutine _check_fabric_manager_source: called CC=4 SCAR=14.5
386 25 my ( $self, $source ) = @_;
387 25 my $fm = $self->fabric_manager_package($source);
388 my $why = defined $fm
389 ? $self->fabric_manager_unavailable($fm)
390 25 ▶ : 'its Fabric Manager package '.( $source->{fabric_manager} // '(none)' )
Branch: 1 branch
BranchTrueFalseTotal
defined $fm ? : 25 0 25
Condition0%0/2
$source->{"fabric_manager"} // "(none)"
l!l
00
MC/DC0%0/1
$source->{"fabric_manager"} // "(none)"
$source->{"fabric_manager"}
Truth table0%0/2
A
A= $source->{"fabric_manager"}
Aresult
11
00
391 .' needs an exact driver branch, and none is known';
392 25 ▶ die 'The NVIDIA driver source '.$source->{name}.' has no Fabric Manager for the '
Branch: 1 branch
BranchTrueFalseTotal
if defined $why 1 24 25
393 .$self->fabric_label.' on this host: '.$why.'. No driver package was installed, only the package sources '
394 ."were prepared. Install the driver and a Fabric Manager of exactly its version yourself\n"
395 if defined $why;
396 24 Rex::Logger::info(' Fabric Manager package: '.$fm);
397 24 return;
398 }
399  
400  
401 84 ▶sub fabric_manager_package {
Subroutine fabric_manager_package: called CC=1 SCAR=0.0
Pod documented
402 84 my ( $self, $source ) = @_;
403 84 return $self->_with_branch($source->{fabric_manager}, $source);
404 }
405  
406 9 ▶sub fabric_manager_unavailable { return }
Subroutine fabric_manager_unavailable: called CC=1 SCAR=0.0
Pod documented
407  
408 103 ▶sub fabric_manager_service { 'nvidia-fabricmanager.service' }
Subroutine fabric_manager_service: called CC=1 SCAR=0.0
Pod documented
409  
410 23 ▶sub install_fabric_manager {
Subroutine install_fabric_manager: called CC=6 SCAR=18.5
Pod documented
411 23 my ( $self, $plan ) = @_;
412 23 ▶ my $source = $plan->{source} // {};
Condition50%1/2
$plan->{"source"} // {}
l!l
230
MC/DC0%0/1
$plan->{"source"} // {}
$plan->{"source"}
Truth table50%1/2
A
A= $plan->{"source"}
Aresult
11
00
413 23 my $fm = $self->fabric_manager_package($source);
414 23 ▶ die 'No Fabric Manager package is known for the '.$self->fabric_label.' on this host; the '
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fm 0 23 23
415 ."driver is installed, Fabric Manager is not\n" unless defined $fm;
416 23 my $version = $self->installed_driver_version($source);
417 21 ▶ die 'Cannot read the installed NVIDIA driver version ('.( $version // 'nothing' ).'); '
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_driver_version($version) 0 21 21
Condition0%0/2
$version // "nothing"
l!l
00
MC/DC0%0/1
$version // "nothing"
$version
Truth table0%0/2
A
A= $version
Aresult
11
00
418 .'Fabric Manager must match it exactly, so none was installed. The driver is '
419 ."installed, Fabric Manager is not\n"
420 unless $self->_is_driver_version($version);
421 21 Rex::Logger::info(' Installing NVIDIA Fabric Manager '.$fm.' '.$version.' ('.$self->fabric_label.')');
422 21 $self->install_versioned_package($fm, $version);
423 20 $self->verify_versioned_package($fm, $version);
424 18 my $unit = $self->fabric_manager_service;
425 18 $self->run_cmd('systemctl enable '.$unit, auto_die => 0);
426 18 ▶ die 'systemctl enable '.$unit.' failed after installing '.$fm.' '.$version."\n"
Branch: 1 branch
BranchTrueFalseTotal
if $? != 0 1 17 18
427 if $? != 0;
428 17 return;
429 }
430  
431  
432 24 ▶sub retrofit_fabric_manager {
Subroutine retrofit_fabric_manager: called CC=16 SCAR=27.7
Pod documented
433 24 my ( $self ) = @_;
434 24 ▶ return 0 unless $self->fabric_manager_needed;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->fabric_manager_needed 0 24 24
435 24 my $unit = $self->fabric_manager_service;
436 24 my $version = $self->loaded_driver_version;
437 24 my @present = $self->installed_fabric_managers;
438 24 ▶ if (@present) {
Branch: 1 branch
BranchTrueFalseTotal
if (@present) 7 17 24
439 7 ▶ my @other = grep { !defined $version || !defined $_->[1] || $_->[1] ne $version } @present;
Condition83%5/6
!(defined $version && defined $_->[1]) || $_->[1] ne $version
l!l&&r!l&&!r
115
defined $version && defined $_->[1]
!ll&&!rl&&r
016
MC/DC66%2/3
!(defined $version && defined $_->[1]) || $_->[1] ne $version
defined $version defined $_->[1] $_->[1] ne $version
Truth table75%3/4
not(A && B) || C
A= defined $versionB= defined $_->[1]C= $_->[1] ne $version
ABCresult
0XX1
10X1
1111
1100
440 7 ▶ Rex::Logger::info($self->fabric_label.': Fabric Manager '.join(', ', map { $_->[0].' '.( $_->[1] // 'unknown' ) } @other)
Branch: 1 branch
BranchTrueFalseTotal
if @other 2 5 7
Condition75%3/4
$_->[1] // "unknown"
l!l
11
$version // "unknown"
l!l
20
MC/DC100%1/1
$_->[1] // "unknown"
$_->[1]
MC/DC0%0/1
$version // "unknown"
$version
Truth table100%2/2
A
A= $_->[1]
Aresult
11
00
Truth table50%1/2
A
A= $version
Aresult
11
00
441 .' is installed, but the loaded NVIDIA driver is '.( $version // 'unknown' )
442 .'. Fabric Manager must match the driver exactly or '.$unit.' refuses to start; '
443 .'it is left as it is -- install the matching version yourself', 'warn')
444 if @other;
445 7 return 0;
446 }
447 17 my $fix = 'install NVIDIA Fabric Manager of exactly the loaded driver version yourself';
448 17 ▶ unless ($self->_is_driver_version($version)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_is_driver_version($version)) 3 14 17
449 3 Rex::Logger::info($self->fabric_label.' present and no Fabric Manager installed, but the loaded '
450 .'driver version cannot be read (nvidia-smi --query-gpu=driver_version); nothing '
451 .'was installed -- '.$fix, 'warn');
452 3 return 0;
453 }
454 14 my ($branch) = $version =~ /^(\d+)\./;
455 14 my ( %seen, @packages );
456 14 for my $source ($self->sources) {
457 35 my $fm = $self->fabric_manager_package({ %$source, branch => $branch });
458 35 ▶ push @packages, $fm if defined $fm && !$seen{$fm}++;
Branch: 1 branch
BranchTrueFalseTotal
if defined $fm and not $seen{$fm}++ 13 22 35
Condition100%3/3
defined $fm and not $seen{$fm}++
!ll&&!rl&&r
41813
MC/DC100%2/2
defined $fm and not $seen{$fm}++
defined $fm not $seen{$fm}++
Truth table100%3/3
A and not(B)
A= defined $fmB= not $seen{$fm}++
ABresult
0X0
100
111
459 }
460 14 ▶ unless (@packages) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@packages) 1 13 14
461 1 Rex::Logger::info($self->fabric_label.' present and no Fabric Manager installed: no driver source '
462 .'Rex::GPU knows on this '.$self->os.' host has a Fabric Manager package, so none is '
463 .'installed for the loaded driver '.$version.' -- '.$fix, 'warn');
464 1 return 0;
465 }
466 13 $self->refresh_package_index;
467 13 my @why;
468 13 for my $fm (@packages) {
469 13 my $why = $self->fabric_manager_version_unavailable($fm, $version);
470 13 ▶ if (defined $why) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $why) 6 7 13
471 6 push @why, $why;
472 6 next;
473 }
474 7 Rex::Logger::info(' Installing NVIDIA Fabric Manager '.$fm.' '.$version
475 .' for the already-installed driver ('.$self->fabric_label.')');
476 7 $self->install_versioned_package($fm, $version);
477 7 $self->verify_versioned_package($fm, $version);
478 6 $self->run_cmd('systemctl enable '.$unit, auto_die => 0);
479 6 ▶ die 'systemctl enable '.$unit.' failed after installing '.$fm.' '.$version
Branch: 1 branch
BranchTrueFalseTotal
if $? != 0 1 5 6
480 ."; the driver is unchanged\n" if $? != 0;
481 5 return 1;
482 }
483 6 Rex::Logger::info($self->fabric_label.' present and no Fabric Manager installed: the package sources '
484 .'configured on this host offer none for the loaded driver '.$version.' ('
485 .join('; ', @why).'). No package source was added and nothing was installed -- '
486 .$fix, 'warn');
487 6 return 0;
488 }
489  
490 0 ▶sub installed_fabric_managers { () }
Subroutine installed_fabric_managers: not called CC=1 SCAR=6.9
Pod documented
491  
492 24 ▶sub loaded_driver_version {
Subroutine loaded_driver_version: called CC=6 SCAR=18.0
Pod documented
493 24 my ( $self ) = @_;
494 24 my $out = $self->run_cmd('nvidia-smi --query-gpu=driver_version --format=csv,noheader 2>&1',
495 auto_die => 0);
496 24 ▶ return if $? != 0 || !defined $out;
Branch: 1 branch
BranchTrueFalseTotal
if $? != 0 or not defined $out 1 23 24
Condition66%2/3
$? != 0 or not defined $out
l!l&&r!l&&!r
1023
MC/DC50%1/2
$? != 0 or not defined $out
$? != 0 not defined $out
Truth table66%2/3
A or not(B)
A= $? != 0B= not defined $out
ABresult
1X1
011
000
497 23 my %v;
498 23 $v{ s/^\s+|\s+$//gr } = 1 for grep { /\S/ } split /\n/, $out;
499 23 ▶ return unless keys %v == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless keys %v == 1 2 21 23
500 21 my ($version) = keys %v;
501 21 ▶ return $self->_is_driver_version($version) ? $version : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_driver_version($version) ? : 21 0 21
502 }
503  
504 4 ▶sub refresh_package_index { }
Subroutine refresh_package_index: called CC=1 SCAR=0.0
Pod documented
505  
506 0 ▶sub fabric_manager_version_unavailable {
Subroutine fabric_manager_version_unavailable: not called CC=1 SCAR=6.9
Pod documented
507 0 my ( $self, $pkg ) = @_;
508 0 return ref($self).' cannot list the versions of '.$pkg.' its package sources offer';
509 }
510  
511 # Pure: is this package name a Fabric Manager (nvidia-fabricmanager,
512 # nvidia-fabricmanager-580, the older nvidia-fabric-manager)? Not -dev or
513 # libnvidia-nscq.
514 15 ▶sub _is_fabric_manager_name {
Subroutine _is_fabric_manager_name: called CC=3 SCAR=11.1
515 15 my ( $self, $name ) = @_;
516 15 ▶ return defined $name && $name =~ /\Anvidia-fabric-?manager(?:-\d+)?\z/ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $name && $name =~ /\Anvidia-fabric-?manager(?:-\d+)?\z/ ? : 11 4 15
Condition66%2/3
defined $name and $name =~ /\Anvidia-fabric-?manager(?:-\d+)?\z/
!ll&&!rl&&r
0411
MC/DC50%1/2
defined $name and $name =~ /\Anvidia-fabric-?manager(?:-\d+)?\z/
defined $name $name =~ /\Anvidia-fabric-?manager(?:-\d+)?\z/
Truth table66%2/3
A and B
A= defined $nameB= $name =~ /\Anvidia-fabric-?manager(?:-\d+)?\z/
ABresult
0X0
100
111
517 }
518  
519 0 ▶sub installed_driver_version {
Subroutine installed_driver_version: not called CC=1 SCAR=6.9
Pod documented
520 0 my ( $self ) = @_;
521 0 die ref($self)." has no packaging layer to read the driver version from\n";
522 }
523  
524 # The package the source's $key (default fabric_manager_match) names, %s
525 # filled with the exact branch -- for the packaging layers'
526 # installed_driver_version. Dies when there is none; the message says what
527 # that leaves undone.
528 413 ▶sub _driver_version_package {
Subroutine _driver_version_package: called CC=4 SCAR=13.9
529 413 my ( $self, $source, $key ) = @_;
530 413 ▶ $key //= 'fabric_manager_match';
Condition100%2/2
$key //= "fabric_manager_match"
l!l
38825
MC/DC100%1/1
$key //= "fabric_manager_match"
$key
Truth table100%2/2
A
A= $key
Aresult
11
00
531 413 my $pkg = $self->_with_branch($source->{$key}, $source);
532 413 ▶ return $pkg if defined $pkg;
Branch: 1 branch
BranchTrueFalseTotal
if defined $pkg 410 3 413
533 3 ▶ die 'The driver source names no package to read the driver version from ('.$key.'); the '
Branch: 1 branch
BranchTrueFalseTotal
$key eq 'fabric_manager_match' ? : 3 0 3
534 .( $key eq 'fabric_manager_match'
535 ? 'driver is installed, Fabric Manager is not'
536 : 'driver packages are installed, their branch was not checked and nothing after them ran' )
537 ."\n";
538 }
539  
540 0 ▶sub install_versioned_package {
Subroutine install_versioned_package: not called CC=1 SCAR=6.9
Pod documented
541 0 my ( $self ) = @_;
542 0 die ref($self)." has no packaging layer to install Fabric Manager with\n";
543 }
544  
545 0 ▶sub verify_versioned_package {
Subroutine verify_versioned_package: not called CC=1 SCAR=6.9
Pod documented
546 0 my ( $self ) = @_;
547 0 die ref($self)." has no packaging layer to verify Fabric Manager with\n";
548 }
549  
550 # Pure: an NVIDIA driver version, "580.95.05" / "570.211.01" -- two or three
551 # dot-separated numbers, nothing else.
552 61 ▶sub _is_driver_version {
Subroutine _is_driver_version: called CC=3 SCAR=11.0
553 61 my ( $self, $version ) = @_;
554 61 ▶ return defined $version && $version =~ /\A\d+\.\d+(?:\.\d+)?\z/ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $version && $version =~ /\A\d+\.\d+(?:\.\d+)?\z/ ? : 57 4 61
Condition100%3/3
defined $version and $version =~ /\A\d+\.\d+(?:\.\d+)?\z/
!ll&&!rl&&r
3157
MC/DC100%2/2
defined $version and $version =~ /\A\d+\.\d+(?:\.\d+)?\z/
defined $version $version =~ /\A\d+\.\d+(?:\.\d+)?\z/
Truth table100%3/3
A and B
A= defined $versionB= $version =~ /\A\d+\.\d+(?:\.\d+)?\z/
ABresult
0X0
100
111
555 }
556  
557 # Pure: a source key's %s filled with the source's exact branch; undef when
558 # there is no key, or a %s and no exact branch.
559 497 ▶sub _with_branch {
Subroutine _with_branch: called CC=4 SCAR=13.9
560 497 my ( $self, $name, $source ) = @_;
561 497 ▶ return unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 7 490 497
562 490 ▶ return $name unless $name =~ /%s/;
Branch: 1 branch
BranchTrueFalseTotal
unless $name =~ /%s/ 433 57 490
563 57 ▶ return unless defined $source->{branch};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $source->{"branch"} 1 56 57
564 56 ( my $filled = $name ) =~ s/%s/$source->{branch}/g;
565 56 return $filled;
566 }
567  
568 #### HGX B200/B300 NVLink fabric (karr #56) ###################################
569  
570  
571 0 ▶sub nvlink_fabric_packages { () }
Subroutine nvlink_fabric_packages: not called CC=1 SCAR=6.9
Pod documented
572  
573 0 ▶sub nvlink_fabric_unavailable {
Subroutine nvlink_fabric_unavailable: not called CC=2 SCAR=17.9
Pod documented
574 0 my ( $self ) = @_;
575 0 ▶ return if $self->nvlink_fabric_packages;
Branch: 1 branch
BranchTrueFalseTotal
if $self->nvlink_fabric_packages 0 0 0
576 0 return ref($self).' knows no package source for the NVLink Subnet Manager (nvlsm)';
577 }
578  
579 4 ▶sub prepare_nvlink_fabric_source { }
Subroutine prepare_nvlink_fabric_source: called CC=1 SCAR=0.0
Pod documented
580  
581 12 ▶sub install_nvlink_fabric {
Subroutine install_nvlink_fabric: called CC=1 SCAR=0.0
Pod documented
582 12 my ( $self, $plan ) = @_;
583 12 $self->warn_nvlink_kernel;
584 12 my @packages = $self->nvlink_fabric_packages;
585 12 Rex::Logger::info(' HGX B200/B300: NVLink Subnet Manager and InfiniBand user space ('
586 .join(', ', @packages).')');
587 12 $self->prepare_nvlink_fabric_source($plan);
588 11 $self->install_packages({ packages => [ @packages ] });
589 11 $self->verify_packages({ verify => [ @packages ] });
590 10 $self->load_ib_umad;
591 10 return;
592 }
593  
594 2 ▶sub retrofit_nvlink_fabric {
Subroutine retrofit_nvlink_fabric: called CC=7 SCAR=19.8
Pod documented
595 2 my ( $self ) = @_;
596 2 $self->warn_nvlink_kernel;
597 2 my @packages = $self->nvlink_fabric_packages;
598 2 my @missing = grep { !$self->_package_installed($_) } @packages;
599 2 $self->run_cmd(q{lsmod | grep -q '^ib_umad '}, auto_die => 0);
600 2 my $loaded = $? == 0;
601 2 ▶ return 0 if !@missing && $loaded;
Branch: 1 branch
BranchTrueFalseTotal
if not @missing and $loaded 1 1 2
Condition66%2/3
not @missing and $loaded
!ll&&!rl&&r
101
MC/DC50%1/2
not @missing and $loaded
not @missing $loaded
Truth table66%2/3
not(A) and B
A= not @missingB= $loaded
ABresult
0X0
100
111
602 1 ▶ if (@missing) {
Branch: 1 branch
BranchTrueFalseTotal
if (@missing) 1 0 1
603 1 Rex::Logger::info(' HGX B200/B300: installing '.join(', ', @missing)
604 .' for the already-installed driver, from the host\'s own package sources');
605 1 $self->refresh_package_index;
606 1 $self->install_packages({ packages => [ @missing ] });
607 1 ▶ if (my @still = grep { !$self->_package_installed($_) } @missing) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@still) = grep({not $self->_package_installed($_);} @missing)) 1 0 1
608 1 ▶ Rex::Logger::info('HGX B200/B300: '.join(', ', @still).' not installed -- the package '
Branch: 2 branches
BranchTrueFalseTotal
@still == 1 ? : 1 0 1
@still == 1 ? : 1 0 1
609 .'sources configured on this host do not offer '.( @still == 1 ? 'it' : 'them' )
610 .' (nvlsm comes from NVIDIA\'s CUDA repository). No package source was added; '
611 .'without nvlsm CUDA fails with cudaErrorSystemNotReady -- install '
612 .( @still == 1 ? 'it' : 'them' ).' yourself', 'warn');
613 }
614 }
615 1 $self->load_ib_umad;
616 1 return 1;
617 }
618  
619 # Whether one of nvlink_fabric_packages is installed: verify_packages for it
620 # alone, which dies when it is not.
621 9 ▶sub _package_installed {
Subroutine _package_installed: called CC=2 SCAR=6.9
622 9 my ( $self, $pkg ) = @_;
623 9 ▶ return eval { $self->verify_packages({ verify => [ $pkg ] }); 1 } ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $self->verify_packages({'verify', [$pkg]}); 1 } } ? : 7 2 9
624 }
625  
626 11 ▶sub load_ib_umad {
Subroutine load_ib_umad: called CC=3 SCAR=12.0
Pod documented
627 11 my ( $self ) = @_;
628 11 $self->file_cmd('/etc/modules-load.d/ib_umad.conf', content => "ib_umad\n");
629 11 $self->run_cmd('modprobe ib_umad', auto_die => 0);
630 11 ▶ Rex::Logger::info('modprobe ib_umad failed: the Fabric Manager start script needs the '
Branch: 1 branch
BranchTrueFalseTotal
if $? != 0 0 11 11
Condition0%0/2
$self->kernel // "\$(uname -r)"
l!l
00
MC/DC0%0/1
$self->kernel // "\$(uname -r)"
$self->kernel
Truth table0%0/2
A
A= $self->kernel
Aresult
11
00
631 .'module, so nvidia-fabricmanager.service will not start until it is loaded (on Ubuntu '
632 .'it is in linux-modules-extra-'.( $self->kernel // '$(uname -r)' ).')', 'warn')
633 if $? != 0;
634 11 return;
635 }
636  
637 16 ▶sub nvlink_kernel_backported { 0 }
Subroutine nvlink_kernel_backported: called CC=1 SCAR=0.0
Pod documented
638  
639 20 ▶sub warn_nvlink_kernel {
Subroutine warn_nvlink_kernel: called CC=8 SCAR=20.8
Pod documented
640 20 my ( $self ) = @_;
641 20 ▶ return if $self->nvlink_kernel_backported;
Branch: 1 branch
BranchTrueFalseTotal
if $self->nvlink_kernel_backported 4 16 20
642 16 my $kernel = $self->kernel;
643 16 ▶ my ( $major, $minor ) = ( $kernel // '' ) =~ /^(\d+)\.(\d+)/;
Condition50%1/2
$kernel // ""
l!l
160
MC/DC0%0/1
$kernel // ""
$kernel
Truth table50%1/2
A
A= $kernel
Aresult
11
00
644 16 ▶ if (!defined $major) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $major) 1 15 16
645 1 ▶ Rex::Logger::info('HGX B200/B300: cannot read the kernel version ('.( $kernel // 'nothing' )
Condition50%1/2
$kernel // "nothing"
l!l
10
MC/DC0%0/1
$kernel // "nothing"
$kernel
Truth table50%1/2
A
A= $kernel
Aresult
11
00
646 .'); NVIDIA requires kernel 5.17 or newer for the NVLink fabric', 'warn');
647 1 return;
648 }
649 15 ▶ return if $major > 5 || ( $major == 5 && $minor >= 17 );
Branch: 1 branch
BranchTrueFalseTotal
if $major > 5 or $major == 5 and $minor >= 17 12 3 15
Condition100%6/6
$major > 5 or $major == 5 and $minor >= 17
l!l&&r!l&&!r
1113
$major == 5 and $minor >= 17
!ll&&!rl&&r
121
MC/DC100%3/3
$major > 5 or $major == 5 and $minor >= 17
$major > 5 $major == 5 $minor >= 17
Truth table100%4/4
A or B and C
A= $major > 5B= $major == 5C= $minor >= 17
ABCresult
1XX1
0111
00X0
0100
650 3 Rex::Logger::info('HGX B200/B300: kernel '.$kernel.' is older than 5.17, which NVIDIA '
651 .'requires for the NVLink 5 fabric (Fabric Manager user guide); Fabric Manager and nvlsm '
652 .'may not come up on it. Boot a newer kernel -- on Ubuntu 22.04 the HWE kernel '
653 .'(linux-generic-hwe-22.04). Rex::GPU does not change the kernel', 'warn');
654 3 return;
655 }
656  
657 11 ▶sub fabric_state_poll { ( 12, 10 ) }
Subroutine fabric_state_poll: called CC=1 SCAR=0.0
Pod documented
658  
659 12 ▶sub check_nvlink_fabric {
Subroutine check_nvlink_fabric: called CC=11 SCAR=24.2
Pod documented
660 12 my ( $self, $active ) = @_;
661 12 my ( $reads, $seconds ) = $self->fabric_state_poll;
662 12 my $want = scalar grep { ref $_ eq 'HASH' } @{ $self->gpus };
663 12 my @states;
664 12 ▶ for my $read (1 .. ( $active ? $reads : 1 )) {
Branch: 1 branch
BranchTrueFalseTotal
$active ? : 10 2 12
665 15 ▶ sleep $seconds if $read > 1 && $seconds;
Branch: 1 branch
BranchTrueFalseTotal
if $read > 1 and $seconds 0 15 15
Condition66%2/3
$read > 1 and $seconds
!ll&&!rl&&r
1230
MC/DC0%0/2
$read > 1 and $seconds
$read > 1 $seconds
Truth table66%2/3
A and B
A= $read > 1B= $seconds
ABresult
0X0
100
111
666 15 my $out = $self->run_cmd('nvidia-smi -q 2>&1', auto_die => 0);
667 15 @states = $self->_fabric_states($out);
668 15 ▶ if ($self->_fabric_complete($want, @states)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_fabric_complete($want, @states)) 9 6 15
669 9 ▶ Rex::Logger::info(' [ok] NVLink fabric: Fabric State Completed, Status Success on '
Branch: 1 branch
BranchTrueFalseTotal
@states == 1 ? : 0 9 9
670 .scalar(@states).' GPU'.( @states == 1 ? '' : 's' ));
671 9 return 1;
672 }
673 }
674 my $seen = @states
675 3 ▶ ? join('; ', map { 'GPU '.$_.': '.( $states[$_]{state} // 'no State' ).' / '
Branch: 1 branch
BranchTrueFalseTotal
@states ? : 2 1 3
676 16 ▶ .( $states[$_]{status} // 'no Status' ) } 0 .. $#states)
Condition50%2/4
$states[$_]{"state"} // "no State"
l!l
160
$states[$_]{"status"} // "no Status"
l!l
160
MC/DC0%0/1
$states[$_]{"state"} // "no State"
$states[$_]{"state"}
MC/DC0%0/1
$states[$_]{"status"} // "no Status"
$states[$_]{"status"}
Truth table50%1/2
A
A= $states[$_]{"state"}
Aresult
11
00
Truth table50%1/2
A
A= $states[$_]{"status"}
Aresult
11
00
677 : 'no Fabric section';
678 3 my $unit = $self->fabric_manager_service;
679 3 ▶ Rex::Logger::info('HGX B200/B300: the NVLink fabric is not up -- nvidia-smi -q reports '
Branch: 1 branch
BranchTrueFalseTotal
$want > @states ? : 1 2 3
680 .$seen.( $want > @states ? ' ('.$want.' GPUs expected)' : '' )
681 .', not State Completed / Status Success on every GPU. CUDA jobs fail with '
682 .'cudaErrorSystemNotReady until it is. Look at systemctl status '.$unit
683 .', journalctl -u '.$unit.', /var/log/nvlsm.log, lsmod | grep ib_umad and the kernel '
684 .'(5.17 or newer); after the first-deploy reboot check again with nvidia-smi -q', 'warn');
685 3 return 0;
686 }
687  
688 # Pure: every "Fabric" section of `nvidia-smi -q` output, in GPU order, as
689 # { state => ..., status => ... } (a key is missing when the section has no
690 # such line). The first State / Status inside the section count; a line
691 # indented no deeper than "Fabric" ends it.
692 22 ▶sub _fabric_states {
Subroutine _fabric_states: called CC=9 SCAR=22.1
693 22 my ( $self, $out ) = @_;
694 22 my ( @states, $cur, $indent );
695 22 ▶ for my $line (split /\n/, $out // '') {
Condition50%1/2
$out // ""
l!l
220
MC/DC0%0/1
$out // ""
$out
Truth table50%1/2
A
A= $out
Aresult
11
00
696 1256 ▶ next unless $line =~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
unless $line =~ /\S/ 0 1256 1256
697 1256 my $depth = length( ( $line =~ /^([ \t]*)/ )[0] );
698 1256 ▶ if ($line =~ /^[ \t]*Fabric[ \t]*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^[ \t]*Fabric[ \t]*$/) 140 1116 1256
699 140 $cur = {};
700 140 $indent = $depth;
701 140 push @states, $cur;
702 140 next;
703 }
704 1116 ▶ next unless $cur;
Branch: 1 branch
BranchTrueFalseTotal
unless $cur 280 836 1116
705 836 ▶ if ($depth <= $indent) { undef $cur; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($depth <= $indent) 140 696 836
706 696 ▶ if ($line =~ /^[ \t]*(State|Status)[ \t]*:[ \t]*(.*?)\s*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^[ \t]*(State|Status)[ \t]*:[ \t]*(.*?)\s*$/) 278 418 696
707 278 ▶ $cur->{ lc $1 } //= $2;
Condition33%1/3
$$cur{lc $1} //= $2
l!l&&r!l&&!r
02780
MC/DC0%0/2
$$cur{lc $1} //= $2
$$cur{lc $1} $2
Truth table33%1/3
A //= B
A= $$cur{lc $1}B= $2
ABresult
1X1
011
000
708 }
709 }
710 22 return @states;
711 }
712  
713 # Pure: at least $want sections (and at least one), each Completed / Success.
714 20 ▶sub _fabric_complete {
Subroutine _fabric_complete: called CC=8 SCAR=20.9
715 20 my ( $self, $want, @states ) = @_;
716 20 ▶ return 0 unless @states && @states >= $want;
Branch: 1 branch
BranchTrueFalseTotal
unless @states and @states >= $want 3 17 20
Condition100%3/3
@states and @states >= $want
!ll&&!rl&&r
2117
MC/DC100%2/2
@states and @states >= $want
@states @states >= $want
Truth table100%3/3
A and B
A= @statesB= @states >= $want
ABresult
0X0
100
111
717 17 for my $s (@states) {
718 91 ▶ return 0 unless ( $s->{state} // '' ) eq 'Completed' && ( $s->{status} // '' ) eq 'Success';
Branch: 1 branch
BranchTrueFalseTotal
unless ($s->{"state"} // "") eq "Completed" and ($s->{"status"} // "") eq "Success" 7 84 91
Condition71%5/7
($s->{"state"} // "") eq "Completed" and ($s->{"status"} // "") eq "Success"
!ll&&!rl&&r
6184
$s->{"state"} // ""
l!l
910
$s->{"status"} // ""
l!l
850
MC/DC0%0/2
($s->{"state"} // "") eq "Completed" and ($s->{"status"} // "") eq "Success"
$s->{"state"} $s->{"status"}
Truth table33%1/3
A and B
A= $s->{"state"}B= $s->{"status"}
ABresult
0X0
100
111
719 }
720 10 return 1;
721 }
722  
723  
724 0 ▶sub prepare_host { }
Subroutine prepare_host: not called CC=1 SCAR=0.0
Pod documented
725 0 ▶sub prepare_source { }
Subroutine prepare_source: not called CC=1 SCAR=0.0
Pod documented
726 0 ▶sub install_packages { }
Subroutine install_packages: not called CC=1 SCAR=0.0
Pod documented
727 0 ▶sub verify_packages { }
Subroutine verify_packages: not called CC=1 SCAR=0.0
Pod documented
728  
729  
730 399 ▶sub verify_driver_branch {
Subroutine verify_driver_branch: called CC=10 SCAR=23.1
Pod documented
731 399 my ( $self, $plan ) = @_;
732 399 ▶ my $source = $plan->{source} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $source = $plan->{"source"} or return 398 1 399
733 398 ▶ return unless defined $source->{driver_version_from};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $source->{"driver_version_from"} 190 208 398
734 208 my $requirement = $self->requirement;
735 208 ▶ return unless defined $requirement->min_branch || defined $requirement->max_branch;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $requirement->min_branch or defined $requirement->max_branch 14 194 208
Condition100%3/3
defined $requirement->min_branch or defined $requirement->max_branch
l!l&&r!l&&!r
1742014
MC/DC100%2/2
defined $requirement->min_branch or defined $requirement->max_branch
defined $requirement->min_branch defined $requirement->max_branch
Truth table100%3/3
A or B
A= defined $requirement->min_branchB= defined $requirement->max_branch
ABresult
1X1
011
000
736 194 my $pkg = $self->_driver_version_package($source, 'driver_version_from');
737 194 my $version = $self->installed_driver_version($source, 'driver_version_from');
738 194 my $branch = $self->_driver_branch_of($version);
739 194 my $for = $requirement->who.' ('.$requirement->describe.')';
740 194 ▶ my $undone = 'The driver packages stay installed; '
Branch: 1 branch
BranchTrueFalseTotal
$self->fabric_manager_needed ? : 12 182 194
741 .( $self->fabric_manager_needed ? 'Fabric Manager, ' : '' )
742 .'the nouveau blacklist, the initramfs and the reboot were not done';
743 194 ▶ die 'Cannot read the installed NVIDIA driver version from '.$pkg.' ('
Branch: 2 branches
BranchTrueFalseTotal
unless defined $branch 3 191 194
defined $version && length $version ? : 0 3 3
Condition33%1/3
defined $version and length $version
!ll&&!rl&&r
300
MC/DC0%0/2
defined $version and length $version
defined $version length $version
Truth table33%1/3
A and B
A= defined $versionB= length $version
ABresult
0X0
100
111
744 .( defined $version && length $version ? $version : 'nothing' ).'), so its branch '
745 .'cannot be checked against what '.$for.' needs. '.$undone."\n"
746 unless defined $branch;
747 191 my $why = $requirement->why_not({ kernel_module => $source->{kernel_module}, branch => $branch });
748 191 ▶ die 'The installed NVIDIA driver does not fit '.$for.': '.$pkg.' is '.$version.', '.$why.'. '
Branch: 1 branch
BranchTrueFalseTotal
if defined $why 7 184 191
749 .$undone.'. Something on the host keeps that branch -- a package hold or pin, a version '
750 .'lock, another enabled module stream or repository; remove it, or install a fitting '
751 ."driver yourself, then run again\n"
752 if defined $why;
753 184 Rex::Logger::info(' Installed driver: '.$pkg.' '.$version.' (branch '.$branch.')');
754 184 return;
755 }
756  
757 # Pure: the driver branch of an upstream version, the number before its
758 # first dot ("580.95.05" => 580, "590.48.01~rc" => 590); undef for anything
759 # that does not start with digits, a dot and a digit (undef, "", an rpm
760 # "package ... is not installed").
761 194 ▶sub _driver_branch_of {
Subroutine _driver_branch_of: called CC=2 SCAR=6.9
762 194 my ( $self, $version ) = @_;
763 194 ▶ return unless defined $version;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $version 3 191 194
764 191 my ($branch) = $version =~ /\A(\d+)\.\d/;
765 191 return $branch;
766 }
767  
768  
769 382 ▶sub post_install {
Subroutine post_install: called CC=1 SCAR=0.0
Pod documented
770 382 my ( $self ) = @_;
771 382 $self->file_cmd('/etc/modprobe.d/blacklist-nouveau.conf',
772 content => "blacklist nouveau\noptions nouveau modeset=0\n");
773 382 $self->run_cmd($self->initramfs_command, auto_die => 0);
774 }
775  
776 205 ▶sub initramfs_command { 'dracut --force 2>/dev/null' }
Subroutine initramfs_command: called CC=1 SCAR=0.0
Pod documented
777  
778 #### Pure helpers #############################################################
779 #
780 # Callable on the class as on an object, and with explicit arguments, because
781 # Rex::GPU::NVIDIA keeps some old private names as thin wrappers over them
782 # (t/ calls those).
783  
784 # Given `nvidia-smi -L` output: is a working driver loaded? Every failure form
785 # (NVML init error, "No devices were found", "command not found") does not
786 # match.
787 603 ▶sub _driver_present {
Subroutine _driver_present: called CC=3 SCAR=11.0
788 603 my ( $self, $smi ) = @_;
789 603 ▶ return 0 unless defined $smi;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $smi 1 602 603
790 602 ▶ return $smi =~ /GPU \d+:/ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$smi =~ /GPU \d+:/ ? : 87 515 602
791 }
792  
793 # Die for a GPU no installable branch supports -- Kepler or older, max_branch
794 # 470. Maintainer decision (epic karr #25): reject loudly instead of
795 # installing the EOL 470 driver. Quiet for every other GPU, 580 included, and
796 # for anything that is not a GPU hashref.
797 802 ▶sub _reject_unsupported_gpu {
Subroutine _reject_unsupported_gpu: called CC=6 SCAR=17.9
798 802 my ( $self, $gpu ) = @_;
799 802 ▶ return unless $gpu && ref $gpu eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless $gpu and ref $gpu eq "HASH" 3 799 802
Condition100%3/3
$gpu and ref $gpu eq "HASH"
!ll&&!rl&&r
12799
MC/DC100%2/2
$gpu and ref $gpu eq "HASH"
$gpu ref $gpu eq "HASH"
Truth table100%3/3
A and B
A= $gpuB= ref $gpu eq "HASH"
ABresult
0X0
100
111
800 799 my $req = $self->requirement_class->from_gpu($gpu);
801 799 ▶ return unless defined $req->max_branch && $req->max_branch < 580;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $req->max_branch and $req->max_branch < 580 749 50 799
Condition100%3/3
defined $req->max_branch and $req->max_branch < 580
!ll&&!rl&&r
59615350
MC/DC100%2/2
defined $req->max_branch and $req->max_branch < 580
defined $req->max_branch $req->max_branch < 580
Truth table100%3/3
A and B
A= defined $req->max_branchB= $req->max_branch < 580
ABresult
0X0
100
111
802 50 ▶ die "NVIDIA GPU '" . ($gpu->{name} // 'unknown') . "' (10de:$gpu->{device_id}) is "
Condition50%1/2
$gpu->{"name"} // "unknown"
l!l
500
MC/DC0%0/1
$gpu->{"name"} // "unknown"
$gpu->{"name"}
Truth table50%1/2
A
A= $gpu->{"name"}
Aresult
11
00
803 . $req->generation." silicon: no driver newer than the end-of-life "
804 . $req->max_branch." branch supports it, and Rex::GPU does not install "
805 . "that. No driver package was installed and no package source was added. "
806 . "Install the driver yourself; once "
807 . "`nvidia-smi -L` lists the GPU and libcuda.so.1 is in the linker cache, "
808 . "install_driver skips the driver step\n";
809 }
810  
811 # Die for a vGPU guest device among the GPUs (karr #24): it needs NVIDIA's
812 # licensed vGPU guest driver, which no package source carries, and the open
813 # nvidia.ko of the datacenter packages refuses an Ampere+ vGPU function. With
814 # a non-vGPU GPU next to it both are named: one NVIDIA kernel module drives
815 # every GPU of the host, so the two drivers cannot both be installed. A GPU
816 # hash without vgpu (a caller that finds its GPUs itself) is not a vGPU.
817 633 ▶sub _reject_vgpu_guest {
Subroutine _reject_vgpu_guest: called CC=8 SCAR=21.3
818 633 my ( $self ) = @_;
819 633 my @gpus = grep { ref $_ eq 'HASH' } @{ $self->gpus };
820 633 my @vgpu = grep { $_->{vgpu} } @gpus;
821 633 ▶ return unless @vgpu;
Branch: 1 branch
BranchTrueFalseTotal
unless @vgpu 607 26 633
822 26 my @other = grep { !$_->{vgpu} } @gpus;
823 die join('; ', map {
824 'NVIDIA vGPU guest (type '.( $_->{vgpu_type} // 'unknown' ).', 10de:'
825 26 ▶ .( $_->{device_id} // '????' ).' sub '.( $_->{subsystem_id} // '????' ).')'
Branch: 1 branch
BranchTrueFalseTotal
@other ? : 12 14 26
Condition50%3/6
$_->{"vgpu_type"} // "unknown"
l!l
260
$_->{"device_id"} // "????"
l!l
260
$_->{"subsystem_id"} // "????"
l!l
260
MC/DC0%0/1
$_->{"vgpu_type"} // "unknown"
$_->{"vgpu_type"}
MC/DC0%0/1
$_->{"device_id"} // "????"
$_->{"device_id"}
MC/DC0%0/1
$_->{"subsystem_id"} // "????"
$_->{"subsystem_id"}
Truth table50%1/2
A
A= $_->{"vgpu_type"}
Aresult
11
00
Truth table50%1/2
A
A= $_->{"device_id"}
Aresult
11
00
Truth table50%1/2
A
A= $_->{"subsystem_id"}
Aresult
11
00
826 } @vgpu)
827 .( @other
828 ? ' next to '.join(', ', map {
829 26 "NVIDIA GPU '".( $_->{name} // 'unknown' )."' (10de:"
830 12 ▶ .( $_->{device_id} // '????' ).', not a vGPU)'
Condition50%2/4
$_->{"name"} // "unknown"
l!l
120
$_->{"device_id"} // "????"
l!l
120
MC/DC0%0/1
$_->{"name"} // "unknown"
$_->{"name"}
MC/DC0%0/1
$_->{"device_id"} // "????"
$_->{"device_id"}
Truth table50%1/2
A
A= $_->{"name"}
Aresult
11
00
Truth table50%1/2
A
A= $_->{"device_id"}
Aresult
11
00
831 } @other)
832 .': one NVIDIA kernel module drives every GPU of the host, and the '
833 .'driver Rex::GPU installs does not drive a vGPU'
834 : '' )
835 .': install the licensed NVIDIA vGPU guest driver, then run again. '
836 ."No driver package was installed and no package source was added\n";
837 }
838  
839 # `uname -m` / dpkg arch -> the token NVIDIA's CUDA repos use under
840 # repos/<distro>/<arch>/: aarch64/arm64 are "sbsa", everything else (an empty
841 # string included) "x86_64". NOT the libnvidia-container toolkit repo's token,
842 # which is "aarch64" for the same machine.
843 291 ▶sub _cuda_repo_arch {
Subroutine _cuda_repo_arch: called CC=4 SCAR=13.9
844 291 my ( $self, $machine ) = @_;
845 291 ▶ $machine //= '';
Condition100%2/2
$machine //= ""
l!l
2901
MC/DC100%1/1
$machine //= ""
$machine
Truth table100%2/2
A
A= $machine
Aresult
11
00
846 291 ▶ return 'sbsa' if $machine eq 'aarch64' || $machine eq 'arm64';
Branch: 1 branch
BranchTrueFalseTotal
if $machine eq "aarch64" or $machine eq "arm64" 6 285 291
Condition100%3/3
$machine eq "aarch64" or $machine eq "arm64"
l!l&&r!l&&!r
15285
MC/DC100%2/2
$machine eq "aarch64" or $machine eq "arm64"
$machine eq "aarch64" $machine eq "arm64"
Truth table100%3/3
A or B
A= $machine eq "aarch64"B= $machine eq "arm64"
ABresult
1X1
011
000
847 285 return 'x86_64';
848 }
849  
850 # Major version from a raw release string ("10.1" -> 10, "trixie/sid" -> 0).
851 # operating_system_version() strips the dots, so it is never the input.
852 876 ▶sub _major_version {
Subroutine _major_version: called CC=3 SCAR=11.0
853 876 my ( $self, $release ) = @_;
854 876 ▶ my ($major) = ($release // '') =~ /^(\d+)/;
Condition100%2/2
$release // ""
l!l
8751
MC/DC100%1/1
$release // ""
$release
Truth table100%2/2
A
A= $release
Aresult
11
00
855 876 ▶ return ($major // 0) + 0;
Condition100%2/2
$major // 0
l!l
8697
MC/DC100%1/1
$major // 0
$major
Truth table100%2/2
A
A= $major
Aresult
11
00
856 }
857  
858 49 1;
859  
860 __END__
« blib/lib/Rex/GPU/Detect.pm ↑ Summary lib/Rex/GPU/AMD/Setup/Apt.pm »