HOME
| OPENMP API Specification: Version 5.0 November 2018

3.6.1  omp_target_alloc

SummaryThe omp_target_alloc routine allocates memory in a device data environment.

Format  

 
void* omp_target_alloc(size_t size, int device_num);  

EffectThe omp_target_alloc routine returns 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, which must be greater than or equal to zero and less than the result of omp_get_num_devices() or the result of a call to omp_get_initial_device(). When called from within a target region the effect of this routine is unspecified. The omp_target_alloc routine returns NULL if it cannot dynamically allocate the memory in the device data environment.

The device address returned by omp_target_alloc can be used in an is_device_ptr clause, Section 2.12.5 on page 478.

Unless unified_address clause appears on a requires directive in the compilation unit, pointer arithmetic is not supported on the device address returned by omp_target_alloc.

Freeing the storage returned by omp_target_alloc with any routine other than omp_target_free results in unspecified behavior.

Execution Model EventsThe target-data-allocation event occurs when a thread allocates data on a target device.

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

Cross References