3.7.1 omp_target_alloc – Allocate device memory

Description:

This routine allocates size bytes of memory in the device environment associated with the device number device_num. If successful, a device pointer is returned, otherwise a null pointer.

In GCC, when the device is the host or the device shares memory with the host, the memory is allocated on the host; in that case, when size is zero, either NULL or a unique pointer value that can later be successfully passed to omp_target_free is returned. When the allocation is not performed on the host, a null pointer is returned when size is zero; in that case, additionally a diagnostic might be printed to standard error (stderr).

Running this routine in a target region except on the initial device is not supported.

C/C++
Prototype:void *omp_target_alloc(size_t size, int device_num)
Fortran:
Interface:type(c_ptr) function omp_target_alloc(size, device_num) bind(C)
use, intrinsic :: iso_c_binding, only: c_ptr, c_int, c_size_t
integer(c_size_t), value :: size
integer(c_int), value :: device_num
See also:

omp_target_free – Free device memory, omp_target_associate_ptr – Associate a device pointer with a host pointer

Reference:

OpenMP specification v5.1, Section 3.8.1