0

I am trying to get total GPU memory value. I tried with WMI but it returns not higher value than 4gb.

After reading few articles I found out Cudafy.

public static ulong GetGpuMemory()
{
    GPGPU gpu = CudafyHost.GetDevice(CudafyModes.Target, CudafyModes.DeviceId);
    var c = gpu.GetDeviceProperties(true);
    var p = c.TotalMemory;

    return p;
}

For some reason it is returning max ulong value.

Any ideas? Do you know any other way to get correct GPU memory value from both - NVIDIA and AMD GPUs? What about taking hex value from registry and then converting it? I tried to write some code but without success. Thanks for any help in advance

jps
  • 20,041
  • 15
  • 75
  • 79
  • You want the real value or simply the value the device says it has ? – Franck Apr 28 '21 at 15:55
  • Does this answer your question? [Get total amount of GPU memory?](https://stackoverflow.com/questions/37601105/get-total-amount-of-gpu-memory) – Liam Apr 28 '21 at 15:59
  • Does this answer your question? [How get GPU information in C#?](https://stackoverflow.com/questions/29667666/how-get-gpu-information-in-c) – JHBonarius Apr 28 '21 at 16:00
  • @Liam he's doing what is stated in that answer, plus the answer doesn't work for the one asking the question there – JHBonarius Apr 28 '21 at 16:01
  • 1
    @JHBonarius Well neither works if he's looking for the real value and not the one output by the controller chip. – Franck Apr 28 '21 at 16:03
  • @Franck real value. I would like to get return with correct total GPU memory (which will work fine for cards with 4gb+) – Verciak Nostale Apr 28 '21 at 16:05
  • 1
    @Liam no, it doesn't. There is information about: WMI, which returns max 4gb value; Cudafy, which is not working in my case (returns max ulong value) SharpDX, which is not working for all GPUs – Verciak Nostale Apr 28 '21 at 16:05
  • 1
    @JHBonarius as above. NVAPI doesn't support AMD too however thanks for any answers! – Verciak Nostale Apr 28 '21 at 16:05
  • @VerciakNostale The real value you have to load the memory controller until it fails. This way it allow to detect some of those fake cards as well as giving their real amount of memory – Franck Apr 28 '21 at 16:44
  • https://github.com/walbourn/directx-sdk-samples/tree/master/VideoMemory guessing that's not so hard to convert this into C#. Btw, SharpDX library exists. – aepot Apr 28 '21 at 20:56
  • Hi again guys, I am wondering what "MaxDedicatedVideoMemory" in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\DirectX really is. Is that the highest dedicated VRAM GPU from all cards, which you have? Is that value accurate? (if there is 4gb, does it mean that your card really has 4gb video card memory)? I've tested it on 3 different PCs (2gb and 2x 4gb) and it seems working...but how will it look on PCs with GPU 8gb+? – Verciak Nostale Apr 29 '21 at 16:50

1 Answers1

0

This should work:

using Microsoft.Win32;
...
long getvideomem()
{
    try
    {
        using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SYSTEM\ControlSet001\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\0000"))
        {
            if (key != null)
            {
                object o = key.GetValue("HardwareInformation.qwMemorySize");
                if (o != null)
                    return (long)o;
            }
        }
    }
    catch { }
    return 0;
}

Multiple GPU systems would need some tweaks however.

colin lamarre
  • 1,714
  • 1
  • 18
  • 25