Intel® C++ Compiler 16.0 User and Reference Guide

offload_attribute

Specifies that all functions and variables declared subsequent to the pragma are available on the target. This pragma only applies to Intel® MIC Architecture and Intel® Graphics Technology.

Syntax

#pragma offload_attribute([push, ] target(target-name)

#pragma offload_attribute(pop)

Arguments

push

Pushes functions and variables on the internal compiler stack to be offloaded to the target until the statement #pragma offload_attribute (pop) or until the end of the compilation unit.

This is the default.

target(target-name)

Represents the target. Can be one of the following values:

gfx

Intel® Graphics Technology

mic

Intel® Xeon Phi™ products

pop

Removes the functions and variables from the top of the internal compiler stack.

none

Turns off the pragma.

Description

This pragma specifies that all functions and variables declared subsequent to the pragma are available on the target.

This pragma enables you to avoid the need to put target attributes or target declspec on individual declarations.

To turn on the pragma, specify push and target(target-name), or specify only a target(target-name). push pushes target-name onto a stack. If you specify target(target-name) only, the compiler does not remember the state before the pragma.

Examples

The following examples demonstrates how to use this pragma.

In the following example, the pragma specifies that all functions and variables between the push and pop statements are sent to the target. Both class A and class B get the target(mic) attribute.

Example

// Push mic target onto the stack.
  #pragma offload_attribute (push, target (mic))
 
// Functions and variables.
  ...
 
// Remove mic target from the stack, return to previous state.
  #pragma offload_attribute (pop) 

Example

fileA.h
#include <vector>
 
class A {
  ...
  private:
  std::vector<int> av;
};
 
fileB.cpp
 
#pragma offload_attribute (push,target(mic)) #include "fileA.h"
  class B : public A { ... };
#pragma offload_attribute (pop)

All data members of the classes, both those added by the user such as the data member av, as well as the internal data members created by the compiler, such as their virtual function tables, get the target(mic) attribute, because they are enclosed within the offload_attribute pragma region.

Notice that the target(mic) or the _Cilk_shared attribute on a class is not inherited, therefore the classes need to be individually marked either explicitly in their definition or through the push/pop mechanism. Also notice that for the correct offloading of member functions via virtual dispatch, all classes in the hierarchy must be marked with the target(mic) or _Cilk_shared attribute.

Example

#pragma offload_attribute (push,target(mic)) namespace U { 
  class C { ... };
  ...
} // original definition of namespace U

#pragma offload_attribute (pop)
namespace U {
  class D { ... };
  ...
} // extended namespace U

In the previous example, class C and the contents of namespace U in the original definition get the target(mic) attribute because they are enclosed with the offload_attribute pragma. However, the namespace U itself does not get marked with the attribute.

Consequently, class D and the contents of the extended namespace U do not get the target(mic) attribute because they are not enclosed with the offload_attribute pragma.