Devices
6. Devices#
The target construct consists of a target directive and an execution region. The target region is executed on the default device or the device specified in the device clause.
In OpenMP version 4.0, by default, all variables within the lexical scope of the construct are copied to and from the device, unless the device is the host, or the data exists on the device from a previously executed data-type construct that has created space on the device and possibly copied host data to the device storage.
The constructs that explicitly create storage, transfer data, and free storage on the device are categorized as structured and unstructured. The target data construct is structured. It creates a data region around target constructs, and is convenient for providing persistent data throughout multiple target regions. The target enter data and target exit data constructs are unstructured, because they can occur anywhere and do not support a “structure” (a region) for enclosing target constructs, as does the target data construct.
The map clause is used on target constructs and the data-type constructs to map host data. It specifies the device storage and data movement to and from the device, and controls on the storage duration.
There is an important change in the OpenMP 4.5 specification that alters the data model for scalar variables and C/C++ pointer variables. The default behavior for scalar variables and C/C++ pointer variables in a 4.5 compliant code is firstprivate. Example codes that have been updated to reflect this new behavior are annotated with a description that describes changes required for correct execution. Often it is a simple matter of mapping the variable as tofrom to obtain the intended 4.0 behavior.
In OpenMP version 4.5 the mechanism for target execution is specified as occurring through a target task . When the target construct is encountered a new target task is generated. The target task completes after the target region has executed and all data transfers have finished.
This new specification does not affect the execution of pre-4.5 code; it is a necessary element for asynchronous execution of the target region when using the new nowait clause introduced in OpenMP 4.5.