Memory object allocation

If you create a memory object with clCreateBuffer or clCreateImage2D/3D, is the memory immediately allocated on the device? Or is it allocated when you make the memory object a kernel argument and execute the kernel?

If you create a memory object with clCreateBuffer or clCreateImage2D/3D, is the memory immediately allocated on the device? Or is it allocated when you make the memory object a kernel argument and execute the kernel?

That is an excellent question. The OpenCL driver can choose one or the other, and unfortunately there is no way for the application to query which method is used.

If the OpenCL implementation you are using delays the allocations until they are needed, you can find that calling clEnqueueNDRange() or clEnqueueTask() return CL_OUT_OF_RESOURCES if there’s not enough memory in the device to allocate those buffers or images.