Login  Register

OpenCL Memory Error

Posted by Edgar Esparza on Aug 03, 2012; 6:11pm
URL: https://forum.jogamp.org/OpenCL-Memory-Error-tp4025750.html

Im running this small test and I keep getting a memory error that I have no idea why its happening.

Test:
public class BesselColtTest {
       
        private static int NUMEL = 5000;
       
        public static void main (String [] args) {
                OpenCLUtil.initializeOpenCL();
               
                for (int i = 1; i <= 50; i++) {
                        NUMEL = i * 5000;
                       
                        double [] vals = new double [NUMEL];
                        for (int j = 0; j < NUMEL; j++) {
                                vals[j] = j * ((double)1 / NUMEL) * 65535;
                        }
                        runCLCode(vals);
                       
                        if (vals != null) { System.out.println(" OK "); }
                }
        }
       
        public static void runCLCode(double [] vals) {

                DoubleBuffer fBuffer = Buffers.newDirectDoubleBuffer(vals);
               
                long start = System.nanoTime();
                fBuffer = OpenCLUtil.besselj1_d(fBuffer);
                System.out.print("Elapsed time: " + (double)(System.nanoTime() - start) / 1000000000 + " sec");
               
                double [] gVals = new double[vals.length];
               
                fBuffer.get(gVals);
        }
}

Error from log:
j  com.jogamp.opencl.llb.impl.CLAbstractImpl.clReleaseMemObject(J)I+28

Buffer Source where error occurs:
public static DoubleBuffer besselj1_d(DoubleBuffer pBuffer) {
               
                //Create a new buffer that OpenCL can use with the input buffer
                CLBuffer<DoubleBuffer> buffer = maxFLOPSContextD.createBuffer(pBuffer, CLMemory.Mem.READ_WRITE);
               
                CLKernel BESSJ1_kernel = getKernel("besselj1_d");
               
                //See how many threads can be used to do the calculation
                int localWorkSize = maxFLOPSQueueD.getDevice().getMaxWorkGroupSize();
                int modulus = pBuffer.capacity() % localWorkSize;
                int globalWorkSize = (modulus == 0) ? pBuffer.capacity() : localWorkSize + pBuffer.capacity() - modulus;
               
                //Send input arguments to kernel
                BESSJ1_kernel.setArg(0, buffer);
               
                //Send the buffer to OpenCL and do all calculations
                maxFLOPSQueueD.putWriteBuffer(buffer, false)
                        .put1DRangeKernel(BESSJ1_kernel, 0, globalWorkSize, localWorkSize)
                        .putBarrier()
                        .putReadBuffer(buffer, true)
                        .putBarrier();
               
                //Make sure all the calculations were finished and reset the kernel
                maxFLOPSQueueD.finish();
                maxFLOPSQueueD.flush();
                BESSJ1_kernel.rewind();
               
                //Retrieve the new buffer and free up its memory
                pBuffer = buffer.getBuffer();
               
                if (!buffer.isReleased()) { buffer.release(); }  //here for some reason the memory is not freed
               
                return pBuffer;
        }

i know its super specific but i would appreciate any help.