6 Replies Latest reply on Jul 27, 2010 12:48 PM by psath

    How to release Physical Memory?

      Excute kernel in a loop Physical Memory usage getting more and more.

      After clSetKernelArg() method, I need to excute the same kernel in a loop,but Physical Memory usage getting more and more, I think it is memory leak, can anyone tell me how to resolve. Thanks !

      for(int i=0;i<10000000;i++) { cl_int errs = clEnqueueNDRangeKernel(queue, kernel, 1, 0, &work_size, 0, 0, 0, 0); }

        • How to release Physical Memory?

          You're queueing up 10 million items in the queue to be performed.  If each item enqueued has to identify the command type, the kernel used, the kernel arguments at the time the kernel is enqueued, the work dimensions, global_work_offset, global_work_size, local work size, all the events in wait list + pointer to event returned, then this is going to take up space.

          At a guess, each item enqueued will take at least (sizeof(kernel_id) + size_of(kernel_args)+ sizeof(work_dim) + 3*work_dim*sizeof(size_t) + sizeof(num_events) + num_events*sizeof(event_id) + sizeof(event_id)) bytes.

          This is likely to be >25 bytes per item enqueued for 1D kernels (but could be less if default values passed in aren't stored fully), and much more for 3D kernels that also have events to be waited on + lots of arguments.  If none of the items enqueued get performed before you end the loop, you will likely be using >250MB of memory, perhaps a lot more.

          What kind of algorithm are you using that applies the same kernel 10 million times?  Workarounds could be to enqueue less items, eg. by waiting for commands to finish before queueing up more commands.  Or perhaps the loop inside the kernel?

          • How to release Physical Memory?

            Try adding a clFlush() after a certain number of kernels have been enqueued.