8

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?

Dmitry
  • 13,797
  • 6
  • 32
  • 48
bairog
  • 3,143
  • 6
  • 36
  • 54
  • I do not think there is a generic way of doing this. Especially for AMD there are integrated and discrete GPUs... – Christoph Fink Apr 24 '14 at 07:35
  • 1
    http://sharpdx.org/ May or may not help you – Machinarius Apr 24 '14 at 07:35
  • @chrfin At least I hope some third-party library, implementing that functionality, exists :) – bairog Apr 24 '14 at 07:37
  • cudafy.codeplex.com also has some card detection logic which may help... – Christoph Fink Apr 24 '14 at 07:37
  • Thx. Maybe some generic approach (without third-party library) exists? – bairog Apr 24 '14 at 07:40
  • I highly doubt it as such a requirement reeks of complex P/Invoke calls. – Machinarius Apr 24 '14 at 07:41
  • Is there any *specific* reason you want to test for this? I'd rather go with feature detection: http://sharpdx.org/documentation/api/p-sharpdx-toolkit-graphics-graphicsadapter-adapters + http://sharpdx.org/documentation/api/m-sharpdx-toolkit-graphics-graphicsadapter-isprofilesupported – Machinarius Apr 24 '14 at 07:53
  • @Machinarius Specific reason - is simply technical task's requirement for my program. So I can do nothing with it. – bairog Apr 24 '14 at 07:55
  • I mean: Why do you want to exclude integrated adapters? They are decently powerful lately and you can test for a DX level to filter out the incompatible cards outright. Aiming for something along the lines of FeatureLevel.Level_11_0 should net you recent graphics cards – Machinarius Apr 24 '14 at 07:57
  • @Machinarius I know they are like low-mid-end discrete cards now, but that's thats requirement, so I have to exclude them.. – bairog Apr 24 '14 at 08:02
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/51326/discussion-between-machinarius-and-bairog) – Machinarius Apr 24 '14 at 08:03

1 Answers1

1

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.

Jeff
  • 2,495
  • 18
  • 38