SummaryThe declaretarget directive specifies that variables, functions (C, C++ and Fortran), and
subroutines (Fortran) are mapped to a device. The declaretarget directive is a declarative
directive.
Syntax
The syntax of the declaretarget directive takes either of the following forms:
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.
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.
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.
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 declaretarget directive.
Instead, they are mapped according to the data mapping rules described in Section 2.19.7 on
page 934.
If a function is referenced in a function that appears as a list item in a to clause on a declaretarget
directive then the name of the referenced function is treated as if it had appeared in a to clause on a
declaretarget 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
declaretarget directive then the name of the referenced variable or function is treated as if it had
appeared in a to clause on a declaretarget directive.
The form of the declaretarget directive that has no clauses and requires a matching
enddeclaretarget 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 declaretarget directive and an enddeclaretarget
directive may contain declaretarget directives. If a device_type clause is present on the
contained declaretarget 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.
If a procedure is referenced in a procedure that appears as a list item in a to clause on a declaretarget
directive then the name of the procedure is treated as if it had appeared in a to clause on a
declaretarget directive.
If a declaretarget 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 declaretarget directive has a device_type clause then any enclosed internal procedures
cannot contain any declaretarget directives. The enclosing device_type clause implicitly applies
to internal procedures.
Restrictions
A
threadprivate
variable
cannot
appear
in
a
declaretarget
directive.
A
variable
declared
in
a
declaretarget
directive
must
have
a
mappable
type.
The
same
list
item
must
not
appear
multiple
times
in
clauses
on
the
same
directive.
The
same
list
item
must
not
explicitly
appear
in
both
a
to
clause
on
one
declaretarget
directive
and
a
link
clause
on
another
declaretarget
directive.
The
function
names
of
overloaded
functions
or
template
functions
may
only
be
specified
within
an
implicit
extended-list.
If
a
lambda
declaration
and
definition
appears
between
a
declare
target
directive
and
the
matching
end
declare
target
directive,
all
variables
that
are
captured
by
the
lambda
expression
must
also
appear
in
a
to
clause.
If
a
list
item
is
a
procedure
name,
it
must
not
be
a
generic
name,
procedure
pointer
or
entry
name.
Any
declaretarget
directive
with
clauses
must
appear
in
a
specification
part
of
a
subroutine
subprogram,
function
subprogram,
program
or
module.
Any
declaretarget
directive
without
clauses
must
appear
in
a
specification
part
of
a
subroutine
subprogram,
function
subprogram
or
interface
body
to
which
it
applies.
If
a
declaretarget
directive
is
specified
in
an
interface
block
for
a
procedure,
it
must
match
a
declaretarget
directive
in
the
definition
of
the
procedure.
If
an
external
procedure
is
a
type-bound
procedure
of
a
derived
type
and
a
declaretarget
directive
is
specified
in
the
definition
of
the
external
procedure,
such
a
directive
must
appear
in
the
interface
block
that
is
accessible
to
the
derived
type
definition.
If
any
procedure
is
declared
via
a
procedure
declaration
statement
that
is
not
in
the
type-bound
procedure
part
of
a
derived-type
definition,
any
declaretarget
with
the
procedure
name
must
appear
in
the
same
specification
part.
A
variable
that
is
part
of
another
variable
(as
an
array,
structure
element
or
type
parameter
inquiry)
cannot
appear
in
a
declaretarget
directive.
The
declaretarget
directive
must
appear
in
the
declaration
section
of
a
scoping
unit
in
which
the
common
block
or
variable
is
declared.
If
a
declaretarget
directive
that
specifies
a
common
block
name
appears
in
one
program
unit,
then
such
a
directive
must
also
appear
in
every
other
program
unit
that
contains
a
COMMON
statement
that
specifies
the
same
name,
after
the
last
such
COMMON
statement
in
the
program
unit.
If
a
list
item
is
declared
with
the
BIND
attribute,
the
corresponding
C
entities
must
also
be
specified
in
a
declaretarget
directive
in
the
C
program.
A
blank
common
block
cannot
appear
in
a
declaretarget
directive.
A
variable
can
only
appear
in
a
declaretarget
directive
in
the
scope
in
which
it
is
declared.
It
must
not
be
an
element
of
a
common
block
or
appear
in
an
EQUIVALENCE
statement.
A
variable
that
appears
in
a
declaretarget
directive
must
be
declared
in
the
Fortran
scope
of
a
module
or
have
the
SAVE
attribute,
either
explicitly
or
implicitly.
Cross References
targetdata
construct,
see
Section 2.12.2
on
page 451.