Results 1 to 6 of 6

Thread: correctly deleting buffers

  1. #1
    Junior Member
    Join Date
    Feb 2010
    Posts
    10

    correctly deleting buffers

    Hi all.
    i have a problem with this code:
    Code :
    //m_buffer is defined elsewhere
    cl::Buffer result_zb = cl::Buffer(context, CL_MEM_WRITE_ONLY, res_zb->Id(), &ciErrNum);
     
    cl::Kernel kernel = OCLUtils::GetInstance()->getCutKernel();
    kernel.setArg(0, m_buffer);
    kernel.setArg(1, result_zb);
     
    cl::vector<cl::Memory> buffers;
    buffers.push_back(m_buffer);
    buffers.push_back(result_zb);
    queue.enqueueAcquireGLObjects(&buffers, NULL, NULL);
     
    //workgroup sizes are defined elsewhere
    cl_int ciErrNum = clEnqueueNDRangeKernel(m_queue(), kernel(), 1, NULL, global_workgroup_size, local_workgroup_size, 0, NULL, NULL);
     
    queue.enqueueReleaseGLObjects(&buffers, NULL, NULL);
     
    clFlush(queue());

    when i execute this code for benchmark purposes, i need to execute it for many times sequentially to get significant running times.
    the problem is that, after a few repetitions that works correctly, i get a CL_OUT_OF_HOST_MEMORY error
    while executing cl::Buffer result_zb = cl::Buffer(context, CL_MEM_WRITE_ONLY, res_zb->Id(), &ciErrNum);

    i think this is because memory coming from result_zb is not freed coorectly, so i have a memory leak and my card's RAM
    fills up.

    how can i correctly free the memory? any hints?

  2. #2
    Junior Member
    Join Date
    Apr 2010
    Posts
    26

    Re: correctly deleting buffers

    Maybe try following this up with clFinish?

    http://www.khronos.org/registry/cl/sdk/ ... Flush.html indicates there is no completion guarantee on clFlush.

  3. #3
    Junior Member
    Join Date
    Apr 2010
    Posts
    26

    Re: correctly deleting buffers

    Quote Originally Posted by AlexAtOSU
    Maybe try following this up with clFinish?

    http://www.khronos.org/registry/cl/sdk/ ... Flush.html indicates there is no completion guarantee on clFlush.
    In addition, is this your real code or you are you also capturing error codes when you call clFlush? Make sure it CL_SUCCESS (e.g. == 0).

  4. #4
    Junior Member
    Join Date
    Feb 2010
    Posts
    10

    Re: correctly deleting buffers

    hi and thanks for the answer.
    unfortunately that hasn't worked.
    do you know where there could be a memory leak or how i can find out where it is?

  5. #5
    Junior Member
    Join Date
    Feb 2010
    Posts
    10

    Re: correctly deleting buffers

    now i checked for the result of clFinish and it's CL_SUCCESS :/

  6. #6
    Junior Member
    Join Date
    Apr 2010
    Posts
    26

    Re: correctly deleting buffers

    I looked in a function I made to clear my memory buffers / images. I have never actually checked to see if the video card memory is freed, but maybe you can test it for me .

    Code :
    bool XXXXXXXXX::releaseMemObject(cl_mem &obj)
    {
      cl_int   err = NULL;
      bool     returnStatus = true;    // true if successful
     
      if (obj != NULL)  // This means it has been initialized
      {
        err = clReleaseMemObject(obj);
        if (err != CL_SUCCESS)
        {
          cout << "Error releasing variable\n";
          returnStatus |= false;
        }
        else
          obj = NULL; /* memory was released, re-initialize pointer to NULL */
      }
     
      return returnStatus;
    }

Similar Threads

  1. Deleting buffer in c++ binding
    By howaidi in forum OpenCL
    Replies: 0
    Last Post: 12-04-2011, 04:07 PM
  2. Draw an area correctly...
    By Eymerich in forum OpenGL ES general technical discussions
    Replies: 1
    Last Post: 02-22-2008, 09:32 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
  •