Function opensn::BindDevice
Defined in File device_binding.h
Function Documentation
-
void opensn::BindDevice(MPI_Comm comm)
Selects the GPU that this MPI rank uses.
Ranks on a node that see the same set of GPUs, in any order, share them round-robin in node-local rank order. A scheduler or launcher that gives each rank its own GPUs, by restricting the GPUs a rank can see (for example with
CUDA_VISIBLE_DEVICES,ROCR_VISIBLE_DEVICESorONEAPI_DEVICE_SELECTOR), puts each rank in a set of its own, so the rank uses the first GPU it was given.With CUDA or HIP, PETSc and OpenSn share the runtime’s current device, and PETSc selects its device while it initializes. When PETSc has a CUDA or HIP backend, this therefore sets its
-device_select_cudaor-device_select_hipoption, whichever matches that backend, to the selected device. Selecting a different PETSc device, for example throughPETSC_OPTIONS, makes PETSc and OpenSn use different GPUs. With SYCL, PETSc keeps its own selection, which does not change the device OpenSn uses.Call once per process, after MPI is initialized and before
PetscInitializeor any GPU work. Collective overcomm. Does nothing without GPU support or on a rank that sees no GPU. If listing or selecting the GPUs fails on any rank, every rank throwsstd::runtime_errorafter the collective calls. The message of a rank that failed names the rank and the cause.