1.问题描述

linux环境下,使用MIC架构的Xeon Phi(至强融核)协处理器进行进行host+mic编程时,源程序运行的毫无问题,但将其通过ar命令生成静态连接库供其他应用程序使用时,就会出现offload error: cannot find offload entry错误。

2.不生成静态链接库的正确版本

为了简化问题,将项目源码缩略为如下示例程序。
源文件offloadtest.cpp:

#include <offload.h>
#include <omp.h>
#include <stdio.h>__attribute__((target(mic)))
void test_kernel(){int thread_num=omp_get_max_threads();//获取处理器最大可并行的线程数#pragma omp parallel for num_threads(thread_num) for(int i=0;i<10;++i)printf("%d:in test kernel\n",i);
}int main(int argc,char* argv[]){int dev=0;#pragma offload target(mic:dev){test_kernel();}
}

编译指令:
使用intel C++编译器icpc进行编译,编译指令如下:

icpc -openmp -o offload.out offloadtest.cpp

执行offload.out,输出结果:
0:in test kernel
7:in test kernel
4:in test kernel
8:in test kernel
2:in test kernel
6:in test kernel
9:in test kernel
3:in test kernel
1:in test kernel
5:in test kernel

可见,for循环的代码已经在MIC上被多线程并行化执行,这样我们就利用MIC达到了CPU和MIC协同编程。

利用offload将设备代码加载到MIC端执行,这种,CPU和MIC协同计算的编程模式叫加载模式(offload模式),CPU端发起主函数,通过offload模式调用kernel到MIC上之行。

3.生成静态链接库供其他程序使用发生错误

在上面的代码中,将main()修改为调用MIC段代码的普通函数,修改结果如下:

#include <offload.h>
#include <omp.h>
#include <stdio.h>__attribute__((target(mic)))
void test_kernel(){int thread_num=omp_get_max_threads();//获取处理器最大可并行的线程数#pragma omp parallel for num_threads(thread_num) for(int i=0;i<10;++i)printf("%d:in test kernel\n",i);
}void userKernel(){int dev=0;#pragma offload target(mic:dev){test_kernel();}
}

利用icpc和ar命令将修改后的代码生成静态连接库offloadtest.a。生成静态链接库库makefile指令如下:

offloadtest.a:offloadtest.oar crv $@ offloadtest.o
offloadtest.o:offloadtest.cppicpc -openmp -o offload.out offloadtest.cpp

执行makefile就会生成静态链接库offloadtest.a。当offloadtest.a链接到其他应用程序时,调用MIC设备端函数test_kernel()时就会出现运行时错误:offload error: cannot find offload entry,程序崩溃。

4.解决办法

生成静态链接库时,使用如下指令:

offloadtest.a:offloadtest.oxiar -qoffload-build crv $@ offloadtest.o
offloadtest.o:offloadtest.cppicpc -openmp -o offload.out offloadtest.cpp

在使用ar或者xiar时,加上-qoffload-build命令选项就可以了。本人实践证明,使用xiar时不加-qoffload-build命令选项也可以。

参考资料来自于Intel开发者社区,其原文如下:

From your question, it is unclear if your OpenMP code that worked was a host only or a host+offload code.

From what you have described, I suspect your app’s build procedure creates or uses static archives and one must contain your routine with the offload section; however, if the archive containing that routine was not built using xiar -qoffload-build then the required MIC specific archive is not created. While your app links, the MIC-image is missing the MIC-instance of the routine, so at execution time the host-side app reaches the offload, loads the MIC-image, but the run-time cannot find the routine because it does not exist.

You can visit this compiler reference on how to create offload libraires using xiar and xild.

但是需要注意的是,ar加上-qoffload-build命令选项或者使用xiar就会生成两个静态链接库,如offloadtest.a和offloadtestMIC.a,使用时,请将这两个静态链接库一并链接到程序中使用。

xiar是Intel 基于ar封装的一个用于生成静态链接库的工具。

查看ar的命令选项:

q[f]         - quick append file(s) to the archive

即,-q后面接相关文件,ar -q的作用就是将指定的文件快速附加到静态链接库中。

参考问下

[1]https://software.intel.com/en-us/forums/intel-many-integrated-core/topic/361425
[2]http://blog.csdn.net/k346k346/article/details/50083895

