Skip to main content

oneapi_host

Function oneapi_host 

Source
pub fn oneapi_host() -> Option<OneApiHost>
Expand description

The host’s Intel oneAPI installation, or None when it is not installed.

Read from the component layout under $ONEAPI_ROOT, falling back to /opt/intel/oneapi. Nothing is linked or executed.

Narrower than it looks: this reports the toolkit, not the GPU runtime. A host running compute through a distro-packaged Level Zero driver with no toolkit installed reports None, because reading that runtime’s version requires linking it rather than reading a file. So Some proves the toolkit is present, while None is the weakest negative of the three probes — it does not rule out a usable Level Zero runtime.

use gpu_probe::OneApiVersion;

if let Some(oneapi) = gpu_probe::oneapi_host()
    && oneapi.version >= OneApiVersion::new(2024, 0, 0)
{
    // pick a oneAPI 2024-or-newer build
}
Examples found in repository?
examples/watch.rs (line 85)
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}