[C#]C# is the simplest way to get the real size of GPU memory

Have you used the following code to obtain the GPU memory capacity?

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

The code above often uses the acquired video memory capacity that is inconsistent with the actual value. Therefore, it is necessary to explore the easiest way to obtain it. One way is to use the cudafy.NET library

GPGPU gpu = CudafyHost.GetDevice(CudafyModes.Target, CudafyModes.DeviceId);
var c = gpu.GetDeviceProperties(true);
var p = c.TotalMemory;
Console.WriteLine(p);

源码:GitHub - lepoco/CUDAfy.NET: CUDAfy .NET allows easy development of high performance GPGPU applications completely from the .NET. It's developed in C#.

Another way is to use SharpDx. For details, please refer to https://stackoverflow.com/questions/37601105/ 

The following is my favorite method. It does not require any libraries. It is just under the cuda installation directory.

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1\extras\demo_suite\deviceQuery.exe, just use the cmd command to obtain it and then simply intercept it. 

おすすめ

転載: blog.csdn.net/FL1623863129/article/details/133440788
おすすめ