offload error: cannot find offload entry解决办法相关推荐

  1. CAS (10) —— JBoss EAP 6.4下部署CAS时出现错误exception.message=Error decoding flow execution的解决办法...

    CAS (10) -- JBoss EAP 6.4下部署CAS时出现错误exception.message=Error decoding flow execution的解决办法 jboss版本: jb ...

  2. mysql 1045错误ODBC_MySQL ERROR 1045 (28000) 错误的解决办法

    错误现象: ERROR 1045 (28000): Access denied for user'ODBC'@'localhost'(using password: NO) ERROR 1045 (2 ...

  3. DedeCMS Error:Tag disabled:php的解决办法

    DedeCMS Error:Tag disabled:"php"的解决办法 2, posted on 2014-02-12 12:15 秦瑞It行程实录 阅读(...) 评论(.. ...

  4. NSIS ERROR NSIS病毒新型变种 解决办法

    NSIS ERROR & NSIS病毒新型变种 & 解决办法 特点综述 如何分类 如何应对"变异前"的病毒 简述特征 第一步,破解EXE安装报错 第二步,杀毒 小结 ...

  5. 微信开发者工具代码仓的管理以及错误:Push failed Error: invalid authentication scheme 的解决办法,微信小程序代码仓项目删除

    文章目录 1.新建代码仓 2.报错:Push failed Error: invalid authentication scheme 的解决办法 3.代码仓项目的删除 1.新建代码仓 如果你的代码已经 ...

  6. VB6程序运行错误Run-time error 339: Tabctl32.ocx的解决办法

    运行错误Run-time error 339: Tabctl32.ocx的解决办法 [问题] 最近一段时间与教研室的各位老师在做一个山东省一级OFFICE模拟软件时,前面的开发工作一切顺利,却在后面的 ...

  7. php数据库报错1046怎么解决,DZ报错MySQL Query Error Errno:1046错误的解决办法

    这篇文章主要为大家详细介绍了DZ报错MySQL Query Error Errno:1046错误的解决办法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下,有需要的朋友可以收藏方便以后借鉴. DZ报 ...

  8. docker mysql 日志_docker中将MySQL运行在容器中失败提示“ InnoDB : Error 22 with aio_write”的解决办法...

    今天利用docker容器创建mysql8.0的时候(window系统),指定了本地宿主机器的一个目录为容器mysql的datadir目录,发现创建失败了. 创建命令: $ docker run -d ...

  9. mysql error nr.2003_[MySQL]在安装windows版MySQL时遇到过如下问题Error Nr.1045和Error.Nr.2003,相应解决办法如下...

    1.准备mysql server-5.0.27.exe 2.按照指导安装,在安装到最后一步时遇到如下两个错误: 2.1.出现错误Error Nr.1045 解决办法: a).停止MySQL服务:我的电 ...

最新文章

  1. 打王者、调小酒、搭乐高,大厂女程序员的别样人生
  2. 前台特效(6) 折叠栏目(动画效果)
  3. Java日志框架-Spring中使用Logback(Spring/Spring MVC)
  4. 我的Java开发学习之旅------Java经典排序算法之二分插入排序
  5. 当sql 没有足够的内存执行程序利用命令执行
  6. [html] 网页上的验证码是为了解决什么问题?说说你了解的验证码种类有哪些
  7. linux查看kafka状态_Linux Page Cache调优在Kafka中的应用
  8. 自主编写的新书出版2个月,竟然上了51cto读书频道的动态首页,兴奋中!
  9. Redis实战(七)
  10. 输入n求N*N矩阵,规定矩阵沿45度线递增
  11. 网站ddos发包服务器,ddos发包搭建
  12. 区块链入门教程(1)--概述
  13. 如何学习平面设计色彩搭配原理
  14. python八卦图时钟代码-Python检测一个对象是否为字符串类的方法
  15. 荣耀magicbook15C语言,荣耀MagicBook 15 2021版评测:轻薄机身+强悍性能 专为高效率办公而生...
  16. delphi技巧总结收集
  17. 教师资格证面试试讲规律!
  18. #2766. 猜测(guess)
  19. 2013总结——告别页游,迎接手游
  20. 浅谈学习编程语言的心得与体会

热门文章

  1. 成都睿铂 | 落差区域无人机倾斜摄影航线的规划要点
  2. linux中程序包管理方式出现的原由(转载)
  3. jvm垃圾收集器与内存分配策略
  4. python实现的简版iconv
  5. SCO UNIX环境下自动增加网关的两种方法
  6. [Java] 蓝桥杯BASIC-28 基础练习 Huffuman树
  7. 1065. 单身狗(25)-PAT乙级真题
  8. bind9局域网其他用户不能解析_linux dns server bind9 内网域名解析
  9. python反序列化漏洞_【事件分析】No.10 影响深远的反序列化漏洞
  10. k8s 安装_二进制安装k8s集群总结