-
Notifications
You must be signed in to change notification settings - Fork 5
/
win-gpu-pv.ps1
98 lines (86 loc) · 4.03 KB
/
win-gpu-pv.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
set-executionpolicy remotesigned
$ErrorActionPreference = "Stop"
$signalLabel="HeartBeat"
$okLabel="OK"
if ((Get-WinSystemLocale).Name -eq "zh-CN") {
$signalLabel="检测信号"
$okLabel="确定"
}
$vmobject = Get-VM | Out-GridView -Title "Select VM to setup GPU-P" -OutputMode Single
$vmid = $vmobject.VMId
Write-Host "Stopping VM"
$vmobject | Stop-VM
Write-Host "Disabling checkpoints for VM"
$vmobject | Set-VM -CheckpointType Disabled
Write-Host "Enabling heartbeat service for VM"
$vmobject | Enable-VMIntegrationService -Name $signalLabel
if ($vmobject | Get-VMGpuPartitionAdapter) { $vmobject | Remove-VMGpuPartitionAdapter }
Write-Host "Starting VM"
$vmobject | Start-VM
do { Start-Sleep 2 } while(($vmobject | Get-VMIntegrationService -Name $signalLabel).PrimaryStatusDescription -ne $okLabel)
Write-Host "Connecting to VM"
$vmsess = New-PSSession -VMId $vmid
Write-Host "Copying display drivers to VM"
Invoke-Command -Session $vmsess {$prologWritten = $false}
$dev = Get-PnpDevice -Class Display -Status OK | Out-GridView -Title "Select Card to setup GPU-P" -OutputMode Single
$props = $dev | Get-PnpDeviceProperty
$pnpinf = ($props | where {$_.KeyName -eq "DEVPKEY_Device_DriverInfPath"}).Data
$infsection = ($props | where {$_.KeyName -eq "DEVPKEY_Device_DriverInfSection"}).Data
$cbsinf = (Get-WindowsDriver -Online | where {$_.Driver -eq "$pnpinf"}).OriginalFileName
If (-not $cbsinf) {
Write-Host "Device not supported: $dev, inf: $pnpinf, cbs: $cbsinf"
return;
}
$gpuName = $dev.FriendlyName
$path = $dev.InstanceId.replace('\', '#').ToLower()
$pvs = Get-VMHostPartitionableGpu
foreach($pv in $pvs){
$name=$pv.Name.ToLower()
echo "$name"
if ($name.contains($path)){
$path = $pv.Name
}
}
echo "============================"
echo "Using: $gpuName, pnpinf: $pnpinf, path: $path"
echo "============================"
$inffile = (Get-Item -LiteralPath $cbsinf)
$drvpkg = $inffile.Directory
Write-Host "Copying driver package $drvpkg to VM, using $dev."
$hostdrvstorepath = Invoke-Command {
New-Item -ItemType Directory "$env:SystemRoot\System32\HostDriverStore\FileRepository" -Force
} -Session $vmsess
# $hostdrvstorepath = Join-Path $remoteSystemRoot "System32\HostDriverStore\FileRepository"
Copy-Item -LiteralPath $drvpkg.FullName -ToSession $vmsess -Destination "$hostdrvstorepath" -Recurse -Force
$vminfpath = join-path (Join-Path $hostdrvstorepath $drvpkg.name) $inffile.Name
Invoke-Command -Session $vmsess -ScriptBlock {
if (-not $prologWritten) {
Set-Content -LiteralPath "$env:SystemDrive\GPUPAdditionalSetup.bat" -Encoding utf8 -Value @"
cd /d %TEMP%
set dirname=gpupaddlsetup%RANDOM%
mkdir %dirname%
cd %dirname%
"@
$prologWritten = $true
}
Add-Content -LiteralPath "$env:SystemDrive\GPUPAdditionalSetup.bat" -Encoding utf8 -Value "start `"`" /wait rundll32 advpack.dll,LaunchINFSectionEx $using:vminfpath,$using:infsection,,4"
}
$scriptWritten = Invoke-Command -Session $vmsess -ScriptBlock {
if ($prologWritten) {
Add-Content -LiteralPath "$env:SystemDrive\GPUPAdditionalSetup.bat" -Encoding utf8 -Value @"
cd ..
rmdir /s /q %dirname%
"@
}
$prologWritten
}
Write-Host "Stopping VM"
$vmobject | Stop-VM
Write-Host "Configuring GPU-P for VM"
$vmobject | Add-VMGpuPartitionAdapter -InstancePath "$path"
$vmobject | Set-VMGpuPartitionAdapter -MinPartitionVRAM 80000000 -MaxPartitionVRAM 100000000 -OptimalPartitionVRAM 100000000 -MinPartitionEncode 80000000 -MaxPartitionEncode 100000000 -OptimalPartitionEncode 100000000 -MinPartitionDecode 80000000 -MaxPartitionDecode 100000000 -OptimalPartitionDecode 100000000 -MinPartitionCompute 80000000 -MaxPartitionCompute 100000000 -OptimalPartitionCompute 100000000
$vmobject | Set-VM -GuestControlledCacheTypes $true -LowMemoryMappedIoSpace 1Gb ¨CHighMemoryMappedIoSpace 32GB
Write-host "Done"
if ($scriptWritten) {
Write-Host "Don't forget to run GPUPAdditionalSetup.bat in system drive as administrator for additional setup. This may enable video codec and alternative graphics/compute APIs."
}