Already figured it out, I was looking from VM to host, but when going to the host and zooming in on the GPU cards, you can also get the VMs connected to that GPU. I needed this because we have VDI VMs on ESXi7 that have NUMA pinning and we want to check if the GPU it is using is remote.
Function Get-VMbyID {
param(
$vmid
)
## Find VM by ID
$VMName = Get-VM -id "VirtualMachine-$vmid"
$NUMANodeAffinity = $VMName | Get-AdvancedSetting -name "numa.nodeAffinity"
Return $($VMName.Name, $NUMANodeAffinity.Value)
}
$cluster = get-cluster | Sort-Object name | Out-GridView -Title "Select cluster" -OutputMode Single
$ESXiHosts = $cluster | Get-VMHost | Sort-Object Name
$Report = @()
Foreach( $ESXi in $ESXiHosts)
{
$ESXiGPUs = $ESXi.ExtensionData.config.Graphicsinfo
$GPUCounter = 0
Foreach( $ESXiGPU in $ESXiGPUs)
{
$GPUVMs = $ESXiGPU.vm
Foreach( $GPUVM in $GPUVMs)
{
$row = "" | Select-Object ESXiName, devicename, vendorname, PciID, GraphicsType, MemorySizeInKB, vmname, vmid, numanode, GPU
$row.ESXiName = $ESXi.Name
$row.DeviceName = $ESXiGPU.DeviceName
$row.VendorName = $ESXiGPU.VendorName
$row.PciID = $ESXiGPU.PciID
$row.GraphicsType = $ESXiGPU.GraphicsType
$row.MemorySizeInKB = $ESXiGPU.MemorySizeInKB
$row.vmid = $GPUVM.Value
$row.vmname, $row.numanode = Get-VMbyID -vmid $GPUVM.Value
$row.GPU = $GPUCounter
$Report += $Row
}
$GPUCounter++
}
}
$Report | export-csv -path h:\GPU-NUMA.csv -NoTypeInformation
Original Message:
Sent: Dec 10, 2024 09:30 AM
From: Gabrie1
Subject: Find the physical GPU a VM is connected to
Hi,
Is there a way to find out to which physical GPU in the host a VMs is connected to?
Using $esxi.ExtensionData.config.GraphicsConfig.DeviceType against a host, will list the device IDs of the physical GPU.
DeviceId GraphicsType
-------- ------------
0000:25:00.0 sharedDirect
0000:59:00.0 sharedDirect
0000:99:00.0 sharedDirect
0000:c5:00.0 sharedDirect
On the VM I configure a PCI device to use the "NVIDIA GRID vGPU" profile, but I can't figure out how I can check which of the physical GPUs in the host (we have 4 NVIDIA T4 adapters per host), the VM is assigned.
Any tips?