为什么我的CUDA数学库sqrt()函数调用失败? [英] Why is my call of the CUDA math library sqrt() function failing?
问题描述
我是Cuda的新人,我有以下功能:
__ global__ void square(float * myArrayGPU)
{
myArrayGPU [threadIdx.x] = sqrt(threadIdx.x);
}
我想使用cuda数学库,我试图 #includemath.h
但我仍然得到错误
错误:调用__host__函数不允许使用__global__函数(square)中的__sqrt)
c $ c> sqrt ?
threadIdx.x
是int类型。 CUDA数学库仅对单精度( float
)和双精度( double
)重载。对于 sqrt()的CUDA版本,您需要为
sqrt()
提供'float'或'double'类型参数$ c
myArrayGPU [threadIdx .x] = sqrt(threadIdx.x);
到
myArrayGPU [threadIdx.x] = sqrt((float)threadIdx.x);
有关详细信息,请参阅 CUDA sqrt()原型文档。
I am new to Cuda, I have the following function:
__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
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
?
threadIdx.x
is of type int. CUDA math library is overloaded only for single precision (float
) and double precision (double
). You need to supply either a 'float' or 'double' type parameter to sqrt()
for the CUDA version of sqrt()
to be called.
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()函数调用失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!