HOME
| OPENMP API Specification: Version 5.1 November 2020

3.8.1  omp_target_alloc

Summary The omp_target_alloc routine allocates memory in a device data environment and returns a device pointer to that memory.

Format

SVG-Viewer needed.

 

 
void* omp_target_alloc(size_t size, int device_num);  

SVG-Viewer needed.

SVG-Viewer needed.

 

 
type(c_ptr) function omp_target_alloc(size, device_num) bind(c) 
use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t, c_int 
integer(c_size_t), value :: size 
integer(c_int), value  :: device_num  

SVG-Viewer needed.

Constraints on Arguments The device_num argument must be greater than or equal to zero and less than or equal to the result of omp_get_num_devices().

Binding The binding task set for an omp_target_alloc region is the generating task, which is the target task generated by the call to the omp_target_alloc routine.

Effect The omp_target_alloc routine returns a device pointer that references the device address of a storage location of size bytes. The storage location is dynamically allocated in the device data environment of the device specified by device_num.

The omp_target_alloc routine executes as if part of a target task that is generated by the call to the routine and that is an included task.

The omp_target_alloc routine returns NULL (or, C_NULL_PTR, for Fortran) if it cannot dynamically allocate the memory in the device data environment.

The device pointer returned by omp_target_alloc can be used in an is_device_ptr clause, Section 2.14.5.

SVG-Viewer needed.

The omp_target_alloc routine requires an explicit interface and so might not be provided in omp_lib.h.

SVG-Viewer needed.

Execution Model Events The target-data-allocation-begin event occurs before a thread initiates a data allocation on a target device.

The target-data-allocation-end event occurs after a thread initiates a data allocation on a target device.

Tool Callbacks A thread dispatches a registered ompt_callback_target_data_op_emi callback with ompt_scope_begin as its endpoint argument for each occurrence of a target-data-allocation-begin event in that thread. Similarly, a thread dispatches a registered ompt_callback_target_data_op_emi callback with ompt_scope_end as its endpoint argument for each occurrence of a target-data-allocation-end event in that thread. These callbacks have type signature ompt_callback_target_data_op_emi_t.

A thread dispatches a registered ompt_callback_target_data_op callback for each occurrence of a target-data-allocation-begin event in that thread. The callback occurs in the context of the target task and has type signature ompt_callback_target_data_op_t.

Restrictions Restrictions to the omp_target_alloc routine are as follows.

Cross References