Java Code Examples for org.lwjgl.PointerBuffer#allocateDirect()
The following examples show how to use
org.lwjgl.PointerBuffer#allocateDirect() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LwjglProgram.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void build(String args, Device... devices) throws KernelCompilationException { PointerBuffer deviceList = null; if (devices != null) { deviceList = PointerBuffer.allocateDirect(devices.length); deviceList.rewind(); for (Device d : devices) { deviceList.put(((LwjglDevice) d).device.getPointer()); } deviceList.flip(); } int ret = CL10.clBuildProgram(program, deviceList, args, null); if (ret != CL10.CL_SUCCESS) { String log = Log(); LOG.log(Level.WARNING, "Unable to compile program:\n{0}", log); if (ret == CL10.CL_BUILD_PROGRAM_FAILURE) { throw new KernelCompilationException("Failed to build program", ret, log); } else { Utils.checkError(ret, "clBuildProgram"); } } else { LOG.log(Level.INFO, "Program compiled:\n{0}", Log()); } }
Example 2
Source File: LwjglProgram.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void build(String args, Device... devices) throws KernelCompilationException { PointerBuffer deviceList = null; if (devices != null) { deviceList = PointerBuffer.allocateDirect(devices.length); deviceList.rewind(); for (Device d : devices) { deviceList.put(((LwjglDevice) d).getDevice()); } deviceList.flip(); } int ret = CL10.clBuildProgram(program, deviceList, args, null, 0); if (ret != CL10.CL_SUCCESS) { String log = Log(); LOG.log(Level.WARNING, "Unable to compile program:\n{0}", log); if (ret == CL10.CL_BUILD_PROGRAM_FAILURE) { throw new KernelCompilationException("Failed to build program", ret, log); } else { Utils.checkError(ret, "clBuildProgram"); } } else { LOG.log(Level.INFO, "Program compiled:\n{0}", Log()); } }
Example 3
Source File: LwjglDevice.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public long[] getMaximumWorkItemSizes() { int dim = (int) getMaximumWorkItemDimensions(); PointerBuffer sizes = PointerBuffer.allocateDirect(dim); Info.clGetDeviceInfoPointers(device, CL10.CL_DEVICE_MAX_WORK_ITEM_SIZES, sizes); long[] sx = new long[dim]; sizes.get(sx); return sx; }
Example 4
Source File: LwjglProgram.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public Kernel[] createAllKernels() { Utils.tempBuffers[0].b16i.rewind(); int ret = CL10.clCreateKernelsInProgram(program, null, Utils.tempBuffers[0].b16i); Utils.checkError(ret, "clCreateKernelsInProgram"); int count = Utils.tempBuffers[0].b16i.get(0); PointerBuffer buf = PointerBuffer.allocateDirect(count); ret = CL10.clCreateKernelsInProgram(program, buf, (IntBuffer) null); Utils.checkError(ret, "clCreateKernelsInProgram"); Kernel[] kx = new Kernel[count]; for (int i=0; i<count; ++i) { kx[i] = new LwjglKernel(buf.get()); } return kx; }
Example 5
Source File: LwjglProgram.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public ByteBuffer getBinary(Device d) { //throw new UnsupportedOperationException("Not supported yet, would crash the JVM"); LwjglDevice device = (LwjglDevice) d; int numDevices = Info.clGetProgramInfoInt(program, CL10.CL_PROGRAM_NUM_DEVICES); PointerBuffer devices = PointerBuffer.allocateDirect(numDevices); int ret = CL10.clGetProgramInfo(program, CL10.CL_PROGRAM_DEVICES, devices, null); Utils.checkError(ret, "clGetProgramInfo: CL_PROGRAM_DEVICES"); int index = -1; for (int i=0; i<numDevices; ++i) { if (devices.get(i) == device.getDevice()) { index = i; } } if (index == -1) { throw new com.jme3.opencl.OpenCLException("Program was not built against the specified device "+device); } PointerBuffer sizes = PointerBuffer.allocateDirect(numDevices); ret = CL10.clGetProgramInfo(program, CL10.CL_PROGRAM_BINARY_SIZES, sizes, null); Utils.checkError(ret, "clGetProgramInfo: CL_PROGRAM_BINARY_SIZES"); int size = (int) sizes.get(index); PointerBuffer binaryPointers = PointerBuffer.allocateDirect(numDevices); for (int i=0; i<binaryPointers.capacity(); ++i) { binaryPointers.put(0L); } binaryPointers.rewind(); ByteBuffer binaries = ByteBuffer.allocateDirect(size); binaryPointers.put(index, binaries); //Fixme: why the hell does this line throw a segfault ?!? ret = CL10.clGetProgramInfo(program, CL10.CL_PROGRAM_BINARIES, binaryPointers, null); Utils.checkError(ret, "clGetProgramInfo: CL_PROGRAM_BINARIES"); return binaries; }
Example 6
Source File: LwjglPlatform.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Returns a list of the available devices on this platform that match the * specified type, filtered by the specified filter. * * Copied from the old release. * * @param device_type the device type * @param filter the device filter * * @return the available devices */ private long[] getDevices(int device_type) { int[] count = new int[1]; int errcode = CL10.clGetDeviceIDs(platform, device_type, null, count); if (errcode == CL10.CL_DEVICE_NOT_FOUND) { return new long[0]; } Utils.checkError(errcode, "clGetDeviceIDs"); int num_devices = count[0]; if (num_devices == 0) { return new long[0]; } PointerBuffer devices = PointerBuffer.allocateDirect(num_devices); errcode = CL10.clGetDeviceIDs(platform, device_type,devices, (IntBuffer) null); Utils.checkError(errcode, "clGetDeviceIDs"); long[] deviceIDs = new long[num_devices]; devices.rewind(); for (int i = 0; i < num_devices; i++) { deviceIDs[i] = devices.get(); } return deviceIDs; }