Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get total amount of GPU memory?

Tags:

c#

.net

wmi

Is there an easy and reliable way to get the total amount of the physical GPU memory?

I have tried this, but the problem is it returns 4096MB and I'm using a GTX 780 with 6144MB, so yeah not displaying correctly.

Code:

using System.Management;        

private void getGpuMem()
{
    ManagementClass c = new ManagementClass("Win32_VideoController");
    foreach (ManagementObject o in c.GetInstances())
    {
        string gpuTotalMem = String.Format("{0} ", o["AdapterRam"]);
        Debug.Write(gpuTotalMem);
    }
}
like image 314
Patrik Fröhler Avatar asked Jun 02 '16 20:06

Patrik Fröhler


1 Answers

As it is said in the MSDN

Hardware that is not compatible with Windows Display Driver Model (WDDM) returns inaccurate property values for instances of this class.

That is why it returns 4gb.

You can try to use CUDAfy.net

GPGPU gpu = CudafyHost.GetDevice(CudafyModes.Target, CudafyModes.DeviceId);
var c = gpu.GetDeviceProperties(true);
var p = c.TotalMemory;
Console.WriteLine(p);
like image 92
Valentin Avatar answered Oct 14 '22 20:10

Valentin