Intel® C++ Compiler 16.0 User and Reference Guide

Placing Variables and Functions on the Processor Graphics

This topic only applies to Intel® 64 and IA-32 architectures targeting Intel® Graphics Technology.

The statement following the offload pragma is converted into an outlined function that runs on the processor graphics. This code is permitted to call other functions. To ensure that these called functions are also available on the processor graphics, you must specify the following special function attribute:

Windows, Linux

__declspec( target (gfx)) function-declaration

Linux

__attribute__((target (gfx))) function-declaration

All functions in the program are always compiled for the CPU and are available to be called on the CPU. However, only functions marked with this special attribute are available to be called by offloaded code, and only these functions can be called on the processor graphics.

Global variables are treated in a similar fashion. All global variables are always present in the CPU code. But only global variables with the target attribute are compiled into the binary offloaded to the target. Specify the following special variable attribute:

Windows, Linux

__declspec( target (gfx))variable-declaration

Linux

__attribute__((target (gfx))) variable-declaration

Compiling only functions and data explicitly marked with the target attribute into the target binary ensures that the code on the processor graphics is as small as possible.

The compiler issues warnings for functions and data referenced within offloaded code that do not have the target attribute.

Note

The presence of a function call within an offloaded construct with a target attribute does not automatically declare that function as available on that target. The function definition must include the appropriate target attribute to ensure that the function is available on the target.

Note

The definition and all declarations of a variable or function with a target attribute must be consistent with each other across all compilation units.

Example

__declspec(target(gfx)) //create a host and a target allocation of the global variable
int global = 55;

__declspec(target(gfx)) //create a host and a target version of the function foo
int foo()
{
    return ++global;
}

int main (int argc, char* argv) 
{
    int i;
    #pragma offload target(gfx) inout(global) //offload the following loop to the target
    _Cilk_for (int i = 0; i < 1; i++)
    {
        foo();
    }
    
    printf("global = %d (should be 56)\n", global);

    if (global == 56) {
        printf("Passed\n");
        return 0;
    }
    else {
        printf("Failed\n");
        return 1;
    }

}

See Also