Zachary Canann
Zachary Canann

Reputation: 1231

Detect if GPU Available on AleaGpu

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.

Upvotes: 1

Views: 384

Answers (2)

Ahmed Osama
Ahmed Osama

Reputation: 874

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.

Upvotes: 2

redb
redb

Reputation: 522

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();
}

Upvotes: 0

Related Questions