为什么我的CUDA数学库sqrt()函数调用失败? [英] Why is my call of the CUDA math library sqrt() function failing?

查看:2665
本文介绍了为什么我的CUDA数学库sqrt()函数调用失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是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'类型参数

  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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