Skip to content

Commit f501d5e

Browse files
committed
JavaCL/JNA: ported fix for issue #297 over to javacl-jna
1 parent 20dae1f commit f501d5e

File tree

5 files changed

+21
-20
lines changed

5 files changed

+21
-20
lines changed

Core/src/main/java/com/nativelibs4java/opencl/CLDevice.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
/**
5555
* OpenCL device (CPU, GPU...).<br/>
5656
* Devices are retrieved from a CLPlatform through
57-
* {@link CLPlatform#listDevices(java.util.EnumSet, boolean) },
57+
* {@link CLPlatform#listDevices(CLDevice.Type, boolean) },
5858
* {@link CLPlatform#listAllDevices(boolean) },
5959
* {@link CLPlatform#listCPUDevices(boolean) },
6060
* {@link CLPlatform#listGPUDevices(boolean) }
@@ -153,7 +153,8 @@ public enum Type implements ValuedEnum {
153153
CPU(CL_DEVICE_TYPE_CPU),
154154
GPU(CL_DEVICE_TYPE_GPU),
155155
Accelerator(CL_DEVICE_TYPE_ACCELERATOR),
156-
Default(CL_DEVICE_TYPE_DEFAULT);
156+
Default(CL_DEVICE_TYPE_DEFAULT),
157+
All(CL_DEVICE_TYPE_ALL);
157158

158159
Type(long value) { this.value = value; }
159160
long value;

Core/src/main/java/com/nativelibs4java/opencl/CLPlatform.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,20 +86,20 @@ protected void clear() {
8686
/**
8787
* Lists all the devices of the platform
8888
* @param onlyAvailable if true, only returns devices that are available
89-
* see {@link CLPlatform#listDevices(java.util.EnumSet, boolean) }
89+
* see {@link CLPlatform#listDevices(CLDevice.Type, boolean) }
9090
*/
9191
public CLDevice[] listAllDevices(boolean onlyAvailable) {
92-
return listDevices(EnumSet.allOf(CLDevice.Type.class), onlyAvailable);
92+
return listDevices(CLDevice.Type.All, onlyAvailable);
9393
}
9494

