pub fn vulkan_host() -> Option<VulkanHost>Expand description
The host’s Vulkan runtime, or None when no loader is installed.
Read from libvulkan.so.1 plus the ICD manifests under
/usr/share/vulkan/icd.d. Nothing is linked or executed, so this costs a
handful of file reads.
The version is the highest any installed driver advertises — neither the
loader’s instance version nor any one GPU’s, both of which would require
calling into the loader. See VulkanHost::api_version.
use gpu_probe::VulkanVersion;
if let Some(vulkan) = gpu_probe::vulkan_host()
&& vulkan.api_version >= VulkanVersion::new(1, 2, 0)
{
// pick a Vulkan 1.2-or-newer build
}Examples found in repository?
examples/watch.rs (line 97)
44fn main() {
45 let gpus = gpu_probe::detect();
46
47 println!("gpu-probe · {} GPU(s)", gpus.len());
48 println!();
49
50 if gpus.is_empty() {
51 println!(" no GPUs detected");
52 }
53
54 for (index, gpu) in gpus.iter().enumerate() {
55 println!("[{index}] {} · {}", gpu.name, gpu.vendor);
56 // The artifact-selection target, whichever form this vendor reports:
57 // `gfx1013` for ROCm/HIP, `sm_89` for CUDA.
58 match gpu.arch_target {
59 Some(arch) => println!(" arch {:>10}", arch.to_string()),
60 None => println!(" arch unavailable"),
61 }
62 println!(" total {:>10}", gib(gpu.total_bytes));
63 match gpu.used_bytes {
64 Some(used) => println!(" used {:>10}", gib(used)),
65 None => println!(" used unknown"),
66 }
67 match gpu.free_bytes {
68 Some(free) => println!(" free {:>10}", gib(free)),
69 None => println!(" free unknown"),
70 }
71 println!(" {}", bar(gpu.used_bytes, gpu.total_bytes));
72 println!();
73 }
74
75 // Host-wide toolchains, unlike the per-GPU fields above. Every row always
76 // prints, including when absent: "we looked and found nothing" is the point
77 // of a probe tool, and a lone row for one vendor reads like it describes
78 // the GPU above it rather than the host.
79 //
80 // They are not the same measurement. `cuda` is the driver version from
81 // NVML; `rocm` and `oneapi` are userspace installs, because neither AMD nor
82 // Intel exposes a driver version anywhere. The architecture each build
83 // targets is the per-GPU `arch` row, which needs none of them installed.
84 println!("host");
85 match gpu_probe::oneapi_host() {
86 Some(oneapi) => println!(" oneapi {:>10}", oneapi.version.to_string()),
87 None => println!(" oneapi unavailable"),
88 }
89 match gpu_probe::rocm_host() {
90 Some(rocm) => println!(" rocm {:>10}", rocm.version.to_string()),
91 None => println!(" rocm unavailable"),
92 }
93 match gpu_probe::cuda_host() {
94 Some(cuda) => println!(" cuda {:>10}", cuda.driver_version.to_string()),
95 None => println!(" cuda unavailable"),
96 }
97 match gpu_probe::vulkan_host() {
98 Some(vulkan) => println!(" vulkan {:>10}", vulkan.api_version.to_string()),
99 None => println!(" vulkan unavailable"),
100 }
101}