Files
management-scripts/Fix-EnableGPUScheduling.ps1
T

43 lines
1.6 KiB
PowerShell
Raw Normal View History

2022-11-23 14:17:38 -05:00
$key = "HKLM:\SYSTEM\CurrentControlSet\Control\GraphicsDrivers"
$name = "HwSchMode"
# Check to see if GPU scheduling is enabled
2022-11-25 11:34:48 -05:00
$HardwareGPUSchedulingEnabled = $false
2022-11-23 15:52:49 -05:00
If ( Test-RegistryProperty -Path $key -Name $name ) {
$setting = (Get-ItemPropertyValue -Path $key -Name $name -ErrorAction SilentlyContinue)
If ( $setting -eq 2 ) {
2023-10-05 13:11:38 -04:00
Write-Output "Hardware assisted GPU scheduling is already enabled"
2022-11-23 15:52:49 -05:00
$HardwareGPUSchedulingEnabled = $true
}
2022-11-25 11:34:48 -05:00
}
If ( $HardwareGPUSchedulingEnabled -eq $false ) {
2023-10-05 13:11:38 -04:00
Write-Output "Hardware assisted GPU scheduling is disabled"
2022-11-23 14:17:38 -05:00
$HardwareGPUSchedulingEnabled = $false
}
# Find a GPU in the system so we can enable GPU scheduling
If ( $HardwareGPUSchedulingEnabled -eq $false ) {
2023-10-05 13:11:38 -04:00
Write-Output " - Attempting to find a discrete Nvidia or AMD GPU"
2022-11-23 14:17:38 -05:00
$GPUs = (Get-WmiObject Win32_VideoController).Name
$FoundDiscreteGPU = $false
ForEach ( $gpu in $GPUs ) {
2022-11-28 14:30:29 -05:00
If ( $gpu -ilike "*NVIDIA*" ) {
2022-11-23 14:17:38 -05:00
$FoundDiscreteGPU = $true
}
}
# If we found a discrete GPU, enable hardware assisted GPU scheduling
If ( $FoundDiscreteGPU -eq $true ) {
2023-10-05 13:11:38 -04:00
Write-Output " - GPU found!"
Write-Output "Enabling hardware assisted GPU scheduling"
2022-11-23 14:17:38 -05:00
Try {
New-ItemProperty -Path $key -Name $name -PropertyType DWord -Value 2 -Force -ErrorAction Stop
2023-10-05 13:11:38 -04:00
Write-Output "A restart is required before this change will take effect"
2022-11-23 14:17:38 -05:00
}
Catch { LogErr $_.Exception.Message }
} Else {
2023-10-05 13:11:38 -04:00
Write-Output " - No GPU was found"
Write-Output "Hardware assisted GPU scheduling will not be enabled"
2022-11-23 14:17:38 -05:00
}
}