Foreign-runtime support for Nvidia GPUs (GNU libgomp) (original) (raw)


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’sinterop directive or, implicitly, when invoking a declare variantprocedure that has the append_args clause. In either case, theprefer_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 deviceis 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:

Property C data type API routine value (if constant)
fr_id omp_interop_fr_t int omp_fr_cuda
fr_name const char * str "cuda"
vendor int int 11
vendor_name const char * str "nvidia"
device_num int int
platform N/A
device int int
device_context N/A
targetsync cudaStream_t ptr

Available properties for a CUDA driver API interop object:

Property C data type API routine value (if constant)
fr_id omp_interop_fr_t int omp_fr_cuda_driver
fr_name const char * str "cuda_driver"
vendor int int 11
vendor_name const char * str "nvidia"
device_num int int
platform N/A
device CUdevice int
device_context CUcontext ptr
targetsync CUstream ptr

Available properties for an HIP interop object:

Property C data type API routine value (if constant)
fr_id omp_interop_fr_t int omp_fr_hip
fr_name const char * str "hip"
vendor int int 11
vendor_name const char * str "nvidia"
device_num int int
platform N/A
device hipDevice_t int
device_context hipCtx_t ptr
targetsync hipStream_t ptr