From d50d5a7b1c0411492d111d9a3e5a781bc8cdfd55 Mon Sep 17 00:00:00 2001 From: Michael Bien Date: Tue, 19 Apr 2011 17:54:25 +0200 Subject: code cleanup in CLProgramBuilder.writeObject(). --- src/com/jogamp/opencl/CLProgramBuilder.java | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'src/com') diff --git a/src/com/jogamp/opencl/CLProgramBuilder.java b/src/com/jogamp/opencl/CLProgramBuilder.java index bcde3db6..389adce8 100644 --- a/src/com/jogamp/opencl/CLProgramBuilder.java +++ b/src/com/jogamp/opencl/CLProgramBuilder.java @@ -286,20 +286,28 @@ public final class CLProgramBuilder implements CLProgramConfiguration, Serializa private void writeObject(ObjectOutputStream out) throws IOException { out.defaultWriteObject(); - Set devices = binariesMap.keySet(); - String suffix = devices.iterator().next().getPlatform().getICDSuffix(); - out.writeUTF(suffix); + CLDevice[] deviceList = null; + String suffix = null; + + if(!binariesMap.isEmpty()) { + CLPlatform platform = binariesMap.keySet().iterator().next().getPlatform(); + deviceList = platform.listCLDevices(); - out.writeInt(binariesMap.size()); + suffix = platform.getICDSuffix(); + } + + out.writeUTF(suffix); // null if we have no binaries or no devices specified + out.writeInt(binariesMap.size()); // may be 0 - for (CLDevice device : devices) { - byte[] binaries = binariesMap.get(device); + for (Map.Entry entry : binariesMap.entrySet()) { + CLDevice device = entry.getKey(); + byte[] binaries = entry.getValue(); // we use the device index as identifier since there is currently no other way // to distinguish identical devices via CL. // it should be persistent between runs but may change on driver/hardware update. In this situations we would // have to build from source anyway (build failures). - int index = indexOf(device, device.getPlatform().listCLDevices()); + int index = indexOf(device, deviceList); out.writeInt(index); out.writeInt(binaries.length); out.write(binaries); -- cgit v1.2.3