There are 2 types of GPU memory - Dedicated Memory & Shared Memory. Dedicated memory remains smaller in size but GPU gives preference to this memory to do its operations.
In C#, I have developed below code, which returns me the current usage of both these memories. You can cross verify the result in Task Manager.
var category = new PerformanceCounterCategory("GPU Adapter Memory");
var counterNames = category.GetInstanceNames();
var gpuCountersDedicated = new List<PerformanceCounter>();
var gpuCountersShared = new List<PerformanceCounter>();
var result = 0f;
foreach (string counterName in counterNames)
{
foreach (var counter in category.GetCounters(counterName))
{
if (counter.CounterName == "Dedicated Usage")
{
gpuCountersDedicated.Add(counter);
}
else if (counter.CounterName == "Shared Usage")
{
gpuCountersShared.Add(counter);
}
}
}
gpuCountersDedicated.ForEach(x =>
{
_ = x.NextValue();
});
await Task.Delay(1000);
gpuCountersDedicated.ForEach(x =>
{
result += x.NextValue();
});
Console.WriteLine("Dedicated memory usage: " + result);
result = 0f;
gpuCountersShared.ForEach(x =>
{
_ = x.NextValue();
});
await Task.Delay(1000);
gpuCountersShared.ForEach(x =>
{
result += x.NextValue();
});
Console.WriteLine("Shared memory usage: " + result);
Output:
Console Output
Task Manager:
Snip from task manager