CUDA - 维护指向全局内存的指针

发布于 2024-09-11 11:22:45 字数 292 浏览 5 评论 0原文

我有一个使用 CUDA 的 .NET 程序。

CUDA 通过 C DLL 访问。

我正在做的是通过在程序启动时在设备上分配缓冲区(cudaMalloc)来初始化我的 CUDA 应用程序。然后,指向这些缓冲区的指针将保存在 DLL 中声明的静态变量中。在整个程序中,数据被复制到缓冲区或从缓冲区复制。程序终止后,先前分配的缓冲区将被释放。

是否可以维护指向分配的设备内存的指针,或者我应该在每次执行内核时重新分配(这似乎非常低效)?

目前我还没有注意到任何副作用,只是想确认这种使用模式是首选且可以接受的。

I have a .NET program that is utilizing CUDA.

The CUDA is accessed through a C DLL.

What I am doing is initializing my CUDA application by allocating buffers (cudaMalloc) on the device at program startup. Pointers to these buffers are then maintained in static variables declared in the DLL. Data is copied to and from the buffers throughout the program. Upon program termination the previously allocated buffers are freed.

Is it ok to maintain pointers to the allocated device memory or should I be reallocating every time I execute the kernel (which would seem to be very inefficient)?

I haven't noticed any side effects at present, but just wanted to confirm that this usage pattern is preferred and acceptable.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

Saygoodbye 2024-09-18 11:22:45

据我所知,使用设备内存的唯一强烈建议是减少复制操作。 cudaMalloc 的工作速度比 cudaMemcpy 快得多。
因此,重用缓冲区并不是什么大问题。如果您正确使用设备内存,它将正常工作

As far as I know the only strong recomendation for using device memory - reduce copy operations. cudaMalloc works much faster than cudaMemcpy.
So, it's not a big deal to reuse buffers. It will work right, if you're using device mem correctly

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文