diff options
Diffstat (limited to 'src/com/jogamp/opencl/CLProgram.java')
-rw-r--r-- | src/com/jogamp/opencl/CLProgram.java | 53 |
1 files changed, 32 insertions, 21 deletions
diff --git a/src/com/jogamp/opencl/CLProgram.java b/src/com/jogamp/opencl/CLProgram.java index 53c2e1d9..d373d5d3 100644 --- a/src/com/jogamp/opencl/CLProgram.java +++ b/src/com/jogamp/opencl/CLProgram.java @@ -29,12 +29,13 @@ package com.jogamp.opencl; import com.jogamp.common.nio.CachedBufferFactory; +import com.jogamp.opencl.llb.CLProgramBinding; import com.jogamp.opencl.util.CLProgramConfiguration; import com.jogamp.opencl.util.CLUtil; import com.jogamp.common.os.Platform; import com.jogamp.common.nio.PointerBuffer; -import com.jogamp.common.nio.PointerBuffer; -import com.jogamp.opencl.impl.BuildProgramCallback; +import com.jogamp.opencl.llb.CLKernelBinding; +import com.jogamp.opencl.llb.impl.BuildProgramCallback; import com.jogamp.opencl.util.CLBuildListener; import java.nio.ByteBuffer; import java.nio.IntBuffer; @@ -48,7 +49,7 @@ import java.util.Map; import java.util.concurrent.locks.ReentrantLock; import static com.jogamp.opencl.CLException.*; -import static com.jogamp.opencl.CL.*; +import static com.jogamp.opencl.llb.CL.*; import static com.jogamp.common.nio.Buffers.*; /** @@ -59,9 +60,10 @@ import static com.jogamp.common.nio.Buffers.*; * @see CLContext#createProgram(java.util.Map) * @author Michael Bien */ -public class CLProgram extends CLObject implements CLResource { +public class CLProgram extends CLObjectResource { private final static ReentrantLock buildLock = new ReentrantLock(); + private final CLProgramBinding binding; private final Set<CLKernel> kernels; private Map<CLDevice, Status> buildStatusMap; @@ -72,6 +74,7 @@ public class CLProgram extends CLObject implements CLResource { private CLProgram(CLContext context, long id) { super(context, id); this.kernels = new HashSet<CLKernel>(); + this.binding = context.getPlatform().getProgramBinding(); } static CLProgram create(CLContext context, String src) { @@ -82,7 +85,8 @@ public class CLProgram extends CLObject implements CLResource { String[] srcArray = new String[] {src}; // Create the program - long id = context.cl.clCreateProgramWithSource(context.ID, 1, srcArray, length, status); + CLProgramBinding binding = context.getPlatform().getProgramBinding(); + long id = binding.clCreateProgramWithSource(context.ID, 1, srcArray, length, status); int err = status.get(); if(err != CL_SUCCESS) { @@ -127,7 +131,8 @@ public class CLProgram extends CLObject implements CLResource { IntBuffer errBuffer = bf.newDirectIntBuffer(1); // IntBuffer status = newDirectByteBuffer(binaries.size()*4).asIntBuffer(); - long id = context.cl.clCreateProgramWithBinary(context.ID, devices.capacity(), devices, lengths, codeBuffers, /*status*/null, errBuffer); + CLProgramBinding binding = context.getPlatform().getProgramBinding(); + long id = binding.clCreateProgramWithBinary(context.ID, devices.capacity(), devices, lengths, codeBuffers, /*status*/null, errBuffer); // while(status.remaining() != 0) { // checkForError(status.get(), "unable to load binaries on all devices"); @@ -167,14 +172,14 @@ public class CLProgram extends CLObject implements CLResource { PointerBuffer size = PointerBuffer.allocateDirect(1); - int ret = cl.clGetProgramBuildInfo(ID, device.ID, flag, 0, null, size); + int ret = binding.clGetProgramBuildInfo(ID, device.ID, flag, 0, null, size); if(ret != CL_SUCCESS) { throw newException(ret, "on clGetProgramBuildInfo with "+device); } ByteBuffer buffer = newDirectByteBuffer((int)size.get(0)); - ret = cl.clGetProgramBuildInfo(ID, device.ID, flag, buffer.capacity(), buffer, null); + ret = binding.clGetProgramBuildInfo(ID, device.ID, flag, buffer.capacity(), buffer, null); if(ret != CL_SUCCESS) { throw newException(ret, "on clGetProgramBuildInfo with "+device); } @@ -190,12 +195,12 @@ public class CLProgram extends CLObject implements CLResource { PointerBuffer size = PointerBuffer.allocateDirect(1); - int ret = cl.clGetProgramInfo(ID, flag, 0, null, size); + int ret = binding.clGetProgramInfo(ID, flag, 0, null, size); checkForError(ret, "on clGetProgramInfo"); ByteBuffer buffer = newDirectByteBuffer((int)size.get(0)); - ret = cl.clGetProgramInfo(ID, flag, buffer.capacity(), buffer, null); + ret = binding.clGetProgramInfo(ID, flag, buffer.capacity(), buffer, null); checkForError(ret, "on clGetProgramInfo"); return CLUtil.clString2JavaString(buffer, (int)size.get(0)); @@ -205,12 +210,15 @@ public class CLProgram extends CLObject implements CLResource { ByteBuffer buffer = newDirectByteBuffer(4); - int ret = cl.clGetProgramBuildInfo(ID, device.ID, flag, buffer.capacity(), buffer, null); + int ret = binding.clGetProgramBuildInfo(ID, device.ID, flag, buffer.capacity(), buffer, null); checkForError(ret, "error on clGetProgramBuildInfo"); return buffer.getInt(); } + private CLKernelBinding getKernelBinding() { + return getPlatform().getKernelBinding(); + } /** * Builds this program for all devices associated with the context. @@ -369,7 +377,7 @@ public class CLProgram extends CLObject implements CLResource { buildLock.lock(); boolean exception = true; try{ - ret = cl.clBuildProgram(ID, count, deviceIDs, options, callback); + ret = binding.clBuildProgram(ID, count, deviceIDs, options, callback); exception = false; }finally{ if(callback == null || exception) { @@ -402,7 +410,7 @@ public class CLProgram extends CLObject implements CLResource { } int[] err = new int[1]; - long id = cl.clCreateKernel(ID, kernelName, err, 0); + long id = getKernelBinding().clCreateKernel(ID, kernelName, err, 0); if(err[0] != CL_SUCCESS) { throw newException(err[0], "unable to create Kernel with name: "+kernelName); } @@ -424,7 +432,8 @@ public class CLProgram extends CLObject implements CLResource { HashMap<String, CLKernel> newKernels = new HashMap<String, CLKernel>(); IntBuffer numKernels = newDirectByteBuffer(4).asIntBuffer(); - int ret = cl.clCreateKernelsInProgram(ID, 0, null, numKernels); + CLKernelBinding kernelBinding = getKernelBinding(); + int ret = kernelBinding.clCreateKernelsInProgram(ID, 0, null, numKernels); if(ret != CL_SUCCESS) { throw newException(ret, "can not create kernels for "+this); } @@ -432,7 +441,7 @@ public class CLProgram extends CLObject implements CLResource { if(numKernels.get(0) > 0) { PointerBuffer kernelIDs = PointerBuffer.allocateDirect(numKernels.get(0)); - ret = cl.clCreateKernelsInProgram(ID, kernelIDs.capacity(), kernelIDs, null); + ret = kernelBinding.clCreateKernelsInProgram(ID, kernelIDs.capacity(), kernelIDs, null); if(ret != CL_SUCCESS) { throw newException(ret, "can not create "+kernelIDs.capacity()+" kernels for "+this); } @@ -465,13 +474,14 @@ public class CLProgram extends CLObject implements CLResource { @Override public void release() { + super.release(); releaseKernels(); executable = false; released = true; buildStatusMap = null; - - int ret = cl.clReleaseProgram(ID); + + int ret = binding.clReleaseProgram(ID); context.onProgramReleased(this); if(ret != CL_SUCCESS) { throw newException(ret, "can not release "+this); @@ -495,14 +505,15 @@ public class CLProgram extends CLObject implements CLResource { if(released) { return new CLDevice[0]; } + PointerBuffer size = PointerBuffer.allocateDirect(1); - int ret = cl.clGetProgramInfo(ID, CL_PROGRAM_DEVICES, 0, null, size); + int ret = binding.clGetProgramInfo(ID, CL_PROGRAM_DEVICES, 0, null, size); if(ret != CL_SUCCESS) { throw newException(ret, "on clGetProgramInfo of "+this); } ByteBuffer bb = newDirectByteBuffer((int) size.get(0)); - ret = cl.clGetProgramInfo(ID, CL_PROGRAM_DEVICES, bb.capacity(), bb, null); + ret = binding.clGetProgramInfo(ID, CL_PROGRAM_DEVICES, bb.capacity(), bb, null); if(ret != CL_SUCCESS) { throw newException(ret, "on clGetProgramInfo of "+this); } @@ -606,7 +617,7 @@ public class CLProgram extends CLObject implements CLResource { CLDevice[] devices = getCLDevices(); PointerBuffer sizes = PointerBuffer.allocateDirect(devices.length); - int ret = cl.clGetProgramInfo(ID, CL_PROGRAM_BINARY_SIZES, sizes.capacity()*sizes.elementSize(), sizes.getBuffer(), null); + int ret = binding.clGetProgramInfo(ID, CL_PROGRAM_BINARY_SIZES, sizes.capacity()*sizes.elementSize(), sizes.getBuffer(), null); if(ret != CL_SUCCESS) { throw newException(ret, "on clGetProgramInfo(CL_PROGRAM_BINARY_SIZES) of "+this); } @@ -628,7 +639,7 @@ public class CLProgram extends CLObject implements CLResource { } addresses.rewind(); - ret = cl.clGetProgramInfo(ID, CL_PROGRAM_BINARIES, addresses.capacity()*addresses.elementSize(), addresses.getBuffer(), null); + ret = binding.clGetProgramInfo(ID, CL_PROGRAM_BINARIES, addresses.capacity()*addresses.elementSize(), addresses.getBuffer(), null); if(ret != CL_SUCCESS) { throw newException(ret, "on clGetProgramInfo(CL_PROGRAM_BINARIES) of "+this); } |