GPU Utilities#

GPU detection and locking utilities used during pipeline startup.

thesis.core.gpu#

GPU availability detection for the thesis framework.

Provides a single check_gpu() function that tests whether a compatible GPU probtrackx2 binary and a suitable CUDA runtime are available on the current system. This check is intended to run once at CLI startup so that every downstream tool sees a consistent config.hardware.gpu_enabled value, rather than each interface performing its own ad-hoc detection.

Typical usage:

from thesis.core.gpu import check_gpu

status = check_gpu()
if status.available:
    print(f"GPU ready: {status.reason}")
else:
    print(f"GPU unavailable: {status.reason}")
class thesis.core.gpu.GPUStatus[source]#

Bases: NamedTuple

Result of a GPU availability check.

Variables:
  • availableTrue if a compatible GPU binary and CUDA runtime were both found.

  • binary – Name of the selected GPU binary (e.g. "probtrackx2_gpu11.0"), or None if unavailable.

  • cuda_version(major, minor) of the detected CUDA runtime, or None.

  • reason – Human-readable one-liner describing the outcome (suitable for log messages and user-facing warnings).

Parameters:
available: bool#

Alias for field number 0

binary: str | None#

Alias for field number 1

cuda_version: Tuple[int, int] | None#

Alias for field number 2

reason: str#

Alias for field number 3

static __new__(_cls, available, binary, cuda_version, reason)#

Create new instance of GPUStatus(available, binary, cuda_version, reason)

Parameters:
thesis.core.gpu.check_gpu()[source]#

Check whether a compatible GPU probtrackx2 binary is available.

Performs three checks in sequence:

  1. Binary presence — looks for each candidate in $FSLDIR/bin/ then $PATH.

  2. CUDA runtime — calls nvidia-smi to determine the maximum CUDA version supported by the installed driver.

  3. Version compatibility — for versioned binaries (e.g. probtrackx2_gpu11.0) the CUDA runtime must be ≥ the encoded version; unversioned binaries (probtrackx2_gpu) only require that some CUDA runtime is present.

The first binary that passes all three checks is selected.

Return type:

GPUStatus

Returns:

GPUStatus with available=True and the chosen binary when a compatible setup is detected, or available=False with a descriptive reason otherwise.

thesis.core.gpu.present_gpu_binaries()[source]#

Return the subset of GPU_BINARIES found on $FSLDIR/bin or $PATH.

Candidates are returned in GPU_BINARIES preference order. This is a presence check only — CUDA compatibility is validated separately by check_gpu().

Return type:

list