Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect discrete GPU

Tags:

c#

gpu

integrated

My goal is to detect discrete GPU on multi-gpu systems (for example integrated Intel HD Graphics + discrete AMD Radeon card) with C#

I've usually use that code:

String gpuName = String.Empty;

ManagementObjectCollection objectCollection = 
new ManagementObjectSearcher("SELECT Name FROM Win32_VideoController").Get();

foreach (ManagementObject managementObject in objectCollection)
{
     foreach (PropertyData propertyData in managementObject.Properties)
     {                    
          if ((gpuName == String.Empty) || (propertyData.Value.ToString().ToLower().IndexOf("intel") == -1))
          {
               gpuName = propertyData.Value.ToString();
               break;                   
          } 
     }
}

It works like a charm for my example, described above.

But it's not suitable for AMD, VIA, etc (I don't know exactly all manufacturers) integrated cards.

So is there universal approach to cut off all integrated GPUs?

like image 254
bairog Avatar asked Apr 24 '14 07:04

bairog


1 Answers

To understand the answer, we need to understand how kernel mode drivers create devices.

To see a list of drivers, invoke msinfo32 from the run dialog, the select Software Environment-->System Drivers. From there you can see all registered drivers on your system, and their start mode (Manual / Boot / System) and state (running / Stopped).

drivers

When plug and play device drivers are loaded (by the plug and play manager), each driver will create one or more a devices (using IoCreateDevice). However some of these drivers are categorized as a bus driver. As a result, the system will enumerate the devices reported by that bus driver, and a tree will be created (starting with an imaginary 'Root' device). For instance if the PCI bus detects a device, it doesn't know anything about the device (could be a network card, sound card, video card, etc). So the plug and play manager will need to find the device's appropriate driver. Any embedded/integrated devices (sound, network, video, usb, firewire, sata, etc) are treated the same and are generally PCI devices as well. Ultimately, the OS doesn't know or care whether the device is embedded or discrete.

Go to Device Manager, choose View-->Devices by connection will display the tree that is created.

device tree

So, pertaining to the @Machinarius PInvoke comment, PInvoke will not help here. However I agree with him with respect to detecting features and capabilities are the way to go. And keep in mind that we do not know what the future holds, so excluding any devices may not be wise. Any 3rd party code to assist will likely be hard-coding values.

Hope this helps.

like image 75
Jeff Avatar answered Sep 28 '22 08:09

Jeff