lib/Rex/GPU/NVIDIA/Requirement.pm

filter: Statementstmt 100% 125 / 125 Branchbran 98.0% 98 / 100 Conditioncond 84.0% 58 / 69 MC/DCmcdc 72.0% 31 / 43 Subroutinesub 100% 21 / 21 Podpod 90.0% 9 / 10 totaltotal 92.9% 342 / 368 CC 79 SCAR 22.6
CC
79
Cov
96%
why_not
20.0
_lookup
13.1
conflicts
10.0
CRAP 9.5
« lib/Rex/GPU/NVIDIA/Setup/UbuntuDrivers.pm ↑ Summary blib/lib/Rex/GPU.pm »
1 # ABSTRACT: What NVIDIA driver a GPU generation needs (experimental)
2  
3 package Rex::GPU::NVIDIA::Requirement;
4 36 our $VERSION = '0.005';
5 36 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 36 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 36 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 36 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 36 my %KERNEL_MODULES = map { $_ => 1 } qw( open proprietary either );
11  
12  
13 36 has generation => ( is => 'ro' );
14  
15  
16 has kernel_module => (
17 is => 'ro',
18 default => 'either',
19 2689 ▶ isa => sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
20 croak __PACKAGE__.'->kernel_module must be open, proprietary or either, not '
21 .( defined $_[0] ? "'".$_[0]."'" : 'undef' )
22 2689 ▶ unless defined $_[0] && $KERNEL_MODULES{ $_[0] };
Branch: 2 branches
BranchTrueFalseTotal
unless defined $_[0] and $KERNEL_MODULES{$_[0]} 3 2686 2689
defined $_[0] ? : 2 1 3
Condition100%3/3
defined $_[0] and $KERNEL_MODULES{$_[0]}
!ll&&!rl&&r
122686
MC/DC100%2/2
defined $_[0] and $KERNEL_MODULES{$_[0]}
defined $_[0] $KERNEL_MODULES{$_[0]}
Truth table100%3/3
A and B
A= defined $_[0]B= $KERNEL_MODULES{$_[0]}
ABresult
0X0
100
111
23 }
24 36 );
25  
26  
27 36 has min_branch => ( is => 'ro', isa => \&_check_branch );
28 36 has max_branch => ( is => 'ro', isa => \&_check_branch );
29  
30 1589 ▶sub _check_branch {
Subroutine _check_branch: called CC=3 SCAR=11.1
31 1589 my ( $branch ) = @_;
32 1589 ▶ croak __PACKAGE__.': a driver branch is an integer like 580, not '."'".$branch."'"
Branch: 1 branch
BranchTrueFalseTotal
if defined $branch and not $branch =~ /^\d+\z/ 1 1588 1589
Condition66%2/3
defined $branch and not $branch =~ /^\d+\z/
!ll&&!rl&&r
015881
MC/DC50%1/2
defined $branch and not $branch =~ /^\d+\z/
defined $branch not $branch =~ /^\d+\z/
Truth table66%2/3
A and not(B)
A= defined $branchB= not $branch =~ /^\d+\z/
ABresult
0X0
100
111
33 if defined $branch && $branch !~ /^\d+\z/;
34 }
35  
36  
37 has device_id => (
38 is => 'ro',
39 2479 ▶ isa => sub {
Subroutine __ANON__: called CC=3 SCAR=11.1
40 2479 ▶ croak __PACKAGE__.'->device_id must be four lowercase hex digits, not '."'".$_[0]."'"
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] and not $_[0] =~ /^[0-9a-f]{4}\z/ 1 2478 2479
Condition66%2/3
defined $_[0] and not $_[0] =~ /^[0-9a-f]{4}\z/
!ll&&!rl&&r
024781
MC/DC50%1/2
defined $_[0] and not $_[0] =~ /^[0-9a-f]{4}\z/
defined $_[0] not $_[0] =~ /^[0-9a-f]{4}\z/
Truth table66%2/3
A and not(B)
A= defined $_[0]B= not $_[0] =~ /^[0-9a-f]{4}\z/
ABresult
0X0
100
111
41 if defined $_[0] && $_[0] !~ /^[0-9a-f]{4}\z/;
42 }
43 36 );
44  
45  
46 36 has name => ( is => 'ro' );
47 2596 ▶has members => ( is => 'ro', default => sub { [] } );
Subroutine __ANON__: called CC=1 SCAR=0.0
48  
49  
50 36 has compute => ( is => 'ro' );
51  
52 2685 ▶sub BUILD {
Subroutine BUILD: called CC=4 SCAR=13.9
Pod undocumented
53 2685 my ( $self ) = @_;
54 2685 ▶ croak __PACKAGE__.': min_branch '.$self->min_branch.' is above max_branch '
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->min_branch and defined $self->max_branch and $self->min_branch > $self->max_branch 1 2684 2685
Condition100%6/6
defined $self->min_branch and defined $self->max_branch and $self->min_branch > $self->max_branch
!ll&&!rl&&r
268311
defined $self->min_branch and defined $self->max_branch
!ll&&!rl&&r
17729112
MC/DC100%3/3
defined $self->min_branch and defined $self->max_branch and $self->min_branch > $self->max_branch
defined $self->min_branch defined $self->max_branch $self->min_branch > $self->max_branch
Truth table100%4/4
A and B and C
A= defined $self->min_branchB= defined $self->max_branchC= $self->min_branch > $self->max_branch
ABCresult
0XX0
10X0
1100
1111
55 .$self->max_branch.': no driver branch can satisfy that'
56 if defined $self->min_branch && defined $self->max_branch
57 && $self->min_branch > $self->max_branch;
58 }
59  
60  
61 # The rows, and where they come from (moved here from Rex::GPU::Detect, karr
62 # #16 and #26). The compute flag decides Rex::GPU::Detect::_is_nvidia_compute
63 # before any name rule (karr #45, #54). Maintainer decision (karr #54): every
64 # GPU usable for AI is compute -- MX, GT and GTX 9xx with 2 GB included -- as
65 # long as a current driver branch supports it; the criterion is the
66 # generation, not the marketing name. So Maxwell through Blackwell Ultra carry
67 # compute => 1 and the Kepler-or-older row compute => 0 (skipped with a
68 # warning, not a die, before the PCI class rule (karr #55): gpu_setup /
69 # Rex::Rancher gpu => 1 keep going without the old card, a K80 included). An ID no row covers (0x3000+
70 # except Blackwell Ultra) has no verdict; Detect uses its name rules and its
71 # unknown-model default compute => 0 there.
72 #
73 # Checked 2026-09-24 against NVIDIA's supportedchips READMEs (Linux-x86_64
74 # 615.71.09, 580.95.05, 580.126.09, 550.163.01, 535.247.01) and pci.ids of
75 # 2026-09-24:
76 # * 580.95.05 / 580.126.09 "current" list starts at 1340: every ID of the
77 # 615 legacy_580 list (1340..1DF6) is current there -- incl. Maxwell Gen1
78 # GM107/GM108: GTX 750 Ti 1380, GTX 745 1382, 940MX 134D, MX130 174D,
79 # MX110 174E -- except 137D (GeForce 940A, subsystem entry only) and 1DF5
80 # (V100-SXM2-16GB), which only the 615 legacy_580 list names.
81 # * No legacy_470-or-older ID is >= 1340; no current/legacy_580 ID < 1340.
82 # * pci.ids: no 10de ID >= 1340 carries a Kepler-or-older codename (GK, GF,
83 # GT2xx, G8x/G9x, NVxx), and no Maxwell-or-newer codename sits below 1340
84 # except HD-audio functions (PCI class 0403, never read by detection).
85 # pci.ids does name two Kepler IDs like Maxwell/Pascal products -- 0FC5
86 # "GK107 [GeForce GT 1030]", 11C7 "GK106 [GeForce GTX 750 Ti]" -- which is
87 # why the ID row decides before any name rule.
88 #
89 # Blackwell (karr #16): NO proprietary kernel module — NVIDIA's open GPU
90 # kernel modules are the only ones that bind — on every architecture, x86_64
91 # included. Source: the supported-GPU table in NVIDIA's open-gpu-kernel-modules
92 # README.md (github.com/NVIDIA/open-gpu-kernel-modules, driver 615.71.09). In
93 # that table the last pre-Blackwell (Ada) ID is 28F8, and every listed ID from
94 # 2901 up to 2F58 is Blackwell: B200 (2901, 2909), GB200 (2941), GeForce RTX
95 # 50xx desktop/laptop and RTX PRO Blackwell (2B85..2F58), GB10 (2E12).
96 # 0x2900-0x2FFF is therefore taken as a block: an unlisted ID inside it is
97 # post-Ada silicon and gets the open module (which supports every GPU from
98 # Turing on). Blackwell Ultra (B300 3182, GB300 31C2/31C3) is listed
99 # explicitly, NOT as a block — whatever else lands at 0x3000+ is unknown.
100 # min_branch 570 / 580: the first branch with Blackwell / Blackwell Ultra
101 # support (research for epic karr #25).
102 #
103 # GB10 (2E12, DGX Spark) is the exception inside the Blackwell block: min 580
104 # (karr #33, checked 2026-09-23 against NVIDIA's primary sources). 2E12 is
105 # absent from the open-gpu-kernel-modules README.md of every 570.x and 575.x
106 # tag and of 580.65.06 .. 580.105.08; it first appears in tag 580.119.02
107 # ("NVIDIA GB10 | 2E12 10DE 21EC"), and is in 580.126.09, 590.48.01, 595.44.02
108 # and 615.71.09 -- but NOT in 590.44.01. The aarch64 driver README
109 # (us.download.nvidia.com/XFree86/aarch64/<ver>/README/supportedchips.html)
110 # agrees: absent in 580.95.05 and 590.44.01, present in 580.119.02 and
111 # 590.48.01. A branch-granular row cannot express "580.119.02 or newer".
112 #
113 # Pre-Turing (karr #26). Source: the legacy sections of NVIDIA's
114 # supportedchips README (driver 615.71.09, us.download.nvidia.com/XFree86/
115 # Linux-x86_64/615.71.09/README/supportedchips.html), checked 2026-09-23:
116 # * "current" list: lowest ID 1E02 (TITAN RTX, Turing). No current ID < 1E02.
117 # * 580.xx legacy list (Maxwell/Pascal/Volta): exactly 1340..1DF6, e.g.
118 # Tesla M60 13F2, M40 17FD, P100 15F7/15F8, P40 1B38, P4 1BB3, TITAN V
119 # 1D81, V100 1DB1/1DB4-1DB6, V100S 1DF6. Proprietary kernel module only —
120 # the open module needs GSP, which these chips lack — and 580 is their last
121 # branch (595+ dropped them).
122 # * 470.xx list (Kepler): 0FC6..12BA. The 390.xx (Fermi) list interleaves
123 # with it (1040..1251) and goes down to 06C0; older legacy lists reach
124 # down to 0020. No list has an ID in 12BB..133F or 1DF7..1E01.
125 # So every ID below 1340 is Kepler or older and no driver newer than 470
126 # supports it: one block, not a Kepler-only range, so a Fermi Tesla (C2050
127 # 06D1, M2090 1091) is rejected too. 1340..1DF6 is taken as a block like the
128 # Blackwell one: an unlisted ID inside it is Maxwell..Volta silicon.
129 #
130 # Turing, Ampere, Ada, Hopper (karr #54): 1DF7..28FF, one block like the
131 # others. The 615.71.09 current list covers 1E02 (TITAN RTX) .. 28F8 in it,
132 # with gaps; nothing in 1DF7..1E01 is listed anywhere. The row sets no
133 # constraint (either module, no bounds -- the driver selection these GPUs got
134 # before they had a row); it exists for the compute flag and the label.
135 #
136 # Grace Hopper GH200 (karr #72): 2342 and 2348 sit inside that block but get
137 # their own rows ahead of it -- open kernel module only, by MAINTAINER
138 # DECISION, not by NVIDIA's driver documentation. The open-only evidence is
139 # NVIDIA's blog post "NVIDIA Transitions Fully Towards Open-Source GPU Kernel
140 # Modules" (2024), which says Grace Hopper and Blackwell platforms must use
141 # the open modules. NVIDIA's driver README disagrees: kernel_open.html
142 # ("Open Linux Kernel Modules", aarch64 and Linux-x86_64 alike) of 560.35.03
143 # .. 580.126.09 says the proprietary flavor supports "later GPUs until
144 # Blackwell", of 590.48.01 and 615.71.09 "Turing, Ampere, Ada, and Hopper",
145 # with no Grace exception in any of them; and NVIDIA-Linux-aarch64-615.71.09
146 # .run ships a proprietary kernel/nv-kernel.o_binary. Checked 2026-09-26.
147 # IDs, from NVIDIA's supportedchips READMEs (aarch64 and Linux-x86_64,
148 # checked 2026-09-26); no other product uses them:
149 # * 2342 GH200 120GB (10DE:16EB, 10DE:1805), GH200 480GB (10DE:1809):
150 # in 535.247.01, 545.29.06 (16EB and 1809 only), 550.54.14, 560.35.03,
151 # 565.77, 570.86.16, 570.172.08, 615.71.09; NOT in 535.104.05. In the
152 # open-gpu-kernel-modules README from tag 550.54.14 on (not up to
153 # 545.23.06). min_branch 535: whole branches only, so an early 535
154 # point release (535.104.05) is not caught here.
155 # * 2348 GH200 144G HBM3e (10DE:18D2): from 565.77 on (not in 560.35.03);
156 # open-gpu-kernel-modules README of 570.172.08, 580.95.05, 615.71.09.
157 # min_branch 565.
158 #
159 # Everything else — the gaps above 2FFF and any future ID — has no row:
160 # either kernel module, no bounds, no compute verdict.
161 2478 ▶sub generations {
Subroutine generations: called CC=1 SCAR=0.0
Pod documented
162 return (
163 2478 { generation => 'Blackwell', first => 0x2e12, last => 0x2e12, # GB10, see above
164 kernel_module => 'open', min_branch => 580, compute => 1 },
165 { generation => 'Blackwell', first => 0x2900, last => 0x2fff, # GB100/GB102, GB20x, GB10
166 kernel_module => 'open', min_branch => 570, compute => 1 },
167 { generation => 'Blackwell Ultra', first => 0x3182, last => 0x3182, # B300 SXM6 AC
168 kernel_module => 'open', min_branch => 580, compute => 1 },
169 { generation => 'Blackwell Ultra', first => 0x31c2, last => 0x31c3, # GB300
170 kernel_module => 'open', min_branch => 580, compute => 1 },
171 { generation => 'Grace Hopper', first => 0x2342, last => 0x2342, # GH200 120GB/480GB, see above
172 kernel_module => 'open', min_branch => 535, compute => 1 },
173 { generation => 'Grace Hopper', first => 0x2348, last => 0x2348, # GH200 144G HBM3e
174 kernel_module => 'open', min_branch => 565, compute => 1 },
175 { generation => 'Turing/Ampere/Ada/Hopper', first => 0x1df7, last => 0x28ff,
176 compute => 1 },
177 { generation => 'Maxwell/Pascal/Volta', first => 0x1340, last => 0x1df6,
178 kernel_module => 'proprietary', max_branch => 580, compute => 1 },
179 { generation => 'Kepler or older', first => 0x0000, last => 0x133f,
180 kernel_module => 'proprietary', max_branch => 470, compute => 0 }
181 );
182 }
183  
184  
185 1068 ▶sub for_device_id {
Subroutine for_device_id: called CC=2 SCAR=8.1
Pod documented
186 1068 my ( $self, $device_id ) = @_;
187 1068 ▶ return ( ref $self || $self )->new( $self->_lookup( $device_id ) );
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
010680
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
188 }
189  
190 1466 ▶sub from_gpu {
Subroutine from_gpu: called CC=4 SCAR=14.2
Pod documented
191 1466 my ( $self, $gpu ) = @_;
192 1466 ▶ croak __PACKAGE__.'->from_gpu needs a GPU hashref from Rex::GPU::Detect::detect'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $gpu eq "HASH" 2 1464 1466
193 unless ref $gpu eq 'HASH';
194 return ( ref $self || $self )->new(
195 $self->_lookup( $gpu->{device_id} ),
196 1464 ▶ defined $gpu->{name} ? ( name => $gpu->{name} ) : ()
Branch: 1 branch
BranchTrueFalseTotal
defined $gpu->{'name'} ? : 1458 6 1464
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
014640
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
197 );
198 }
199  
200 # Constructor arguments for a device ID. The format check is the one
201 # Rex::GPU::Detect used before this table existed, kept as it was so the
202 # wrappers there return exactly what they did.
203 2532 ▶sub _lookup {
Subroutine _lookup: called CC=13 SCAR=25.7
204 2532 my ( $self, $device_id ) = @_;
205 2532 ▶ return () unless defined $device_id && $device_id =~ /^[0-9a-f]{4}$/i;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $device_id and $device_id =~ /^[0-9a-f]{4}$/i 54 2478 2532
Condition100%3/3
defined $device_id and $device_id =~ /^[0-9a-f]{4}$/i
!ll&&!rl&&r
41132478
MC/DC100%2/2
defined $device_id and $device_id =~ /^[0-9a-f]{4}$/i
defined $device_id $device_id =~ /^[0-9a-f]{4}$/i
Truth table100%3/3
A and B
A= defined $device_idB= $device_id =~ /^[0-9a-f]{4}$/i
ABresult
0X0
100
111
206 2478 my $id = hex $device_id;
207 2478 my %args = ( device_id => lc substr( $device_id, 0, 4 ) );
208 2478 for my $row ( $self->generations ) {
209 croak __PACKAGE__.'->generations: every row needs first and last'
210 14120 ▶ unless defined $row->{first} && defined $row->{last};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $row->{"first"} and defined $row->{"last"} 0 14120 14120
Condition33%1/3
defined $row->{"first"} and defined $row->{"last"}
!ll&&!rl&&r
0014120
MC/DC0%0/2
defined $row->{"first"} and defined $row->{"last"}
defined $row->{"first"} defined $row->{"last"}
Truth table33%1/3
A and B
A= defined $row->{"first"}B= defined $row->{"last"}
ABresult
0X0
100
111
211 14120 ▶ next unless $id >= $row->{first} && $id <= $row->{last};
Branch: 1 branch
BranchTrueFalseTotal
unless $id >= $row->{"first"} and $id <= $row->{"last"} 11686 2434 14120
Condition100%3/3
$id >= $row->{"first"} and $id <= $row->{"last"}
!ll&&!rl&&r
967920072434
MC/DC100%2/2
$id >= $row->{"first"} and $id <= $row->{"last"}
$id >= $row->{"first"} $id <= $row->{"last"}
Truth table100%3/3
A and B
A= $id >= $row->{"first"}B= $id <= $row->{"last"}
ABresult
0X0
100
111
212 return (
213 %args,
214 generation => $row->{generation},
215 kernel_module => $row->{kernel_module} // 'either',
216 defined $row->{min_branch} ? ( min_branch => $row->{min_branch} ) : (),
217 defined $row->{max_branch} ? ( max_branch => $row->{max_branch} ) : (),
218 2434 ▶ defined $row->{compute} ? ( compute => $row->{compute} ? 1 : 0 ) : ()
Branch: 4 branches
BranchTrueFalseTotal
defined $row->{'min_branch'} ? : 845 1589 2434
defined $row->{'max_branch'} ? : 656 1778 2434
defined $row->{'compute'} ? : 2432 2 2434
$row->{'compute'} ? : 2266 166 2432
Condition100%2/2
$row->{"kernel_module"} // "either"
l!l
1501933
MC/DC100%1/1
$row->{"kernel_module"} // "either"
$row->{"kernel_module"}
Truth table100%2/2
A
A= $row->{"kernel_module"}
Aresult
11
00
219 );
220 }
221 44 return %args;
222 }
223  
224  
225 34 ▶sub satisfied_by {
Subroutine satisfied_by: called CC=2 SCAR=6.9
Pod documented
226 34 my ( $self, $source ) = @_;
227 34 ▶ return defined $self->why_not( $source ) ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->why_not($source) ? : 14 17 31
228 }
229  
230 1134 ▶sub why_not {
Subroutine why_not: called CC=20 SCAR=30.0
Pod documented
231 1134 my ( $self, $source ) = @_;
232 1134 ▶ croak __PACKAGE__.'->satisfied_by needs a source hashref { kernel_module, branch }'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $source eq "HASH" 1 1133 1134
233 unless ref $source eq 'HASH';
234 1133 my ( $branch, $floor ) = @{ $source }{qw( branch branch_at_least )};
235 1133 for my $n ( $branch, $floor ) {
236 2265 ▶ croak __PACKAGE__.'->satisfied_by: branch must be an integer like 580, not '."'".$n."'"
Branch: 1 branch
BranchTrueFalseTotal
if defined $n and not $n =~ /^\d+\z/ 2 2263 2265
Condition100%3/3
defined $n and not $n =~ /^\d+\z/
!ll&&!rl&&r
114311202
MC/DC100%2/2
defined $n and not $n =~ /^\d+\z/
defined $n not $n =~ /^\d+\z/
Truth table100%3/3
A and not(B)
A= defined $nB= not $n =~ /^\d+\z/
ABresult
0X0
100
111
237 if defined $n && $n !~ /^\d+\z/;
238 }
239  
240 1131 ▶ if ( $self->kernel_module ne 'either' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->kernel_module ne "either") 719 412 1131
241 719 my $module = $source->{kernel_module};
242 719 ▶ return ( defined $module ? $module : 'unknown' ).' kernel module, the '
Branch: 2 branches
BranchTrueFalseTotal
unless defined $module and $module eq $self->kernel_module 195 524 719
defined $module ? : 194 1 195
Condition100%3/3
defined $module and $module eq $self->kernel_module
!ll&&!rl&&r
1194524
MC/DC100%2/2
defined $module and $module eq $self->kernel_module
defined $module $module eq $self->kernel_module
Truth table100%3/3
A and B
A= defined $moduleB= $module eq $self->kernel_module
ABresult
0X0
100
111
243 .$self->kernel_module.' one is needed'
244 unless defined $module && $module eq $self->kernel_module;
245 }
246 936 my ( $min, $max ) = ( $self->min_branch, $self->max_branch );
247 936 ▶ return unless defined $min || defined $max;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $min or defined $max 409 527 936
Condition100%3/3
defined $min or defined $max
l!l&&r!l&&!r
265262409
MC/DC100%2/2
defined $min or defined $max
defined $min defined $max
Truth table100%3/3
A or B
A= defined $minB= defined $max
ABresult
1X1
011
000
248  
249 527 ▶ if ( defined $branch ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $branch) 282 245 527
250 282 ▶ return 'branch '.$branch.' is older than '.$min if defined $min && $branch < $min;
Branch: 1 branch
BranchTrueFalseTotal
if defined $min and $branch < $min 6 276 282
Condition100%3/3
defined $min and $branch < $min
!ll&&!rl&&r
224526
MC/DC100%2/2
defined $min and $branch < $min
defined $min $branch < $min
Truth table100%3/3
A and B
A= defined $minB= $branch < $min
ABresult
0X0
100
111
251 276 ▶ return 'branch '.$branch.' is newer than '.$max if defined $max && $branch > $max;
Branch: 1 branch
BranchTrueFalseTotal
if defined $max and $branch > $max 4 272 276
Condition100%3/3
defined $max and $branch > $max
!ll&&!rl&&r
522204
MC/DC100%2/2
defined $max and $branch > $max
defined $max $branch > $max
Truth table100%3/3
A and B
A= defined $maxB= $branch > $max
ABresult
0X0
100
111
252 272 return;
253 }
254 245 ▶ return 'driver branch not known, '.( defined $min ? $min.' or newer' : $max.' or older' )
Branch: 2 branches
BranchTrueFalseTotal
unless defined $floor 4 241 245
defined $min ? : 1 3 4
255 .' is needed'
256 unless defined $floor;
257 241 ▶ return 'installs the newest branch it carries, which can be newer than '.$max
Branch: 1 branch
BranchTrueFalseTotal
if defined $max 35 206 241
258 if defined $max;
259 206 ▶ return 'installs the newest branch it carries, known only to be '.$floor
Branch: 1 branch
BranchTrueFalseTotal
if $floor < $min 5 201 206
260 .' or newer; '.$min.' is needed'
261 if $floor < $min;
262 201 return;
263 }
264  
265  
266 491 ▶sub intersect {
Subroutine intersect: called CC=9 SCAR=22.0
Pod documented
267 491 my ( $self, @requirements ) = @_;
268 491 ▶ unshift @requirements, $self if ref $self;
Branch: 1 branch
BranchTrueFalseTotal
if ref $self 2 489 491
269 491 my @members = $self->_members_of( @requirements );
270 489 ▶ return $requirements[0] if @requirements == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @requirements == 1 395 94 489
271  
272 94 my @conflicts = $self->conflicts( @members );
273 94 ▶ croak __PACKAGE__.'->intersect: no single NVIDIA driver supports all GPUs on this host: '
Branch: 1 branch
BranchTrueFalseTotal
if @conflicts 4 90 94
274 .join( '; ', @conflicts )
275 if @conflicts;
276  
277 90 my %module = map { $_->kernel_module => 1 } @members;
278 90 my ( $lower, $upper ) = $self->_bounds( @members );
279 90 ▶ my $class = ref $self || $self;
Condition66%2/3
ref $self || $self
l!l&&r!l&&!r
1890
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table66%2/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
280 return $class->new(
281 kernel_module => $module{open} ? 'open'
282 90 ▶ : $module{proprietary} ? 'proprietary'
Branch: 4 branches
BranchTrueFalseTotal
$module{'open'} ? : 61 29 90
$module{'proprietary'} ? : 16 13 29
$lower ? : 59 31 90
$upper ? : 16 74 90
283 : 'either',
284 $lower ? ( min_branch => $lower->min_branch ) : (),
285 $upper ? ( max_branch => $upper->max_branch ) : (),
286 members => \@members
287 );
288 }
289  
290 596 ▶sub conflicts {
Subroutine conflicts: called CC=10 SCAR=23.0
Pod documented
291 596 my ( $self, @requirements ) = @_;
292 596 ▶ unshift @requirements, $self if ref $self;
Branch: 1 branch
BranchTrueFalseTotal
if ref $self 2 594 596
293 596 my @members = $self->_members_of( @requirements );
294  
295 596 my %by_module;
296 596 push @{ $by_module{ $_->kernel_module } }, $_ for @members;
297 596 my ( $lower, $upper ) = $self->_bounds( @members );
298  
299 596 my @conflicts;
300 30 ▶ push @conflicts, join( ', ', map { $_->who } @{ $by_module{open} } )
Branch: 1 branch
BranchTrueFalseTotal
@{$by_module{'open'};} == 1 ? : 30 0 30
301 30 .' need'.( @{ $by_module{open} } == 1 ? 's' : '' ).' the open kernel module, but '
302 31 ▶ .join( ', ', map { $_->who } @{ $by_module{proprietary} } )
Branch: 1 branch
BranchTrueFalseTotal
@{$by_module{'proprietary'};} == 1 ? : 29 1 30
303 30 .' need'.( @{ $by_module{proprietary} } == 1 ? 's' : '' ).' the proprietary one'
304 596 ▶ if $by_module{open} && $by_module{proprietary};
Branch: 1 branch
BranchTrueFalseTotal
if $by_module{"open"} and $by_module{"proprietary"} 30 566 596
Condition100%3/3
$by_module{"open"} and $by_module{"proprietary"}
!ll&&!rl&&r
35121530
MC/DC100%2/2
$by_module{"open"} and $by_module{"proprietary"}
$by_module{"open"} $by_module{"proprietary"}
Truth table100%3/3
A and B
A= $by_module{"open"}B= $by_module{"proprietary"}
ABresult
0X0
100
111
305 596 ▶ push @conflicts, $lower->who.' needs driver branch '.$lower->min_branch
Branch: 1 branch
BranchTrueFalseTotal
if $lower and $upper and $lower->min_branch > $upper->max_branch 3 593 596
Condition100%6/6
$lower and $upper and $lower->min_branch > $upper->max_branch
!ll&&!rl&&r
565283
$lower and $upper
!ll&&!rl&&r
35620931
MC/DC100%3/3
$lower and $upper and $lower->min_branch > $upper->max_branch
$lower $upper $lower->min_branch > $upper->max_branch
Truth table100%4/4
A and B and C
A= $lowerB= $upperC= $lower->min_branch > $upper->max_branch
ABCresult
0XX0
10X0
1100
1111
306 .' or newer, but '.$upper->who.' is supported only up to branch '.$upper->max_branch
307 if $lower && $upper && $lower->min_branch > $upper->max_branch;
308 596 return @conflicts;
309 }
310  
311 # Validated, flattened members of a list of requirements.
312 1087 ▶sub _members_of {
Subroutine _members_of: called CC=7 SCAR=19.5
313 1087 my ( $self, @requirements ) = @_;
314 1087 ▶ croak __PACKAGE__.'->intersect needs at least one requirement'
Branch: 1 branch
BranchTrueFalseTotal
unless @requirements 1 1086 1087
315 unless @requirements;
316 1086 for my $req ( @requirements ) {
317 1704 ▶ croak __PACKAGE__.'->intersect: not a '.__PACKAGE__.' object: '.( $req // 'undef' )
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($req) and $req->isa(__PACKAGE__) 1 1703 1704
Condition60%3/5
builtin::blessed($req) and $req->isa(__PACKAGE__)
!ll&&!rl&&r
101703
$req // "undef"
l!l
10
MC/DC50%1/2
builtin::blessed($req) and $req->isa(__PACKAGE__)
builtin::blessed($req) $req->isa(__PACKAGE__)
MC/DC0%0/1
$req // "undef"
$req
Truth table66%2/3
A and B
A= builtin::blessed($req)B= $req->isa(__PACKAGE__)
ABresult
0X0
100
111
Truth table50%1/2
A
A= $req
Aresult
11
00
318 unless blessed( $req ) && $req->isa( __PACKAGE__ );
319 }
320 1085 ▶ return map { @{ $_->members } ? @{ $_->members } : $_ } @requirements;
Branch: 1 branch
BranchTrueFalseTotal
@{$_->members;} ? : 1 1701 1702
321 }
322  
323 # The member with the highest lower bound and the one with the lowest upper
324 # bound (either may be undef).
325 686 ▶sub _bounds {
Subroutine _bounds: called CC=1 SCAR=0.0
326 686 my ( $self, @members ) = @_;
327 599 my ( $lower ) = sort { $b->min_branch <=> $a->min_branch }
328 686 grep { defined $_->min_branch } @members;
329 8 my ( $upper ) = sort { $a->max_branch <=> $b->max_branch }
330 686 grep { defined $_->max_branch } @members;
331 686 return ( $lower, $upper );
332 }
333  
334  
335 523 ▶sub describe {
Subroutine describe: called CC=6 SCAR=17.9
Pod documented
336 523 my ( $self ) = @_;
337 523 ▶ my $module = $self->kernel_module eq 'either'
Branch: 1 branch
BranchTrueFalseTotal
$self->kernel_module eq 'either' ? : 210 313 523
338 ? 'any kernel module'
339 : $self->kernel_module.' kernel module';
340 523 my ( $min, $max ) = ( $self->min_branch, $self->max_branch );
341 523 ▶ my $branch = defined $min && defined $max ? 'driver branch '.$min.' to '.$max
Branch: 3 branches
BranchTrueFalseTotal
defined $min && defined $max ? : 1 522 523
defined $min ? : 178 344 522
defined $max ? : 129 215 344
Condition100%3/3
defined $min and defined $max
!ll&&!rl&&r
3441781
MC/DC100%2/2
defined $min and defined $max
defined $min defined $max
Truth table100%3/3
A and B
A= defined $minB= defined $max
ABresult
0X0
100
111
342 : defined $min ? 'driver branch '.$min.' or newer'
343 : defined $max ? 'driver branch '.$max.' or older'
344 : 'any driver branch';
345 523 return $module.', '.$branch;
346 }
347  
348  
349 840 ▶sub who {
Subroutine who: called CC=5 SCAR=16.1
Pod documented
350 840 my ( $self ) = @_;
351 840 ▶ return join( ', ', map { $_->who } @{ $self->members } ) if @{ $self->members };
Branch: 1 branch
BranchTrueFalseTotal
if @{$self->members;} 81 759 840
352 759 ▶ my @what = grep { defined } $self->generation,
Branch: 1 branch
BranchTrueFalseTotal
defined $self->device_id ? : 743 16 759
353 defined $self->device_id ? '10de:'.$self->device_id : undef;
354 759 ▶ my $who = $self->name // 'NVIDIA GPU';
Condition100%2/2
$self->name // "NVIDIA GPU"
l!l
7545
MC/DC100%1/1
$self->name // "NVIDIA GPU"
$self->name
Truth table100%2/2
A
A= $self->name
Aresult
11
00
355 759 ▶ return @what ? $who.' ('.join( ', ', @what ).')' : $who;
Branch: 1 branch
BranchTrueFalseTotal
@what ? : 743 16 759
356 }
357  
358 36 1;
359  
360 __END__
« lib/Rex/GPU/NVIDIA/Setup/UbuntuDrivers.pm ↑ Summary blib/lib/Rex/GPU.pm »