[refactor]: created a method that searches and returns a program associated with a device if it has already been added
@@ -197,10 +197,7 @@ public class OCLContext extends TornadoLogger {
return program;
}
- public OCLProgram createProgramWithBinary(long deviceId, byte[] binary, long[] lengths, OCLDeviceContext deviceContext) {
- OCLProgram program = null;
-
- try {
+ private OCLProgram lookupFPGAOpenCLProgram(long deviceId) {
// search if program has been already loaded
int programsLength = programs.size();
for (int i=0; i<programsLength; i++) {
@@ -213,8 +210,18 @@ public class OCLContext extends TornadoLogger {
}
}
}
+ return null;
+ }
+
+ public OCLProgram createProgramWithBinary(long deviceId, byte[] binary, long[] lengths, OCLDeviceContext deviceContext) {
+ OCLProgram program = null;
+
+ try {
+ program = lookupFPGAOpenCLProgram(deviceId);
+ if (program == null) {
program = new OCLProgram(clCreateProgramWithBinary(id, deviceId, binary, lengths), deviceContext);
programs.add(program);
+ }
} catch (OCLException e) {
error(e.getMessage());
}
