calling a __host__ function("XXX") from a __global__ function is not allowed

原因一:

error : calling a __host__ function("fmod ") from a __global__ function

This is happening because of a template argument mismatch. You are calling fmod with a floating point argument and an integer argument. There is only a device template argument for a pair of single precision or double precision floating point arguments .

What you are probably looking for is fmod(float, (float)int)....



原因二:

遇到了这样的错误:

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 not allowed
calling a host function("cuComplex::cuComplex") from a __device__/__global__ function("cuComplex::operator +") is not allowed
显然应该是同一个问题 ,有如下解决方案
在定义结构体cuComplex的时候,cuComplex(float a, float b) : r(a), i(b) {}前面要加上__device__
通过
也就是说,初始化结构体也要放在device中才能被kernel函数调用


原因三:

经过查找后,发现问题出在VS2010默认的设置和本机不符。这个错误之前也处理过,现在把解决办法搬过来就好。

发现问题出在默认的设置里,计算能力是1.0,SM也是1.0,而这与本机的配置是不匹配的,修改方法只需:

      右键解决方案属性-》配置属性-》CUDA C/C++-》Device-》Code Generation,加入compute_20,sm_20,并且把下面的“从父级或项目属性默认设置继承”的勾选去掉,如下图所示。


calling a __host__ function(


PS.这里的compute_20,sm_20是根据你自己机器显卡的计算能力来决定的,比如你的是2.0那就相应改成2.0,3.0,3.5依次类推。


你可能感兴趣的:(GPU/CUDA)