Skip to content

Commit 497d6a1

Browse files
committed
Fix OpenCL detection to handle already-initialized state
When CL.create() throws IllegalStateException with 'already been created', treat this as OpenCL being available rather than NOT_AVAILABLE.
1 parent 9221568 commit 497d6a1

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

gpu-test-framework/src/main/java/com/hellblazer/gpu/test/support/TestSupportMatrix.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,26 @@ private boolean detectCIEnvironment() {
117117
}
118118

119119
private void detectBackendSupport() {
120-
// OpenCL detection
120+
// OpenCL detection - handle already-initialized state correctly
121+
// Note: We do NOT destroy CL after detection because subsequent code may need it
121122
try {
122-
CL.create();
123+
try {
124+
CL.create();
125+
log.debug("OpenCL initialized successfully");
126+
} catch (IllegalStateException e) {
127+
// "OpenCL has already been created" means it's available
128+
if (e.getMessage() != null && e.getMessage().contains("already been created")) {
129+
log.debug("OpenCL already initialized - treating as available");
130+
} else {
131+
throw e; // Re-throw other IllegalStateExceptions
132+
}
133+
}
134+
135+
// OpenCL is available (either we created it or it was already created)
123136
backendSupport.put(Backend.OPENCL, ciEnvironment ? SupportLevel.MOCK : SupportLevel.FULL);
124137
} catch (Throwable t) {
125-
backendSupport.put(Backend.OPENCL,
138+
log.debug("OpenCL not available: {}", t.getMessage());
139+
backendSupport.put(Backend.OPENCL,
126140
ciEnvironment ? SupportLevel.MOCK : SupportLevel.NOT_AVAILABLE);
127141
}
128142

0 commit comments

Comments
 (0)