JOCL v2.6.0-rc-20250722
JOCL, OpenCL® API Binding for Java™ (public API).
JoclVersion.java
Go to the documentation of this file.
1/**
2 * Copyright 2014 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;
30
31import static com.jogamp.common.util.VersionUtil.getPlatformInfo;
32
33import com.jogamp.common.GlueGenVersion;
34import com.jogamp.common.os.Platform;
35import com.jogamp.common.util.VersionUtil;
36import com.jogamp.common.util.JogampVersion;
37
38import java.io.PrintWriter;
39import java.io.StringWriter;
40import java.util.ArrayList;
41import java.util.List;
42import java.util.Map;
43import java.util.Set;
44import java.util.jar.Manifest;
45
46public class JoclVersion extends JogampVersion {
47
48 protected static volatile JoclVersion jogampCommonVersionInfo;
49
50 protected JoclVersion(final String packageName, final Manifest mf) {
51 super(packageName, mf);
52 }
53
54 public static JoclVersion getInstance() {
55 if(null == jogampCommonVersionInfo) { // volatile: ok
56 synchronized(JoclVersion.class) {
57 if( null == jogampCommonVersionInfo ) {
58 final String packageName = "com.jogamp.opencl";
59 final Manifest mf = VersionUtil.getManifest(JoclVersion.class.getClassLoader(), packageName);
60 jogampCommonVersionInfo = new JoclVersion(packageName, mf);
61 }
62 }
63 }
65 }
66
67 public StringBuilder getAllVersions(StringBuilder sb) {
68 if(null==sb) {
69 sb = new StringBuilder();
70 }
71
72 try{
73 getPlatformInfo(sb);
74 sb.append(Platform.getNewline());
75 GlueGenVersion.getInstance().toString(sb);
76 sb.append(Platform.getNewline());
77 toString(sb);
78 sb.append(Platform.getNewline());
79 } catch (final Exception e) {
80 sb.append(e.getMessage());
81 e.printStackTrace();
82 }
83
84 return sb;
85 }
86
87 private volatile int maxKeyStrlen = -1;
88
89 public StringBuilder getOpenCLTextInfo(StringBuilder sb) {
90 if(null==sb) {
91 sb = new StringBuilder();
92 }
93
94 final CLPlatform[] platforms;
95 try {
96 platforms = CLPlatform.listCLPlatforms();
97 } catch (final Throwable t) {
98 final Throwable cause;
99 {
100 Throwable pre = null;
101 Throwable next = t;
102 while( null != next ) {
103 pre = next;
104 next = next.getCause();
105 }
106 cause = pre;
107 }
108 System.err.println("CLPlatform.listCLPlatforms() failed, exception: "+cause.getMessage());
109 t.printStackTrace();
110 sb.append("CLPlatform.listCLPlatforms() failed, exception: "+cause.getMessage());
111 final StringWriter stackTrace = new StringWriter();
112 cause.printStackTrace(new PrintWriter(stackTrace));
113 sb.append(stackTrace.toString());
114 return sb;
115 }
116
117 // platforms
118 final List<Map<String, String>> platProps = new ArrayList<Map<String, String>>();
119 if( 0 > maxKeyStrlen ) {
120 synchronized(this) {
121 if( 0 > maxKeyStrlen ) {
122 for (final CLPlatform p : platforms) {
123 platProps.add(p.getProperties());
124 final CLDevice[] devices = p.listCLDevices();
125 for (final CLDevice d : devices) {
126 final Map<String,String> props = d.getProperties();
127 final Set<Map.Entry<String, String>> entries = props.entrySet();
128 for(final Map.Entry<String, String> e : entries) {
129 maxKeyStrlen = Math.max(maxKeyStrlen, e.getKey().length());
130 }
131 }
132 }
133 }
134 }
135 }
136 sb.append(String.format("PP:DD:EE - Platform (PP), Device (DD), Entry (EE)%n"));
137 int pI = 0;
138 for (final CLPlatform p : platforms) {
139 pI++;
140 platProps.add(p.getProperties());
141 final CLDevice[] devices = p.listCLDevices();
142 int dI = 0;
143 for (final CLDevice d : devices) {
144 dI++;
145 final Map<String,String> props = d.getProperties();
146 final Set<Map.Entry<String, String>> entries = props.entrySet();
147 int eI = 0;
148 for(final Map.Entry<String, String> e : entries) {
149 eI++;
150 sb.append(String.format("%02d:%02d:%02d %"+maxKeyStrlen+"s: %s%n", pI, dI, eI, e.getKey(), e.getValue()));
151 }
152 }
153 }
154 return sb;
155 }
156
157 public StringBuilder getOpenCLHtmlInfo(StringBuilder sb) {
158 if(null==sb) {
159 sb = new StringBuilder();
160 }
161
162 final CLPlatform[] platforms;
163 try {
164 platforms = CLPlatform.listCLPlatforms();
165 } catch (final Throwable t) {
166 final Throwable cause;
167 {
168 Throwable pre = null;
169 Throwable next = t;
170 while( null != next ) {
171 pre = next;
172 next = next.getCause();
173 }
174 cause = pre;
175 }
176 System.err.println("CLPlatform.listCLPlatforms() failed, exception: "+cause.getMessage());
177 t.printStackTrace();
178 sb.append("<pre>CLPlatform.listCLPlatforms() failed, exception: "+cause.getMessage());
179 final StringWriter stackTrace = new StringWriter();
180 cause.printStackTrace(new PrintWriter(stackTrace));
181 sb.append(stackTrace.toString()).append("</pre>");
182 return sb;
183 }
184 sb.append("<table border=\"1\">");
185
186 // platforms
187 final List<Map<String, String>> platProps = new ArrayList<Map<String, String>>();
188 final List<Integer> spans = new ArrayList<Integer>();
189 for (final CLPlatform p : platforms) {
190 platProps.add(p.getProperties());
191 spans.add(p.listCLDevices().length);
192 }
193 fillHtmlTable(platProps, spans, sb);
194
195 // devices
196 final ArrayList<Map<String, String>> devProps = new ArrayList<Map<String, String>>();
197 for (final CLPlatform p : platforms) {
198 final CLDevice[] devices = p.listCLDevices();
199 for (final CLDevice d : devices) {
200 devProps.add(d.getProperties());
201 }
202 }
203 fillHtmlTable(devProps, sb);
204 sb.append("</table>");
205
206 return sb;
207 }
208
209 private static void fillHtmlTable(final List<Map<String, String>> properties, final StringBuilder sb) {
210 final ArrayList<Integer> spans = new ArrayList<Integer>(properties.size());
211 for (int i = 0; i < properties.size(); i++) {
212 spans.add(1);
213 }
214 fillHtmlTable(properties, spans, sb);
215 }
216
217 private static void fillHtmlTable(final List<Map<String, String>> properties, final List<Integer> spans, final StringBuilder sb) {
218 boolean header = true;
219 for (final String key : properties.get(0).keySet()) {
220 sb.append("<tr>");
221 htmlCell(sb, key);
222 int i = 0;
223 for (final Map<String, String> map : properties) {
224 htmlCell(sb, spans.get(i), map.get(key), header);
225 i++;
226 }
227 sb.append("</tr>");
228 header = false;
229 }
230 }
231
232 private static void htmlCell(final StringBuilder sb, final String value) {
233 sb.append("<td>").append(value).append("</td>");
234 }
235
236 private static void htmlCell(final StringBuilder sb, final int span, final String value, final boolean header) {
237 if(header) {
238 sb.append("<th colspan=\"").append(span).append("\">").append(value).append("</th>");
239 }else{
240 sb.append("<td colspan=\"").append(span).append("\">").append(value).append("</td>");
241 }
242 }
243
244 public static void main(final String args[]) {
245 System.err.println(VersionUtil.getPlatformInfo());
246 System.err.println(GlueGenVersion.getInstance());
247 // System.err.println(NativeWindowVersion.getInstance());
249 System.err.println(v.toString());
250 if( CLPlatform.isAvailable() ) {
251 System.err.println(v.getOpenCLTextInfo(null).toString());
252 // System.err.println(v.getOpenCLHtmlInfo(null).toString());
253 } else {
254 System.err.println("JOCL/OpenCL not available");
255 }
256 }
257}
258
This object represents an OpenCL device.
Definition: CLDevice.java:53
CLPlatfrorm representing a OpenCL implementation (e.g.
Definition: CLPlatform.java:99
static boolean isAvailable()
static CLPlatform[] listCLPlatforms()
Lists all available OpenCL implementations.
static void main(final String args[])
static volatile JoclVersion jogampCommonVersionInfo
JoclVersion(final String packageName, final Manifest mf)
StringBuilder getOpenCLTextInfo(StringBuilder sb)
StringBuilder getAllVersions(StringBuilder sb)
StringBuilder getOpenCLHtmlInfo(StringBuilder sb)
static JoclVersion getInstance()
Configures the mapping process.
Definition: CLMemory.java:402