mirror of
https://github.com/Dreeam-qwq/Gale.git
synced 2025-12-20 15:29:30 +00:00
140 lines
7.0 KiB
Diff
140 lines
7.0 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Martijn Muijsers <martijnmuijsers@live.nl>
|
|
Date: Thu, 24 Nov 2022 01:19:12 +0100
|
|
Subject: [PATCH] SIMD support
|
|
|
|
License: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
|
|
Gale - https://galemc.org
|
|
|
|
This patch is based on the following patch:
|
|
"Add SIMD utilities"
|
|
By: Kevin Raneri <kevin.raneri@gmail.com>
|
|
As part of: Pufferfish (https://github.com/pufferfish-gg/Pufferfish)
|
|
Licensed under: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
|
|
|
|
diff --git a/build.gradle.kts b/build.gradle.kts
|
|
index 8f97350aac2f19a0d19e35630261dacc7b46ce52..13d1908b378e5311d8bb7f9317b4b1c2d82ea042 100644
|
|
--- a/build.gradle.kts
|
|
+++ b/build.gradle.kts
|
|
@@ -73,6 +73,7 @@ tasks.withType<JavaCompile> {
|
|
compilerArgs.add("-Xlint:-module")
|
|
compilerArgs.add("-Xlint:-removal")
|
|
compilerArgs.add("-Xlint:-dep-ann")
|
|
+ compilerArgs.add("--add-modules=jdk.incubator.vector") // Gale - Pufferfish - SIMD support
|
|
}
|
|
// Gale end - hide irrelevant compilation warnings
|
|
|
|
@@ -182,6 +183,7 @@ fun TaskContainer.registerRunTask(
|
|
minHeapSize = "${memoryGb}G"
|
|
maxHeapSize = "${memoryGb}G"
|
|
jvmArgs("--enable-preview") // Gale - enable preview features for development runs
|
|
+ jvmArgs("--add-modules=jdk.incubator.vector") // Gale - Pufferfish - SIMD support
|
|
|
|
doFirst {
|
|
workingDir.mkdirs()
|
|
diff --git a/src/main/java/com/destroystokyo/paper/Metrics.java b/src/main/java/com/destroystokyo/paper/Metrics.java
|
|
index 16ecdf3c56809100032ca627a1769e4e8c452f08..f921771c0aeba72f3f208703dbf300e8748ded17 100644
|
|
--- a/src/main/java/com/destroystokyo/paper/Metrics.java
|
|
+++ b/src/main/java/com/destroystokyo/paper/Metrics.java
|
|
@@ -928,6 +928,46 @@ public class Metrics {
|
|
metrics.addCustomChart(new Metrics.DrilldownPie("gale_semantic_version", () -> semanticVersionMap));
|
|
// Gale end - semantic version - include in metrics
|
|
|
|
+ // Gale start - SIMD support - include in metrics
|
|
+ Map<String, Map<String, Integer>> simdSupportMap = new HashMap<>(2); // Empty until initialized
|
|
+ metrics.addCustomChart(new Metrics.DrilldownPie("simd_support", () -> {
|
|
+ if (!gg.pufferfish.pufferfish.simd.SIMDDetection.isInitialized()) {
|
|
+ return null;
|
|
+ }
|
|
+ if (simdSupportMap.isEmpty()) {
|
|
+ // Initialize
|
|
+ boolean isEnabled = gg.pufferfish.pufferfish.simd.SIMDDetection.isEnabled();
|
|
+
|
|
+ // use details as lower dimension
|
|
+ Map<String, Integer> entry = new HashMap<>(2);
|
|
+ String details;
|
|
+ if (isEnabled) {
|
|
+ details = "int " + gg.pufferfish.pufferfish.simd.SIMDDetection.intVectorBitSize() + "*" + gg.pufferfish.pufferfish.simd.SIMDDetection.intElementSize() + ", float " + gg.pufferfish.pufferfish.simd.SIMDDetection.floatVectorBitSize() + "*" + gg.pufferfish.pufferfish.simd.SIMDDetection.floatElementSize();
|
|
+ } else {
|
|
+ if (!gg.pufferfish.pufferfish.simd.SIMDDetection.supportingJavaVersion()) {
|
|
+ details = "unsupported Java";
|
|
+ try {
|
|
+ var javaVersion = gg.pufferfish.pufferfish.simd.SIMDDetection.getJavaVersion();
|
|
+ details += " (" + javaVersion + ")";
|
|
+ } catch (Throwable ignored) {}
|
|
+ } else if (!gg.pufferfish.pufferfish.simd.SIMDDetection.testRunCompleted()) {
|
|
+ details = "test failed";
|
|
+ } else if (gg.pufferfish.pufferfish.simd.SIMDDetection.unsupportingLaneSize()) {
|
|
+ details = "no supporting lane size";
|
|
+ } else {
|
|
+ details = "other reason";
|
|
+ }
|
|
+ }
|
|
+ entry.put(details, 1);
|
|
+
|
|
+ // use enabled or not as higher dimension
|
|
+ simdSupportMap.put(String.valueOf(isEnabled), entry);
|
|
+
|
|
+ }
|
|
+ return simdSupportMap;
|
|
+ }));
|
|
+ // Gale end - SIMD support - include in metrics
|
|
+
|
|
}
|
|
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
|
|
index d42d6237831d500d0686b58abc4750896a1985c8..4fbdd8b1ead384762164c2d13180bfa230c40262 100644
|
|
--- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
|
|
+++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
|
|
@@ -20,6 +20,8 @@ import java.util.Locale;
|
|
import java.util.Optional;
|
|
import java.util.function.BooleanSupplier;
|
|
import javax.annotation.Nullable;
|
|
+
|
|
+import gg.pufferfish.pufferfish.simd.SIMDDetection;
|
|
import net.minecraft.DefaultUncaughtExceptionHandler;
|
|
import net.minecraft.DefaultUncaughtExceptionHandlerWithName;
|
|
import net.minecraft.SharedConstants;
|
|
@@ -58,6 +60,7 @@ import net.minecraft.world.level.GameType;
|
|
import net.minecraft.world.level.block.entity.SkullBlockEntity;
|
|
import net.minecraft.world.level.storage.LevelStorageSource;
|
|
import org.galemc.gale.command.GaleCommands;
|
|
+import org.galemc.gale.configuration.GaleGlobalConfiguration;
|
|
import org.slf4j.Logger;
|
|
|
|
// CraftBukkit start
|
|
@@ -244,6 +247,13 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
|
|
com.destroystokyo.paper.Metrics.PaperMetrics.startMetrics(); // Paper - start metrics
|
|
com.destroystokyo.paper.VersionHistoryManager.INSTANCE.getClass(); // Paper - load version history now
|
|
|
|
+ // Gale start - Pufferfish - SIMD support
|
|
+ // Initialize vectorization
|
|
+ try {
|
|
+ SIMDDetection.initialize();
|
|
+ } catch (Throwable ignored) {}
|
|
+ // Gale start - Pufferfish - SIMD support
|
|
+
|
|
this.setPvpAllowed(dedicatedserverproperties.pvp);
|
|
this.setFlightAllowed(dedicatedserverproperties.allowFlight);
|
|
this.setMotd(dedicatedserverproperties.motd);
|
|
diff --git a/src/main/java/org/galemc/gale/configuration/GaleGlobalConfiguration.java b/src/main/java/org/galemc/gale/configuration/GaleGlobalConfiguration.java
|
|
index 2a3cd1baab364126d10a42c8ab59f3da8ca9bdfb..5ade5d2ff3a68cf9e0240fc86e4b63432cb899c0 100644
|
|
--- a/src/main/java/org/galemc/gale/configuration/GaleGlobalConfiguration.java
|
|
+++ b/src/main/java/org/galemc/gale/configuration/GaleGlobalConfiguration.java
|
|
@@ -25,6 +25,14 @@ public class GaleGlobalConfiguration extends ConfigurationPart {
|
|
|
|
public int dummyValue = 0;
|
|
|
|
+ // Gale start - Pufferfish - SIMD support
|
|
+ public Simd simd;
|
|
+ public class Simd extends ConfigurationPart {
|
|
+ public boolean warnIfDisabled = true;
|
|
+ public boolean logVectorSizesToConsole = false;
|
|
+ }
|
|
+ // Gale end - Pufferfish - SIMD support
|
|
+
|
|
}
|
|
|
|
public Misc misc;
|