From 74b6fa0b645d13403786d056364ea7483c9ad65b Mon Sep 17 00:00:00 2001 From: rektdie Date: Thu, 10 Apr 2025 03:32:02 +0200 Subject: [PATCH 1/4] makefile fix --- Makefile | 28 ++++++++++++---------------- source/board.h | 4 ++-- source/search.cpp | 14 +++++++------- source/search.h | 10 +++++----- source/stopwatch.h | 10 +++++----- source/tt.h | 4 ++-- 6 files changed, 33 insertions(+), 37 deletions(-) diff --git a/Makefile b/Makefile index 13d387a..7eb18e8 100644 --- a/Makefile +++ b/Makefile @@ -1,16 +1,11 @@ -# Define the directories +# Define directories SRC_DIR := source OBJ_DIR := obj -# Set default C++ compiler, but allow override from the command line CXX ?= g++ - -# Set default executable name, but allow override from the command line EXE ?= Eleanor +EVALFILE := ./nnue.bin -EVALFILE = ./nnue.bin - -# Determine platform ifeq ($(OS),Windows_NT) EXE_EXT := .exe MKDIR := mkdir @@ -25,29 +20,30 @@ endif MAKEFLAGS += -j -# List of source files +# Source and object files SRCS := $(wildcard $(SRC_DIR)/*.cpp) +OBJS := $(patsubst $(SRC_DIR)/%.cpp, $(OBJ_DIR)/%.o, $(SRCS)) -# Link the executable -$(EXE)$(EXE_EXT): $(SRCS) - $(CXX) $(CXXFLAGS) -DEVALFILE=\"$(EVALFILE)\" $(SRCS) ./external/fmt/format.cc -o $@ -O3 -lpthread -march=native -flto -ftree-vectorize +# Final binary +$(EXE)$(EXE_EXT): $(OBJS) + $(CXX) $(CXXFLAGS) -DEVALFILE=\"$(EVALFILE)\" $^ ./external/fmt/format.cc -o $@ -O3 -lpthread -march=native -flto -ftree-vectorize -# Rule to compile source files to object files +# Compile .cpp -> .o $(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp | $(OBJ_DIR) $(CXX) -std=c++23 -c -o $@ $< -O3 -lpthread -march=native -flto -ftree-vectorize -# Create the object directory if it doesn't exist +# Create object directory $(OBJ_DIR): $(MKDIR) $(OBJ_DIR) -# Clean up build artifacts +# Clean up and rebuild .PHONY: clean clean: ifeq ($(OS),Windows_NT) @if exist $(OBJ_DIR) $(RM) $(OBJ_DIR) @if exist $(EXE)$(EXE_EXT) $(DEL) $(EXE)$(EXE_EXT) else - @rm -rf $(OBJ_DIR) - @rm -f $(EXE)$(EXE_EXT) + @$(RM) $(OBJ_DIR) + @$(DEL) $(EXE)$(EXE_EXT) endif $(MAKE) diff --git a/source/board.h b/source/board.h index 9a95964..5ac1cbc 100644 --- a/source/board.h +++ b/source/board.h @@ -10,8 +10,8 @@ constexpr int noEPTarget = -1; constexpr int MAX_MOVES = 218; -thread_local inline int positionIndex = 0; -thread_local inline U64 positionHistory[1000]; +inline int positionIndex = 0; +inline U64 positionHistory[1000]; class Board { public: diff --git a/source/search.cpp b/source/search.cpp index 2b74cac..ebe253c 100644 --- a/source/search.cpp +++ b/source/search.cpp @@ -10,16 +10,16 @@ namespace SEARCH { -thread_local U64 nodes = 0; -thread_local U64 nodesToGo = 0; -thread_local bool benchStarted = false; +U64 nodes = 0; +U64 nodesToGo = 0; +bool benchStarted = false; -thread_local static inline int timeToSearch = 0; -thread_local static inline bool doingNullMove = false; +static inline int timeToSearch = 0; +static inline bool doingNullMove = false; -thread_local inline PVLine pvLine; +inline PVLine pvLine; -thread_local Stopwatch sw; +Stopwatch sw; void InitLMRTable() { for (int depth = 0; depth <= MAX_DEPTH; depth++) { diff --git a/source/search.h b/source/search.h index d90542f..4b31cdb 100644 --- a/source/search.h +++ b/source/search.h @@ -19,15 +19,15 @@ constexpr int MAX_DEPTH = 64; constexpr int MAX_PLY = 128; constexpr int MAX_HISTORY = 16384; -thread_local extern U64 nodes; -thread_local extern bool benchStarted; +extern U64 nodes; +extern bool benchStarted; constexpr int inf = 100000; -thread_local inline bool searchStopped = false; +inline bool searchStopped = false; // [id][ply] -thread_local inline int killerMoves[2][MAX_PLY]; +inline int killerMoves[2][MAX_PLY]; inline int lmrTable[MAX_DEPTH+1][MAX_MOVES]; @@ -75,7 +75,7 @@ public: } }; -thread_local inline History history; +inline History history; class PVLine { private: diff --git a/source/stopwatch.h b/source/stopwatch.h index fe47086..47ab088 100644 --- a/source/stopwatch.h +++ b/source/stopwatch.h @@ -3,20 +3,20 @@ class Stopwatch { private: - std::chrono::high_resolution_clock::time_point start = - std::chrono::high_resolution_clock::now(); + std::chrono::steady_clock::time_point start = + std::chrono::steady_clock::now(); public: void Restart() { - start = std::chrono::high_resolution_clock::now(); + start = std::chrono::steady_clock::now(); } int GetElapsedMS() { - auto current = std::chrono::high_resolution_clock::now(); + auto current = std::chrono::steady_clock::now(); return std::chrono::duration_cast(current - start).count(); } double GetElapsedSec() { - auto current = std::chrono::high_resolution_clock::now(); + auto current = std::chrono::steady_clock::now(); return std::chrono::duration_cast< std::chrono::duration>(current - start).count(); } diff --git a/source/tt.h b/source/tt.h index a6e4136..e8607c4 100644 --- a/source/tt.h +++ b/source/tt.h @@ -21,7 +21,7 @@ constexpr U64 maxHash = (64* 1000000) / sizeof(TTEntry); // 5 MB constexpr U64 defaultHash = (5 * 1000000) / sizeof(TTEntry); -thread_local inline U64 hashSize = defaultHash; +inline U64 hashSize = defaultHash; constexpr int invalidEntry = 111111; @@ -61,4 +61,4 @@ public: void WriteEntry(U64 &hashKey, int depth, int score, int nodeType, Move besteMove); }; -thread_local inline TTable TT; +inline TTable TT; From a957e46bdc40a4f313179ebfafbdf5f4df6efbf1 Mon Sep 17 00:00:00 2001 From: rektdie Date: Thu, 10 Apr 2025 06:04:47 +0200 Subject: [PATCH 2/4] using clang instead of g++ | bench 1857933 --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 7eb18e8..a9860ba 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ SRC_DIR := source OBJ_DIR := obj -CXX ?= g++ +CXX ?= clang++ EXE ?= Eleanor EVALFILE := ./nnue.bin @@ -26,11 +26,11 @@ OBJS := $(patsubst $(SRC_DIR)/%.cpp, $(OBJ_DIR)/%.o, $(SRCS)) # Final binary $(EXE)$(EXE_EXT): $(OBJS) - $(CXX) $(CXXFLAGS) -DEVALFILE=\"$(EVALFILE)\" $^ ./external/fmt/format.cc -o $@ -O3 -lpthread -march=native -flto -ftree-vectorize + $(CXX) $(CXXFLAGS) -DEVALFILE=\"$(EVALFILE)\" $^ ./external/fmt/format.cc -o $@ -O3 -march=native -fuse-ld=lld -flto # Compile .cpp -> .o $(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp | $(OBJ_DIR) - $(CXX) -std=c++23 -c -o $@ $< -O3 -lpthread -march=native -flto -ftree-vectorize + $(CXX) -std=c++23 -c -o $@ $< -O3 -march=native -fuse-ld=lld -flto # Create object directory $(OBJ_DIR): From a84cf720b9f16de65644984fd679c4e50ad48bf0 Mon Sep 17 00:00:00 2001 From: rektdie Date: Thu, 10 Apr 2025 06:09:35 +0200 Subject: [PATCH 3/4] fell back to c++20 | bench 1857933 --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index a9860ba..7b676d7 100644 --- a/Makefile +++ b/Makefile @@ -26,11 +26,11 @@ OBJS := $(patsubst $(SRC_DIR)/%.cpp, $(OBJ_DIR)/%.o, $(SRCS)) # Final binary $(EXE)$(EXE_EXT): $(OBJS) - $(CXX) $(CXXFLAGS) -DEVALFILE=\"$(EVALFILE)\" $^ ./external/fmt/format.cc -o $@ -O3 -march=native -fuse-ld=lld -flto + $(CXX) $(CXXFLAGS) -DEVALFILE=\"$(EVALFILE)\" $^ ./external/fmt/format.cc -o $@ -O3 -march=native -flto # Compile .cpp -> .o $(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp | $(OBJ_DIR) - $(CXX) -std=c++23 -c -o $@ $< -O3 -march=native -fuse-ld=lld -flto + $(CXX) -std=c++20 -c -o $@ $< -O3 -march=native -flto # Create object directory $(OBJ_DIR): From 4c2e932d15b8cfa0cbdfe6a29fcc2d04feabdb16 Mon Sep 17 00:00:00 2001 From: rektdie Date: Thu, 10 Apr 2025 06:16:27 +0200 Subject: [PATCH 4/4] final touches on makefile --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 7b676d7..9d74e96 100644 --- a/Makefile +++ b/Makefile @@ -26,11 +26,11 @@ OBJS := $(patsubst $(SRC_DIR)/%.cpp, $(OBJ_DIR)/%.o, $(SRCS)) # Final binary $(EXE)$(EXE_EXT): $(OBJS) - $(CXX) $(CXXFLAGS) -DEVALFILE=\"$(EVALFILE)\" $^ ./external/fmt/format.cc -o $@ -O3 -march=native -flto + $(CXX) $(CXXFLAGS) -DEVALFILE=\"$(EVALFILE)\" $^ ./external/fmt/format.cc -o $@ -O3 -fuse-ld=lld -march=native -flto -static # Compile .cpp -> .o $(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp | $(OBJ_DIR) - $(CXX) -std=c++20 -c -o $@ $< -O3 -march=native -flto + $(CXX) -std=c++20 -c -o $@ $< -O3 -march=native -fuse-ld=lld -flto -static # Create object directory $(OBJ_DIR):