GuillaumeGomez / sysinfo

Cross-platform library to fetch system information
MIT License
2.02k stars 301 forks source link

Add support for GPU #1026

Open GuillaumeGomez opened 1 year ago

GuillaumeGomez commented 1 year ago

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

JaydenElliott commented 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?

GuillaumeGomez commented 1 year ago

I'd prefer to not have any GPU-specific code as it greatly increases the code complexity.

Notarin commented 11 months ago

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
}
GuillaumeGomez commented 11 months ago

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.

GuillaumeGomez commented 8 months ago

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 using vkGetPhysicalDeviceMemoryProperties. The VkPhysicalDeviceMemoryProperties returned by that function contains all available memory heaps in the memoryHeaps 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.

Notarin commented 8 months ago

@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