OpenCL我需要释放主机指针(OpenCL do I need to free host pointer)

编程入门 行业动态 更新时间:2024-10-27 03:31:03
OpenCL我需要释放主机指针(OpenCL do I need to free host pointer)

如果我使用选项CL_MEM_USE_HOST_PTR创建一个OpenCL缓冲区,然后在使用它之后在缓冲区上调用clReleaseMemObject,我仍然需要在动态分配的内存上调用free。 此外,如果内核写入缓冲区,它会在调用clReleaseMemObject后与主机指针同步,以便我可以读取结果吗?

If I create an OpenCL buffer with the option CL_MEM_USE_HOST_PTR and then call clReleaseMemObject on the buffer after using it do I still need to call free on the memory I dynamically allocated. Also if a kernel write to the buffer will it sync with the host pointer after I call clReleaseMemObject so I can read the result?

最满意答案

你必须释放记忆本身。

想想看 - OpenCL如何知道为您释放内存的正确方法? 也许它来自malloc ,或者它来自alloca ,或者它来自VirtualAlloc (在Windows上)或sbrk (在Linux上),或者它可能是一个全局变量,或者它可能是一个内存映射文件,或者它可能是字符串字面量。 也许你可以想到更多。

OpenCL不知道哪些是真的,即使它确实如此,它甚至不知道你想要释放内存。 (取消映射该文件只是因为你已经完成了对它的使用OpenCL?也许你想在相同的数据上运行一些非OpenCL代码!)

You must free the memory itself.

Think about it - how would OpenCL know the right way to free the memory for you? Maybe it came from malloc, or maybe it came from alloca, or maybe it came from VirtualAlloc (on Windows) or sbrk (on Linux), or maybe it's a global variable, or maybe it's a memory-mapped file, or maybe it's a string literal. Perhaps you can think of even more.

OpenCL doesn't know which of those are true, and even if it did, it doesn't even know that you want the memory freed. (Unmap that file just because you've finished using OpenCL on it? Maybe you want to run some non-OpenCL code on the same data!)

更多推荐

本文发布于:2023-08-07 21:57:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1466035.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:指针   主机   OpenCL   pointer   host

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!