src/policy.cpp runs the network train/policy writes: 3072 threat inputs (side to move's view, flipped horizontally when its king is on files e-h, +768 attacked, +1536 defended), a hidden layer with CReLU and pairwise product, and one output row per move, i8 weights scaled by 128. The hidden width is read from the file's size, so any trained width loads. When a network is loaded, eval::policy uses its logits plus the butterfly-history bias instead of the move heuristics; the temperature and softmax are unchanged. A network is built in with make POLICYFILE=<net> (default: none, so the engine plays as before) or loaded at runtime with the UCI option PolicyFile. policyfens prints the priors of the trainer's --check positions. Checked: with a smoke-trained network policyfens matches the trainer's float output to a few tenths of a percent in all six positions (black to move, mirrored king, castling, promotion). Speed with a network: -13% nps at 512 hidden, -41% at 2048. A zero network built in with POLICYFILE gives uniform priors. Without a network the bench is unchanged. Bench: 529903 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
96 lines
2.1 KiB
Makefile
96 lines
2.1 KiB
Makefile
# Rigby - MCTS chess engine
|
|
# OpenBench calls: make EXE=<name> [EVALFILE=<net>] [CXX=<compiler>]
|
|
# A policy network is built in with POLICYFILE=<net> (default: none).
|
|
|
|
SRC_DIR := src
|
|
OBJ_DIR := obj
|
|
|
|
EXE ?= Rigby
|
|
# The value network embedded into the binary
|
|
EVALFILE ?= networks/rigby-value-v1.bin
|
|
# The policy network embedded into the binary; none means move heuristics
|
|
POLICYFILE ?=
|
|
CXX ?= clang++
|
|
ifeq ($(origin CXX),default)
|
|
CXX := clang++
|
|
endif
|
|
|
|
ifeq ($(OS),Windows_NT)
|
|
EXE_EXT := .exe
|
|
PLATFORM := windows
|
|
else
|
|
EXE_EXT :=
|
|
UNAME_S := $(shell uname -s)
|
|
ARCH := $(shell uname -m)
|
|
ifeq ($(UNAME_S),Darwin)
|
|
PLATFORM := mac
|
|
else
|
|
PLATFORM := unix
|
|
endif
|
|
endif
|
|
|
|
CXXFLAGS := -std=c++20 -O3 -flto -Wall -Wextra -DNDEBUG -Iexternal
|
|
LDFLAGS := -O3 -flto
|
|
|
|
ifeq ($(PLATFORM),windows)
|
|
ARCH_FLAGS := -march=native
|
|
# clang on Windows defaults to MSVC; use the MinGW runtime like Eleanor does.
|
|
ifneq ($(findstring clang,$(CXX)),)
|
|
CXXFLAGS += --target=x86_64-w64-windows-gnu
|
|
LDFLAGS += --target=x86_64-w64-windows-gnu
|
|
endif
|
|
CXXFLAGS += -pthread
|
|
LDFLAGS += -pthread -static
|
|
else ifeq ($(PLATFORM),mac)
|
|
ifeq ($(ARCH),arm64)
|
|
ARCH_FLAGS := -mcpu=apple-m1
|
|
else
|
|
ARCH_FLAGS := -march=native
|
|
endif
|
|
CXXFLAGS += -pthread
|
|
LDFLAGS += -pthread
|
|
else
|
|
ifeq ($(ARCH),aarch64)
|
|
ARCH_FLAGS := -mcpu=native
|
|
else
|
|
ARCH_FLAGS := -march=native
|
|
endif
|
|
CXXFLAGS += -pthread
|
|
LDFLAGS += -pthread -static
|
|
endif
|
|
|
|
CXXFLAGS += -DEVALFILE=\"$(EVALFILE)\"
|
|
ifneq ($(POLICYFILE),)
|
|
CXXFLAGS += -DPOLICYFILE=\"$(POLICYFILE)\"
|
|
endif
|
|
|
|
CXXFLAGS += $(ARCH_FLAGS)
|
|
LDFLAGS += $(ARCH_FLAGS)
|
|
|
|
SRCS := $(wildcard $(SRC_DIR)/*.cpp)
|
|
OBJS := $(patsubst $(SRC_DIR)/%.cpp,$(OBJ_DIR)/%.o,$(SRCS))
|
|
DEPS := $(OBJS:.o=.d)
|
|
|
|
MAKEFLAGS += -j
|
|
|
|
$(EXE)$(EXE_EXT): $(OBJS)
|
|
$(CXX) $^ -o $@ $(LDFLAGS)
|
|
|
|
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp | $(OBJ_DIR)
|
|
$(CXX) $(CXXFLAGS) -MMD -MP -c -o $@ $<
|
|
|
|
$(OBJ_DIR):
|
|
mkdir $(OBJ_DIR)
|
|
|
|
# Rebuild the network's translation unit when the network changes
|
|
$(OBJ_DIR)/nnue.o: $(EVALFILE)
|
|
ifneq ($(POLICYFILE),)
|
|
$(OBJ_DIR)/policy.o: $(POLICYFILE)
|
|
endif
|
|
|
|
-include $(DEPS)
|
|
|
|
.PHONY: clean
|
|
clean:
|
|
rm -rf $(OBJ_DIR) $(EXE)$(EXE_EXT)
|