Problem with clEnqueueNDRangeKernel, memory leak

I use java binding for work with openCl, driver ATI version 11-2_xp32_dd_ccc_ocl. I detect that memory leak occur every time when method clEnqueueNDRangeKernel launch. The memory leak is small, about 300 bytes per call. But if application call kernel permanently that occure to significant memory leak. Personally, my memory is lost at a rate of 10 MB per second. Also error CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST occure after 700000 call of method clEnqueueNDRangeKernel. ?alculations performed correctly in the program, but the crash occurred about twenty minutes to work. For detection of thid problem i create simple test

    FileUtils.setJavaLibraryPath("geo.controller.logic.ocl.dlls");      

    // Obtain the platform IDs and initialize the context properties
    System.out.println("Obtaining platform...");
    cl_platform_id platforms[] = new cl_platform_id[1];
    clGetPlatformIDs(platforms.length, platforms, null);
    cl_context_properties contextProperties = new cl_context_properties();
    contextProperties.addProperty(CL_CONTEXT_PLATFORM, platforms[0]);
    
    // Create an OpenCL context on a GPU device
    cl_context context = clCreateContextFromType(
        contextProperties, CL_DEVICE_TYPE_GPU, null, null, null);

    // Enable exceptions and subsequently omit error checks in this sample
    CL.setExceptionsEnabled(true);
    
    cl_program fake_programm = clCreateProgramWithSource(context, 1, new String[]{KERNEL_SRC}, null, null);
    clBuildProgram(fake_programm, 0, null, null, null, null);
    
    cl_kernel fakeKernel = clCreateKernel(fake_programm, "fakeKernel", null);
    
    long numBytes[] = new long[1];
    // Enable exceptions and subsequently omit error checks in this sample
    CL.setExceptionsEnabled(true);
    
    // Get the list of GPU devices associated with the context
    clGetContextInfo(context, CL_CONTEXT_DEVICES, 0, null, numBytes); 
    
    // Obtain the cl_device_id for the first device
    int numDevices = (int) numBytes[0] / Sizeof.cl_device_id;
    cl_device_id devices[] = new cl_device_id[numDevices];
    clGetContextInfo(context, CL_CONTEXT_DEVICES, numBytes[0], Pointer.to(devices), null);
    
    cl_command_queue oclComands = clCreateCommandQueue(context, devices[0], 0, null);
    
    for(int i = 0; i < 1000000; i ++){
      if(i%1000 == 0)
        System.out.println("iterations = " + i);
      clEnqueueNDRangeKernel(oclComands, fakeKernel, 1, null, new long[]{0}, null, 0, null, null);
      clFinish(oclComands);
    }
  }```
Kernel text:```
__kernel void fakeKernel(){
}

Crash occure on 700000 iterations when i use java binding JOCL-0.1.4-beta, bat with C++ binding this test work fine.

Hello,

Indeed, this one was my fault…-_- There had been reports about memory leaks recently (e.g. in this thread) but they seemed to be mainly related to creating/releasing cl_mem-Objects with the NVIDIA implementation. Now I checked this again, and finally found a wrong application of cl_events in the clEnqueue* Operations which caused events to be created with every call.

I have uploaded a new version, which currently contains only the Windows 32 binaries - you might want to test it. I’ll try to add the other binaries and create a Maven release as soon as possible.

The memory leak for cl_mem’s on NVIDIA platforms still exists, but this is far less critical than the one for the clEnqueue* operations that should be fixed now.

Thanks for pointing this out!
Marco

Thanks, Problem solved