CUDA.Net 的 Hello-world
我正在尝试使用 CUDA.Net 编写一个幼稚的应用程序,但我运气不好。
我发现:
using GASS.CUDA;
// ...
var c = new CUDA();
// c.Launch(myfunc); // ???? how ???
myfunc
显然应该是 GASS.CUDA.Types.CUfunction
类型,但我没有找到如何定义它。
I'm trying to write a childish app with CUDA.Net, but I'm out of luck.
I've figured out to:
using GASS.CUDA;
// ...
var c = new CUDA();
// c.Launch(myfunc); // ???? how ???
myfunc
apparently should be of type GASS.CUDA.Types.CUfunction
but I didn't find how to define one.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,您需要一个带有内核的 .cu 文件(要在 GPU 上执行的函数)。让我们有一个文件 mykernel.cu:
必须使用 nvcc 编译器将其编译为 .cubin 文件。为了让编译器知道 Visual C++ 编译器,您需要从 Visual Studio 命令提示符中调用它:
这会在同一目录中创建 mykernel.cubin 文件。
然后,您可以在 C# 代码中加载此二进制模块并执行内核。在 GASS.CUDA 的高级对象 API 中,它看起来像这样:
就是这样!
nvcc 编译器应该作为构建操作来调用,而不是手动调用。如果有人知道如何实现这一点,请告诉我们。
First you need a .cu file with your kernel (function to be executed on a GPU). Let's have a file mykernel.cu:
This have to be compiled into a .cubin file with the nvcc compiler. In order to let the compiler know of the Visual C++ compiler, you need to call it from within the Visual Studio Command Prompt:
This creates the mykernel.cubin file in the same directory.
Then in a C# code you can load this binary module and execute the kernel. In the higher-level object API of GASS.CUDA it can look like this:
That's it!
The nvcc compiler should be called as a build action better than calling it by hand. If anyone knows how to accomplish that, please let us know.
不幸的是,CUDA.net 的文档记录非常糟糕,但是 http ://www.hoopoe-cloud.com/files/cuda.net/2.0/CUDA.NET_2.0.pdf 应该可以帮助您入门。此外,您仍然需要在 CUDA C 中编写内核,因此 http://developer.download.nvidia.com/compute/cuda/3_2_prod/toolkit/docs/CUDA_C_Programming_Guide.pdf 也是一个值得一看的好主意,也许可以尝试从头开始CUDA C 应用程序在移植到 CUDA.net 之前。
Unfortunately CUDA.net is very badly documented, but http://www.hoopoe-cloud.com/files/cuda.net/2.0/CUDA.NET_2.0.pdf should help you get started. Furthermore you still need to write your kernel in CUDA C, so http://developer.download.nvidia.com/compute/cuda/3_2_prod/toolkit/docs/CUDA_C_Programming_Guide.pdf will be a good idea to have a look at as well, and perhaps try to start with a start CUDA C application before porting it to CUDA.net.