Good question. The docu says:
The life span of an OpenCL object is determined by its reference count, an internal count of the number of references to the object. When you create an object in OpenCL, its reference count is set to one. Subsequent calls to the appropriate retain API (such as clRetainContext, clRetainCommandQueue) increment the reference count. Calls to the appropriate release API (such as clReleaseContext, clReleaseCommandQueue) decrement the reference count. Implementations may also modify the reference count, e.g. to track attached objects or to ensure correct operation of in-progress or scheduled activities. The object becomes inaccessible to host code when the number of release operations performed matches the number of retain operations plus the allocation of the object. At this point the reference count may be zero but this is not guaranteed.
Does it means that the context is basically always there on the device? So if I release it on the host side then the context will just stop being available on the host side, but still is the same on the device side?
I just tried to release the context and try to write/read from a buffer using the command queue and it works.
def queue = queueFactory.create(context, device)
float values = [0, 1, 2, 3, 4, 5, 6, 7]
def size = Sizeof.cl_float * 8
def pointer = Pointer.to(values)
def buffer = bufferFactory.create(context, CL_MEM_READ_WRITE, size)
context.close() // <-- released the context
buffer.write(queue.get(), 0, size, pointer)
float dest = new float;
assert dest == values