HOME
| OPENMP API Specification: Version 5.0 November 2018

2.12.7  declare target Directive

SummaryThe declare target directive specifies that variables, functions (C, C++ and Fortran), and subroutines (Fortran) are mapped to a device. The declare target directive is a declarative directive.

Syntax

SVG-Viewer needed.

The syntax of the declare target directive takes either of the following forms:  

 
#pragma omp declare target new-line 
declaration-definition-seq 
#pragma omp end declare target new-line  

or  

 
#pragma omp declare target (extended-list) new-line  

or  

 
#pragma omp declare target clause[ [,] clause ... ] new-line  

where clause is one of the following:  

 
to(extended-list) 
link(list) 
device_type(host | nohost | any)  

SVG-Viewer needed.

SVG-Viewer needed.

The syntax of the declare target directive is as follows:  

 
!$omp declare target (extended-list)  

or  

 
!$omp declare target [clause[ [,] clause] ... ]  

where clause is one of the following:  

 
to(extended-list) 
link(list) 
device_type(host | nohost | any)  

SVG-Viewer needed.

Description The declaretarget directive ensures that procedures and global variables can be executed or accessed on a device. Variables are mapped for all device executions, or for specific device executions through a link clause.

If an extended-list is present with no clause then the to clause is assumed.

The device_type clause specifies if a version of the procedure should be made available on host, device or both. If host is specified only a host version of the procedure is made available. If nohost is specified then only a device version of the procedure is made available. If any is specified then both device and host versions of the procedure are made available.

SVG-Viewer needed.

If a function appears in a to clause in the same translation unit in which the definition of the function occurs then a device-specific version of the function is created.

If a variable appears in a to clause in the same translation unit in which the definition of the variable occurs then the original list item is allocated a corresponding list item in the device data environment of all devices.

SVG-Viewer needed.

SVG-Viewer needed.

If an internal procedure appears in a to clause then a device-specific version of the procedure is created.

If a variable that is host associated appears in a to clause then the original list item is allocated a corresponding list item in the device data environment of all devices.

SVG-Viewer needed.

If a variable appears in a to clause then the corresponding list item in the device data environment of each device is initialized once, in the manner specified by the program, but at an unspecified point in the program prior to the first reference to that list item. The list item is never removed from those device data environments as if its reference count is initialized to positive infinity.

Including list items in a link clause supports compilation of functions called in a target region that refer to the list items. The list items are not mapped by the declare target directive. Instead, they are mapped according to the data mapping rules described in Section 2.19.7 on page 934.

SVG-Viewer needed.

If a function is referenced in a function that appears as a list item in a to clause on a declare target directive then the name of the referenced function is treated as if it had appeared in a to clause on a declare target directive.

If a variable with static storage duration or a function (except lambda for C++) is referenced in the initializer expression list of a variable with static storage duration that appears as a list item in a to clause on a declare target directive then the name of the referenced variable or function is treated as if it had appeared in a to clause on a declare target directive.

The form of the declare target directive that has no clauses and requires a matching end declare target directive defines an implicit extended-list to an implicit to clause. The implicit extended-list consists of the variable names of any variable declarations at file or namespace scope that appear between the two directives and of the function names of any function declarations at file, namespace or class scope that appear between the two directives.

The declaration-definition-seq defined by a declare target directive and an end declare target directive may contain declare target directives. If a device_type clause is present on the contained declare target directive, then its argument determines which versions are made available. If a list item appears both in an implicit and explicit list, the explicit list determines which versions are made available.

SVG-Viewer needed.

SVG-Viewer needed.

If a procedure is referenced in a procedure that appears as a list item in a to clause on a declare target directive then the name of the procedure is treated as if it had appeared in a to clause on a declare target directive.

If a declare target does not have any clauses then an implicit extended-list to an implicit to clause of one item is formed from the name of the enclosing subroutine subprogram, function subprogram or interface body to which it applies.

If a declare target directive has a device_type clause then any enclosed internal procedures cannot contain any declare target directives. The enclosing device_type clause implicitly applies to internal procedures.

SVG-Viewer needed.

Restrictions

SVG-Viewer needed.

SVG-Viewer needed.

SVG-Viewer needed.

SVG-Viewer needed.

Cross References