[英]Why is my call of the CUDA math library sqrt() function failing?
I am new to Cuda, I have the following function: 我是Cuda的新手,我有以下功能:
__global__ void square(float *myArrayGPU)
{
myArrayGPU[threadIdx.x] = sqrt(threadIdx.x);
}
I want to use the cuda math library, I tried to #include "math.h"
but I still get the error 我想使用cuda数学库,我试着
#include "math.h"
但我仍然得到错误
error: calling a __host__ function("__sqrt") from a __global__ function("square") is not allowed
Any idea what library should I include to use the sqrt
? 知道我应该包含什么库才能使用
sqrt
?
threadIdx.x
is of type int. threadIdx.x
的类型为int。 CUDA math library is overloaded only for single precision ( float
) and double precision ( double
). CUDA数学库仅针对单精度(
float
)和双精度( double
精度)进行重载。 You need to supply either a 'float' or 'double' type parameter to sqrt()
for the CUDA version of sqrt()
to be called. 您需要提供无论是“浮动”或“双”类型参数
sqrt()
为的CUDA版本sqrt()
被调用。
Change 更改
myArrayGPU[threadIdx.x] = sqrt(threadIdx.x);
into 成
myArrayGPU[threadIdx.x] = sqrt( (float) threadIdx.x);
For more detailed information, take a look at the CUDA sqrt() prototype documentation . 有关更多详细信息,请查看CUDA sqrt()原型文档 。
sqrt
expects a floating type variable. sqrt
期望浮点型变量。 Try sqrt((float)(threadIdx.x))
尝试
sqrt((float)(threadIdx.x))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.