blib/lib/Rex/GPU/Detect.pm

filter: Statementstmt 100% 249 / 249 Branchbran 95.3% 124 / 130 Conditioncond 78.9% 60 / 76 MC/DCmcdc 63.4% 26 / 41 Subroutinesub 100% 44 / 44 Podpod 100% 11 / 11 totaltotal 93.2% 514 / 551 CC 103 SCAR 19.9
CC
103
Cov
95%
detect
17.0
_resolve_amd
13.0
_nvidia_compute_by_name
10.0
CRAP 7.3
« lib/Rex/GPU/NVIDIA/Setup/Debian.pm ↑ Summary lib/Rex/GPU/NVIDIA/Setup.pm »
1 # ABSTRACT: GPU hardware detection via PCI class codes
2  
3 package Rex::GPU::Detect;
4 40 our $VERSION = '0.006';
5 40 ▶use v5.14.4;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 40 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 40 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 40 ▶use Rex::Commands::Gather ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 40 ▶use Rex::Commands::Pkg;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 40 ▶use Rex::Commands::Run;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 40 ▶use Rex::Config ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 40 ▶use Rex::Logger;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 40 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
15 40 ▶use Rex::GPU::AMD ();
Subroutine BEGIN: called CC=1 SCAR=0.0
16 40 ▶use Rex::GPU::AMD::Hardware;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 40 ▶use Rex::GPU::NVIDIA ();
Subroutine BEGIN: called CC=1 SCAR=0.0
18 40 ▶use Rex::GPU::NVIDIA::Requirement;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 40 ▶use Rex::GPU::NVIDIA::VGPU;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 40 require Rex::Exporter;
22 40 ▶use base qw(Rex::Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 40 ▶use vars qw(@EXPORT);
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 40 @EXPORT = qw(
27 detect
28 );
29  
30 # PCI class codes for display controllers
31 # [0300] = VGA controller, [0302] = 3D controller (datacenter GPUs)
32 40 my $PCI_DISPLAY_RE = qr/\[03(?:00|02)\]/;
33  
34 # [0380] = "Display controller" (karr #75): AMD Instinct MI100/MI210/MI250
35 # and the Strix Halo APU (1002:1586, live on synapse) enumerate there.
36 # [1200] = "Processing accelerators" (karr k1): the MI300 and MI350 series
37 # (MI300A/MI300X/MI325X/MI350X/MI355X) enumerate there, not at [0380] as the
38 # k75 comment had it (hardware curator for k1, from AMD's acceptance
39 # guides). Both are accepted for vendor 1002 only, never as display classes
40 # of their own -- an NVIDIA device at [0380] or [1200] stays unlisted.
41 40 my $AMD_ACCELERATOR_RE = qr/\[(?:0380|1200)\]/;
42  
43 # Virtual GPU vendor IDs — skip these (no host driver needed): virtio,
44 # QEMU/QXL, VMware, VirtualBox. Read through virtual_display_vendor_ids, by
45 # this lspci path and by Rex::GPU::Detect::Sysfs alike (karr #73).
46 40 my @VIRTUAL_DISPLAY_VENDOR_IDS = qw( 1af4 1b36 15ad 80ee );
47  
48 # NVIDIA vendor ID
49 40 my $NVIDIA_VENDOR_RE = qr/\[10de:[0-9a-f]{4}\]/i;
50  
51 # AMD vendor ID
52 40 my $AMD_VENDOR_RE = qr/\[1002:[0-9a-f]{4}\]/i;
53  
54 # NVSwitch (karr #23): an HGX baseboard's NVSwitches enumerate as NVIDIA
55 # (10de) "Bridge" devices, PCI class [0680] (PCI_CLASS_BRIDGE_OTHER, the class
56 # the NVSwitch kernel driver claims: open-gpu-kernel-modules
57 # kernel-open/nvidia/linux_nvswitch.c). A device counts as an NVSwitch only if
58 # its ID is listed here or pci.ids named it "... NVSwitch" -- NVIDIA also
59 # made other 10de:0680 devices (nForce chipset bridges), and an unknown one
60 # must not trigger a Fabric Manager install. IDs from the Fabric Manager user
61 # guide's baseboard topology listings (docs.nvidia.com/datacenter/tesla/
62 # fabric-manager-user-guide/, checked 2026-09-24) and pci.ids:
63 # 1ac2 HGX-2 (V100) NVSwitch gen1
64 # 1af1 HGX A100 NVSwitch gen2, "GA100 [A100 NVSwitch]"
65 # 22a3 HGX H100/H200/H800/H20 NVSwitch gen3, "GH100 [H100 NVSwitch]"
66 # NOT here, deliberately: HGX B200/B300/B100 (NVSwitch gen4). The guide says
67 # their NVSwitches "are not recognized as PCIe devices on the host system";
68 # the host sees ConnectX-7 bridge functions instead, so lspci cannot find them.
69 # GB200/GB300 NVL72 compute trays run no Fabric Manager at all (it runs on
70 # the NVLink switch trays). Read through nvswitch_device_ids, by this lspci
71 # path and by Rex::GPU::Detect::Sysfs alike (karr #73).
72 40 my $NVSWITCH_CLASS_RE = qr/\[0680\]/;
73 40 my %NVSWITCH_DEVICE_IDS = (
74 '1ac2' => { generation => 1 },
75 '1af1' => { generation => 2 },
76 '22a3' => { generation => 3 }
77 );
78  
79 # Rex::GPU::Detect::open_kernel_module_required and legacy_driver_requirement
80 # below are wrappers over Rex::GPU::NVIDIA::Requirement, kept with their exact
81 # return values for Rex::GPU::NVIDIA's install paths (epic karr #25).
82  
83  
84  
85 144 ▶sub detect {
Subroutine detect: called CC=17 SCAR=28.3
Pod documented
86 144 ▶ my $class = _invocant(@_) // return __PACKAGE__->configured_class->detect(@_);
Condition100%2/2
_invocant(@_) // (return __PACKAGE__->configured_class->detect(@_))
l!l
7371
MC/DC100%1/1
_invocant(@_) // (return __PACKAGE__->configured_class->detect(@_))
_invocant(@_)
Truth table100%2/2
A
A= _invocant(@_)
Aresult
11
00
87 73 $class->_ensure_lspci;
88  
89 70 my $pci_output = run "lspci -nn 2>&1 | grep -E '\\[03(00|02)\\]|\\[(0380|1200)\\].*\\[1002:'",
90 auto_die => 0;
91  
92 70 my $result = { nvidia => [], amd => [], nvswitch => [] };
93  
94 70 ▶ return $result unless $pci_output;
Branch: 1 branch
BranchTrueFalseTotal
unless $pci_output 3 67 70
95  
96 # Virtual displays are skipped PER LINE, not by matching the whole blob: a
97 # passthrough host (vfio-pci) or cloud GPU VM shows an emulated console
98 # (QXL, virtio-vga, ...) next to the real card, and a blob match hid the
99 # real card (karr #17). Vendor checks run first, so a [10de:]/[1002:] line
100 # is never classified virtual — only a line that is not NVIDIA/AMD can be.
101 67 my $virtual_ids = join '|', map { quotemeta } $class->virtual_display_vendor_ids;
102 67 my $virtual_re = qr/\[(?:$virtual_ids):[0-9a-f]{4}\]/i;
103 67 my $virtual = 0;
104 67 my @nvidia_slots;
105 67 for my $line (split /\n/, $pci_output) {
106 # [0380] and [1200] count for AMD only (karr #75, k1), whatever the grep
107 # let through.
108 94 ▶ next if $line =~ $AMD_ACCELERATOR_RE && $line !~ $AMD_VENDOR_RE;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /$AMD_ACCELERATOR_RE/u and not $line =~ /$AMD_VENDOR_RE/u 5 89 94
Condition100%3/3
$line =~ /$AMD_ACCELERATOR_RE/u and not $line =~ /$AMD_VENDOR_RE/u
!ll&&!rl&&r
75145
MC/DC100%2/2
$line =~ /$AMD_ACCELERATOR_RE/u and not $line =~ /$AMD_VENDOR_RE/u
$line =~ /$AMD_ACCELERATOR_RE/u not $line =~ /$AMD_VENDOR_RE/u
Truth table100%3/3
A and not(B)
A= $line =~ /$AMD_ACCELERATOR_RE/uB= not $line =~ /$AMD_VENDOR_RE/u
ABresult
0X0
100
111
109 89 ▶ if ($line =~ $NVIDIA_VENDOR_RE) {
Branch: 3 branches
BranchTrueFalseTotal
if ($line =~ /$NVIDIA_VENDOR_RE/u) { } 58 31 89
elsif ($line =~ /$AMD_VENDOR_RE/u) { } 23 8 31
elsif ($line =~ /$virtual_re/u) { } 6 2 8
110 58 my $gpu = $class->_parse_nvidia_line($line);
111 58 ▶ next unless $gpu;
Branch: 1 branch
BranchTrueFalseTotal
unless $gpu 0 58 58
112 58 push @{$result->{nvidia}}, $gpu;
113 58 push @nvidia_slots, $class->_pci_slot($line);
114 }
115 elsif ($line =~ $AMD_VENDOR_RE) {
116 23 my $gpu = $class->_parse_amd_line($line);
117 23 ▶ push @{$result->{amd}}, $gpu if $gpu;
Branch: 1 branch
BranchTrueFalseTotal
if $gpu 23 0 23
118 }
119 elsif ($line =~ $virtual_re) {
120 6 $virtual++;
121 6 Rex::Logger::info(" [skip] virtual display: $line");
122 }
123 }
124  
125 Rex::Logger::info("Virtual GPU detected (virtio/QEMU/VMware/VBox) — skipping")
126 67 ▶ if $virtual && !@{$result->{nvidia}} && !@{$result->{amd}};
Branch: 1 branch
BranchTrueFalseTotal
if $virtual and not @{$result->{"nvidia"};} and not @{$result->{"amd"};} 3 64 67
Condition83%5/6
$virtual and not @{$result->{"nvidia"};} and not @{$result->{"amd"};}
!ll&&!rl&&r
6403
$virtual and not @{$result->{"nvidia"};}
!ll&&!rl&&r
6223
MC/DC66%2/3
$virtual and not @{$result->{"nvidia"};} and not @{$result->{"amd"};}
$virtual not @{$result->{"nvidia"};} not @{$result->{"amd"};}
Truth table75%3/4
A and not(B) and not(C)
A= $virtualB= not @{$result->{"nvidia"};}C= not @{$result->{"amd"};}
ABCresult
0XX0
10X0
1100
1111
127  
128 # AMD (karr k1): the running driver's gfx target, only where there is an
129 # AMD GPU, so a host without one runs no extra command.
130 67 ▶ $class->_resolve_amd($result->{amd}) if @{$result->{amd}};
Branch: 1 branch
BranchTrueFalseTotal
if @{$result->{"amd"};} 22 45 67
131  
132 # NVSwitch (karr #23): only where there is an NVIDIA GPU for it to connect,
133 # so a host without one runs no extra command.
134 67 ▶ $result->{nvswitch} = $class->_detect_nvswitch if @{$result->{nvidia}};
Branch: 1 branch
BranchTrueFalseTotal
if @{$result->{"nvidia"};} 40 27 67
135  
136 # vGPU guest (karr #24): likewise only with an NVIDIA GPU, read-only.
137 67 ▶ $class->_detect_vgpu($result->{nvidia}, \@nvidia_slots) if @{$result->{nvidia}};
Branch: 1 branch
BranchTrueFalseTotal
if @{$result->{"nvidia"};} 40 27 67
138  
139 67 return $result;
140 }
141  
142 # karr #46: lspci present => install nothing (read-only; OCP needs no
143 # pciutils then). `command -v` through run, not can_run: can_run stats the
144 # path through the file interface, which needs SFTP on SSH/OpenSSH, and it
145 # answers under the same PATH the `lspci -nn` below runs with. Rex::Pkg dies
146 # "OS/Provider not supported" on the RHEL-family names lsb_release gives
147 # (karr #39), so those get dnf + rpm -q, as Setup::RHEL's install_helpers
148 # does; the name list is Rex::GPU::NVIDIA's (nvidia_class), not a copy.
149 73 ▶sub _ensure_lspci {
Subroutine _ensure_lspci: called CC=6 SCAR=17.9
150 73 my ( $class ) = @_;
151 73 ▶ return if $class->_has_lspci;
Branch: 1 branch
BranchTrueFalseTotal
if $class->_has_lspci 64 9 73
152  
153 9 ▶ if ($class->nvidia_class->_rhel_family_name(Rex::Commands::Gather::operating_system())) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class->nvidia_class->_rhel_family_name(Rex::Commands::Gather::operating_system())) { } 4 5 9
154 4 Rex::Logger::info('lspci not found -- installing pciutils with dnf');
155 4 run 'dnf install -y pciutils', auto_die => 0;
156 4 run 'rpm -q pciutils 2>&1', auto_die => 0;
157 4 ▶ croak 'pciutils not installed after dnf install -- check dnf output; '
Branch: 1 branch
BranchTrueFalseTotal
if $? != 0 1 3 4
158 .'GPU detection needs lspci' if $? != 0;
159 }
160 else {
161 5 ▶ pkg ["pciutils"], ensure => "present" unless is_installed("pciutils");
Branch: 1 branch
BranchTrueFalseTotal
unless is_installed("pciutils") 4 1 5
162 }
163  
164 8 ▶ croak 'lspci not found on the host after installing pciutils -- '
Branch: 1 branch
BranchTrueFalseTotal
unless $class->_has_lspci 2 6 8
165 .'GPU detection needs lspci on the PATH' unless $class->_has_lspci;
166 }
167  
168 54 ▶sub _has_lspci {
Subroutine _has_lspci: called CC=2 SCAR=6.9
169 54 my ( $class ) = @_;
170 54 run 'command -v lspci >/dev/null 2>&1', auto_die => 0;
171 54 ▶ return $? == 0 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$? == 0 ? : 43 11 54
172 }
173  
174 # Read-only: `lspci -nn -d 10de:` filtered to class [0680]; one hashref per
175 # recognised NVSwitch.
176 40 ▶sub _detect_nvswitch {
Subroutine _detect_nvswitch: called CC=5 SCAR=16.1
177 40 my ( $class ) = @_;
178 40 my $out = run "lspci -nn -d 10de: 2>/dev/null | grep -F '[0680]'", auto_die => 0;
179 40 my @switches;
180 40 ▶ for my $line (split /\n/, $out // '') {
Condition50%1/2
$out // ""
l!l
400
MC/DC0%0/1
$out // ""
$out
Truth table50%1/2
A
A= $out
Aresult
11
00
181 27 my $switch = $class->_parse_nvswitch_line($line);
182 27 ▶ push @switches, $switch if $switch;
Branch: 1 branch
BranchTrueFalseTotal
if $switch 4 23 27
183 }
184 40 ▶ Rex::Logger::info(' [ok] NVSwitch: '.scalar(@switches).' ('.$switches[0]{name}.')')
Branch: 1 branch
BranchTrueFalseTotal
if @switches 1 39 40
185 if @switches;
186 40 return \@switches;
187 }
188  
189 # vGPU guest (karr #24): lspci -nn shows a vGPU with the physical GPU's
190 # device ID, so only the subsystem ID tells it apart -- NVIDIA gives every
191 # vGPU type its own (Rex::GPU::NVIDIA::VGPU). `lspci -vmmnn -d 10de:` prints
192 # it per slot; each GPU gets subsystem_vendor_id/subsystem_id (undef if its
193 # slot is not in that output), vgpu 0|1 and, for 1, vgpu_type. compute is
194 # not touched: whether a driver can be installed is install_driver's call.
195 40 ▶sub _detect_vgpu {
Subroutine _detect_vgpu: called CC=9 SCAR=22.0
196 40 my ( $class, $gpus, $slots ) = @_;
197 40 my $out = run 'lspci -vmmnn -d 10de: 2>/dev/null', auto_die => 0;
198 40 my $sub = $class->_parse_lspci_vmm($out);
199 40 for my $i (0 .. $#$gpus) {
200 58 my $gpu = $gpus->[$i];
201 58 ▶ my $rec = defined $slots->[$i] ? $sub->{ $slots->[$i] } : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $slots->[$i] ? : 57 1 58
202 # a slot whose device ID is not the GPU's is not that GPU
203 undef $rec if $rec && defined $gpu->{device_id}
204 58 ▶ && ( $rec->{device_id} // '' ) ne lc $gpu->{device_id};
Branch: 1 branch
BranchTrueFalseTotal
if $rec and defined $gpu->{"device_id"} and ($rec->{"device_id"} // "") ne lc $gpu->{"device_id"} 1 57 58
Condition75%6/8
$rec and defined $gpu->{"device_id"} and ($rec->{"device_id"} // "") ne lc $gpu->{"device_id"}
!ll&&!rl&&r
5161
$rec and defined $gpu->{"device_id"}
!ll&&!rl&&r
5107
$rec->{"device_id"} // ""
l!l
70
MC/DC33%1/3
$rec and defined $gpu->{"device_id"} and ($rec->{"device_id"} // "") ne lc $gpu->{"device_id"}
$rec defined $gpu->{"device_id"} $rec->{"device_id"}
Truth table50%2/4
A and B and C
A= $recB= defined $gpu->{"device_id"}C= $rec->{"device_id"}
ABCresult
0XX0
10X0
1100
1111
205 58 ▶ $gpu->{subsystem_vendor_id} = $rec ? $rec->{subsystem_vendor_id} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$rec ? : 6 52 58
206 58 ▶ $gpu->{subsystem_id} = $rec ? $rec->{subsystem_id} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$rec ? : 6 52 58
207 58 $class->_mark_vgpu($gpu);
208 }
209 40 return;
210 }
211  
212 # vgpu 0|1 and, for 1, vgpu_type on a GPU hash whose device_id,
213 # subsystem_vendor_id and subsystem_id are set (four lowercase hex digits or
214 # undef). Shared with Rex::GPU::Detect::Sysfs, which reads the subsystem IDs
215 # from sysfs instead of lspci -vmmnn.
216 89 ▶sub _mark_vgpu {
Subroutine _mark_vgpu: called CC=3 SCAR=11.0
217 89 my ( $class, $gpu ) = @_;
218 my $type = $class->vgpu_class->type_for(
219 89 $gpu->{device_id}, $gpu->{subsystem_id}, $gpu->{subsystem_vendor_id});
220 89 ▶ $gpu->{vgpu} = defined $type ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $type ? : 4 85 89
221 89 ▶ return unless defined $type;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type 85 4 89
222 4 $gpu->{vgpu_type} = $type;
223 Rex::Logger::info(' [vgpu] NVIDIA: '.$gpu->{name}.' is an NVIDIA vGPU guest device (type '
224 .$type.', 10de:'.$gpu->{device_id}.' subsystem '.$gpu->{subsystem_id}
225 4 .') -- it needs the licensed NVIDIA vGPU guest driver');
226 4 return;
227 }
228  
229 # `lspci -vmmnn` records (blank-line separated "Key:<TAB>value" lines) =>
230 # { slot => { device_id, subsystem_vendor_id, subsystem_id } }, IDs
231 # lowercase, undef where lspci printed none. Anything else is ignored.
232 45 ▶sub _parse_lspci_vmm {
Subroutine _parse_lspci_vmm: called CC=9 SCAR=22.0
233 45 my ( $class, $out ) = @_;
234 45 my %by_slot;
235 45 ▶ for my $record (split /\n\s*\n/, $out // '') {
Condition100%2/2
$out // ""
l!l
441
MC/DC100%1/1
$out // ""
$out
Truth table100%2/2
A
A= $out
Aresult
11
00
236 36 my %f;
237 36 for my $line (split /\n/, $record) {
238 148 ▶ $f{$1} = $2 if $line =~ /\A(Slot|Device|SVendor|SDevice):\s*(.*?)\s*\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /\A(Slot|Device|SVendor|SDevice):\s*(.*?)\s*\z/u 62 86 148
239 }
240 36 ▶ next unless defined $f{Slot};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $f{"Slot"} 20 16 36
241 16 my $slot = $class->_normalize_slot($f{Slot});
242 16 ▶ next unless defined $slot;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $slot 5 11 16
243 my %id = map {
244 11 ▶ my ( $id ) = ( $f{$_} // '' ) =~ /\[([0-9a-f]{4})\]\z/i;
Condition100%2/2
$f{$_} // ""
l!l
312
MC/DC100%1/1
$f{$_} // ""
$f{$_}
Truth table100%2/2
A
A= $f{$_}
Aresult
11
00
245 33 ▶ ( $_ => defined $id ? lc $id : undef );
Branch: 1 branch
BranchTrueFalseTotal
defined $id ? : 31 2 33
246 } qw( Device SVendor SDevice );
247 $by_slot{$slot} = {
248 device_id => $id{Device},
249 subsystem_vendor_id => $id{SVendor},
250 subsystem_id => $id{SDevice}
251 11 };
252 }
253 45 return \%by_slot;
254 }
255  
256 # The PCI address an `lspci -nn` line starts with, normalized.
257 61 ▶sub _pci_slot {
Subroutine _pci_slot: called CC=1 SCAR=0.0
258 61 my ( $class, $line ) = @_;
259 61 my ( $slot ) = $line =~ /\A(\S+)\s/;
260 61 return $class->_normalize_slot($slot);
261 }
262  
263 # lspci -nn prints every slot with its domain once any device has a non-zero
264 # one; -vmm prints it only for a device whose domain is non-zero. The
265 # domain 0000 is dropped so both forms of the same device compare equal.
266 77 ▶sub _normalize_slot {
Subroutine _normalize_slot: called CC=5 SCAR=16.1
267 77 my ( $class, $slot ) = @_;
268 77 ▶ return unless defined $slot
Branch: 1 branch
BranchTrueFalseTotal
unless defined $slot and $slot =~ /\A(?:([0-9a-f]{4,}):)?([0-9a-f]{2}:[0-9a-f]{2}\.[0-7])\z/iu 6 71 77
Condition66%2/3
defined $slot and $slot =~ /\A(?:([0-9a-f]{4,}):)?([0-9a-f]{2}:[0-9a-f]{2}\.[0-7])\z/iu
!ll&&!rl&&r
0671
MC/DC50%1/2
defined $slot and $slot =~ /\A(?:([0-9a-f]{4,}):)?([0-9a-f]{2}:[0-9a-f]{2}\.[0-7])\z/iu
defined $slot $slot =~ /\A(?:([0-9a-f]{4,}):)?([0-9a-f]{2}:[0-9a-f]{2}\.[0-7])\z/iu
Truth table66%2/3
A and B
A= defined $slotB= $slot =~ /\A(?:([0-9a-f]{4,}):)?([0-9a-f]{2}:[0-9a-f]{2}\.[0-7])\z/iu
ABresult
0X0
100
111
269 && $slot =~ /\A(?:([0-9a-f]{4,}):)?([0-9a-f]{2}:[0-9a-f]{2}\.[0-7])\z/i;
270 71 my ( $domain, $bdf ) = ( $1, lc $2 );
271 71 ▶ return defined $domain && $domain !~ /\A0+\z/ ? lc($domain).':'.$bdf : $bdf;
Branch: 1 branch
BranchTrueFalseTotal
defined $domain && !($domain =~ /\A0+\z/u) ? : 17 54 71
Condition100%3/3
defined $domain and not $domain =~ /\A0+\z/u
!ll&&!rl&&r
50417
MC/DC100%2/2
defined $domain and not $domain =~ /\A0+\z/u
defined $domain not $domain =~ /\A0+\z/u
Truth table100%3/3
A and not(B)
A= defined $domainB= not $domain =~ /\A0+\z/u
ABresult
0X0
100
111
272 }
273  
274 34 ▶sub _parse_nvswitch_line {
Subroutine _parse_nvswitch_line: called CC=7 SCAR=19.5
275 34 my ( $class, $line ) = @_;
276 34 ▶ return unless defined $line && $line =~ $NVSWITCH_CLASS_RE && $line =~ $NVIDIA_VENDOR_RE;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line and $line =~ /$NVSWITCH_CLASS_RE/u and $line =~ /$NVIDIA_VENDOR_RE/u 25 9 34
Condition83%5/6
defined $line and $line =~ /$NVSWITCH_CLASS_RE/u and $line =~ /$NVIDIA_VENDOR_RE/u
!ll&&!rl&&r
2419
defined $line and $line =~ /$NVSWITCH_CLASS_RE/u
!ll&&!rl&&r
02410
MC/DC66%2/3
defined $line and $line =~ /$NVSWITCH_CLASS_RE/u and $line =~ /$NVIDIA_VENDOR_RE/u
defined $line $line =~ /$NVSWITCH_CLASS_RE/u $line =~ /$NVIDIA_VENDOR_RE/u
Truth table75%3/4
A and B and C
A= defined $lineB= $line =~ /$NVSWITCH_CLASS_RE/uC= $line =~ /$NVIDIA_VENDOR_RE/u
ABCresult
0XX0
10X0
1100
1111
277 9 my ($device_id) = $line =~ /\[10de:([0-9a-f]{4})\]/i;
278 9 my ($name) = $line =~ /:\s+NVIDIA\s+Corporation\s+(.+?)\s*\[10de:/;
279 9 ▶ $name //= 'Unknown NVIDIA bridge';
Condition50%1/2
$name //= "Unknown NVIDIA bridge"
l!l
90
MC/DC0%0/1
$name //= "Unknown NVIDIA bridge"
$name
Truth table50%1/2
A
A= $name
Aresult
11
00
280 9 ▶ unless (( grep { $_ eq lc $device_id } $class->nvswitch_device_ids )
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {$_ eq lc $device_id;} $class->nvswitch_device_ids or $name =~ /\bNVSwitch\b/iu) 2 7 9
Condition100%3/3
grep {$_ eq lc $device_id;} $class->nvswitch_device_ids or $name =~ /\bNVSwitch\b/iu
l!l&&r!l&&!r
612
MC/DC100%2/2
grep {$_ eq lc $device_id;} $class->nvswitch_device_ids or $name =~ /\bNVSwitch\b/iu
grep {$_ eq lc $device_id;} $class->nvswitch_device_ids $name =~ /\bNVSwitch\b/iu
Truth table100%3/3
A or B
A= grep {$_ eq lc $device_id;} $class->nvswitch_device_idsB= $name =~ /\bNVSwitch\b/iu
ABresult
1X1
011
000
281 || $name =~ /\bNVSwitch\b/i) {
282 2 Rex::Logger::info(" [skip] NVIDIA bridge device not known as an NVSwitch: $name [10de:$device_id]");
283 2 return;
284 }
285 return {
286 7 name => $name,
287 vendor => 'nvidia',
288 pci_class => '0680',
289 device_id => lc $device_id
290 };
291 }
292  
293 790 ▶sub _parse_nvidia_line {
Subroutine _parse_nvidia_line: called CC=4 SCAR=13.9
294 790 my ( $class, $line ) = @_;
295  
296 790 my ($pci_class) = $line =~ /\[(03\d{2})\]/;
297 790 my ($device_id) = $line =~ /\[10de:([0-9a-f]{4})\]/i;
298 790 my ($name) = $line =~ /:\s+NVIDIA\s+Corporation\s+(.+?)\s*\[10de:/;
299 790 ▶ $name //= 'Unknown NVIDIA GPU';
Condition50%1/2
$name //= "Unknown NVIDIA GPU"
l!l
7900
MC/DC0%0/1
$name //= "Unknown NVIDIA GPU"
$name
Truth table50%1/2
A
A= $name
Aresult
11
00
300 790 ▶ $pci_class //= '0300';
Condition50%1/2
$pci_class //= "0300"
l!l
7900
MC/DC0%0/1
$pci_class //= "0300"
$pci_class
Truth table50%1/2
A
A= $pci_class
Aresult
11
00
301  
302 790 my $compute = $class->_is_nvidia_compute($pci_class, $name, $device_id);
303  
304 790 ▶ my $status = $compute ? 'ok' : 'skip';
Branch: 1 branch
BranchTrueFalseTotal
$compute ? : 705 85 790
305 790 Rex::Logger::info(" [$status] NVIDIA: $name (PCI class $pci_class)");
306  
307 return {
308 790 name => $name,
309 vendor => 'nvidia',
310 pci_class => $pci_class,
311 compute => $compute,
312 device_id => $device_id, # e.g. "2e12"; undef if the line had no [10de:XXXX]
313 };
314 }
315  
316 # 1 (compute) or 0: the generation row or the PCI class decides; only where
317 # neither does, the name (karr #73: Rex::GPU::Detect::Sysfs has no name and
318 # overrides that half to return undef, "undecided"). Always exactly one
319 # value, also in list context.
320 919 ▶sub _is_nvidia_compute {
Subroutine _is_nvidia_compute: called CC=2 SCAR=6.9
321 919 my ( $class, $pci_class, $name, $device_id ) = @_;
322 919 my $compute = $class->_nvidia_compute_by_generation($pci_class, $name, $device_id);
323 919 ▶ return $compute if defined $compute;
Branch: 1 branch
BranchTrueFalseTotal
if defined $compute 869 50 919
324 50 return scalar $class->_nvidia_compute_by_name($pci_class, $name, $device_id);
325 }
326  
327 # 0 or 1 where the device ID's generation row or the PCI class decides; undef
328 # (bare return) where neither does.
329 919 ▶sub _nvidia_compute_by_generation {
Subroutine _nvidia_compute_by_generation: called CC=6 SCAR=17.9
330 919 my ( $class, $pci_class, $name, $device_id ) = @_;
331  
332 # The generation decides, not the marketing name (karr #45, #54; maintainer
333 # decision: every GPU usable for AI counts, MX/GT/GTX 9xx included). The
334 # rows of Rex::GPU::NVIDIA::Requirement cover every ID 0000-2FFF plus
335 # Blackwell Ultra: Maxwell .. Blackwell Ultra => 1, Kepler or older => 0.
336 # lspci prints the ID even when a stale pci.ids leaves the name as "Device".
337 919 my $req = $class->requirement_class->for_device_id($device_id);
338  
339 # A Kepler-or-older row wins over the PCI class (karr #55): a class-0302
340 # Tesla K80/K40/K20 is skipped like a Kepler display card, instead of
341 # reaching plan as compute and stopping the install for every other GPU.
342 919 ▶ if (defined $req->compute && !$req->compute) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $req->compute and not $req->compute) 92 827 919
Condition100%3/3
defined $req->compute and not $req->compute
!ll&&!rl&&r
5477392
MC/DC100%2/2
defined $req->compute and not $req->compute
defined $req->compute not $req->compute
Truth table100%3/3
A and not(B)
A= defined $req->computeB= not $req->compute
ABresult
0X0
100
111
343 # Skipped, not died: gpu_setup (and Rex::Rancher's gpu => 1) go on
344 # without a driver for the old card, and install for the newer ones.
345 92 ▶ Rex::Logger::info(' NVIDIA GPU '.$name.' (10de:'.$req->device_id.') is '
Branch: 1 branch
BranchTrueFalseTotal
defined $req->max_branch ? : 92 0 92
346 .$req->generation.' silicon'
347 .( defined $req->max_branch
348 ? ': it needs driver branch '.$req->max_branch.' or older, which current '
349 .'distributions no longer package'
350 : '' )
351 .' -- skipped, no driver installed', 'warn');
352 92 return 0;
353 }
354  
355 # PCI class [0302] = 3D Controller — compute/datacenter GPU; with no row
356 # (or no ID) the class alone decides.
357 827 ▶ return 1 if $pci_class eq '0302';
Branch: 1 branch
BranchTrueFalseTotal
if $pci_class eq "0302" 253 574 827
358 574 ▶ return 1 if $req->compute;
Branch: 1 branch
BranchTrueFalseTotal
if $req->compute 524 50 574
359 50 return;
360 }
361  
362 # The name rules, for a GPU the generation and the class left undecided: 1
363 # for a name of Maxwell or later, else 0 with the unknown-model warning.
364 44 ▶sub _nvidia_compute_by_name {
Subroutine _nvidia_compute_by_name: called CC=10 SCAR=23.0
365 44 my ( $class, $pci_class, $name, $device_id ) = @_;
366  
367 # Name rules: reached only for an ID no generation row covers (0x3000 and
368 # up, bar Blackwell Ultra: silicon newer than the table) or no ID at all.
369 # Each one names only products of Maxwell or later: checked against every
370 # name in NVIDIA's supportedchips lists (615.71.09), no Kepler-or-older
371 # product matches. pci.ids names a few Kepler IDs like later products
372 # (0FC5 "GK107 [GeForce GT 1030]", 11C7 "GK106 [GeForce GTX 750 Ti]", GK107
373 # "...-A1" samples) -- the Kepler row catches those by ID before this. No
374 # negative rules: anything else is the unknown default below, 0 either way.
375 44 ▶ return 1 if $name =~ /\bRTX\b/i; # Turing and later only
Branch: 1 branch
BranchTrueFalseTotal
if $name =~ /\bRTX\b/iu 1 43 44
376 43 ▶ return 1 if $name =~ /\bGTX\s*1\d{3}\b/i; # GTX 10xx Pascal, 16xx Turing
Branch: 1 branch
BranchTrueFalseTotal
if $name =~ /\bGTX\s*1\d{3}\b/iu 2 41 43
377 41 ▶ return 1 if $name =~ /\bGTX\s*(?:9\d{2}|745|750)(?!\d)/i; # Maxwell (GTX 76x-78x are Kepler)
Branch: 1 branch
BranchTrueFalseTotal
if $name =~ /\bGTX\s*(?:9\d{2}|745|750)(?!\d)/iu 2 39 41
378 39 ▶ return 1 if $name =~ /\bGT\s*1\d{3}\b/i; # GT 1010/1030 Pascal
Branch: 1 branch
BranchTrueFalseTotal
if $name =~ /\bGT\s*1\d{3}\b/iu 1 38 39
379 38 ▶ return 1 if $name =~ /\bGeForce\s+MX\s*\d{3}\b/i; # MX110..MX570; not GeForce2/4 MX
Branch: 1 branch
BranchTrueFalseTotal
if $name =~ /\bGeForce\s+MX\s*\d{3}\b/iu 1 37 38
380 37 ▶ return 1 if $name =~ /\bTITAN\s+(?:X|Xp|V|RTX)\b/i; # not the Kepler GTX TITAN/Black/Z
Branch: 1 branch
BranchTrueFalseTotal
if $name =~ /\bTITAN\s+(?:X|Xp|V|RTX)\b/iu 1 36 37
381 36 ▶ return 1 if $name =~ /\bQuadro\s+(?:GP|GV|[MPT])\s*\d/i; # Quadro M/P/T/GP/GV; K is mixed
Branch: 1 branch
BranchTrueFalseTotal
if $name =~ /\bQuadro\s+(?:GP|GV|[MPT])\s*\d/iu 1 35 36
382 35 ▶ return 1 if $name =~ /\bTesla\s+(?:[PV]\d|T4\b|M\d{1,2}\b)/; # not Fermi M20x0, Kepler K
Branch: 1 branch
BranchTrueFalseTotal
if $name =~ /\bTesla\s+(?:[PV]\d|T4\b|M\d{1,2}\b)/u 1 34 35
383 34 ▶ return 1 if $name =~ /\b[AHLVP]\d{1,3}[GSi]?\b/; # A100, H100, L40, V100, P40, ...
Branch: 1 branch
BranchTrueFalseTotal
if $name =~ /\b[AHLVP]\d{1,3}[GSi]?\b/u 5 29 34
384  
385 # Unknown — safe default
386 29 Rex::Logger::info(" Unknown NVIDIA GPU model: $name — not in compute list", "warn");
387 29 return 0;
388 }
389  
390  
391 70 ▶sub open_kernel_module_required {
Subroutine open_kernel_module_required: called CC=3 SCAR=11.0
Pod documented
392 70 ▶ my $class = _invocant(@_) // return __PACKAGE__->configured_class->open_kernel_module_required(@_);
Condition100%2/2
_invocant(@_) // (return __PACKAGE__->configured_class->open_kernel_module_required(@_))
l!l
3535
MC/DC100%1/1
_invocant(@_) // (return __PACKAGE__->configured_class->open_kernel_module_required(@_))
_invocant(@_)
Truth table100%2/2
A
A= _invocant(@_)
Aresult
11
00
393 35 my ( undef, $device_id ) = @_;
394 35 ▶ return $class->requirement_class->for_device_id($device_id)->kernel_module eq 'open'
Branch: 1 branch
BranchTrueFalseTotal
$class->requirement_class->for_device_id($device_id)->kernel_module eq 'open' ? : 16 19 35
395 ? 1 : 0;
396 }
397  
398  
399 90 ▶sub legacy_driver_requirement {
Subroutine legacy_driver_requirement: called CC=3 SCAR=11.0
Pod documented
400 90 ▶ my $class = _invocant(@_) // return __PACKAGE__->configured_class->legacy_driver_requirement(@_);
Condition100%2/2
_invocant(@_) // (return __PACKAGE__->configured_class->legacy_driver_requirement(@_))
l!l
4545
MC/DC100%1/1
_invocant(@_) // (return __PACKAGE__->configured_class->legacy_driver_requirement(@_))
_invocant(@_)
Truth table100%2/2
A
A= _invocant(@_)
Aresult
11
00
401 45 my ( undef, $device_id ) = @_;
402 45 my $req = $class->requirement_class->for_device_id($device_id);
403 45 ▶ return unless defined $req->max_branch;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $req->max_branch 21 24 45
404 24 return { generation => $req->generation, max_branch => $req->max_branch };
405 }
406  
407 28 ▶sub _parse_amd_line {
Subroutine _parse_amd_line: called CC=6 SCAR=18.1
408 28 my ( $class, $line ) = @_;
409  
410 28 my ($pci_class) = $line =~ /\[(03\d{2}|1200)\]/;
411 # Same form as _parse_nvidia_line: vendor stripped, the rest up to the
412 # [1002:xxxx] id as lspci prints it. Vendor 1002 spellings across pci.ids
413 # versions: current, the 2010-era "nee ATI" one, and the pre-2010 one.
414 28 my ($name) = $line =~ /:\s+(?:Advanced\s+Micro\s+Devices,\s+Inc\.\s+\[AMD\/ATI\]|Advanced\s+Micro\s+Devices\s+\[AMD\]\s+nee\s+ATI|ATI\s+Technologies\s+Inc\.?)\s+(.+?)\s*\[1002:/;
415 28 ▶ $name //= 'Unknown AMD GPU';
Condition100%2/2
$name //= "Unknown AMD GPU"
l!l
271
MC/DC100%1/1
$name //= "Unknown AMD GPU"
$name
Truth table100%2/2
A
A= $name
Aresult
11
00
416 28 ▶ $pci_class //= '0300';
Condition50%1/2
$pci_class //= "0300"
l!l
280
MC/DC0%0/1
$pci_class //= "0300"
$pci_class
Truth table50%1/2
A
A= $pci_class
Aresult
11
00
417 28 my ($device_id) = $line =~ /\[1002:([0-9a-f]{4})\]/i;
418 28 ▶ $device_id = lc $device_id if defined $device_id;
Branch: 1 branch
BranchTrueFalseTotal
if defined $device_id 28 0 28
419 28 my ($slot) = $line =~ /\A(\S+)\s/;
420 # A pci.ids without the device (Ubuntu 24.04's for 1002:1586, live on
421 # synapse) makes lspci print the bare placeholder "Device" (older pciutils
422 # "Device 1586"): named like the sysfs path instead, so messages say which
423 # GPU (karr k1).
424 28 ▶ $name = 'AMD GPU [1002:'.( $device_id // '????' ).']'
Branch: 1 branch
BranchTrueFalseTotal
if $name =~ /\ADevice(?:\s+[0-9a-f]{4})?\z/iu 7 21 28
Condition50%1/2
$device_id // "????"
l!l
70
MC/DC0%0/1
$device_id // "????"
$device_id
Truth table50%1/2
A
A= $device_id
Aresult
11
00
425 if $name =~ /\ADevice(?:\s+[0-9a-f]{4})?\z/i;
426  
427 28 return $class->_amd_gpu(
428 name => $name,
429 pci_class => $pci_class,
430 slot => $class->amd_class->normalize_slot($slot),
431 device_id => $device_id,
432 );
433 }
434  
435 # An AMD element (karr k1): gfx_target, compute and integrated from the
436 # device table (amd_hardware_class), all undef for an ID without a row --
437 # compute undef is "unknown", and gpu_setup installs nothing for it. The keys
438 # are always there. _resolve_amd may refine them from the running driver.
439 36 ▶sub _amd_gpu {
Subroutine _amd_gpu: called CC=1 SCAR=0.0
440 36 my ( $class, %gpu ) = @_;
441 36 my $hw = $class->amd_hardware_class->resolve(device_id => $gpu{device_id}, name => $gpu{name});
442 return {
443 vendor => 'amd',
444 %gpu,
445 36 map { $_ => $hw->{$_} } qw( gfx_target compute integrated )
446 };
447 }
448  
449 # One read-only command, the AMD driver state (Rex::GPU::AMD's state
450 # script): a GPU the running driver lists in the KFD topology gets that gfx
451 # target, which wins over the device table (with a warning when they
452 # differ). A state that cannot be read leaves the table's values; detection
453 # never dies over it. Then one status line per AMD GPU.
454 30 ▶sub _resolve_amd {
Subroutine _resolve_amd: called CC=13 SCAR=25.7
455 30 my ( $class, $gpus ) = @_;
456 30 my $amd = $class->amd_class;
457 30 my $state = eval { $amd->parse_state(scalar run($amd->state_script, auto_die => 0)) };
458 30 ▶ Rex::Logger::info(' [info] AMD driver state not readable -- gfx targets from the device table only')
Branch: 1 branch
BranchTrueFalseTotal
unless $state 12 18 30
459 unless $state;
460 30 for my $gpu (@$gpus) {
461 31 ▶ my ( $node ) = $state ? $amd->kfd_nodes($state, $gpu) : ();
Branch: 1 branch
BranchTrueFalseTotal
$state ? : 19 12 31
462 31 ▶ if ($node && defined $node->{gfx_target}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node and defined $node->{"gfx_target"}) 17 14 31
Condition66%2/3
$node and defined $node->{"gfx_target"}
!ll&&!rl&&r
14017
MC/DC50%1/2
$node and defined $node->{"gfx_target"}
$node defined $node->{"gfx_target"}
Truth table66%2/3
A and B
A= $nodeB= defined $node->{"gfx_target"}
ABresult
0X0
100
111
463 my $hw = $class->amd_hardware_class->resolve(device_id => $gpu->{device_id},
464 17 kfd_gfx_target => $node->{gfx_target}, name => $gpu->{name});
465 17 $gpu->{$_} = $hw->{$_} for qw( gfx_target compute integrated );
466 }
467 31 ▶ my $status = !defined $gpu->{compute} ? 'undecided' : $gpu->{compute} ? 'ok' : 'skip';
Branch: 2 branches
BranchTrueFalseTotal
!defined($gpu->{'compute'}) ? : 2 29 31
$gpu->{'compute'} ? : 27 2 29
468 Rex::Logger::info(' ['.$status.'] AMD: '.$gpu->{name}.' (PCI class '.$gpu->{pci_class}
469 .( defined $gpu->{slot} ? ', '.$gpu->{slot} : '' ).', '
470 .( $gpu->{gfx_target} // 'gfx target unknown' )
471 .( $gpu->{integrated} ? ', integrated' : '' ).')'
472 31 ▶ .( defined $gpu->{compute} ? '' : ' -- no hardware row, compute left undecided (undef)' ));
Branch: 3 branches
BranchTrueFalseTotal
defined $gpu->{'slot'} ? : 31 0 31
$gpu->{'integrated'} ? : 10 21 31
defined $gpu->{'compute'} ? : 29 2 31
Condition100%2/2
$gpu->{"gfx_target"} // "gfx target unknown"
l!l
292
MC/DC100%1/1
$gpu->{"gfx_target"} // "gfx target unknown"
$gpu->{"gfx_target"}
Truth table100%2/2
A
A= $gpu->{"gfx_target"}
Aresult
11
00
473 }
474 30 return;
475 }
476  
477  
478 249 ▶sub configured_class {
Subroutine configured_class: called CC=6 SCAR=18.0
Pod documented
479 249 my ( $class, $detect ) = @_;
480 249 my $origin = 'detect =>';
481 249 ▶ unless (defined $detect && $detect ne '') {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $detect and $detect ne "") 236 13 249
Condition66%2/3
defined $detect and $detect ne ""
!ll&&!rl&&r
236013
MC/DC50%1/2
defined $detect and $detect ne ""
defined $detect $detect ne ""
Truth table66%2/3
A and B
A= defined $detectB= $detect ne ""
ABresult
0X0
100
111
482 236 $detect = Rex::Config->get('gpu_detect_class');
483 236 $origin = 'set gpu_detect_class';
484 236 ▶ return __PACKAGE__ unless defined $detect && $detect ne '';
Branch: 1 branch
BranchTrueFalseTotal
unless defined $detect and $detect ne "" 233 3 236
Condition100%3/3
defined $detect and $detect ne ""
!ll&&!rl&&r
22313
MC/DC100%2/2
defined $detect and $detect ne ""
defined $detect $detect ne ""
Truth table100%3/3
A and B
A= defined $detectB= $detect ne ""
ABresult
0X0
100
111
485 }
486 16 ▶ croak 'GPU detection class from '.$origin.' must be a class name, not '.$detect
Branch: 1 branch
BranchTrueFalseTotal
if ref $detect 0 16 16
487 .'. Nothing was changed on the host'
488 if ref $detect;
489 16 return $class->nvidia_class->load_user_class($detect,
490 base => __PACKAGE__, what => 'GPU detection class', origin => $origin);
491 }
492  
493 998 ▶sub requirement_class { 'Rex::GPU::NVIDIA::Requirement' }
Subroutine requirement_class: called CC=1 SCAR=0.0
Pod documented
494  
495 89 ▶sub vgpu_class { 'Rex::GPU::NVIDIA::VGPU' }
Subroutine vgpu_class: called CC=1 SCAR=0.0
Pod documented
496  
497 25 ▶sub nvidia_class { 'Rex::GPU::NVIDIA' }
Subroutine nvidia_class: called CC=1 SCAR=0.0
Pod documented
498  
499 66 ▶sub amd_class { 'Rex::GPU::AMD' }
Subroutine amd_class: called CC=1 SCAR=0.0
Pod documented
500  
501 53 ▶sub amd_hardware_class { 'Rex::GPU::AMD::Hardware' }
Subroutine amd_hardware_class: called CC=1 SCAR=0.0
Pod documented
502  
503 34 ▶sub nvswitch_device_ids { sort keys %NVSWITCH_DEVICE_IDS }
Subroutine nvswitch_device_ids: called CC=1 SCAR=0.0
Pod documented
504  
505 108 ▶sub virtual_display_vendor_ids { @VIRTUAL_DISPLAY_VENDOR_IDS }
Subroutine virtual_display_vendor_ids: called CC=1 SCAR=0.0
Pod documented
506  
507 # Called as a method (Rex::GPU::Detect->detect, My::GPU::Detect->detect):
508 # the invocant, a class name or object that isa Rex::GPU::Detect. Called as a
509 # function (detect() from a Rexfile, Rex::GPU::Detect::detect(),
510 # open_kernel_module_required('2b85')): undef -- a device ID is no package of
511 # ours, and nothing is loaded to find out.
512 346 ▶sub _invocant {
Subroutine _invocant: called CC=5 SCAR=16.5
513 346 my ( $first ) = @_;
514 346 ▶ return unless defined $first && ( !ref $first || blessed $first );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $first and !ref($first) || builtin::blessed($first) 74 272 346
Condition50%3/6
defined $first and !ref($first) || builtin::blessed($first)
!ll&&!rl&&r
740272
not ref $first or builtin::blessed($first)
l!l&&r!l&&!r
27200
MC/DC33%1/3
defined $first and !ref($first) || builtin::blessed($first)
defined $first not ref $first builtin::blessed($first)
Truth table50%2/4
A and not(B) or C
A= defined $firstB= not ref $firstC= builtin::blessed($first)
ABCresult
0XX0
1000
11X1
1011
515 272 ▶ return $first if eval { $first->isa(__PACKAGE__) };
Branch: 1 branch
BranchTrueFalseTotal
if eval { do { $first->isa(__PACKAGE__) } } 194 78 272
516 78 return;
517 }
518  
519 40 1;
520  
521 __END__
« lib/Rex/GPU/NVIDIA/Setup/Debian.pm ↑ Summary lib/Rex/GPU/NVIDIA/Setup.pm »