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.



Enumerations

enum, bind(c)

Enumerators

enumerator:: BACKEND_CPU = 0
enumerator:: BACKEND_GPU = 1
enumerator:: BACKEND_ROCALUTION_CPU = 2
enumerator:: BACKEND_ROCALUTION_GPU = 3

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