Results 1 to 2 of 2

Thread: safe deleting cpu data

  1. #1
    Junior Member
    Join Date
    May 2012

    safe deleting cpu data

    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?

  2. #2
    Senior Member
    Join Date
    Aug 2011

    Re: safe deleting cpu data

    You have to use events, or some other mechanism which synchronises the calls (e.g. job completion).

    All the 'enqueue' commands - not surprisingly - only enqueue requests, they do not wait for anything. The only guarantee is that the copy will be finished before the kernel is executed: but neither has any synchronisation relation to the host code (enqueue calls).

    I tend to allocate all buffers necessary for a task and keep them around until i'm well and truly done. Or use events to arbitrate.

    You could use event callbacks or a cleanup thread (which synchronisly waits on the events) if you want explicit control.

Similar Threads

  1. Deleting buffer in c++ binding
    By howaidi in forum OpenCL
    Replies: 0
    Last Post: 12-04-2011, 03:07 PM
  2. correctly deleting buffers
    By whites11 in forum OpenCL
    Replies: 5
    Last Post: 07-02-2010, 08:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean