zoukankan      html  css  js  c++  java
  • MIC中函数和变量的声明

    c++/c使用

    __declspec(target(mic))函数或变量声明

    __attribute__((target(mic)))函数或变量声明

    举例如下:

    __attribute__((target(mic))) int a;
    __attribute__((target(mic))) void func();

    如果变量或函数较多,MIC问为我们提供了批量声明的办法,让我们一次可以申请多个函数或变量,并且函数或变量,并且函数和变量可以混合声明。

    #pragma offload_attribute([push,]target(target-name))
       // 变量或函数声明
    #pragma offload_atrribute(pop|{target(none)})

    C/C++有两种方法:

    #pragma offload_attribute(push,target(mic))
    //函数或变量声明
    #pragma offload_attribute (pop)

    #pragma offload_attribute(target(mic))
    //函数或变量声明
    #pragma offload_arrtibute (target(none))

    举例如下:

    #pragma offload_attribute(push,target(mic))
        inta;
        float func();
    #pragma offload_attribute(pop)

    这里注意attribute前后均是两个下划线,示例代码如下:

    #include<stdlib.h>
    #include<stdio.h>
    #include<string.h>
    #define LEN 5
    __attribute__((target(mic))) void funcheck(int h){
        #ifdef    __MIC__
            printf("Index on MIC: %d 
    ",h);
        #else
            printf("Index on CPU: %d 
    ",h);
        #endif    
    }
    
    int main(int argc,int** argv){
        int i;
        #pragma offload target(mic)
        for(i=0;i<LEN;i++){
            funcheck(i);
        }
        return 0;
    }

    MIC前后也均是两个下划线,这段代码中__MIC__是MIC提供的一个宏定义,这个宏定义用来检查程序是否运行在设备端,也就是MIC端,需要注意的是,这个定义不能在offload代码段内检查!

    编译 icc -o demo demo.c 

    执行 ./demo 

    结果如下:

    Index on MIC: 0
    Index on MIC: 1
    Index on MIC: 2
    Index on MIC: 3
    Index on MIC: 4

  • 相关阅读:
    【转】Android开发——MediaProvider源码分析(2)
    关于ActivityGroup使用过程中遇到的一点问题
    HttpWebRequest详解
    关于Assembly.CreateInstance()与Activator.CreateInstance()方法的区别
    你会在C#的类库中添加web service引用吗?
    ASP.NET跳转网页的三种方法的比较
    .net发送HTTP POST包
    依赖注入
    微软ASP.NET MVC Beta版本发布
    随笔~
  • 原文地址:https://www.cnblogs.com/sdxk/p/4209413.html
Copyright © 2011-2022 走看看