The ATTRIBUTES directive option OFFLOAD ensures that variables and procedures are available on the coprocessor. This directive option only applies to Intel® MIC Architecture. It takes the following form:
cDEC$ ATTRIBUTES OFFLOAD: target-name:: object-name
c |
Is one of the following: C (or c), !, or *. (See Syntax Rules for Compiler Directives.) |
target-name |
Is a specific target. The only supported value for this argument is MIC. |
object-name |
Is the name of a procedure or variable. |
The statement following the directive is converted into an outlined function that runs on the coprocessor. This code is permitted to call other procedures. To ensure that these called procedures are also available on the coprocessor, they should also include the ATTRIBUTES OFFLOAD:MIC directive.
All procedures in the program are always compiled for the CPU and are available to be called on the CPU. However, only procedures that include the ATTRIBUTES OFFLOAD:MIC directive are available to be called by offloaded code, and only these procedures can be called on the coprocessor.
Global variables are treated in a similar fashion. All global variables are always present in the CPU code. But only global variables declared with the ATTRIBUTES OFFLOAD:MIC directive are compiled into the code offloaded to the coprocessor.
Compiling only procedures and data explicitly marked with the ATTRIBUTES OFFLOAD:MIC directive into the Intel® MIC Architecture binary ensures that the code on the coprocessor is as small as possible.
The compiler issues warnings for procedures and data referenced within offloaded code that do not include the ATTRIBUTES OFFLOAD:MIC directive.
The definition and all declarations of a variable or procedure with the ATTRIBUTES OFFLOAD:MIC directive must be consistent with each other across all compilation units.
module m
integer :: global = 55
!dir$ attributes offload:mic :: global
contains
function foo ()
integer :: foo
! dir$ attributes offload:mic :: foo
use m
global = global + 1
foo = global
end function foo
end module m
main p
use m
integer :: i
external foo
integer :: foo
! dir$ attributes offload:mic :: foo
!dir$ offload target(mic) in(global) out(i, global)
i = foo()
write (*, ‘( “ global = “, i0, “ I = “, i0) ‘, global, i
end
Note that the presence of the function call foo() within an offloaded construct that contains the ATTRIBUTES OFFLOAD:MIC directive does not automatically declare that the procedure as available on that target. The procedure definition must include the ATTRIBUTES OFFLOAD:MIC directive to ensure that the procedure is available on the target.