2022-04-18 15:02:25 -07:00

37 lines
1.6 KiB
TeX

\pagebreak
\section{\code{requires} Directive}
\label{sec:requires}
\index{directives!requires@\code{requires}}
\index{requires directive@\code{requires} directive}
The declarative \code{requires} directive can be used to
specify features that an implementation must provide to compile and
execute correctly.
\index{requires directive@\code{requires} directive!unified_shared_memory clause@\scode{unified_shared_memory} clause}
\index{clauses!unified_shared_memory@\scode{unified_shared_memory}}
\index{unified_shared_memory clause@\scode{unified_shared_memory} clause}
In the following example the \code{unified\_shared\_memory} clause
of the \code{requires} directive ensures that the host and all
devices accessible through OpenMP provide a \plc{unified address} space
for memory that is shared by all devices.
The example illustrates the use of the \code{requires} directive specifying
\plc{unified shared memory} in file scope, before any device
directives or device routines. No \code{map} clause is needed for
the \plc{p} structure on the device (and its address \plc{\&p}, for the C++ code,
is the same address on the host and device).
However, scalar variables referenced within the \code{target}
construct still have a default data-sharing attribute of firstprivate.
The \plc{q} scalar is incremented on the device, and its change is
not updated on the host.
% will defaultmap(toform:scalar) make q use shared address space?
%Or will it be ignored at this point.
% Does before device routines also mean before prototype?
%\pagebreak
\cppexample[5.0]{requires}{1}
\ffreeexample[5.0]{requires}{1}