Intel® C++ Compiler 16.0 User and Reference Guide

Placing Variables and Functions on the Coprocessor

These attributes ensure that variables and functions are available on the coprocessor.

This topic only applies to Intel® Many Integrated Core Architecture (Intel® MIC Architecture).

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

__declspec( target (mic)) function-declaration

__declspec( target (mic))variable-declaration

__attribute__ (( target (mic))) function-declaration

__attribute__ (( target (mic))) variable-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 the special attribute are available to be called by offloaded code, and only these functions 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 with the target attribute are compiled into the binary offloaded to the coprocessor.

Compiling only functions and data explicitly marked with the target attribute into the Intel® MIC Architecture binary ensures that the code on the coprocessor is as small as possible.

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

Example

__declspec(target(mic))
 int global = 55;

__declspec(target(mic))
 int foo()
{
	return ++global;
}
main()
{
	int i;
	#pragma offload target(mic) in(global) out(i, global)
	{
		i = foo();
	}
	printf("global = %d, i = %d (should be the same)\n",
			global, i);
}

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.

See Also