How get GPU information in C#?
You can get basic information using this library:
https://github.com/falahati/NvAPIWrapper
For now, it doesn't support clock speed or GPU usage, nor it does support sensor information (temp), but it can get you the bus width, memory, used memory and cores. However, there is a solid ground for adding new functions to the library and as result, you can also expand it to fit your needs, probably in less than an hour or something if you know what function of NVAPI you need to add to the library and you are familiar with basics of marshaling.
Update 2018: It now supports GPU clock information, temp sensors, and usage information.
But for the information that is currently retrievable, you need to get a list of all currently connected physical GPUs. This is possible using the NvAPIWrapper.GPU.PhysicalGPU.GetPhysicalGPUs()
static method.
This method returns an array of NvAPIWrapper.GPU.PhysicalGPU
s.
Now you can retrieve the information you desire using the properties of this class.
NvAPIWrapper.GPU.PhysicalGPU.Bios
: Gives you VBIOS versionNvAPIWrapper.GPU.PhysicalGPU.Board
: Gives you graphic board informationNvAPIWrapper.GPU.PhysicalGPU.BusInfo
: Gets GPU bus informationNvAPIWrapper.GPU.PhysicalGPU.CUDACores
: Gets total number of cores defined for this GPUNvAPIWrapper.GPU.PhysicalGPU.CurrentPCIEDownStreamWidth
: Gets number of PCIE lanes being used for the PCIE interface downstreamNvAPIWrapper.GPU.PhysicalGPU.FullName
: Gets GPU full nameNvAPIWrapper.GPU.PhysicalGPU.GPUType
: Indicates if the GPU is integrated or discreteNvAPIWrapper.GPU.PhysicalGPU.IRQ
: Gets GPU interrupt numberNvAPIWrapper.GPU.PhysicalGPU.IsQuadro
: Indicates if this GPU is of the Quadro line of productsNvAPIWrapper.GPU.PhysicalGPU.MemoryInfo
: Gives you every information about the memory and memory usageNvAPIWrapper.GPU.PhysicalGPU.PCIIdentifiers
: Gives you information about the hardware PCI idsNvAPIWrapper.GPU.PhysicalGPU.PhysicalFrameBufferSize
andNvAPIWrapper.GPU.PhysicalGPU.VirtualFrameBufferSize
: Gets the size of frame buffer in KB for this GPUNvAPIWrapper.GPU.PhysicalGPU.ShaderSubPipeLines
: Gets number of GPU Shader SubPipes or SM units
If you need a specific function you can't find in this version of the library, please feel free to open an issue.
I don't have any experience with the AMD tools, but we managed to use NVIDIA's NVAPI (https://developer.nvidia.com/nvapi) from C#
The version we use is only supplied as a static library do we can't p/invoke. We ended up create a thin wrapper library in C++/CLR that we could then call from our C# code.
Maybe the Win32_VideoController CLASS or the GPUinformation Class can help you.
Example:
using System.Management;
public partial class Win_Win32_VideoController : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
using (var searcher = new ManagementObjectSearcher("select * from Win32_VideoController"))
{
foreach (ManagementObject obj in searcher.Get())
{
Response.Write("Name - " + obj["Name"] + "</br>");
Response.Write("DeviceID - " + obj["DeviceID"] + "</br>");
Response.Write("AdapterRAM - " + obj["AdapterRAM"] + "</br>");
Response.Write("AdapterDACType - " + obj["AdapterDACType"] + "</br>");
Response.Write("Monochrome - " + obj["Monochrome"] + "</br>");
Response.Write("InstalledDisplayDrivers - " + obj["InstalledDisplayDrivers"] + "</br>");
Response.Write("DriverVersion - " + obj["DriverVersion"] + "</br>");
Response.Write("VideoProcessor - " + obj["VideoProcessor"] + "</br>");
Response.Write("VideoArchitecture - " + obj["VideoArchitecture"] + "</br>");
Response.Write("VideoMemoryType - " + obj["VideoMemoryType"] + "</br>");
}
}
}
}
You can also consult the CUDAfy.net library.