如何在 CUDA 中释放 __device__ 内存
__device__ int data;
__constant__ int var1;
如何释放CUDA中的“data”和“var1”?
谢谢
__device__ int data;
__constant__ int var1;
How to free the "data" and "var1" in the CUDA?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
凭借 sm_20 及以上的设备计算能力,您可以简单地使用 new 或 delete 关键字,
更好的是使用 CUDA Thrust API(它是 GPU 上标准模板库的实现),这真的很酷。
http://code.google.com/p/thrust/
With Device compute capability of sm_20 and above you can simply use new or delete keyword,
even better would be to use CUDA thrust API ( it an implementation of standard template library on top of GPU) really cool stuff .
http://code.google.com/p/thrust/
你无法释放它。当程序结束时它会自动释放。
类似地,就像在主机代码中一样,您不会释放全局变量。
You can't free it. It gets automatically freed when the program ends.
Similarly, as in host code you don't free global variables.
正如@CygnusX1 所说,你无法释放它。正如您所声明的,内存将在程序的生命周期内分配——注意:即使您从未调用内核。
但是,您可以使用 cudaMalloc 和 cudaFree(或 CUDA 4.0 中的 new/delete)来临时分配和释放内存。当然,您必须使用指针来操作所有内容,但是如果您需要存储多个大对象,释放它们,然后存储多个大对象,那么这是一个巨大的节省......
As @ CygnusX1 said, you can't free it. As you have declared it, the memory will be allocated for the life of your program -- NOTE: Even if you never call the kernel.
You can however use cudaMalloc, and cudaFree (or new/delete within in CUDA 4.0) to allocate and free memory temporarily. Of course you must manipulate everything with pointers, but this is a huge savings if you need to store several large objects, free them, and then store several more large objects...