OpenCL allows 2 ways in order to read buffer data, blocking or not blocking. The first way is essentially similar to the method used internally in ocland to exchange data, but the second one, that i called asynchronous buffer reading, is really more complex, but i developed this solution…
- Server and client must exchange all the parameters (command queue, buffer, sizes, …).
- Server must allocate memory and call to clEnqueueReadBuffer, recovering inmediately the control because is a not blocking operation.
- Then the server opens a new socket on a new port, and reports it to the client (the memory transfer done asynchronously can’t interfere with the following client commands).
- Client opens a new connection in the purposed socket.
- Server and client opens a new thread in order to don’t block the execution while data is transfered.
- Server waits until OpenCL reports that memory is available.
- Server sends the data to the client in the new thread using the new connection.
- Server marks the work as done.
In order to the scheme purposed can run, I needed to develope the ocland_event, a layer over the OpenCL cl_event entity. This new layer stores the cl_event associated, and a status flag. Since both cl_event and ocland_event are pointers, the client never will know that transfered event is in reallity an ocland_event, and will use it as a truly cl_event, and when calls to wait over the event, server knows that must wait for the ocland_event, and then for the internally stored cl_event.