void* omp_target_alloc(size_t size, int device_num);
Summary The omp_target_alloc routine allocates memory in a device data environment and returns a device pointer to that memory.
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.
The omp_target_alloc routine requires an explicit interface and so might not be provided in omp_lib.h.
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.
∙ Unless the unified_address clause appears on a requires directive in the compilation unit, pointer arithmetic is not supported on the device pointer returned by omp_target_alloc.