9595
/**
9696
* Lists all the GPU devices of the platform
9797
* @param onlyAvailable if true, only returns GPU devices that are available
98-
* see {@link CLPlatform#listDevices(java.util.EnumSet, boolean) }
98+
* see {@link CLPlatform#listDevices(CLDevice.Type, boolean) }
9999
*/
100100
public CLDevice[] listGPUDevices(boolean onlyAvailable) {
101101
try {
102-
return listDevices(EnumSet.of(CLDevice.Type.GPU), onlyAvailable);
102+
return listDevices(CLDevice.Type.GPU, onlyAvailable);
103103
} catch (CLException ex) {
104104
if (ex.getCode() == CL_DEVICE_NOT_FOUND) {
105105
return new CLDevice[0];
@@ -111,11 +111,11 @@ public CLDevice[] listGPUDevices(boolean onlyAvailable) {
111111
/**
112112
* Lists all the CPU devices of the platform
113113
* @param onlyAvailable if true, only returns CPU devices that are available
114-
* see {@link CLPlatform#listDevices(java.util.EnumSet, boolean) }
114+
* see {@link CLPlatform#listDevices(CLDevice.Type, boolean) }
115115
*/
116116
public CLDevice[] listCPUDevices(boolean onlyAvailable) {
117117
try {
118-
return listDevices(EnumSet.of(CLDevice.Type.CPU), onlyAvailable);
118+
return listDevices(CLDevice.Type.CPU, onlyAvailable);
119119
} catch (CLException ex) {
120120
if (ex.getCode() == CL_DEVICE_NOT_FOUND) {
121121
return new CLDevice[0];
@@ -400,11 +400,9 @@ public void apply(Pointer<java.lang.Byte > errInfo, Pointer<? > private_info, @P
400400
* List all the devices of the specified types, with only the ones declared as available if onlyAvailable is true.
401401
*/
402402
@SuppressWarnings("deprecation")
403-
public CLDevice[] listDevices(EnumSet<CLDevice.Type> types, boolean onlyAvailable) {
404-
int flags = (int) CLDevice.Type.getValue(types);
405-
403+
public CLDevice[] listDevices(CLDevice.Type type, boolean onlyAvailable) {
406404
IntByReference pCount = new IntByReference();
407-
error(CL.clGetDeviceIDs(getEntity(), flags, 0, (PointerByReference) null, pCount));
405+
error(CL.clGetDeviceIDs(getEntity(), type.value(), 0, (PointerByReference) null, pCount));
408406

409407
int nDevs = pCount.getValue();
410408
if (nDevs == 0) {
@@ -413,7 +411,7 @@ public CLDevice[] listDevices(EnumSet<CLDevice.Type> types, boolean onlyAvailabl
413411

414412
cl_device_id[] ids = new cl_device_id[nDevs];
415413

416-
error(CL.clGetDeviceIDs(getEntity(), flags, nDevs, ids, pCount));
414+
error(CL.clGetDeviceIDs(getEntity(), type.value(), nDevs, ids, pCount));
417415
return getDevices(ids, onlyAvailable);
418416
}
419417

Core/src/main/java/com/nativelibs4java/opencl/CLProgram.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -717,8 +717,11 @@ public synchronized CLProgram build() throws CLBuildException {
717717
if (isCached() && !readBinaries) {
718718
JavaCL.userCacheDir.mkdirs();
719719
try {
720-
writeBinaries(getBinaries(), getSource(), contentSignature, new FileOutputStream(cacheFile));
721-
assert log(Level.INFO, "Wrote binaries cache to '" + cacheFile + "'");
720+
Map<CLDevice, byte[]> binaries = getBinaries();
721+
if (!binaries.isEmpty()) {
722+
writeBinaries(getBinaries(), getSource(), contentSignature, new FileOutputStream(cacheFile));
723+
assert log(Level.INFO, "Wrote binaries cache to '" + cacheFile + "'");
724+
}
722725
} catch (Exception ex) {
723726
new IOException("[JavaCL] Failed to cache program", ex).printStackTrace();
724727
}

Generator/src/main/java/com/nativelibs4java/opencl/generator/JavaCLGenerator.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public class JavaCLGenerator extends JNAerator {
2727
public JavaCLGenerator(JNAeratorConfig config) {
2828
super(config);
2929

30-
config.noMangling = true;
3130
config.noCPlusPlus = true;
3231
config.genCPlusPlus = false;
3332
config.gccLong = true;
@@ -184,7 +183,7 @@ public void convertFunction(Function function, Signatures signatures, boolean is
184183

185184
String functionName = function.getName().toString();
186185
String kernelVarName = functionName + "_kernel";
187-
if (signatures.variablesSignatures.add(kernelVarName))
186+
if (signatures.addVariable(kernelVarName))
188187
out.addDeclaration(new VariablesDeclaration(typeRef(CLKernel.class), new Declarator.DirectDeclarator(kernelVarName)));
189188
Function method = new Function(Function.Type.JavaMethod, ident(functionName), typeRef(CLEvent.class));
190189
method.addModifiers(ModifierType.Public, ModifierType.Synchronized);
@@ -228,7 +227,7 @@ public void convertFunction(Function function, Signatures signatures, boolean is
228227
))
229228
);
230229
method.setBody(block(statements.toArray(new Statement[statements.size()])));
231-
if (signatures.methodsSignatures.add(method.computeSignature(false)))
230+
if (signatures.addMethod(method))
232231
out.addDeclaration(method);
233232
}
234233
};

OpenCL4Java/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ For more info, please visit http://code.google.com/p/nativelibs4java/wiki/OpenCL
3838

3939
<build>
4040
<plugins>
41-
41+
<!--
4242
<plugin>
4343
<groupId>com.nativelibs4java</groupId>
4444
<artifactId>maven-jnaerator-plugin</artifactId>
@@ -48,7 +48,7 @@ For more info, please visit http://code.google.com/p/nativelibs4java/wiki/OpenCL
4848
<scalaOutputDirectory>src/main/scala</scalaOutputDirectory>
4949
</configuration>
5050
</plugin>
51-
51+
-->
5252
</plugins>
5353
</build>
5454
</project>

0 commit comments

Comments
 (0)