diff --git a/.github/workflows/release-pipeline.yaml b/.github/workflows/release-pipeline.yaml index f1855a4..337226f 100644 --- a/.github/workflows/release-pipeline.yaml +++ b/.github/workflows/release-pipeline.yaml @@ -25,7 +25,7 @@ jobs: working-directory: Sapling id: get_version run: | - VERSION=1.0.5 + VERSION=1.1.0 echo "Application version: $VERSION" echo "::set-output name=version::$VERSION" diff --git a/Sapling.Engine/BoardState.cs b/Sapling.Engine/BoardState.cs index 6f5871c..977e6d1 100644 --- a/Sapling.Engine/BoardState.cs +++ b/Sapling.Engine/BoardState.cs @@ -1,19 +1,6 @@ using Sapling.Engine.Evaluation; -using System.Runtime.Intrinsics.X86; -using System.Runtime.Intrinsics; namespace Sapling.Engine; -#if AVX512 -using AvxIntrinsics = System.Runtime.Intrinsics.X86.Avx512BW; -using VectorType = System.Runtime.Intrinsics.Vector512; -using VectorInt = System.Runtime.Intrinsics.Vector512; -using VectorShort = System.Runtime.Intrinsics.Vector512; -#else -using AvxIntrinsics = Avx2; -using VectorType = Vector256; -using VectorInt = Vector256; -using VectorShort = Vector256; -#endif using System.Runtime.InteropServices; diff --git a/Sapling.Engine/BoardStateExtensions.cs b/Sapling.Engine/BoardStateExtensions.cs index a6e7772..62c5f1c 100644 --- a/Sapling.Engine/BoardStateExtensions.cs +++ b/Sapling.Engine/BoardStateExtensions.cs @@ -3,20 +3,8 @@ using Sapling.Engine.MoveGen; using Sapling.Engine.Pgn; using System.Runtime.Intrinsics.X86; -using System.Runtime.Intrinsics; namespace Sapling.Engine; -#if AVX512 -using AvxIntrinsics = System.Runtime.Intrinsics.X86.Avx512BW; -using VectorType = System.Runtime.Intrinsics.Vector512; -using VectorInt = System.Runtime.Intrinsics.Vector512; -using VectorShort = System.Runtime.Intrinsics.Vector512; -#else -using AvxIntrinsics = Avx2; -using VectorType = Vector256; -using VectorInt = Vector256; -using VectorShort = Vector256; -#endif public static class BoardStateExtensions { diff --git a/Sapling.Engine/Evaluation/NnueEvaluator.cs b/Sapling.Engine/Evaluation/NnueEvaluator.cs index 445fc05..fe254b6 100644 --- a/Sapling.Engine/Evaluation/NnueEvaluator.cs +++ b/Sapling.Engine/Evaluation/NnueEvaluator.cs @@ -1,21 +1,7 @@ using System.Runtime.CompilerServices; -using System.Runtime.Intrinsics; -using System.Runtime.Intrinsics.X86; namespace Sapling.Engine.Evaluation; -#if AVX512 -using AvxIntrinsics = System.Runtime.Intrinsics.X86.Avx512BW; -using VectorType = System.Runtime.Intrinsics.Vector512; -using VectorInt = System.Runtime.Intrinsics.Vector512; -using VectorShort = System.Runtime.Intrinsics.Vector512; -#else -using AvxIntrinsics = Avx2; -using VectorType = Vector256; -using VectorInt = Vector256; -using VectorShort = Vector256; -#endif - public static unsafe class NnueEvaluator { #if AVX512 diff --git a/Sapling.Engine/Evaluation/NnueWeights.cs b/Sapling.Engine/Evaluation/NnueWeights.cs index f0bf263..aa1cefe 100644 --- a/Sapling.Engine/Evaluation/NnueWeights.cs +++ b/Sapling.Engine/Evaluation/NnueWeights.cs @@ -1,22 +1,8 @@ using System.Reflection; using System.Runtime.InteropServices; -using System.Runtime.Intrinsics; -using System.Runtime.Intrinsics.X86; using System.Text; namespace Sapling.Engine.Evaluation; -#if AVX512 -using AvxIntrinsics = System.Runtime.Intrinsics.X86.Avx512BW; -using VectorType = System.Runtime.Intrinsics.Vector512; -using VectorInt = System.Runtime.Intrinsics.Vector512; -using VectorShort = System.Runtime.Intrinsics.Vector512; -#else -using AvxIntrinsics = Avx2; -using VectorType = Vector256; -using VectorInt = Vector256; -using VectorShort = Vector256; -#endif - public static class NnueWeights { public const int InputSize = 768; @@ -152,162 +138,4 @@ public static unsafe void Dispose() Marshal.FreeHGlobal((IntPtr)OutputWeights); } } -} - -//using System.Reflection; -//using System.Runtime.InteropServices; -//using System.Runtime.Intrinsics; -//using System.Runtime.Intrinsics.X86; -//using System.Text; - -//namespace Sapling.Engine.Evaluation; -//#if AVX512 -//using AvxIntrinsics = System.Runtime.Intrinsics.X86.Avx512BW; -//using VectorType = System.Runtime.Intrinsics.Vector512; -//using VectorInt = System.Runtime.Intrinsics.Vector512; -//using VectorShort = System.Runtime.Intrinsics.Vector512; -//#else -//using AvxIntrinsics = Avx2; -//using VectorType = Vector256; -//using VectorInt = Vector256; -//using VectorShort = Vector256; -//#endif - -//public static class NnueWeights -//{ -// public const int InputSize = 768; -// public const int Layer1Size = 768; - -// public const short OutputBuckets = 8; - -// public static readonly unsafe VectorShort* FeatureWeights; -// public static readonly unsafe VectorShort* FeatureBiases; -// public static readonly unsafe VectorShort* OutputWeights; -// public static readonly unsafe short* OutputBiases; - -// static unsafe NnueWeights() -// { -// var assembly = Assembly.GetAssembly(typeof(GameState)); -// var info = assembly.GetName(); -// var name = info.Name; -// using var stream = assembly -// .GetManifestResourceStream($"{name}.Resources.sapling.nnue")!; - -// var featureWeightsCount = InputSize * Layer1Size; -// var featureBiasesCount = Layer1Size; -// var outputWeightsCount = Layer1Size * 2 * OutputBuckets; -// var outputBiasesCount = OutputBuckets; - - -// var featureWeights = stackalloc short[featureWeightsCount]; -// var featureBiases = stackalloc short[featureBiasesCount]; -// var outputWeights = stackalloc short[outputWeightsCount]; -// var outputBiases = stackalloc short[outputBiasesCount]; - -// using var reader = new BinaryReader(stream, Encoding.UTF8, false); -// for (var i = 0; i < featureWeightsCount; i++) -// { -// featureWeights[i] = reader.ReadInt16(); -// } - -// for (var i = 0; i < featureBiasesCount; i++) -// { -// featureBiases[i] = reader.ReadInt16(); -// } - -// for (var i = 0; i < outputWeightsCount; i++) -// { -// outputWeights[i] = reader.ReadInt16(); -// } - -// var transposedWeights = stackalloc short[outputWeightsCount]; - -// // Transposing logic -// for (var i = 0; i < 2 * Layer1Size; i++) -// { -// for (var j = 0; j < OutputBuckets; j++) -// { -// // Original index calculation -// var originalIndex = i * OutputBuckets + j; - -// // Transposed index calculation -// var transposedIndex = j * 2 * Layer1Size + i; - -// // Assign value to transposed position -// transposedWeights[transposedIndex] = outputWeights[originalIndex]; -// } -// } - -// outputWeights = transposedWeights; - -// for (var i = 0; i < outputBiasesCount; i++) -// { -// outputBiases[i] = reader.ReadInt16(); -// } - -// // Allocate unmanaged memory -// FeatureWeights = AlignedAllocZeroedShort((nuint)featureWeightsCount); -// FeatureBiases = AlignedAllocZeroedShort((nuint)featureBiasesCount); -// OutputWeights = AlignedAllocZeroedShort((nuint)outputWeightsCount); -// OutputBiases = AlignedAllocZeroed((nuint)outputBiasesCount); - -// // Copy managed array to unmanaged memory -// Buffer.MemoryCopy(featureWeights, FeatureWeights, featureWeightsCount * sizeof(short), -// featureWeightsCount * sizeof(short)); - -// Buffer.MemoryCopy(featureBiases, FeatureBiases, featureBiasesCount * sizeof(short), -// featureBiasesCount * sizeof(short)); - -// Buffer.MemoryCopy(outputWeights, OutputWeights, outputWeightsCount * sizeof(short), -// outputWeightsCount * sizeof(short)); - -// Buffer.MemoryCopy(outputBiases, OutputBiases, outputBiasesCount * sizeof(short), -// outputBiasesCount * sizeof(short)); -// } - -// public static unsafe VectorShort* AlignedAllocZeroedShort(nuint items) -// { -// const nuint alignment = 64; -// var bytes = sizeof(short) * items; -// var block = NativeMemory.AlignedAlloc(bytes, alignment); -// if (block == null) -// { -// throw new OutOfMemoryException("Failed to allocate aligned memory."); -// } - -// NativeMemory.Clear(block, bytes); -// return (VectorShort*)block; -// } - -// public static unsafe short* AlignedAllocZeroed(nuint items) -// { -// const nuint alignment = 64; -// var bytes = sizeof(short) * items; -// var block = NativeMemory.AlignedAlloc(bytes, alignment); -// if (block == null) -// { -// throw new OutOfMemoryException("Failed to allocate aligned memory."); -// } - -// NativeMemory.Clear(block, bytes); -// return (short*)block; -// } - -// public static unsafe void Dispose() -// { -// if (FeatureWeights != null) -// { -// Marshal.FreeHGlobal((IntPtr)FeatureWeights); -// } - -// if (FeatureBiases != null) -// { -// Marshal.FreeHGlobal((IntPtr)FeatureBiases); -// } - -// if (OutputWeights != null) -// { -// Marshal.FreeHGlobal((IntPtr)OutputWeights); -// } -// } -//} \ No newline at end of file +} \ No newline at end of file diff --git a/Sapling.Engine/GlobalUsings.cs b/Sapling.Engine/GlobalUsings.cs new file mode 100644 index 0000000..458349d --- /dev/null +++ b/Sapling.Engine/GlobalUsings.cs @@ -0,0 +1,12 @@ +// GlobalUsings.cs +#if AVX512 +global using AvxIntrinsics = System.Runtime.Intrinsics.X86.Avx512BW; +global using VectorType = System.Runtime.Intrinsics.Vector512; +global using VectorInt = System.Runtime.Intrinsics.Vector512; +global using VectorShort = System.Runtime.Intrinsics.Vector512; +#else +global using AvxIntrinsics = System.Runtime.Intrinsics.X86.Avx2; +global using VectorType = System.Runtime.Intrinsics.Vector256; +global using VectorInt = System.Runtime.Intrinsics.Vector256; +global using VectorShort = System.Runtime.Intrinsics.Vector256; +#endif \ No newline at end of file diff --git a/Sapling.Engine/Resources/WeightsHistory/15_hl1024.bin b/Sapling.Engine/Resources/WeightsHistory/15_hl1024.bin new file mode 100644 index 0000000..470e8e5 Binary files /dev/null and b/Sapling.Engine/Resources/WeightsHistory/15_hl1024.bin differ diff --git a/Sapling.Engine/Resources/WeightsHistory/log.txt b/Sapling.Engine/Resources/WeightsHistory/log.txt index fb77a3b..a72dddb 100644 --- a/Sapling.Engine/Resources/WeightsHistory/log.txt +++ b/Sapling.Engine/Resources/WeightsHistory/log.txt @@ -125,4 +125,12 @@ SuperBatches: 180 Data: 1.3bn positions WDL: 0.4 LR: CosineDecayLR 0.001 * 0.3 * 0.3 * 0.3 +SuperBatches: 180 + +---------------------------------- +15_hl1024.bin +---------------------------------- +Data: 1bn positions +WDL: 0.4 +LR: CosineDecayLR 0.001 * 0.3 * 0.3 * 0.3 SuperBatches: 180 \ No newline at end of file diff --git a/Sapling.Engine/Resources/sapling.nnue b/Sapling.Engine/Resources/sapling.nnue index 65af6b3..470e8e5 100644 Binary files a/Sapling.Engine/Resources/sapling.nnue and b/Sapling.Engine/Resources/sapling.nnue differ diff --git a/Sapling.Engine/Search/NegaMaxSearch.cs b/Sapling.Engine/Search/NegaMaxSearch.cs index da09b05..ab72f3b 100644 --- a/Sapling.Engine/Search/NegaMaxSearch.cs +++ b/Sapling.Engine/Search/NegaMaxSearch.cs @@ -5,17 +5,6 @@ using Sapling.Engine.Transpositions; namespace Sapling.Engine.Search; -#if AVX512 -using AvxIntrinsics = System.Runtime.Intrinsics.X86.Avx512BW; -using VectorType = System.Runtime.Intrinsics.Vector512; -using VectorInt = System.Runtime.Intrinsics.Vector512; -using VectorShort = System.Runtime.Intrinsics.Vector512; -#else -using AvxIntrinsics = Avx2; -using VectorType = Vector256; -using VectorInt = Vector256; -using VectorShort = Vector256; -#endif public partial class Searcher { diff --git a/Sapling.Engine/Search/QuiescenceSearch.cs b/Sapling.Engine/Search/QuiescenceSearch.cs index 804b654..46b334f 100644 --- a/Sapling.Engine/Search/QuiescenceSearch.cs +++ b/Sapling.Engine/Search/QuiescenceSearch.cs @@ -1,23 +1,11 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using System.Runtime.Intrinsics; using System.Runtime.Intrinsics.X86; using Sapling.Engine.Evaluation; using Sapling.Engine.MoveGen; using Sapling.Engine.Transpositions; namespace Sapling.Engine.Search; -#if AVX512 -using AvxIntrinsics = System.Runtime.Intrinsics.X86.Avx512BW; -using VectorType = System.Runtime.Intrinsics.Vector512; -using VectorInt = System.Runtime.Intrinsics.Vector512; -using VectorShort = System.Runtime.Intrinsics.Vector512; -#else -using AvxIntrinsics = Avx2; -using VectorType = Vector256; -using VectorInt = Vector256; -using VectorShort = Vector256; -#endif public partial class Searcher { diff --git a/Sapling.Engine/Search/Searcher.cs b/Sapling.Engine/Search/Searcher.cs index 14cd84d..aa0b282 100644 --- a/Sapling.Engine/Search/Searcher.cs +++ b/Sapling.Engine/Search/Searcher.cs @@ -1,22 +1,9 @@ using System.Runtime.InteropServices; -using System.Runtime.Intrinsics; -using System.Runtime.Intrinsics.X86; using System.Text; using Sapling.Engine.MoveGen; using Sapling.Engine.Transpositions; namespace Sapling.Engine.Search; -#if AVX512 -using AvxIntrinsics = System.Runtime.Intrinsics.X86.Avx512BW; -using VectorType = System.Runtime.Intrinsics.Vector512; -using VectorInt = System.Runtime.Intrinsics.Vector512; -using VectorShort = System.Runtime.Intrinsics.Vector512; -#else -using AvxIntrinsics = Avx2; -using VectorType = Vector256; -using VectorInt = Vector256; -using VectorShort = Vector256; -#endif public unsafe partial class Searcher { diff --git a/Sapling/Sapling.csproj b/Sapling/Sapling.csproj index 5b9549e..db702ab 100644 --- a/Sapling/Sapling.csproj +++ b/Sapling/Sapling.csproj @@ -7,9 +7,9 @@ enable logo.ico Sapling - 1.0.5.0 - 1.0.5.0 - 1.0.5.0 + 1.1.0.0 + 1.1.0.0 + 1.1.0.0 true