-1

I am currently trying to find realtime/set data from a GPU. This is program is being made in a WPF template, using C#. After searching for close to an hour, I thought some of you might have an answer to my problem.

I am specifically looking at finding one's GPU usage, as well as a GPU's free/available VRAM. I am looking at DirectX/SharpDX, because DirectX is able to find the specific data that I am looking for. But given that DirectX isn't really supported for current versions of .net, I am looking at SharpDX as a possible solution.

However, I cannot find any examples on how to find GPU usage or free VRAM when using SharpDX. Any answers/links would be appreciated. Thanks!

Aaron
  • 97
  • 12
  • the code for OpenHardwareMonitor may help: https://github.com/openhardwaremonitor/openhardwaremonitor – Sasha Jul 20 '18 at 14:11
  • 2
    Possible duplicate of [Profiling GPU usage in C#](https://stackoverflow.com/questions/28572016/profiling-gpu-usage-in-c-sharp) – Winter Jul 20 '18 at 14:13
  • 1
    May also be useful: https://stackoverflow.com/q/12224181/5771029 – Winter Jul 20 '18 at 14:14
  • @Jaxi, I actually am currently using that NuGet package for ohm, but the usage percentages are a bit cryptic, and do not give a solid value. – Aaron Jul 20 '18 at 14:31
  • @Winter, it is not a duplicate. That is a different subject on GPU usage. That is for determining ONLY the GPU's memory, not GPU usage as a whole value. – Aaron Jul 20 '18 at 14:32
  • 1
    Winter's second link looks like a dupe to me. –  Jul 20 '18 at 18:01

2 Answers2

0

Try using System.Management namespace. Following is a sample code

using System.Management;    
ManagementObjectSearcher objSearch= new ManagementObjectSearcher("select * from Win32_VideoController");

foreach (ManagementObject share in objSearch.Get())
{   
    // Some logic...

    //if want to loop through properties
    foreach (PropertyData PC in share.Properties)
    {
         //some logic...
    }
}
rk.
  • 11
  • 1
  • I understand that I can use WMI for getting certain aspects of hardware information, but I need to know how/what I should be measuring for GPU Utilization. This will only tell me of the properties already shown in WMI. – Aaron Jul 20 '18 at 18:30
0

In SharpDX.Direct3D12, GPU memory usage can be displayed by

var factory = new Factory4();
var adapter = new Adapter4(factory.GetAdapter1(1).NativePointer);
var device = new Device(adapter, SharpDX.Direct3D.FeatureLevel.Level_11_0);
MessageBox.Show($"Dedicated Memory Usage: {adapter.QueryVideoMemoryInfo(0, MemorySegmentGroup.Local).CurrentUsage}");
MessageBox.Show($"Shared Memory Usage: {adapter.QueryVideoMemoryInfo(0, MemorySegmentGroup.NonLocal).CurrentUsage}");

GetAdapter(1) means to get a second adapter, you can change that number. Have fun.