C++/C use
__declspec (target (MIC)) function or variable declaration
Or
__ATTRIBUTE__ ((Target (MIC))) function or variable declaration
Examples are as follows:
intvoid func ();
Note here that there are two underscores before and after attribute, the sample code is as follows:
#include <stdlib.h>#include<stdio.h>#include<string.h>#defineLEN 5__attribute__ ((Target (MIC)))voidFuncheck (inth) {#ifdef __mic__ printf ("Index on MIC:%d \ n", h); #elseprintf ("Index on CPU:%d \ n", h); #endif }intMainintargcint**argv) { inti; #pragmaOffload Target (MIC) for(i=0; i<len;i++) {Funcheck (i); } return 0;}
Before and after the mic is also two underline, this code __mic__ is a macro definition provided by the mic, this macro definition is used to check whether the program runs on the device side, that is, the mic side, it is important to note that this definition can not be checked in the offload code snippet!
Compiling icc-o Demo demo.c
Execution ./demo
The results are as follows:
Index on mic:0
Index on Mic:1
Index on Mic:2
Index on Mic:3
Index on Mic:4
Declarations of functions and variables in the mic