1

Is it possible to detect if a GPU is present before running GPU code with AleaGPU?

Will Gpu.Default be null? Is there a property on this object that can be checked?

I basically want to run a faster version of an algorithm if the GPU is present, otherwise I want to run the original slow version.

Zachary Canann
  • 1,131
  • 2
  • 13
  • 23

2 Answers2

2

I have disabled my GPU then tried this line:

Console.WriteLine(Alea.Device.Devices.Count().ToString());

And i got this exception System.Exception was unhandled Message=[CUDAError] CUDA_ERROR_UNKNOWN, and you get same exception if you tried to access Gpu.Default. So you can do something like this:

bool GpuEnabled = false;
try
{
    GpuEnabled = Alea.Device.Devices.Count() > 0;
}
catch
{
    GpuEnabled = false;
}
Console.WriteLine(GpuEnabled.ToString());

Note: i'm not sure if Alea thrown an exception because i have a GPU but it was disabled, or it will behave the same way with a machine that doesn't have a GPU at all, anyway, this code should handle both assumptions safely.

Ahmed Osama
  • 854
  • 1
  • 8
  • 17
0

This is probably the easiest way: (It makes you API independent)

var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_DisplayConfiguration");

var q = searcher.Get()
                .SelectMany(x => x.Properties)
                .Where(x => x.Name == "Description")

foreach (var item in q)
{
   yield return item.Value.ToString();
}
redb
  • 512
  • 8
  • 22