I have some code like this:
Code :buffer = clCreateBuffer( ... ); ... float* temp = new float[ size ]; ... clEnqueueWriteBuffer( ..., temp, ... ); clEnqueueBarrier( cq ); kernel = clCreateKernel( prog, "mykernel", ... ); clSetKernelArg( kernel, ..., &buffer ); clEnqueueNDRangeKernel( kernel, .... ); delete temp; <--------- safe?
My question is: Without using events and clWaitForEvents(), where can I do delete my cpu buffer being sure that the cpu->gpu copy (clEnqueuWriteBuffer) has finished?
In my code I delete the cpu buffer after the execution of a kernel that must wait for the previous enqueued command (that copies "buffer" from cpu to gpu). Both clEnqueueWriteBuffer and clEnqueueNDRangeKernel are asynchronous, so my doubt is żdoes clEnqueueNDRangeKernel stall until clEnqueueWriteBuffer has finished?