使用 pycuda (lerp) 进行线性插值
我是一个刚刚接触 pyCUDA 的休闲 Python 爱好者。我试图弄清楚如何使用 pyCUDA 实现线性插值(lerp)。 CUDA CG函数为: http://http.developer.nvidia.com/Cg/lerp .html
我的最终目标是在 pycuda 中根据一组加权随机点进行双线性插值。我从来没有编写过 C 语言或 CUDA 程序,并且正在边学习边学习。
这就是我已经取得的进展:
import pycuda.autoinit
import pycuda.driver as drv
import pycuda.compiler as comp
lerpFunction = """__global__ float lerp(float a, float b, float w)
{
return a + w*(b-a);
}"""
mod = comp.SourceModule(lerpFunction) # This returns an error telling me a global must return a void. :(
对此的任何帮助都非常棒!
I am a recreational pythonista who just got into pyCUDA. I am trying to figure out how to implement a linear interpolation (lerp) using pyCUDA. The CUDA CG function is: http://http.developer.nvidia.com/Cg/lerp.html
My ultimate goal is a bilinear interpolation in pycuda from a set of weighted random points. I've never programmed C, or CUDA for that matter, and am learning as I go.
This is how far I've gotten:
import pycuda.autoinit
import pycuda.driver as drv
import pycuda.compiler as comp
lerpFunction = """__global__ float lerp(float a, float b, float w)
{
return a + w*(b-a);
}"""
mod = comp.SourceModule(lerpFunction) # This returns an error telling me a global must return a void. :(
Any help on this would be fantastic!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
错误消息非常明确 - CUDA 内核无法返回值,它们必须声明为 void,并且可修改的参数作为指针传递。将 lerp 实现声明为这样的设备函数会更有意义:
然后从内核内部调用每个需要插值的值。您的 lerp 函数缺乏很多“基础设施”来成为有用的 CUDA 内核。
编辑:一个真正基本的内核沿着同样的路线可能看起来像这样:
The error message is pretty explicit - CUDA kernels cannot return values, they must be declared
void
, and modifiable arguments passed as pointers. It would make more sense for your lerp implementation to be declared as a device function like this:and then called from inside a kernel for each value that requires interpolation. Your lerp function lacks a lot of "infrastructure" to be a useful CUDA kernel.
EDIT: A really basic kernel along the same lines might look something like this: