Device configuration (sbd.device_config)¶
Selects the backend a solver call runs on. Pass a DeviceConfig as the
device_config argument of sbd.sbd_solver.solve_sci_batch() or
solve_sci().
- class DeviceConfig(device='cpu', use_precalculated_dets=True, max_memory_gb=-1, use_gpu=None)[source]¶
Bases:
objectHelper class to configure CPU vs GPU execution for SBD calculations.
Usage:
from sbd.device_config import DeviceConfig from sbd.sbd_solver import solve_sci_batch device = DeviceConfig.auto() # best backend that is built device = DeviceConfig.cpu() # or force one device = DeviceConfig.gpu(max_memory_gb=16) results = solve_sci_batch(..., device_config=device)
Initialize device configuration.
- Parameters:
device (str) – Backend device key — ‘cpu’, ‘gpu’ (NVHPC Thrust, NVIDIA-only), ‘gpu-omp’ (OpenMP target offload, NVIDIA or AMD), or any alias known to
sbd._device_aliases. Default ‘cpu’.use_precalculated_dets (bool) – Use precalculated determinants (GPU only)
max_memory_gb (int) – Maximum GPU memory in GB (-1 = auto)
use_gpu (bool | None) – Deprecated boolean. If supplied without
device,Truemaps to ‘gpu’ (Thrust) andFalseto ‘cpu’ for backward compatibility with pre-OMP-offload code.
- classmethod auto(max_memory_gb=-1)[source]¶
Auto-detect the best available backend and use it.
Chooses among the backends that were actually built, not merely the hardware present, so an AMD host or a CPU-only build is never handed a backend it lacks. The preference order is Thrust (‘gpu’) where it exists, then OpenMP offload (‘gpu-omp’), then CPU, the same order
sbd.get_backend('auto')uses.- Parameters:
max_memory_gb (int) – Maximum GPU memory in GB (-1 = auto)
- Returns:
DeviceConfig for the best backend that is both built and runnable
- Return type:
- classmethod gpu(use_precalculated_dets=True, max_memory_gb=-1)[source]¶
Force NVHPC Thrust GPU execution. NVIDIA only.
Requires SBD compiled with THRUST (the
_core_gpu_thrustextension, i.e.SBD_BUILD_BACKEND=gpu, or the defaultauto).There is no AMD equivalent: upstream SBD wires the Thrust path to
nvc++ -cuda, so no rocThrust configuration exists to build. On an AMD host usegpu_omp()instead.- Parameters:
- Return type:
- classmethod gpu_omp(max_memory_gb=-1)[source]¶
Force OpenMP target-offload GPU execution. Works on NVIDIA and AMD.
Requires SBD compiled with the OMP-offload backend (the
_core_gpu_omp_offloadextension), which the defaultSBD_BUILD_BACKEND=autobuilds whenever a GPU compiler is present; narrow it togpu_omp_offloadto build only this one.One module and one device string serve both vendors – the same source and macros, compiled by
nvc++ -mp=gpuwith NVHPC’slibnvomp, or byamdclang++ --offload-arch=gfx*with LLVM’slibomp/libomptarget.sbd.get_backend('gpu-omp').__sbd_offload_target__reports which, e.g.'amdgcn-amd-amdhsa:gfx90a'.It installs alongside the CPU backend (and Thrust, on NVIDIA) – backends are imported lazily, one per process, which is what keeps them apart. The one combination to avoid in a single process is this backend together with the CPU one: they share an OpenMP runtime (
libnvompon NVIDIA,libompon AMD), and loading_core_cpufirst leaves it initialised host-only, after which offload regions run on the host.sbd.has_backend_conflict()reports that combination.- Parameters:
max_memory_gb (int)
- Return type: