some_func() -- assume that we are running on same context, valid kernel etc.
{
allocate memory for a
clEnqueueWriteBuffer(a)
clEnqueueNDRangeKernel(using data in a)
deallocate memory for a
}
would the above code always work if clEnqueueWriteBuffer(a) is a non-blocking write ?
not-necessarily due to the following
From http://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/clEnqueueWriteBuffer.html
Indicates if the write operations are
blocking or nonblocking.
If
blocking_write is CL_TRUE, the OpenCL implementation copies the data referred to by ptr and enqueues the write operation in the command-queue. The memory pointed to by ptr can be reused by the application after the clEnqueueWriteBuffer call returns.
If
blocking_write is CL_FALSE, the OpenCL implementation will use ptr to perform a nonblocking write. As the write is non-blocking the implementation can return immediately. The memory pointed to by ptr cannot be reused by the application after the call returns. The eventargument returns an event object which can be used to query the execution status of the write command. When the write command has completed, the memory pointed to by ptr can then be reused by the application."Reads are also affected by blocking, so use blocking carefully. Especially be careful for that extra computation line in your function which may induce enough time for the non-blocking read to complete sometimes and not other times.
Ref:
http://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/clEnqueueReadBuffer.html
http://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/clEnqueueWriteBuffer.html
No comments:
Post a Comment