Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alter GPU resource allocation. #117

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions Change-GPUResourceAllocation.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<#
If you are opening this file in Powershell ISE you should modify the params section like so...

Param (
[string]$VMName = "NameofyourVM",
[int]$GPUResourceAllocationPercentage = 50
)

#>

Param (
[string]$VMName,
[int]$GPUResourceAllocationPercentage
)

$VM = Get-VM -VMName $VMName

if (($VMName -AND $GPUResourceAllocationPercentage) -ne [string]$null) {
If ($VM.state -eq "Running") {
[bool]$state_was_running = $true
}

if ($VM.state -ne "Off"){
"Attemping to shutdown VM..."
Stop-VM -Name $VMName -Force
}

While ($VM.State -ne "Off") {
Start-Sleep -s 3
"Waiting for VM to shutdown - make sure there are no unsaved documents..."
}

[float]$devider = [math]::round($(100 / $GPUResourceAllocationPercentage), 2)

Set-VMGpuPartitionAdapter -VMName $VMName -MinPartitionVRAM ([math]::round($(1000000000 / $devider))) -MaxPartitionVRAM ([math]::round($(1000000000 / $devider))) -OptimalPartitionVRAM ([math]::round($(1000000000 / $devider)))
Set-VMGPUPartitionAdapter -VMName $VMName -MinPartitionEncode ([math]::round($(18446744073709551615 / $devider))) -MaxPartitionEncode ([math]::round($(18446744073709551615 / $devider))) -OptimalPartitionEncode ([math]::round($(18446744073709551615 / $devider)))
Set-VMGpuPartitionAdapter -VMName $VMName -MinPartitionDecode ([math]::round($(1000000000 / $devider))) -MaxPartitionDecode ([math]::round($(1000000000 / $devider))) -OptimalPartitionDecode ([math]::round($(1000000000 / $devider)))
Set-VMGpuPartitionAdapter -VMName $VMName -MinPartitionCompute ([math]::round($(1000000000 / $devider))) -MaxPartitionCompute ([math]::round($(1000000000 / $devider))) -OptimalPartitionCompute ([math]::round($(1000000000 / $devider)))

If ($state_was_running){
"Previous State was running so starting VM..."
Start-VM $VMName
}

"Done..."
}
16 changes: 8 additions & 8 deletions CopyFilesToVM.ps1
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
$params = @{
VMName = "GPUPV"
SourcePath = "C:\Users\james\Downloads\Win11_English_x64.iso"
VMName = "Win11LABENV"
SourcePath = "E:\Users\simon\Downloads\Win11_23H2_English_x64.iso"
Edition = 6
VhdFormat = "VHDX"
DiskLayout = "UEFI"
SizeBytes = 40GB
SizeBytes = 128GB
MemoryAmount = 8GB
CPUCores = 4
CPUCores = 6
NetworkSwitch = "Default Switch"
VHDPath = "C:\Users\Public\Documents\Hyper-V\Virtual Hard Disks\"
VHDPath = "D:\Hyper-V\Virtual Hard Disks\"
UnattendPath = "$PSScriptRoot"+"\autounattend.xml"
GPUName = "AUTO"
GPUName = "NVIDIA GeForce RTX 2070 SUPER"
GPUResourceAllocationPercentage = 50
Team_ID = ""
Key = ""
Username = "GPUVM"
Password = "CoolestPassword!"
Username = "LABENV"
Password = "qwerty"
Autologon = "true"
}

Expand Down