Originally posted by: Raistmer With this code I had memory leak that eated all host memory in few minutes: if(gpu_data) clReleaseMemObject(gpu_data); gpu_data = clCreateBuffer(context, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR, fft_len*sizeof(float)*2, data, &err); if(!gpu_data) { fprintf(stderr,"ERROR: clCreateBuffer failed, gpu_data\n"); } and if(gpu_chirps) clReleaseMemObject(gpu_chirps); gpu_chirps= clCreateBuffer( context, CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR, sizeof(fftwf_complex)*state.fft_len*state.dm_chunk_small, chirp, &err); if(err != CL_SUCCESS) { fprintf(stderr,"Error: clCreateBuffer (gpu_chirp)\n"); } And I have no memory leak when allocate them once and use write buffer: err|=clEnqueueWriteBuffer(cq,gpu_data,CL_TRUE,0,fft_len*sizeof(float)*2,data,0,NULL,NULL); clEnqueueWriteBuffer(cq,gpu_chirps,CL_TRUE,0,sizeof(fftwf_complex)*state.fft_len*state.dm_chunk_small, chirp,0,NULL,NULL); The question is: why there was memory leak ? buffers should be deleted before new allocation, right?
Raistmer,
Could you please give test case for memory leaks?
Originally posted by: Raistmer Please, specify what you mean. I gave exact lines of code that were and that I changed to get rid of memory leak. Do you need complete source? Or kernels that were called over these buffers? I can give complete source if needed, no prob it's open source, but it seems it's impractical to post it in forum...
Please send to streamdeveloper@amd.com mail id if it is very big.
Originally posted by: Raistmer Done.
Raistmer,
Please send instructions to run your application sent streamdeveloper mail id. We are waiting for your reply
calling clRelease is not the same as calling free on the host; it merely decrements the reference count to the buffer. When the reference count reaches zero AND all enqueued tasks referencing the buffer complete, then the runtime is free to deallocate the buffer.
However, it looks like you're using blocking writes, which implicitly flushes the queue and runs until the write completes. Is there a kernel running or something that takes a long time while you allocate the buffer for the next round or what have you? If so, put a clFinish after it.