HOME
| OPENMP API Specification: Version 5.1 November 2020

2.14.7  Declare Target Directive

Summary The 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 is as follows:  

 
#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  

or  

 
#pragma omp begin declare target [clause[ [,] clause] ... ] new-line 
    declaration-definition-seq 
#pragma omp end declare target new-line  

where clause is one of the following:  

 
to(extended-list) 
link(list) 
device_type(host | nohost | any) 
indirect[(invoked-by-fptr)]  

where invoked-by-fptr is a constant boolean expression that evaluates to true or false at compile time.

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) 
indirect[(invoked-by-fptr)]  

where invoked-by-fptr is a constant logical expression that is evaluated at compile time.

SVG-Viewer needed.

Description The declare target 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 or variable should be made available on the host, device or both. If host is specified only a host version of the procedure or variable is made available. If any is specified then both device and host versions of the procedure or variable are made available. If nohost is specified for a procedure then only a device version of the procedure is made available. If nohost is specified for a variable then that variable is not available on the host. If no device_type clause is present then the behavior is as if the device_type clause appears with any specified.

If a variable with static storage duration is declared in a device routine then the named variable is treated as if it had appeared in a to clause on a declare target directive.

SVG-Viewer needed.

If a function appears in a to clause in the same compilation 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 compilation 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 a procedure appears in a to clause in the same compilation unit in which the definition of the procedure occurs 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 was 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.21.7.

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 that does not specify a device_type clause with host and the function reference is not enclosed in a target construct that specifies a device clause in which the ancestordevice-modifier appears 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, preceded by either the declare target directive that has no clauses and no extended-list or the begin declare target directive and followed by a matching end declare target directive, defines an implicit extended-list. 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 implicit extended-list is converted to an implicit to clause.

The declaration-definition-seq preceded by either begin declare target directive or a declare target directive without any clauses or an extended-list and followed by 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 that does not specify a device_type clause with host and the procedure reference is not enclosed in a target construct that specifies a device clause in which the ancestordevice-modifier appears then the name of the referenced 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 and does not have an extended-list then an implicit to clause with 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.

If the indirect clause is present and invoked-by-fptr is not specified, the effect of the clause is as if invoked-by-fptr evaluates to true.

If the indirect clause is present and invoked-by-fptr evaluates to true, any procedures that appear in a to clause on the directive may be called with an indirect device invocation. If the indirect clause is present and invoked-by-fptr does not evaluate to true, any procedures that appear in a to clause on the directive may not be called with an indirect device invocation. Unless otherwise specified by an indirect clause, procedures may not be called with an indirect device invocation.

SVG-Viewer needed.

If a function appears in the to clause of a begin declare target directive and in the to clause of a declare target directive that is contained in the declaration-definition-seq associated with the begin declare target directive, and if an indirect clause appears on both directives, then the indirect clause on the begin declare target directive has no effect for that function.

SVG-Viewer needed.

Execution Model Events The target-global-data-op event occurs when an original variable is associated with a corresponding variable on a device as a result of a declare target directive; the event occurs before the first access to the corresponding variable.

Tool Callbacks A thread dispatches a registered ompt_callback_target_data_op callback, or a registered ompt_callback_target_data_op_emi callback with ompt_scope_beginend as its endpoint argument for each occurrence of a target-global-data-op event in that thread. These callbacks have type signature ompt_callback_target_data_op_t or ompt_callback_target_data_op_emi_t, respectively.

Restrictions Restrictions to the declare target directive are as follows:

SVG-Viewer needed.

SVG-Viewer needed.

SVG-Viewer needed.

SVG-Viewer needed.

Cross References