-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgpu_lookup_tableGUI.ps1
983 lines (886 loc) · 30.3 KB
/
gpu_lookup_tableGUI.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
[CmdletBinding()]
Param (
[string]$ConfigFile
)
if (! $ConfigFile) { $ConfigFile = '.\instance.json' }
$config = (Get-Content $ConfigFile) | ConvertFrom-Json
$AM_API = $config.params.awesomeMinerAPIConfig.enabled
$AM_API_URL = $config.params.awesomeMinerAPIConfig.awesomeHostURL
$AM_API_KEY = $config.params.awesomeMinerAPIConfig.awesomeAPIKey
# External Programs
$putty = $config.programs.putty
$plink = $config.programs.plink
if (-not $config.tests.testMode)
{
. .\p7zip_util.ps1
$P7Zip = $config.programs.p7zip
}
# HELPERS
[Regex]$BUSID_REGEX = '(:[0-9a-f]{2}){2}\.\d'
[Regex]$GPU_BUSID_REGEX = '(:[0-9a-f]{2})(:00)\.\d'
# Supported baseboard names
$SUPPORTED_BASEBOARDS = @(
'BTC-T37',
'BTC-S37',
'ONDA B250 BTC V1.05',
'TB85',
# OctoMiner
'12XTREME',
'X12ULTRA',
'B85 ULTRA',
'CRESCENTBAY',
'B75',
'skylake'
)
## PIRQ MAPS
# ONDA B250
$b250_pirq_hard_map = @(16, 37, 38, 39, 40, 41, 42, 43, 48, 53, 54, 55)
# BTC-T37, BTC-S37
$x37_pirq_hard_map = @(16, 9, 10, 16, 17, 18, 33, 34)
# TB85
$tb85_pirq_hard_map = @(16, 33, 34, 8, 9, 10)
# Octo 8x (ULTRA)
$octo8_pirq_hard_map = @(34, 33, 32, 39, 35, 36, 37, 38)
# CRESCENTBAY
$crescentbay_pirq_hard_map = @(16, 33, 34, 35, 36, 37, 38, 39)
# B75
$b75_pirq_hard_map = @(33, 34, 8, 9, 10, 6, 17, 18) #slot 6 doesn't have a slot number
# skylake
$skylake_pirq_hard_map = @(32, 37, 36, 35, 40, 43, 41, 33)
## End PIRQ MAPS
# OctoMiner 12x (XTREME/ULTRA)
$octo12_hard_map = @('01', '07', '0c', '0d', '0b', '05', '0a', '04', '09', '03', '08', '02')
# FUNCTIONS
Function Find-GPU-Context-Offset
{
$gpu_driver_context = Get-GPU-Driver
if ($gpu_driver_context -eq 'nvidia')
{
return 1
}
elseif ($gpu_driver_context -eq 'amdgpu')
{
if ((Get-Content .\lspcimm.txt | Select-String -Pattern 'Ellesmere').Matches)
{
return 1
}
return 2
}
return $gpu_driver_context
}
Function Find-AM-GPU-Miner
{
$miners = (Get-Content .\miners.json) | ConvertFrom-Json
if (-not $config.options.checkBypassAM)
{
foreach ($miner in $miners)
{
if ($miner.type -eq 'GPU' -and $miner.hostname -eq $remote_ip)
{
$miner = (Invoke-WebRequest -UseBasicParsing -Uri "$AM_API_URL/miners/$($miner.id)?key=$AM_API_KEY").Content | ConvertFrom-Json
# miner can't be offline or disabled
if (! $miner.isOffline)
{
return $miner
}
else
{ Throw 'ERROR (Offline Miner: unable to fetch miner due to it being offline.)' }
}
}
Throw 'ERROR (Unknown Miner: unable to find miner. Miner could be disabled or has recently been added to AM.)'
}
}
Function Read-All-PCI-Busids
{
if (
$PIRQ_FOUND -or
# PRIME Z390 exemption
$mb_product_name -eq 'PRIME Z390-P'
)
{
$pdev = @()
# Navi Support
if ((Get-Content .\lspcimm.txt | Select-String -Pattern 'Navi').Matches)
{
$pci_bridges = (Get-Content .\lspcimm.txt | Select-String -Pattern 'Upstream Port of PCI').Line | ForEach-Object { $_ | Show-Column -Column 0 }
}
# Vega Support
elseif ((Get-Content .\lspcimm.txt | Select-String -Pattern 'Vega').Matches)
{
$pci_bridges = (Get-Content .\lspcimm.txt | Select-String -Pattern 'PCIe Bridge" -rc3').Line | ForEach-Object { $_ | Show-Column -Column 0 }
}
else
{ $pci_bridges = (Get-Content .\lspcimm.txt | Select-String -Pattern '"PCI bridge" "Intel').Line | ForEach-Object { $_ | Show-Column -Column 0 } }
foreach ($bus in $pci_bridges)
{
$is_lshwpci_gpu = (Get-Content .\lshwpci.txt | Select-String -Pattern "0000:$bus" -Context 0, (Find-GPU-Context-Offset) | Out-String -Stream | Select-String -Pattern $GPU_BUSID_REGEX -AllMatches).Matches
if ($is_lshwpci_gpu)
{
$lshwpci_gpu = $is_lshwpci_gpu[-1].Value.Trim(':')
$is_ethernet = (Get-Content .\lspcimm.txt | Select-String -Pattern $lshwpci_gpu | Out-String -Stream | Select-String 'Ethernet')
if (-not $is_ethernet.Matches)
{
$pdev += $bus
}
}
}
return Write-Output -NoEnumerate $pdev
}
Write-Output -NoEnumerate $BUSID_REGEX.Matches((& Get-Content .\dmidecodet9.txt | Select-String -Pattern 'Bus Address')) | ForEach-Object { $_.Value.Trim(':') }
}
Function Read-All-GPU-Busids
{
$gdev = @()
foreach ($bus in $pci_busids)
{
$installed_gpu = (Get-Content .\lshwpci.txt | Select-String -Pattern "0000:$bus" -Context 0, (Find-GPU-Context-Offset ) | Out-String -Stream | Select-String -Pattern $GPU_BUSID_REGEX -AllMatches).Matches[-1].Value.Trim(':')
$gdev += $installed_gpu
}
return Write-Output -NoEnumerate $gdev
}
Function Get-GPU-Driver
{
$gpu_driver = (Get-Content .\gpu_driver.txt)
if (! $gpu_driver)
{
Throw 'ERROR (Unknown GPU Driver: unable to find gpu driver.)'
}
return $gpu_driver
}
Function Get-GPU-Info
{
$gpu_infos = @()
$gpu_driver = Get-GPU-Driver
$gpu_data = (Get-Content .\nvidiasmi.txt)
$gpu_type = 'nvidia'
if ($gpu_driver -eq 'amdgpu')
{
$gpu_data = (Get-Content .\dmesgamd.txt)
$gpu_type = 'amd'
}
foreach ($bus in $gpu_busids)
{
if ($bus -eq 'MISSING') { continue }
$subvender = (Get-Content .\lspcimm.txt | Select-String -Pattern "$bus").Line | Show-Column -Delimiter '"' -Column 7
if ($gpu_type -eq 'amd')
{
$name = (Get-Content .\lspcimm.txt | Select-String -Pattern "$bus").Line | Show-Column -Delimiter '"' -Column 5
$mem = ($gpu_data | Select-String -Pattern "amdgpu 0000:${bus}:.*?VRAM:\s([^\s]+)").Matches.Groups[1].Value
}
elseif ($gpu_type -eq 'nvidia')
{
$name = ($gpu_data | Select-String -Pattern "00000000:$bus").Line | Show-Column -Delimiter ',' -Column 1
$mem = ($gpu_data | Select-String -Pattern "00000000:$bus").Line | Show-Column -Delimiter ',' -Column 2
}
$gpu_infos += '{0} {1} {2}' -f ($subvender, $name, $mem)
}
return Write-Output -NoEnumerate $gpu_infos
}
Function Read-Filtered-PCI-Busids
{
$pdev = @()
foreach ($bus in $gpu_busids)
{
$attached_pci = (Get-Content .\lshwpci.txt | Select-String -Pattern "0000:$bus" -Context (Find-GPU-Context-Offset), 0 | Out-String -Stream | Select-String -Pattern $BUSID_REGEX -AllMatches).Matches[0].Value.Trim(':')
$pdev += $attached_pci
}
return Write-Output -NoEnumerate $pdev
}
Function Read-PCI-Slot-Info
{
param(
[string]$query
)
if ($mb_product_name -eq 'PRIME Z390-P')
{
$pci_busids = Write-Output -NoEnumerate $BUSID_REGEX.Matches((& Get-Content .\dmidecodet9.txt | Select-String -Pattern 'Bus Address')) | ForEach-Object { $_.Value.Trim(':') }
}
$empty_index = 0
$empty_pci_slot_lines = (Get-Content .\dmidecodet9.txt | Select-String -Pattern '0000:00:00.0').LineNumber
$pci_query_info = @()
for ($idx = 0; $idx -lt $pci_busids.count; $idx++)
{
$pci_slot_info = (Get-Content .\dmidecodet9.txt | Select-String -Pattern $pci_busids[$idx] -Context 12, 0 | Out-String -Stream | Select-String -CaseSensitive -Pattern $query | Show-Column -Column 3)
if ($pci_busids[$idx] -eq '00:00.0')
{
$pci_slot_info = (Get-Content .\dmidecodet9.txt -TotalCount ($empty_pci_slot_lines[$empty_index]) | Select-String -CaseSensitive -Pattern $query -Context 12, 0).Line | Select-Object -Last 1 | Show-Column -Column 1
$empty_index++
}
if ($mb_product_name -eq 'TB360-BTC D+')
{
if ($query -eq 'Designation')
{
if ($idx -eq 0)
{
$pci_query_info += $pci_slot_info
}
else
{
$pci_query_info += Write-Output "PEX16_$($pci_slot_info[-1].ToString().ToInt32($null) + 1)"
}
}
else
{ $pci_query_info += $pci_slot_info }
}
else
{ $pci_query_info += $pci_slot_info }
}
return Write-Output -NoEnumerate $pci_query_info
}
Function Get-PCI-Handle-Count
{
$pci_handles = @((Get-Content .\dmidecodet9.txt | Select-String -Pattern 'Handle ' -AllMatches) | ForEach-Object { $_ | Show-Column -Column 1 })
return $pci_handles.Count
}
Function Get-Baseboard-Product-Name
{
return (Get-Content .\mb_product_name.txt)
}
# PIRQ TABLE FUNCS
Function Test-For-PIRQ-Table
{
if ((Get-Content .\biosdecode.txt | Select-String -Pattern 'PCI Interrupt Routing').Matches) { return 0 }
return 1
}
Function Read-Baseboard-BIOS
{
return (Get-Content .\dmidecodebios.txt)
}
Function Update-Baseboard-Product-Name
{
for ($idx = 0; $idx -lt $SUPPORTED_BASEBOARDS.Count; $idx++)
{
if ($SUPPORTED_BASEBOARDS[$idx] -eq $mb_product_name)
{
return ( $idx + 1 )
}
}
return $mb_product_name
}
Function Search-PIRQ-Hard-Maps
{
$support_idx = $mb_product -as [int]
if ($null -eq $support_idx)
{ Throw "ERROR (Unsupported: The detected motherboard model is not supported: $mb_product)" }
switch ($support_idx)
{
# BTC-S37, BTC-T37
{ ($_ -eq 1) -or ($_ -eq 2) } { return Write-Output -NoEnumerate $x37_pirq_hard_map }
# ONDA B250
3 { return Write-Output -NoEnumerate $b250_pirq_hard_map }
# TB85
4 { return Write-Output -NoEnumerate $tb85_pirq_hard_map }
# 12XTREME, X12ULTRA
{ ($_ -eq 5) -or ($_ -eq 6) } { return Write-Output -NoEnumerate $octo12_hard_map }
# B85 ULTRA
7 { return Write-Output -NoEnumerate $octo8_pirq_hard_map }
# CRESCENTBAY
8 { return Write-Output -NoEnumerate $crescentbay_pirq_hard_map }
# B75
9 { return Write-Output -NoEnumerate $b75_pirq_hard_map }
# skylake
10 { return Write-Output -NoEnumerate $skylake_pirq_hard_map }
}
}
Function Read-PIRQ-Device-Slot-Ids
{
$devices = $gpu_busids
if ((Get-Content .\gpu_driver.txt | Select-String -Pattern 'amdgpu').Matches -and (Find-GPU-Context-Offset) -ne 1)
{
$devices = $pci_busids
}
$pirq_device_slot_ids = @()
# OctoMiner 12x
if ($mb_product_name -eq '12XTREME' -or $mb_product_name -eq 'X12ULTRA')
{
foreach ($bus in $devices)
{
for ($idx = 0; $idx -lt $pirq_map.Count; $idx++)
{
if ("$bus".Substring(0, 2) -eq $pirq_map[$idx])
{
$pirq_device_slot_ids += $idx
break
}
}
}
return Write-Output -NoEnumerate $pirq_device_slot_ids
}
$cp_of_pirq_map = $pirq_map.Clone()
foreach ($bus in $devices)
{
if ($bus -eq 'MISSING') { continue }
$is_pirq_slot_number_match = (Get-Content .\biosdecode.txt | Select-String -Pattern $bus.Split('.')[0] | Out-String -Stream | Select-String -Pattern 'slot(?: number | )([0-9]{1,})')
try
{
$pirq_slot_number = $is_pirq_slot_number_match.Matches.Groups[1].Value
}
catch
{
#
}
# little bit of headache to get around multiple "16" entries with crescentbay boards
if ($bus -eq '01:00.0' -and $pirq_slot_number -eq '16')
{
$pirq_device_slot_ids += 0
$cp_of_pirq_map[0] = ''
continue
}
elseif ($pirq_slot_number -eq '16' -and $bus -ne '01:00.0')
{
$cp_of_pirq_map[0] = ''
}
# fix BTC-X37 showing slot 1 MISSING when slot 7 is MISSING
if ($mb_product_name -eq 'BTC-T37' -or $mb_product_name -eq 'BTC-S37')
{
if ($pirq_slot_number -eq '33' -and $bus -eq '01:00.0')
{
$pirq_device_slot_ids += 0
$cp_of_pirq_map[0] = ''
continue
}
}
# fix B75 slot 6 not having slot number
if ($mb_product_name -eq 'B75')
{
if ($null -eq $is_pirq_slot_number_match)
{
$pirq_device_slot_ids += 5
$cp_of_pirq_map[5] = ''
continue
}
}
for ($idx = 0; $idx -lt $cp_of_pirq_map.Count; $idx++)
{
if ($cp_of_pirq_map[$idx] -eq $pirq_slot_number)
{
$pirq_device_slot_ids += $idx
$cp_of_pirq_map[$idx] = ''
break
}
}
}
Remove-Variable devices
Remove-Variable cp_of_pirq_map
return Write-Output -NoEnumerate $pirq_device_slot_ids
}
Function Get-Missing-Slot-Ids
{
$missing_slot_ids = @()
if ($PIRQ_FOUND)
{
$slot_ids = @(0..($pirq_map.Count - 1))
}
else
{ $slot_ids = @(0..((Get-PCI-Handle-Count) - 1)) }
foreach ($id in $slot_ids)
{
if ($pci_info_ids -notcontains $id)
{
$missing_slot_ids += $id
}
}
return Write-Output -NoEnumerate $missing_slot_ids
}
Function Get-PIRQ-Device-Designations
{
$pirq_device_slot_designations = @()
foreach ($id in $pci_info_ids)
{
$pirq_device_slot_designations += "PCIE $( $id + 1 )"
}
return Write-Output -NoEnumerate $pirq_device_slot_designations
}
## END PIRQ TABLE FUNCS
Function Request-Data
{
# Need to make manual connection first to accept remote host key
Write-Output 'Ensuring remote host is trusted and can connect...'
Write-Output 'y' | & $plink -ssh $username@$remote_ip 2> $null
$bios_info = '#'
$gi_info = '#'
if ($config.debug.debugBIOS)
{
$bios_info = " for d in system-manufacturer system-product-name bios-release-date bios-version; do echo `"`${d^} : `" `$(echo `"$pl_passwd`" | sudo -S -k dmidecode -s `$d); done > /tmp/dmidecodebios.txt"
}
if ($config.options.checkGI)
{
$gi_info = " head -n 60 /var/log/awesome/$($miner.softwareType)*/console_output.txt > /tmp/console_output.txt;"
}
@"
function check_depends {
echo `"$pl_passwd`" | sudo -S -k apt-get update &> /dev/null
for d in dmidecode lshw; do
PKG_OK=`$(dpkg-query -W --showformat='`${Status}\n' `"`$d`" | grep `"install ok installed`")
if [[ `"`" == `"`$PKG_OK`" ]]; then
echo `"$pl_passwd`" | sudo -S -k apt-get install `"`$d`" &> /dev/null
fi
done
}
if [[ `$(groups `"`$USER`" | grep -qE 'sudo|root') -eq 1 ]]; then
echo "ERROR: `$USER is not sudoer!"
else
check_depends
$bios_info
$gi_info
lsmod | grep -oE 'nvidia|amdgpu' -m 1 > /tmp/gpu_driver.txt
echo `"$pl_passwd`" | sudo -S -k dmesg | grep 'amdgpu 0000:' > /tmp/dmesgamd.txt
nvidia-smi --query-gpu=gpu_bus_id,name,memory.total --format=csv,noheader > /tmp/nvidiasmi.txt
echo `"$pl_passwd`" | sudo -S -k dmidecode -s baseboard-product-name > /tmp/mb_product_name.txt
echo `"$pl_passwd`" | sudo -S -k dmidecode -t 9 > /tmp/dmidecodet9.txt
echo `"$pl_passwd`" | sudo -S -k biosdecode > /tmp/biosdecode.txt
lspci -mm > /tmp/lspcimm.txt
echo `"$pl_passwd`" | sudo -S -k lshw | grep 'pci@' > /tmp/lshwpci.txt
cd /tmp && tar -jcf - gpu_driver.txt dmesgamd.txt nvidiasmi.txt mb_product_name.txt dmidecodebios.txt dmidecodet9.txt biosdecode.txt lspcimm.txt lshwpci.txt console_output.txt
fi
"@ | Out-File -Encoding ascii -FilePath .\payload
$cmd_string = "`"$plink`" -ssh -pw `"$pl_passwd`" -batch $username@$remote_ip -m .\payload > ..\$remote_ip.tar.bz2"
& $CMD /c $cmd_string 2> $null
# lets exit if we encounter errors with plink
if ($LASTEXITCODE -eq 1) { Throw 'ERROR (Connection Error: unable to connect to remote IP. Supplied password may not have been accepted)' }
if ((Get-Content "..\$remote_ip.tar.bz2" | Select-String -Pattern 'ERROR').Line)
{
Throw 'ERROR (Permission Error: Supplied User is not sudoer)'
}
Expand-Tar "..\$remote_ip.tar.bz2" .
Expand-Tar "$remote_ip.tar" .
if ($config.debug.keepFiles)
{
$miner | ConvertTo-Json -Depth 4 | Out-File 'miner.json'
Update-Tar "$remote_ip.tar" 'miner.json', 'instance.json'
Update-Tar "..\$remote_ip.tar.bz2" "$remote_ip.tar"
}
else
{
Write-Verbose 'Keep not supplied, removing remote files...'
Remove-Item "..\$remote_ip.tar.bz2" -ErrorAction SilentlyContinue
}
Remove-Item "$remote_ip.tar" -ErrorAction SilentlyContinue
Remove-Item .\payload -ErrorAction SilentlyContinue
}
Function Get-GPU-Ids
{
$gids = [string[]]::new($gpu_busids.Count)
$gid = 0
for ($idx = 0; $idx -lt $gpu_busids.Count; $idx++)
{
if ($gpu_busids[$idx] -ne 'MISSING')
{
$gids[$idx] = $gid
$gid++
}
else
{ $gids[$idx] = '-' }
}
return Write-Output -NoEnumerate $gids
}
Function Get-GPU-Busids-Length
{
$length = 0
foreach ($dev in $gpu_busids)
{
if ($dev -ne 'MISSING')
{
$length++
}
}
Write-Output $length
}
Function Test-GPU-Indexes
{
param(
[string[]]$gpu_indexes
)
$validated = @()
foreach ($gpu_index in $gpu_indexes)
{
$gix = $gpu_index -as [int]
if ($null -eq $gix)
{
Write-Warning "Invalid filter input: $gpu_index is not a valid index. Continuing..."
continue
}
if ($gix -ge $n_system_slots)
{
Write-Warning "Invalid filter input: $gix is out of range of number of PCIE slots in the system. Continuing..."
continue
}
if ($gpu_ids -notcontains $gix)
{
Write-Warning "Invalid filter input: $gix is non-existent GPU ID. Continuing..."
continue
}
$validated += $gix
}
if ($validated.Length)
{
return Write-Output -NoEnumerate $validated
}
}
Function Test-If-Empty
{
param(
$arr
)
if ($arr -and $arr[0] -is [int])
{
return ('@(' + ($arr -join ', ') + ')')
}
elseif ($arr)
{
return ('@("' + ($arr -join '", "') + '")')
}
else
{
return '$null'
}
}
Function Format-Lookup-Table
{
if ($config.debug.debugMode)
{
$table = 0..($gpu_busids.Length - 1) | ForEach-Object {
[PSCustomObject]@{ GPU_ID = $gpu_ids[$_]; PCI_SLOT_ID = $pci_info_ids[$_]; PCI_LOCATOR = $pci_info_designations[$_]; PCI_BUS_IDS = $pci_busids[$_]; GPU_BUS_IDS = $gpu_busids[$_]; GPU_NAME = $gpu_detect_info[$_]; }
}
if ($config.options.checkGI)
{
$table = 0..($gpu_busids.Length - 1) | ForEach-Object {
[PSCustomObject]@{ GPU_ID = $gpu_ids[$_]; PCI_SLOT_ID = $pci_info_ids[$_]; PCI_LOCATOR = $pci_info_designations[$_]; PCI_BUS_IDS = $pci_busids[$_]; GPU_BUS_IDS = $gpu_busids[$_]; GPU_GI_INDICATORS = $gi_indicators[$_]; GPU_NAME = $gpu_detect_info[$_]; }
}
}
return $table
}
$table = 0..($gpu_busids.Length - 1) | ForEach-Object {
[PSCustomObject]@{ GPU_ID = $gpu_ids[$_]; SLOT_NUMBER = $pci_info_designations[$_]; GPU_BUS_IDS = $gpu_busids[$_]; GPU_NAME = $gpu_detect_info[$_]; }
}
if (! $config.options.checkGI -and ! $config.options.checkAll)
{
Write-Warning 'Only showing MISSING PCI/GPU devices'
$table = 0..($gpu_busids.Length - 1) | ForEach-Object {
if ($pci_busids[$_] -eq 'MISSING' -or $gpu_busids[$_] -eq 'MISSING')
{
[PSCustomObject]@{ GPU_ID = $gpu_ids[$_]; SLOT_NUMBER = $pci_info_designations[$_]; GPU_BUS_IDS = $gpu_busids[$_]; GPU_NAME = $gpu_detect_info[$_]; }
}
}
return $table
}
elseif ($config.options.checkGI -and ! $config.options.checkAll)
{
Write-Warning 'Only showing GPUs with indicated GIs'
$table = 0..($gpu_busids.Length - 1) | ForEach-Object {
if ($gi_indicators[$_])
{
[PSCustomObject]@{ GPU_ID = $gpu_ids[$_]; SLOT_NUMBER = $pci_info_designations[$_]; GPU_BUS_IDS = $gpu_busids[$_]; GPU_GI_INDICATORS = $gi_indicators[$_]; GPU_NAME = $gpu_detect_info[$_] }
}
}
return $table
}
elseif ($config.options.checkGI -and $config.options.checkAll)
{
$table = 0..($gpu_busids.Length - 1) | ForEach-Object {
[PSCustomObject]@{ GPU_ID = $gpu_ids[$_]; SLOT_NUMBER = $pci_info_designations[$_]; GPU_BUS_IDS = $gpu_busids[$_]; GPU_GI_INDICATORS = $gi_indicators[$_]; GPU_NAME = $gpu_detect_info[$_]; }
}
}
if ($config.options.filterMode -and $search_list)
{
$filtered_table = @()
$filter_list = Write-Output -NoEnumerate (Test-GPU-Indexes $search_list)
if ($null -eq $filter_list)
{
Write-Warning 'Filter input was invalid or missing. Returning normal table...'
return $table
}
foreach ($row in $table)
{
if ($filter_list -contains $row.GPU_ID)
{
$filtered_table += $row
}
}
return $filtered_table
}
return $table
}
Function Show-Table
{
Write-Output 'GPU Lookup Table'
if ($config.options.filterMode -and $search_list -and $config.options.checkAll)
{
Write-Output "for $remote_ip`: $( $search_list -join ', ' )"
}
else
{ Write-Output "for $remote_ip" }
Write-Output '####################################################'
if ($config.debug.debugBIOS)
{
Write-Output (Read-Baseboard-BIOS)
Remove-Item .\dmidecodebios.txt -ErrorAction SilentlyContinue
}
if ($config.options.listView)
{
Write-Output (Format-Lookup-Table) | Sort-Object -Property { [int]($_.SLOT_NUMBER -split '\s')[1] } | Format-List
}
else
{ Write-Output (Format-Lookup-Table) | Format-Table -AutoSize }
Write-Output ('Total Detected Cards: {0}' -f $n_detected_cards)
}
Function Show-Column
{
param (
[Parameter(Mandatory, ValueFromPipeline)][string]$line,
[string]$Delimiter,
[int]$Column
)
if (! $Delimiter) { $Delimiter = ' ' }
($line -split $Delimiter)[$Column]
}
Function Unprotect-SecureString
{
param (
[System.Security.SecureString]$SecureString
)
$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($SecureString)
$Plain = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
[System.Runtime.InteropServices.Marshal]::ZeroFreeBSTR($BSTR)
$SecureString = $SecureString.Dispose()
Return $Plain
}
if ($config.debug.debugMode)
{
$DebugPreference = 'Continue'
Write-Debug 'Debug Mode Enabled.'
}
# cmd
$CMD = 'C:\Windows\System32\cmd.exe'
$remote_ip = $config.options.input.remoteIP
$username = $config.options.input.username
$remote_passwd = $config.options.input.passwd
$search_list = ($config.options.input.filterList).Split(',')
# Comment when debugging
if (-not $config.debug.debugMode -and -not $config.tests.testMode)
{
if (! $username.Length)
{
$username = 'user'
}
if (! $remote_passwd.Length)
{
if (! $env:Default) { Throw 'ERROR (Missing Credentials: No password for remote target supplied)' }
$remote_passwd = $env:Default | ConvertTo-SecureString
}
else
{ $remote_passwd = $remote_passwd | ConvertTo-SecureString }
$pl_passwd = Unprotect-SecureString $remote_passwd
$remote_passwd = $remote_passwd.Dispose()
# Fetch miner via ip from AM api
if ($putty -and $config.options.checkPutty)
{
# Launch a new PuTTY session for further debugging
$cmd_args = "-ssh -l $username -pw `"$pl_passwd`" $remote_ip"
Start-Process -FilePath $putty -ArgumentList $cmd_args
}
if ($AM_API)
{
$miner = Find-AM-GPU-Miner
}
Write-Verbose "Setting up remote connection to $remote_ip..."
Request-Data
Remove-Variable pl_passwd -ErrorAction SilentlyContinue
}
elseif ((Test-Path .\miner.json))
{
$miner = (Get-Content .\miner.json) | ConvertFrom-Json
}
$PIRQ_FOUND = $FALSE # Flag for $PIRQ table found
$mb_product_name = (Get-Baseboard-Product-Name)
Write-Debug "Baseboard: $mb_product_name"
$mb_product = (Update-Baseboard-Product-Name)
if (
(Test-For-PIRQ-Table) -eq 0 -or
# OctoMiner 12x exemption
$mb_product_name -eq '12XTREME' -or $mb_product_name -eq 'X12ULTRA'
)
{
$PIRQ_FOUND = $TRUE
$pirq_map = Search-PIRQ-Hard-Maps
Write-Debug 'Using the BIOS PIRQ Table: '
Write-Debug "$pirq_map"
}
else
{
Write-Warning "`$PIRQ Table not found. Continuing..."
Write-Warning 'The table information may be inaccurate, or flat-out incomplete.'
}
Write-Verbose 'Fetching PCI(E) and attached GPU bus addresses...'
$pci_busids = Read-All-PCI-Busids
Write-Debug ('PCI BUSIDS - {0}' -f ($pci_busids -join ','))
$gpu_busids = Read-All-GPU-Busids
Write-Debug ('GPU BUSIDS - {0}' -f ($gpu_busids -join ','))
# find the number on system slots
if ($PIRQ_FOUND)
{
$n_system_slots = $pirq_map.Count
}
else
{ $n_system_slots = (Get-PCI-Handle-Count) }
Write-Verbose 'Examining System for MISSING PCI(E) slots and devices...'
$pci_missing_devices = @()
$gpu_missing_devices = @()
for ($idx = 0; $idx -lt $n_system_slots; $idx++)
{
if ($null -eq $pci_busids[$idx])
{
$pci_busids += 'MISSING'
$pci_missing_devices += 'MISSING'
}
if ($pci_busids[$idx] -eq '00:00.0' -or $pci_busids[$idx] -eq 'MISSING')
{
if ($gpu_busids[$idx])
{
$gpu_busids[$idx] = 'MISSING'
}
else
{ $gpu_busids += 'MISSING' }
$gpu_missing_devices += 'MISSING'
}
}
$n_detected_cards = Get-GPU-Busids-Length
$gpu_ids = Get-GPU-Ids
Write-Verbose 'Fetching GPU Make and Model Info...'
$gpu_detect_info = Get-GPU-Info
Write-Verbose 'Fetching PCI(E) slot ids and designations...'
if ($PIRQ_FOUND)
{
$pci_info_ids = Read-PIRQ-Device-Slot-Ids
if ($pci_missing_devices.Count -gt 0)
{
$pci_info_ids += (Get-Missing-Slot-Ids)
}
$pci_info_designations = Get-PIRQ-Device-Designations
}
else
{
$pci_info_ids = (Read-PCI-Slot-Info 'ID')
if ($pci_missing_devices.Count -gt 0)
{
$pci_info_ids += (Get-Missing-Slot-Ids)
}
$pci_info_designations = (Read-PCI-Slot-Info 'Designation')
}
if ($config.options.checkGI)
{
$gi_indicators = @()
$available_gpu_busids = @()
Write-Verbose 'Examining GPU Devices for GI...'
# THERMAL CONSTS
$high_temp_value = 78
$throttle_temp_value = 84
$mining_software = $miner.softwareType
$expected_hash = [System.Math]::Floor($miner.speedInfo.avgHashrateValue / $miner.gpuList.Count)
Write-Debug "Found $mining_software for Miner Software."
# GI vs. DETECTED DEVICES
for ($idx = 0; $idx -lt $pci_busids.Count; $idx++)
{
# MISSING
if ($gpu_busids[$idx] -eq 'MISSING' -or $null -eq $gpu_busids[$idx])
{
$gi_indicators += 'MISSING'
Continue
}
# NOT AVAILABLE
# not detected in the miner process (TeamRed and Trex only)
if ($mining_software -eq 'TrexMiner' -or $mining_software -eq 'TeamRedMiner')
{
$bus = $gpu_busids[$idx].Split('.')[0].Split(':')
if ($mining_software -eq 'TrexMiner')
{
[Array]::Reverse($bus)
}
$gpu_device = (Get-Content .\console_output.txt -ReadCount 0 | Select-String -Pattern ("($($gpu_busids[$idx].Split('.')[0])|_)\.0" -replace '_', ($bus -join ':'))).Line
if (-not $gpu_device -or $gpu_device.Contains("- GPU #$idx"))
{
$gi_indicators += 'NOT AVAILABLE'
Continue
}
}
if ($null -eq $gi_indicators[$idx])
{
$gi_indicators += ''
$available_gpu_busids += $gpu_busids[$idx]
}
}
# # GI vs. AVAILABLE CARDS
for ($idx = 0; $idx -lt $available_gpu_busids.Count; $idx++)
{
$gpu = $miner.gpuList[$idx]
# DEAD
if ($gpu.statusInfo.statusDisplay -match 'Dead' -or ($gpu.speedInfo.hashrateValue -eq 0 -and $gpu.deviceInfo.gpuActivity -eq 0))
{
$gi_indicators[$idx] = 'DEAD'
Continue
}
# THERMALS
# here we use the avg expected hash and compare with the current hash
# if hot and low hash = throttling
# if 0 load and low hash = throttling
if (($gpu.deviceInfo.temperature -ge $throttle_temp_value -and $gpu.speedInfo.hashrateValue -lt (0.95 * $expected_hash)) -or
($gpu.speedInfo.hashrateValue -lt (0.95 * $expected_hash) -and $gpu.deviceInfo.gpuActivity -eq 0)
)
{
$gi_indicators[$idx] = 'THROTTLING'
}
elseif ($gpu.deviceInfo.temperature -ge $high_temp_value)
{
$gi_indicators[$idx] = 'HIGH TEMP'
}
}
}
Remove-Item .\console_output.txt -ErrorAction SilentlyContinue
Write-Verbose 'Generating GPU Lookup table...'
if (-not $config.tests.testMode)
{
Show-Table
if ($config.debug.genExpected)
{
if (-not (Test-Path .\expected.ps1))
{
$expected = @'
#{0}
$expected_mb_product_name = "{1}"
$expected_PIRQ_FOUND = ${2}
$expected_pirq_map = {3}
$expected_pci_busids = @({4})
$expected_pci_missing_devices = {5}
$expected_pci_info_ids = @({6})
$expected_pci_info_designations = @({7})
$expected_gpu_busids = @({8})
$expected_gpu_missing_devices = {9}
$expected_gpu_ids = @({10})
$expected_gi_indicators = {11}
$expected_total_detected_cards = {12}
'@
$expected -f 'expected.ps1',
$mb_product_name,
$PIRQ_FOUND,
(Test-If-Empty $pirq_map),
('"' + ($pci_busids -join '", "') + '"'),
$pci_missing_devices.Count,
($pci_info_ids -join ', '),
('"' + ($pci_info_designations -join '", "') + '"'),
('"' + ($gpu_busids -join '", "') + '"'),
$gpu_missing_devices.Count,
('"' + ($gpu_ids -join '", "') + '"'),
(Test-If-Empty $gi_indicators),
$n_detected_cards | Out-File '.\expected.ps1'
}
Expand-Tar "..\$remote_ip.tar.bz2" .
Expand-Tar "$remote_ip.tar" .
Update-Tar "$remote_ip.tar" .\expected.ps1
Update-Tar "..\$remote_ip.tar.bz2" "$remote_ip.tar"
Remove-Item "$remote_ip.tar"
Remove-Item .\expected.ps1
Write-Verbose 'Successfully updated archive with test file.'
}
}
Write-Verbose 'Done!'
Exit 0