Line data Source code
1 : #pragma once
2 :
3 : #include "definition.hpp"
4 :
5 : #ifdef WITH_NNUE
6 :
7 : #include <algorithm>
8 : #include <array>
9 : #include <cmath>
10 : #include <cstring>
11 : #include <filesystem>
12 : #include <fstream>
13 : #include <iostream>
14 : #include <string>
15 : #include <utility>
16 :
17 : #ifdef USE_SIMD_INTRIN
18 : #include "simd.hpp" // manual simd implementations
19 : #endif
20 :
21 : // NNUE implementation was initially taken from Seer implementation in October 2020.
22 : // see https://github.com/connormcmonigle/seer-nnue
23 :
24 : #define INCBIN_PREFIX
25 : #define INCBIN_STYLE INCBIN_STYLE_CAMEL
26 : #include "incbin.h"
27 :
28 : namespace nnue {
29 :
30 : #ifdef EMBEDDEDNNUEPATH
31 : namespace embedded {
32 : INCBIN_EXTERN(weightsFile);
33 : }
34 : #endif
35 :
36 : namespace FeatureIdx {
37 :
38 : inline constexpr size_t major = 64 * 12;
39 : inline constexpr size_t minor = 64;
40 :
41 : inline constexpr size_t usPawnOffset = 0;
42 : inline constexpr size_t usKnightOffset = usPawnOffset + minor;
43 : inline constexpr size_t usBishopOffset = usKnightOffset + minor;
44 : inline constexpr size_t usRookOffset = usBishopOffset + minor;
45 : inline constexpr size_t usQueenOffset = usRookOffset + minor;
46 : inline constexpr size_t usKingOffset = usQueenOffset + minor;
47 :
48 : inline constexpr size_t themPawnOffset = usKingOffset + minor;
49 : inline constexpr size_t themKnightOffset = themPawnOffset + minor;
50 : inline constexpr size_t themBishopOffset = themKnightOffset + minor;
51 : inline constexpr size_t themRookOffset = themBishopOffset + minor;
52 : inline constexpr size_t themQueenOffset = themRookOffset + minor;
53 : inline constexpr size_t themKingOffset = themQueenOffset + minor;
54 :
55 : [[nodiscard]] constexpr size_t usOffset(const Piece pt) {
56 159183857 : switch (pt) {
57 : case P_wp: return usPawnOffset;
58 : case P_wn: return usKnightOffset;
59 : case P_wb: return usBishopOffset;
60 : case P_wr: return usRookOffset;
61 : case P_wq: return usQueenOffset;
62 : case P_wk: return usKingOffset;
63 : default: return usPawnOffset;
64 : }
65 : }
66 :
67 : [[nodiscard]] constexpr size_t themOffset(const Piece pt) {
68 16946148 : switch (pt) {
69 : case P_wp: return themPawnOffset;
70 : case P_wn: return themKnightOffset;
71 : case P_wb: return themBishopOffset;
72 : case P_wr: return themRookOffset;
73 : case P_wq: return themQueenOffset;
74 : case P_wk: return themKingOffset;
75 : default: return themPawnOffset;
76 : }
77 : }
78 :
79 : } // namespace FeatureIdx
80 :
81 : #include "evaluator.hpp"
82 :
83 : } // namespace nnue
84 :
85 : #endif // WITH_NNUE
|