JOCL v2.6.0-rc-20250722
JOCL, OpenCL® API Binding for Java™ (public API).
CLDeviceFilters.java
Go to the documentation of this file.
1/*
2 * Copyright 2011 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28
29package com.jogamp.opencl.util;
30
31import com.jogamp.opencl.CLCommandQueue.Mode;
32import com.jogamp.opencl.CLDevice;
33import java.nio.ByteOrder;
34import java.util.Arrays;
35import java.util.EnumSet;
36import java.util.List;
37
38/**
39 * Pre-defined filters.
40 * @author Michael Bien
41 * @see com.jogamp.opencl.CLPlatform#listCLDevices(com.jogamp.opencl.util.Filter[])
42 * @see com.jogamp.opencl.CLPlatform#getMaxFlopsDevice(com.jogamp.opencl.util.Filter[])
43 */
44public class CLDeviceFilters {
45
46 /**
47 * Accepts all devices of the given type.
48 */
49 public static Filter<CLDevice> type(final CLDevice.Type... types) {
50 return new Filter<CLDevice>() {
51 private final EnumSet<CLDevice.Type> set = EnumSet.copyOf(Arrays.asList(types));
52 public boolean accept(final CLDevice item) {
53 if(set.contains(CLDevice.Type.ALL)) {
54 return true;
55 }
56 return set.contains(item.getType());
57 }
58 };
59 }
60
61 /**
62 * Accepts all devices of the given {@link ByteOrder}.
63 */
64 public static Filter<CLDevice> byteOrder(final ByteOrder order) {
65 return new Filter<CLDevice>() {
66 public boolean accept(final CLDevice item) {
67 return item.getByteOrder().equals(order);
68 }
69 };
70 }
71
72 /**
73 * Accepts all devices which support OpenGL-OpenCL interoperability.
74 */
75 public static Filter<CLDevice> glSharing() {
76 return new Filter<CLDevice>() {
77 public boolean accept(final CLDevice item) {
78 return item.isGLMemorySharingSupported();
79 }
80 };
81 }
82
83 /**
84 * Accepts all devices supporting the given extensions.
85 */
86 public static Filter<CLDevice> extension(final String... extensions) {
87 return new Filter<CLDevice>() {
88 private final List<String> extensionList = Arrays.asList(extensions);
89 public boolean accept(final CLDevice item) {
90 return item.getExtensions().containsAll(extensionList);
91 }
92 };
93 }
94
95 /**
96 * Accepts all devices supporting the specified command queue modes.
97 */
98 public static Filter<CLDevice> queueMode(final Mode... modes) {
99 return new Filter<CLDevice>() {
100 private final List<Mode> modeList = Arrays.asList(modes);
101 public boolean accept(final CLDevice item) {
102 return item.getQueueProperties().containsAll(modeList);
103 }
104 };
105 }
106
107}
This object represents an OpenCL device.
Definition: CLDevice.java:53
Type getType()
Returns the type of this device.
Definition: CLDevice.java:166
Set< String > getExtensions()
Returns all device extension names as unmodifiable Set.
Definition: CLDevice.java:688
ByteOrder getByteOrder()
Returns ByteOrder#LITTLE_ENDIAN or ByteOrder#BIG_ENDIAN.
Definition: CLDevice.java:676
boolean isGLMemorySharingSupported()
Returns isExtensionAvailable("cl_khr_gl_sharing") || isExtensionAvailable("cl_APPLE_gl_sharing").
Definition: CLDevice.java:661
EnumSet< CLCommandQueue.Mode > getQueueProperties()
Returns the command-queue properties supported by the device.
Definition: CLDevice.java:589
static Filter< CLDevice > type(final CLDevice.Type... types)
Accepts all devices of the given type.
static Filter< CLDevice > extension(final String... extensions)
Accepts all devices supporting the given extensions.
static Filter< CLDevice > byteOrder(final ByteOrder order)
Accepts all devices of the given ByteOrder.
static Filter< CLDevice > queueMode(final Mode... modes)
Accepts all devices supporting the specified command queue modes.
static Filter< CLDevice > glSharing()
Accepts all devices which support OpenGL-OpenCL interoperability.
Enumeration for the command-queue settings.
Enumeration for the type of a device.
Definition: CLDevice.java:798