Intel® Fortran Compiler 18.0 Developer Guide and Reference
The ATTRIBUTES directive option OFFLOAD ensures that variables, COMMON blocks, and procedures are available on the target. This directive option only applies when targeting Intel® Xeon Phi™ products.
!DIR$ ATTRIBUTES OFFLOAD: target-name:: object-name
target-name |
Is a specific target. The only supported value for this argument is MIC. |
object-name |
Is the name of a procedure, or a variable, or a COMMON block name (enclosed in slashes). |
The statement following an OFFLOAD directive is converted into an outlined function that runs on the processor. This code is permitted to call other procedures. To ensure that these called procedures are also available on the processor, 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 processor.
Global variables and COMMON blocks are treated in a similar fashion. All global variables are always present in the CPU code. But only global variables and COMMON blocks declared with the ATTRIBUTES OFFLOAD:MIC directive are compiled into the code offloaded to the processor. If an data object in a named COMMON block is given the OFFLOAD:MIC attribute, the entire named COMMON block is given the OFFLOAD:MIC attribute.
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 processor 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
!dir$ attributes offload:mic :: global
integer :: global = 55
end module m
!dir$ attributes offload:mic :: foo
function foo ()
use m
integer :: foo
global = global + 1
foo = global
end function foo
program main
use m
integer :: i
!dir$ attributes offload:mic :: foo
integer :: foo
!dir$ offload target(mic) in(global) out(i, global)
i = foo()
write(*, '( " global = ", i0, " I = ", i0)' ) global, i
end program main
Calling function foo() within an offloaded construct requires adding the ATTRIBUTES OFFLOAD:MIC directive within both the calling routine's scope and the function definition/scope for foo() itself.