Skip to main content

rocm_host

Function rocm_host 

Source
pub fn rocm_host() -> Option<RocmHost>
Expand description

The host’s ROCm installation, or None when ROCm is not installed.

Read from $ROCM_PATH/.info/version, falling back to /opt/rocm — the plain text file the rocm-core package writes. Nothing is linked or executed, so this costs one file read.

Some is the signal that ROCm is installed and the host can run its builds. None is weaker: the install was not found at the prefixes above, which a distro shipping ROCm into /usr — or a container carrying only the runtime libraries — will trigger despite working. Treat Some as proof and None as “probably not, worth confirming”.

None does not mean the GPU is unusable for compute: the kernel side is a separate component, and what a build has to target is GpuInfo::arch_target, reported with no ROCm installed at all.

use gpu_probe::RocmVersion;

if let Some(rocm) = gpu_probe::rocm_host()
    && rocm.version >= RocmVersion::new(6, 0, 0)
{
    // pick a `ROCm` 6 build
}
Examples found in repository?
examples/watch.rs (line 89)
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}