device_handling_m Module

Functionality to choose accelerator device (GPU) When PARALLAX is compiled stand-alone, get_device_count always returns 1 (i.e. the CPU), and set_device_id is a sanity check confirming that it's called with id 0.

When PARALLAX is linked to the PAccX library, these subroutines are simple wrappers around paccx_solver_get_device_count and paccx_solver_set_device. In turn, PAccX may be linked to different backends. As of 2025-03-14 a CXX (i.e. CPU) backend is always present, and an optional GPU backend is also available (CUDA or HIP, chosen at CMake configure time). Note: these subroutines control the global device settings of the calling process/thread. If your code links against PARALLAX and another accelerator-capable library, please test thoroughly and ensure the code behaves as desired.


Uses

  • module~~device_handling_m~~UsesGraph module~device_handling_m device_handling_m iso_c_binding iso_c_binding module~device_handling_m->iso_c_binding module~comm_handling_m comm_handling_m module~device_handling_m->module~comm_handling_m module~error_handling_m error_handling_m module~device_handling_m->module~error_handling_m module~screen_io_m screen_io_m module~device_handling_m->module~screen_io_m module~status_codes_m status_codes_m module~device_handling_m->module~status_codes_m mpi mpi module~device_handling_m->mpi module~comm_handling_m->mpi module~error_handling_m->module~comm_handling_m module~error_handling_m->module~screen_io_m module~error_handling_m->module~status_codes_m module~error_handling_m->mpi module~precision_m precision_m module~error_handling_m->module~precision_m netcdf netcdf module~error_handling_m->netcdf iso_fortran_env iso_fortran_env module~screen_io_m->iso_fortran_env module~screen_io_m->module~precision_m module~screen_io_m->netcdf module~precision_m->iso_c_binding module~precision_m->mpi module~precision_m->iso_fortran_env module~precision_m->netcdf

Used by

  • module~~device_handling_m~~UsedByGraph module~device_handling_m device_handling_m module~helmholtz_solver_factory_m helmholtz_solver_factory_m module~helmholtz_solver_factory_m->module~device_handling_m module~paccx_m PAccX_m module~paccx_m->module~device_handling_m program~benchmark_helmholtz_solvers benchmark_helmholtz_solvers program~benchmark_helmholtz_solvers->module~device_handling_m program~benchmark_helmholtz_solvers->module~helmholtz_solver_factory_m module~helmholtz_solver_mgmres_cxx_s helmholtz_solver_mgmres_cxx_s module~helmholtz_solver_mgmres_cxx_s->module~paccx_m

Enumerations

enum, bind(c)

Enumerators

enumerator:: BACKEND_CPU = 0
enumerator:: BACKEND_GPU = 1
enumerator:: BACKEND_ROCALUTION = 4
enumerator:: BACKEND_AMGX = 5
enumerator:: BACKEND_HYPRE = 6

Description

Enumerator defining the backends These values MUST agree with the corresponding enum in paccx.hxx from PAccX


Interfaces

public interface cxx_get_device_count

  • public function PAccX_CXX_get_device_count(backend, count) bind(c, name='paccx_solver_get_device_count')

    Arguments

    Type IntentOptional Attributes Name
    integer(kind=c_int32_t), intent(in) :: backend
    integer(kind=c_int32_t), intent(out) :: count

    Return Value integer(kind=c_int32_t)

public interface cxx_set_device

  • public function PAccX_CXX_set_device(backend, device_id) bind(c, name='paccx_solver_set_device')

    Arguments

    Type IntentOptional Attributes Name
    integer(kind=c_int32_t), intent(in) :: backend
    integer(kind=c_int32_t), intent(in) :: device_id

    Return Value integer(kind=c_int32_t)

public interface cxx_sync_device

  • public function PAccX_CXX_sync_device(backend) bind(c, name='paccx_solver_sync_device')

    Arguments

    Type IntentOptional Attributes Name
    integer(kind=c_int32_t), intent(in) :: backend

    Return Value integer(kind=c_int32_t)


Subroutines

public subroutine get_device_count(backend, count)

Get the number of available devices for the backend specified.

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: backend

Backend to use. Should be one of * BACKEND_CPU * BACKEND_GPU

integer, intent(out) :: count

Number of available devices

public subroutine set_device_id(backend, device_id)

Given a specific backend, set the device to use

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: backend

Backend to use. Should be one of * BACKEND_CPU * BACKEND_GPU

integer, intent(in) :: device_id

Desired device id to use. If there are count devices, device_id ranges from 0 to count-1.

public subroutine impose_default_device_affinity(object_type)

Assign devices to MPI ranks in order. Only works if number of ranks is greater or equal to number of devices Device assigned to rank rr is (rr modulo total_number_of_devices).

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: object_type

Object type. For now this means "solver_type".

public subroutine sync_device(backend)

Get the number of available devices for the backend specified.

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: backend

Backend to use. Should be one of * BACKEND_CPU * BACKEND_GPU