Skip to content

Commit

Permalink
Enable SIMD on java 21
Browse files Browse the repository at this point in the history
  • Loading branch information
kev626 committed Jul 6, 2024
1 parent 1f3ad02 commit b1ab664
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions patches/api/0004-Add-SIMD-utilities.patch
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ and API spec stability is NOT guaranteed. If you use this in plugins,
they WILL break eventually.

diff --git a/build.gradle.kts b/build.gradle.kts
index f499b87fcecc01078e1316850d5edf9b8a6c5360..80833c13a2d19e31d6f648e7ef5b3456025e767e 100644
index 1961ce5188d69ab4db860de64cc1bde60c6e2289..9164120d299d062c62529a7ef74eac0ded367993 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -110,6 +110,13 @@ val generateApiVersioningFile by tasks.registering {
Expand All @@ -27,7 +27,7 @@ index f499b87fcecc01078e1316850d5edf9b8a6c5360..80833c13a2d19e31d6f648e7ef5b3456
into("META-INF/maven/${project.group}/${project.name}")
diff --git a/src/main/java/gg/pufferfish/pufferfish/simd/SIMDChecker.java b/src/main/java/gg/pufferfish/pufferfish/simd/SIMDChecker.java
new file mode 100644
index 0000000000000000000000000000000000000000..ab5fea0b03224bf249352ce340e94704ff713345
index 0000000000000000000000000000000000000000..3441cdad70da1bd523c5933b1a914688718c2657
--- /dev/null
+++ b/src/main/java/gg/pufferfish/pufferfish/simd/SIMDChecker.java
@@ -0,0 +1,40 @@
Expand All @@ -48,7 +48,7 @@ index 0000000000000000000000000000000000000000..ab5fea0b03224bf249352ce340e94704
+ @Deprecated
+ public static boolean canEnable(Logger logger) {
+ try {
+ if (SIMDDetection.getJavaVersion() != 17 && SIMDDetection.getJavaVersion() != 18 && SIMDDetection.getJavaVersion() != 19) {
+ if (SIMDDetection.getJavaVersion() < 17 || SIMDDetection.getJavaVersion() > 21) {
+ return false;
+ } else {
+ SIMDDetection.testRun = true;
Expand Down
8 changes: 4 additions & 4 deletions patches/server/0004-Add-SIMD-utilities.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Subject: [PATCH] Add SIMD utilities


diff --git a/build.gradle.kts b/build.gradle.kts
index 869db984d1bdf851ee46ae078c94f0b8230c9e18..e5f6b7897afa18f73b561c97819b4a2adba56f71 100644
index 80548cbe3ffa1ed205e927c64fc0946f3fe2a9bb..ef2810db890e5f36fb5681e993d7474638db34a7 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -70,6 +70,14 @@ dependencies {
Expand All @@ -24,7 +24,7 @@ index 869db984d1bdf851ee46ae078c94f0b8230c9e18..e5f6b7897afa18f73b561c97819b4a2a
archiveClassifier.set("dev")

diff --git a/src/main/java/gg/pufferfish/pufferfish/PufferfishConfig.java b/src/main/java/gg/pufferfish/pufferfish/PufferfishConfig.java
index deb52c185705c4b4186c7bae02f2a827620c20ca..d1a8bfb29817d2b73689713b4d5f04d7f2c0eaf4 100644
index deb52c185705c4b4186c7bae02f2a827620c20ca..84389e2e01b4e548ef402044f1f05db887d829bf 100644
--- a/src/main/java/gg/pufferfish/pufferfish/PufferfishConfig.java
+++ b/src/main/java/gg/pufferfish/pufferfish/PufferfishConfig.java
@@ -1,5 +1,6 @@
Expand All @@ -42,15 +42,15 @@ index deb52c185705c4b4186c7bae02f2a827620c20ca..d1a8bfb29817d2b73689713b4d5f04d7
+ // Attempt to detect vectorization
+ try {
+ SIMDDetection.isEnabled = SIMDDetection.canEnable(PufferfishLogger.LOGGER);
+ SIMDDetection.versionLimited = SIMDDetection.getJavaVersion() != 17 && SIMDDetection.getJavaVersion() != 18 && SIMDDetection.getJavaVersion() != 19;
+ SIMDDetection.versionLimited = SIMDDetection.getJavaVersion() < 17 || SIMDDetection.getJavaVersion() > 21;
+ } catch (NoClassDefFoundError | Exception ignored) {
+ ignored.printStackTrace();
+ }
+
+ if (SIMDDetection.isEnabled) {
+ PufferfishLogger.LOGGER.info("SIMD operations detected as functional. Will replace some operations with faster versions.");
+ } else if (SIMDDetection.versionLimited) {
+ PufferfishLogger.LOGGER.warning("Will not enable SIMD! These optimizations are only safely supported on Java 17, Java 18, and Java 19.");
+ PufferfishLogger.LOGGER.warning("Will not enable SIMD! These optimizations are only safely supported on Java 17-21.");
+ } else {
+ PufferfishLogger.LOGGER.warning("SIMD operations are available for your server, but are not configured!");
+ PufferfishLogger.LOGGER.warning("To enable additional optimizations, add \"--add-modules=jdk.incubator.vector\" to your startup flags, BEFORE the \"-jar\".");
Expand Down

0 comments on commit b1ab664

Please sign in to comment.