Open GuillaumeGomez opened 1 year ago
would you consider wrapping nvidia-smi
and putting it behind a nvidia-gpu feature flag? or are you hoping to keep it generic enough to use across device types?
I'd prefer to not have any GPU-specific code as it greatly increases the code complexity.
In case it assists, this was my method of getting GPU information (in my implementation i only needed names), I used gfx_hal.
fn get_gpus() -> Vec<String> {
let instance: gfx_backend_vulkan::Instance =
back::Instance::create("hayabusa", 1).unwrap();
let adapters: Vec<Adapter<Backend>> = instance.enumerate_adapters();
let mut names: Vec<String> = Vec::new();
for adapter in adapters {
names.push(adapter.info.name.to_string());
}
names
}
I had in mind to use opengl/vulkan to query information like GPU type, name, total memory and if possible % usage, memory usage and temperature.
If you are interested into adding this, it'd be very welcome! Also thanks for allowing me to discover gfx-hal
, didn't know about this crate.
So to get the total memory and potentially memory usage (I got it from here):
The VRAM size though can be determined by finding the memory heap with the
DEVICE_LOCAL
bit set usingvkGetPhysicalDeviceMemoryProperties
. TheVkPhysicalDeviceMemoryProperties
returned by that function contains all available memory heaps in thememoryHeaps
member. The configuration differs esp. between discrete and integrated GPUs, so this may not always be what you're looking for, e.g. on integrated GPUs with shared memory.
To get the GPU name/type, we can use vkGetPhysicalDeviceProperties
.
@GuillaumeGomez Juggling a lot of things rn, but ty for putting this back on my radar, may see what I can do with it, if I fork even for purposes as simple as playing around with this I'll leave a comment
It's possible to gather some GPU information with vulkan, like memory available and memory usage: https://www.asawicki.info/news_1695_there_is_a_way_to_query_gpu_memory_usage_in_vulkan_-_use_dxgi
An example of getting GPU usage on mac: https://github.com/vladkens/macmon