Skip to content

Commit 9119caf

Browse files
committed
JavaCL: fixed issue #81 (include os name + version & OpenCL platform version to cached binaries' signatures)
1 parent d4f557d commit 9119caf

2 files changed

Lines changed: 36 additions & 14 deletions

File tree

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,17 @@ protected int getInfo(cl_platform_id entity, int infoTypeEnum, NativeSize size,
6666

6767
@Override
6868
public String toString() {
69-
return getName() + " {vendor: " + getVendor() + ", version: " + getVersion() + ", profile: " + getProfile() + ", extensions: " + Arrays.toString(getExtensions()) + "}";
69+
return toString(new StringBuilder()).toString();
70+
}
71+
StringBuilder toString(StringBuilder out) {
72+
out.
73+
append(getName()).
74+
append(" {vendor: ").append(getVendor()).
75+
append(", version: ").append(getVersion()).
76+
append(", profile: ").append(getProfile()).
77+
append(", extensions: ").append(Arrays.toString(getExtensions())).
78+
append("}");
79+
return out;
7080
}
7181

7282
@Override

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

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -599,32 +599,44 @@ public synchronized boolean isCached() {
599599
}
600600

601601
protected String computeCacheSignature() throws IOException {
602-
StringBuilder b = new StringBuilder(1024);
602+
StringBuilder b = new StringBuilder(16 * 1024);
603+
getContext().getPlatform().toString(b);
604+
b.append('\n');
603605
for (CLDevice device : getDevices())
604-
b.append(device).append("\n");
606+
b.append(device).append('\n');
605607

606608
b.append(getOptionsString()).append('\n');
607-
if (macros != null)
609+
if (macros != null && !macros.isEmpty())
608610
for (Map.Entry<String, Object> m : macros.entrySet())
609-
b.append("-D").append(m.getKey()).append("=").append(m.getValue()).append('\n');
611+
b.append("-D").append(m.getKey()).append('=').append(m.getValue()).append('\n');
610612

611-
if (includes != null)
613+
if (includes != null && !includes.isEmpty())
612614
for (String path : includes)
613615
b.append("-I").append(path).append('\n');
614616

615-
if (sources != null)
617+
if (sources != null && !sources.isEmpty())
616618
for (String source : sources)
617-
b.append(source).append("\n");
619+
b.append(source).append('\n');
618620

619621
Map<String, URL> inclusions = resolveInclusions();
620-
for (Map.Entry<String, URL> e : inclusions.entrySet()) {
621-
URLConnection con = e.getValue().openConnection();
622-
InputStream in = con.getInputStream();
623-
b.append('#').append(e.getKey()).append(con.getLastModified()).append('\n');
624-
in.close();
625-
}
622+
if (inclusions != null && !inclusions.isEmpty())
623+
for (Map.Entry<String, URL> e : inclusions.entrySet()) {
624+
URLConnection con = e.getValue().openConnection();
625+
InputStream in = con.getInputStream();
626+
b.append('#').append(e.getKey()).append(con.getLastModified()).append('\n');
627+
in.close();
628+
}
629+
630+
for (String name : propsToIncludeInSignature)
631+
b.append(name).append('=').append(System.getProperty(name)).append('\n');
632+
626633
return b.toString();
627634
}
635+
private final String[] propsToIncludeInSignature = new String[] {
636+
//"java.vm.version", // probably superfluous...
637+
"os.version",
638+
"os.name"
639+
};
628640

629641
boolean built;
630642
/**

0 commit comments

Comments
 (0)