Intel® C++ Compiler XE 13.1 User and Reference Guides

offload_attribute

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

Syntax

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

#pragma offload_attribute(pop|{target(none)})

Arguments

target-name

The name of the target.

The implementation pre-defines an identifier that represents the target (mic).

push

Turns on the pragma. Pushes target-name onto an internal compiler stack. All subsequent functions and variables are targeted for Intel® MIC Architecture until the statement #pragma offload_attribute (pop, target(target-name)) or until the end of the compilation unit.

Default.

pop

Turns off the pragma. Removes target-name from the top of the internal compiler stack.

none

Using none for the target-name turns off the pragma.

Description

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

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

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

If you specify push, pop turns off the pragma.

If you don't specify push, then specifying none for target-name effectively turns off the pragma.

Example

In the following example, all functions and variables between the push and pop statements are targets for the coprocessor.

// 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) 

In the following example, all functions and variables between the target(mic) and target(none) statements are targets for the coprocessor.

// Change target architecture to mic, Do not place target on stack.
#pragma offload_attribute (target (mic)) 

// Functions and variables.
...                                

// Change target architecture to none, turning off pragma.
#pragma offload_attribute (target(none))

In the following example, both class A and class B get the target(mic) attribute.

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.

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)

In the following example, class C and the contents of namespace A 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.

#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

Submit feedback on this help topic