29package com.jogamp.opencl;
31import com.jogamp.opencl.llb.CL;
32import com.jogamp.opencl.impl.CLTLAccessorFactory;
33import com.jogamp.common.nio.Buffers;
34import com.jogamp.common.JogampRuntimeException;
35import com.jogamp.common.nio.PointerBuffer;
36import com.jogamp.opencl.spi.CLPlatformInfoAccessor;
37import com.jogamp.opencl.util.CLUtil;
38import com.jogamp.opencl.llb.impl.CLImpl11;
39import com.jogamp.opencl.llb.impl.CLImpl12;
40import com.jogamp.opencl.llb.impl.CLImpl20;
41import com.jogamp.opencl.spi.CLAccessorFactory;
42import com.jogamp.opencl.spi.CLInfoAccessor;
43import com.jogamp.opencl.util.Filter;
45import java.nio.IntBuffer;
46import java.util.ArrayList;
47import java.util.Collections;
48import java.util.HashSet;
51import java.util.Scanner;
54import static com.jogamp.opencl.CLException.*;
55import static com.jogamp.opencl.llb.CL.*;
104 public final long ID;
115 private Set<String> extensions;
126 if(factory ==
null) {
127 this.factory = defaultFactory;
129 this.factory = factory;
146 public static void initialize() throws JogampRuntimeException {
162 if(defaultFactory ==
null) {
163 if(factory ==
null) {
164 defaultFactory =
new CLTLAccessorFactory();
166 defaultFactory = factory;
170 if( !CLImpl11.isAvailable() ) {
171 throw new JogampRuntimeException(
"JOCL is not available");
189 if(platforms.length > 0) {
190 return latest(platforms);
199 if (platform.version.compareTo(best.
version) > 0) {
222 final IntBuffer ib = Buffers.newDirectIntBuffer(1);
225 checkForError(ret,
"can not enumerate platforms");
228 final PointerBuffer platformId = PointerBuffer.allocateDirect(ib.get(0));
230 checkForError(ret,
"can not enumerate platforms");
232 final List<CLPlatform> platforms =
new ArrayList<CLPlatform>();
234 for (
int i = 0; i < platformId.capacity(); i++) {
236 addIfAccepted(platform, platforms, filter);
239 return platforms.toArray(
new CLPlatform[platforms.size()]);
276 checkForError(ret,
"error while sending unload compiler hint");
287 catch(CLInvalidDeviceTypeException ignore){
298 final List<CLDevice> list =
new ArrayList<CLDevice>();
300 for(
int t = 0; t < types.length; t++) {
301 final CLDevice.Type type = types[t];
306 for (
int n = 0; n < deviceIDs.length; n++) {
311 return list.toArray(
new CLDevice[list.size()]);
321 final List<CLDevice> list =
new ArrayList<CLDevice>();
326 for (
int n = 0; n < deviceIDs.length; n++) {
328 addIfAccepted(device, list, filters);
331 return list.toArray(
new CLDevice[list.size()]);
339 private static <I>
void addIfAccepted(
final I item,
final List<I> list,
final Filter<I>[] filters) {
340 if(filters ==
null) {
343 boolean accepted =
true;
344 for (
final Filter<I> filter : filters) {
345 if(!filter.accept(item)) {
356 static CLDevice findMaxFlopsDevice(
final CLDevice[] devices) {
357 return findMaxFlopsDevice(devices,
null);
360 static CLDevice findMaxFlopsDevice(
final CLDevice[] devices,
final CLDevice.Type type) {
363 CLDevice maxFLOPSDevice =
null;
367 for (
int i = 0; i < devices.length; i++) {
369 final CLDevice device = devices[i];
371 if(type ==
null || type.equals(device.getType())) {
373 final int maxComputeUnits = device.getMaxComputeUnits();
374 final int maxClockFrequency = device.getMaxClockFrequency();
375 final int flops = maxComputeUnits*maxClockFrequency;
377 if(flops > maxflops) {
379 maxFLOPSDevice = device;
385 return maxFLOPSDevice;
450 public boolean isAtLeast(
final int major,
final int minor) {
474 return getVendor().contains(
"Advanced Micro Devices");
505 if(extensions ==
null) {
506 extensions =
new HashSet<String>();
508 final Scanner scanner =
new Scanner(ext);
510 while(scanner.hasNext())
511 extensions.add(scanner.next());
514 extensions = Collections.unmodifiableSet(extensions);
549 return getClass().getSimpleName()+
" [name: " +
getName()
556 public boolean equals(
final Object obj) {
560 if (getClass() != obj.getClass()) {
564 if (this.ID != other.
ID) {
573 hash = 71 * hash + (int) (this.ID ^ (this.ID >>> 32));
This object represents an OpenCL device.
Version of an OpenCL Implementation.
boolean isEqual(final CLVersion other)
String getSpecVersion()
Returns '"OpenCL " + major + "." + minor'.
static final CLVersion CL_1_2
static final CLVersion CL_2_0
boolean isAtLeast(final CLVersion other)
Java bindings to OpenCL, the Open Computing Language (generated).
static boolean isAvailable()
Accessor.
Java bindings to OpenCL, the Open Computing Language (generated).
Java bindings to OpenCL, the Open Computing Language (generated).
static Map< String, String > obtainPlatformProperties(final CLPlatform platform)
Reads all platform properties and returns them as key-value map.
Enumeration for the type of a device.
Configures the mapping process.
Java bindings to OpenCL, the Open Computing Language.
int clGetPlatformIDs(int num_entries, PointerBuffer platforms, IntBuffer num_platforms)
Interface to C language function: cl_int {@native clGetPlatformIDs}(cl_uint num_entries,...
int clUnloadCompiler()
Interface to C language function: cl_int {@native clUnloadCompiler}()
Implementations of this interface are factories responsible for creating CLAccessors.
CLInfoAccessor createDeviceInfoAccessor(CL cl, long id)
CLPlatformInfoAccessor createPlatformInfoAccessor(CL cl, long id)
Internal utility for common OpenCL clGetFooInfo calls.
String getString(int key)
Returns the String value for the given key.