Question about cl_mem in OpenCL

I use cl_mem in some of my OpenCL templates, but I used it through the context, and not for a clear understanding of what exactly is happening. I use it as the type of memory that I click on and close the board that still floats. I tried to look at OpenCL docs, but cl_mem does not appear (right?). Is there any documentation on it, or is it simple and can someone explain.

+4
source share
2 answers

For a computer, cl_mem is a number (for example, a file handler for Linux) that is reserved for use as a "memory identifier" (the API / driver all stores information about your memory under this number, that it knows what it holds / how big it is etc)

+6
source

The cl_mem type is a handle to the "Memory Object" (as described in Section 3.5 of the OpenCL 1.1 Spec ). These are essentially inputs and outputs for OpenCL cores and are returned from OpenCL API calls to host code such as clCreateBuffer

cl_mem clCreateBuffer (cl_context context, cl_mem_flags flags, size_t size, void *host_ptr, cl_int *errcode_ret) 

In the presented memory areas, various access patterns may be allowed, for example. Only reading or allocating in different memory areas depending on the flags set in the buffer creation calls.

Typically, the handle is stored to allow a later call to free memory, for example:

 cl_int clReleaseMemObject (cl_mem memobj) 

In short, it provides an abstraction over where the memory actually resides: you can copy data to the appropriate memory or return via the OpenCL API clEnqueueWriteBuffer and clEnqueueReadBuffer, but the OpenCL implementation can allocate the space in which it wants.

+10
source

All Articles