Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Question about cl_mem in OpenCL

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.

like image 244
smuggledPancakes Avatar asked Oct 11 '10 14:10

smuggledPancakes


People also ask

What is Cl_mem?

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) Follow this answer to receive notifications.

What is OpenCL buffer?

OpenCL global buffers are the conduit through which data is communicated from the host application to OpenCL C kernels running on the C66x DSP.


2 Answers

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

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

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:

cl_int  clReleaseMemObject (cl_mem memobj)  

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.

like image 103
grrussel Avatar answered Sep 21 '22 19:09

grrussel


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)

like image 26
Quonux Avatar answered Sep 22 '22 19:09

Quonux