public List<CLImageFormat> getSupportedImageFormats(final CLContext context, final long flags, final int image_type, final Filter<CLImageFormat> filter) { final IntBuffer numBuffer = APIUtil.getBufferInt(); clGetSupportedImageFormats(context, flags, image_type, null, numBuffer); final int num_image_formats = numBuffer.get(0); if ( num_image_formats == 0 ) return null; final ByteBuffer formatBuffer = BufferUtils.createByteBuffer(num_image_formats * CLImageFormat.STRUCT_SIZE); clGetSupportedImageFormats(context, flags, image_type, formatBuffer, null); final List<CLImageFormat> formats = new ArrayList<CLImageFormat>(num_image_formats); for ( int i = 0; i < num_image_formats; i++ ) { final int offset = num_image_formats * CLImageFormat.STRUCT_SIZE; final CLImageFormat format = new CLImageFormat( formatBuffer.getInt(offset), formatBuffer.getInt(offset + 4) ); if ( filter == null || filter.accept(format) ) formats.add(format); } return formats.size() == 0 ? null : formats; }
public List<CLPlatform> getPlatforms(final Filter<CLPlatform> filter) { final IntBuffer numBuffer = APIUtil.getBufferInt(); clGetPlatformIDs(null, numBuffer); final int num_platforms = numBuffer.get(0); if ( num_platforms == 0 ) return null; final PointerBuffer platformIDs = APIUtil.getBufferPointer(num_platforms); clGetPlatformIDs(platformIDs, null); final List<CLPlatform> platforms = new ArrayList<CLPlatform>(num_platforms); for ( int i = 0; i < num_platforms; i++ ) { final CLPlatform platform = CLPlatform.getCLPlatform(platformIDs.get(i)); if ( filter == null || filter.accept(platform) ) platforms.add(platform); } return platforms.size() == 0 ? null : platforms; }
public List<CLDevice> getDevices(final CLPlatform platform, final int device_type, final Filter<CLDevice> filter) { platform.checkValid(); final IntBuffer numBuffer = APIUtil.getBufferInt(); clGetDeviceIDs(platform, device_type, null, numBuffer); final int num_devices = numBuffer.get(0); if ( num_devices == 0 ) return null; final PointerBuffer deviceIDs = APIUtil.getBufferPointer(num_devices); clGetDeviceIDs(platform, device_type, deviceIDs, null); final List<CLDevice> devices = new ArrayList<CLDevice>(num_devices); for ( int i = 0; i < num_devices; i++ ) { final CLDevice device = platform.getCLDevice(deviceIDs.get(i)); if ( filter == null || filter.accept(device) ) devices.add(device); } return devices.size() == 0 ? null : devices; }
private void initCL() throws LWJGLException { CL.create(); final List<CLPlatform> platforms = CLPlatform.getPlatforms(); if ( platforms == null ) throw new RuntimeException("No OpenCL platforms found."); final CLPlatform platform = platforms.get(0); final PointerBuffer ctxProps = BufferUtils.createPointerBuffer(3); ctxProps.put(CL_CONTEXT_PLATFORM).put(platform.getPointer()).put(0).flip(); // Find devices with GL sharing support final Filter<CLDevice> glSharingFilter = new Filter<CLDevice>() { public boolean accept(final CLDevice device) { final CLDeviceCapabilities caps = CLCapabilities.getDeviceCapabilities(device); return caps.CL_KHR_gl_sharing; } }; final List<CLDevice> devices = platform.getDevices(CL_DEVICE_TYPE_GPU, glSharingFilter); if ( devices == null ) throw new RuntimeException("No OpenCL GPU device found."); clDevice = devices.get(0); // Make sure we use only 1 device devices.clear(); devices.add(clDevice); clContext = CLContext.create(platform, devices, new CLContextCallback() { protected void handleMessage(final String errinfo, final ByteBuffer private_info) { System.out.println("[CONTEXT MESSAGE] " + errinfo); } }, Display.getDrawable(), errorCode); checkCLError(errorCode); queue = clCreateCommandQueue(clContext, clDevice, 0, errorCode); checkCLError(errorCode); }
public List<CLImageFormat> getSupportedImageFormats(final long flags, final int image_type, final Filter<CLImageFormat> filter) { return util.getSupportedImageFormats(this, flags, image_type, filter); }
private void initCL() throws LWJGLException { CL.create(); final List<CLPlatform> platforms = CLPlatform.getPlatforms(); if ( platforms == null ) throw new RuntimeException("No OpenCL platforms found."); final Filter<CLDevice> glSharingFilter = new Filter<CLDevice>() { public boolean accept(final CLDevice device) { final CLDeviceCapabilities caps = CLCapabilities.getDeviceCapabilities(device); return caps.CL_KHR_gl_sharing; } }; CLPlatform platform = null; List<CLDevice> devices = null; for ( CLPlatform p : platforms ) { // Find devices with GL sharing support devices = p.getDevices(CL_DEVICE_TYPE_GPU, glSharingFilter); if ( devices != null ) { platform = p; break; } } if ( devices == null ) throw new RuntimeException("No OpenCL GPU device found."); clDevice = devices.get(0); // Make sure we use only 1 device devices.clear(); devices.add(clDevice); clContext = CLContext.create(platform, devices, new CLContextCallback() { protected void handleMessage(final String errinfo, final ByteBuffer private_info) { System.out.println("[CONTEXT MESSAGE] " + errinfo); } }, Display.getDrawable(), errorCode); checkCLError(errorCode); queue = clCreateCommandQueue(clContext, clDevice, 0, errorCode); checkCLError(errorCode); }
/** * Returns a list of the available platforms, filtered by the specified filter. * * @param filter the platform filter * * @return the available platforms */ public static List<CLPlatform> getPlatforms(final Filter<CLPlatform> filter) { return util.getPlatforms(filter); }
/** * Returns a list of the available devices on this platform that * match the specified type, filtered by the specified filter. * * @param device_type the device type * @param filter the device filter * * @return the available devices */ public List<CLDevice> getDevices(final int device_type, final Filter<CLDevice> filter) { return util.getDevices(this, device_type, filter); }