calling a host function from a __device__/__global__ function is not allowed

来源:互联网 发布:中国最美的地方 知乎 编辑:程序博客网 时间:2024/05/17 04:44

昨天开始实现《GPU高性能编程CUDA实战》上面的例子,碰到了生成julia集,很兴奋,赶紧实现。


基于CPU的,用到"cpu_bitmap.h"这个头文件,我电脑上没有,不过直接从网上找了一个,添加到我的工程中就行
"cpu_bitmap.h"中又用到"gl_helper.h"这个头文件,我觉得没啥用,直接注释掉了
不过因为"cpu_bitmap.h"中用到了glut的函数和exit(),需要自己手动添加头文件<gl\glut.h> 
<stdlib.h>
或者直接去网上把"gl_helper.h"找到,添加进工程,此时编译仍出错,添加<stdlib.h>即可

基于GPU除了那些问题之外,遇到了这样的错误:
calling a host function("cuComplex::cuComplex") from a__device__/__global__ function("julia") is not allowed
calling a host function("cuComplex::cuComplex") from a__device__/__global__ function("julia") is not allowed
calling a host function("cuComplex::cuComplex") from a__device__/__global__ function("cuComplex::operator *") is notallowed
calling a host function("cuComplex::cuComplex") from a__device__/__global__ function("cuComplex::operator +") is notallowed
显然应该是同一个问题
google一下,官网有解决方案
在定义结构体cuComplex的时候,cuComplex(float a, float b) : r(a), i(b){}前面要加上__device__
通过
也就是说,初始化结构体也要放在device中才能被kernel函数调用

calling <wbr>a <wbr>host <wbr>function <wbr>from <wbr>a <wbr>__device__/__global__ <wbr>function <wbr>is <wbr>not <wbr>allowed

改变阈值很有意思啊
calling <wbr>a <wbr>host <wbr>function <wbr>from <wbr>a <wbr>__device__/__global__ <wbr>function <wbr>is <wbr>not <wbr>allowed

原文来自:http://blog.sina.com.cn/s/blog_772645ff0100wl0n.html

原创粉丝点击