|
13 | 13 |
|
14 | 14 | import java.nio.ByteOrder; |
15 | 15 | import java.util.*; |
| 16 | +import java.util.regex.Matcher; |
| 17 | +import java.util.regex.Pattern; |
| 18 | +import java.util.logging.*; |
| 19 | + |
16 | 20 | import static com.nativelibs4java.opencl.JavaCL.*; |
17 | 21 | import static com.nativelibs4java.opencl.CLException.*; |
18 | 22 |
|
@@ -397,6 +401,36 @@ public String getVersion() { |
397 | 401 | return infos.getString(getEntity(), CL_PLATFORM_VERSION); |
398 | 402 | } |
399 | 403 |
|
| 404 | + private double versionValue = Double.NaN; |
| 405 | + private static final Pattern VERSION_PATTERN = Pattern.compile("OpenCL (\\d+\\.\\d+)\\b.*"); |
| 406 | + double getVersionValue() { |
| 407 | + if (Double.isNaN(versionValue)) { |
| 408 | + String versionString = getVersion(); |
| 409 | + Matcher matcher = VERSION_PATTERN.matcher(versionString); |
| 410 | + if (matcher.matches()) { |
| 411 | + String str = matcher.group(1); |
| 412 | + versionValue = Double.parseDouble(str); |
| 413 | + } else { |
| 414 | + log(Level.SEVERE, "Failed to parse OpenCL version: '" + versionString + "'"); |
| 415 | + } |
| 416 | + } |
| 417 | + return versionValue; |
| 418 | + } |
| 419 | + void requireMinVersionValue(String feature, double minValue) { |
| 420 | + requireMinVersionValue(feature, minValue, Double.NaN); |
| 421 | + } |
| 422 | + void requireMinVersionValue(String feature, double minValue, double deprecationValue) { |
| 423 | + double value = getVersionValue(); |
| 424 | + if (value < minValue) { |
| 425 | + throw new CLVersionException(feature + " requires OpenCL version " + minValue + |
| 426 | + " (detected version is " + value + ")"); |
| 427 | + } else if (!(value < deprecationValue)) { |
| 428 | + // The above test will work fine (i.e. will fail) with NaN. |
| 429 | + log(Level.WARNING, feature + " is deprecated from OpenCL version " + deprecationValue + |
| 430 | + " (detected version is " + value + ")"); |
| 431 | + } |
| 432 | + } |
| 433 | + |
400 | 434 | /** |
401 | 435 | * Platform name string. |
402 | 436 | */ |
@@ -463,7 +497,8 @@ public boolean isGLSharingSupported() { |
463 | 497 | */ |
464 | 498 | @Deprecated |
465 | 499 | public void unloadPlatformCompiler() { |
466 | | - return clUnloadPlatformCompiler(getEntity()); |
| 500 | + requireMinVersionValue("clUnloadPlatformCompiler", 1.1, 1.2); |
| 501 | + error(CL.clUnloadPlatformCompiler(getEntity())); |
467 | 502 | } |
468 | 503 |
|
469 | 504 | } |
0 commit comments