12.2.1 OpenMP interop – Foreign-Runtime Support for Nvidia GPUs

On Nvidia GPUs, the foreign runtimes APIs are the CUDA runtime API, the CUDA driver API, and HIP, the C++ Heterogeneous-Compute Interface for Portability that is—on CUDA-based systems—a very thin layer on top of the CUDA API. By default, CUDA is used. The interop object is created using OpenMP’s interop directive or, implicitly, when invoking a declare variant procedure that has the append_args clause. In either case, the prefer_type modifier determines whether CUDA, CUDA driver, or HSA is used.

When specifying the targetsync modifier, a CUDA stream is created using the CU_STREAM_DEFAULT flag.

Invoke the Interoperability Routines on an interop object to obtain the following properties. For properties with integral (int), pointer (ptr), or string (str) data type, call omp_get_interop_int, omp_get_interop_ptr, or omp_get_interop_str, respectively. Note that device_num is the OpenMP device number while device is the CUDA, CUDA Driver, or HIP device number.

When using HIP with C and C++, the __HIP_PLATFORM_NVIDIA__ preprocessor macro must be defined before including the HIP header files.

For the API routine call, add the prefix omp_ipr_ to the property name; for instance:

omp_interop_rc_t ret;
int device_num = omp_get_interop_int (my_interop_obj, omp_ipr_device_num, &ret);

Available properties for a CUDA runtime API interop object:

PropertyC data typeAPI routinevalue (if constant)
fr_idomp_interop_fr_tintomp_fr_cuda
fr_nameconst char *str"cuda"
vendorintint11
vendor_nameconst char *str"nvidia"
device_numintint
platformN/A
deviceintint
device_contextN/A
targetsynccudaStream_tptr

Available properties for a CUDA driver API interop object:

PropertyC data typeAPI routinevalue (if constant)
fr_idomp_interop_fr_tintomp_fr_cuda_driver
fr_nameconst char *str"cuda_driver"
vendorintint11
vendor_nameconst char *str"nvidia"
device_numintint
platformN/A
deviceCUdeviceint
device_contextCUcontextptr
targetsyncCUstreamptr

Available properties for an HIP interop object:

PropertyC data typeAPI routinevalue (if constant)
fr_idomp_interop_fr_tintomp_fr_hip
fr_nameconst char *str"hip"
vendorintint11
vendor_nameconst char *str"nvidia"
device_numintint
platformN/A
devicehipDevice_tint
device_contexthipCtx_tptr
targetsynchipStream_tptr