Skip to content

Commit

Permalink
Improved network, released v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Timmoth committed Sep 23, 2024
1 parent 31e2137 commit df13d30
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 252 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release-pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
13 changes: 0 additions & 13 deletions Sapling.Engine/BoardState.cs
Original file line number Diff line number Diff line change
@@ -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<int>;
using VectorShort = System.Runtime.Intrinsics.Vector512<short>;
#else
using AvxIntrinsics = Avx2;
using VectorType = Vector256;
using VectorInt = Vector256<int>;
using VectorShort = Vector256<short>;
#endif

using System.Runtime.InteropServices;

Expand Down
12 changes: 0 additions & 12 deletions Sapling.Engine/BoardStateExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>;
using VectorShort = System.Runtime.Intrinsics.Vector512<short>;
#else
using AvxIntrinsics = Avx2;
using VectorType = Vector256;
using VectorInt = Vector256<int>;
using VectorShort = Vector256<short>;
#endif

public static class BoardStateExtensions
{
Expand Down
14 changes: 0 additions & 14 deletions Sapling.Engine/Evaluation/NnueEvaluator.cs
Original file line number Diff line number Diff line change
@@ -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<int>;
using VectorShort = System.Runtime.Intrinsics.Vector512<short>;
#else
using AvxIntrinsics = Avx2;
using VectorType = Vector256;
using VectorInt = Vector256<int>;
using VectorShort = Vector256<short>;
#endif

public static unsafe class NnueEvaluator
{
#if AVX512
Expand Down
174 changes: 1 addition & 173 deletions Sapling.Engine/Evaluation/NnueWeights.cs
Original file line number Diff line number Diff line change
@@ -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<int>;
using VectorShort = System.Runtime.Intrinsics.Vector512<short>;
#else
using AvxIntrinsics = Avx2;
using VectorType = Vector256;
using VectorInt = Vector256<int>;
using VectorShort = Vector256<short>;
#endif

public static class NnueWeights
{
public const int InputSize = 768;
Expand Down Expand Up @@ -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<int>;
//using VectorShort = System.Runtime.Intrinsics.Vector512<short>;
//#else
//using AvxIntrinsics = Avx2;
//using VectorType = Vector256;
//using VectorInt = Vector256<int>;
//using VectorShort = Vector256<short>;
//#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);
// }
// }
//}
}
12 changes: 12 additions & 0 deletions Sapling.Engine/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -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<int>;
global using VectorShort = System.Runtime.Intrinsics.Vector512<short>;
#else
global using AvxIntrinsics = System.Runtime.Intrinsics.X86.Avx2;
global using VectorType = System.Runtime.Intrinsics.Vector256;
global using VectorInt = System.Runtime.Intrinsics.Vector256<int>;
global using VectorShort = System.Runtime.Intrinsics.Vector256<short>;
#endif
Binary file not shown.
8 changes: 8 additions & 0 deletions Sapling.Engine/Resources/WeightsHistory/log.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Binary file modified Sapling.Engine/Resources/sapling.nnue
Binary file not shown.
11 changes: 0 additions & 11 deletions Sapling.Engine/Search/NegaMaxSearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>;
using VectorShort = System.Runtime.Intrinsics.Vector512<short>;
#else
using AvxIntrinsics = Avx2;
using VectorType = Vector256;
using VectorInt = Vector256<int>;
using VectorShort = Vector256<short>;
#endif

public partial class Searcher
{
Expand Down
12 changes: 0 additions & 12 deletions Sapling.Engine/Search/QuiescenceSearch.cs
Original file line number Diff line number Diff line change
@@ -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<int>;
using VectorShort = System.Runtime.Intrinsics.Vector512<short>;
#else
using AvxIntrinsics = Avx2;
using VectorType = Vector256;
using VectorInt = Vector256<int>;
using VectorShort = Vector256<short>;
#endif

public partial class Searcher
{
Expand Down
13 changes: 0 additions & 13 deletions Sapling.Engine/Search/Searcher.cs
Original file line number Diff line number Diff line change
@@ -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<int>;
using VectorShort = System.Runtime.Intrinsics.Vector512<short>;
#else
using AvxIntrinsics = Avx2;
using VectorType = Vector256;
using VectorInt = Vector256<int>;
using VectorShort = Vector256<short>;
#endif

public unsafe partial class Searcher
{
Expand Down
6 changes: 3 additions & 3 deletions Sapling/Sapling.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
<Nullable>enable</Nullable>
<ApplicationIcon>logo.ico</ApplicationIcon>
<Title>Sapling</Title>
<AssemblyVersion>1.0.5.0</AssemblyVersion>
<FileVersion>1.0.5.0</FileVersion>
<Version>1.0.5.0</Version>
<AssemblyVersion>1.1.0.0</AssemblyVersion>
<FileVersion>1.1.0.0</FileVersion>
<Version>1.1.0.0</Version>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

Expand Down

0 comments on commit df13d30

Please sign in to comment.