关于OpenCL中cl_mem的问题
我一直在我的一些 OpenCL 样板代码中使用 cl_mem,但我一直在上下文中使用它,并没有清楚地理解它到底是什么。我一直使用它作为我在板上推入和推出的内存的类型,到目前为止,它一直是浮动的。我尝试查看 OpenCL 文档,但 cl_mem 没有显示(是吗?)。有没有相关的文档,或者是否简单,有人可以解释一下。
I have been using cl_mem in some of my OpenCL boilerplate code, but I have been using it through context and not a sharp understanding of what exactly it is. I have been using it as a type for the memory I push on and off the board, which has so far been floats. I tried looking at the OpenCL docs, but cl_mem doesn't show up (does it?). Is there any documentation on it, or is it simple and can someone explain.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
cl_mem 类型是“内存对象”的句柄(如 OpenCL 1.1 规范)。这些本质上是 OpenCL 内核的输入和输出,并从主机代码中的 OpenCL API 调用返回,例如 clCreateBuffer
所表示的内存区域可以允许不同的访问模式,例如只读,或者分配在不同的内存区域,具体取决于设置的标志在创建缓冲区调用中。
句柄通常被存储以允许稍后调用释放内存,例如:
简而言之,它提供了对内存实际位置的抽象:您可以将数据复制到关联的内存中或通过 OpenCL API clEnqueueWriteBuffer 和 clEnqueueReadBuffer 退出,但 OpenCL 实现可以在需要的地方分配空间。
The cl_mem type is a handle to a "Memory Object" (as described in Section 3.5 of the OpenCL 1.1 Spec). These essentially are inputs and outputs for OpenCL kernels, and are returned from OpenCL API calls in host code such as clCreateBuffer
The memory areas represented can be permitted different access patterns e.g. Read Only, or be allocated in different memory regions, depending on the flags set in the create buffer calls.
The handle is typically stored to allow a later call to release the memory, e.g:
In short, it provides an abstraction over where the memory actually is: you can copy data into the associated memory or back out via the OpenCL APIs clEnqueueWriteBuffer and clEnqueueReadBuffer, but the OpenCL implementation can allocate the space where it wants.
对于计算机来说,cl_mem 是一个数字(类似于 Linux 的文件处理程序),保留用作“内存标识符”(API/驱动程序将有关内存的信息存储在这个数字下,它知道它保存的内容/如何存储)它很大,诸如此类的东西)
For the computer a cl_mem is a number (like a file handler for Linux) that is reserved for the use as a "memory identifier"( the API/driver whatever stores information about your memory under this number that it knows what it holds/how big it is and stuff like that)