Alex2262 / AltairChessEngine

A strong chess engine made in c++
MIT License
56 stars 5 forks source link

Embedded Network #160

Closed Negatil07 closed 8 months ago

Negatil07 commented 8 months ago

How do I compile with an embedded network and with PGO build?

Alex2262 commented 8 months ago

Sorry for the late response.

Altair is automatically built with an embedded network, solaris-net currently.

PGO was recently removed from Altair due to some issues in testing; however, by copying the makefile from a commit such as cc4154b706e6e74f4641bc260832b35c3c194a9d, you can build PGO with make by default.

The makefile in one of these commits with PGO:


# engine name
EXE      = Altair

SOURCES      := src/evaluation.cpp src/main.cpp src/move.cpp src/perft.cpp src/position.cpp src/search.cpp \
                src/useful.cpp src/uci.cpp src/bench.cpp src/see.cpp src/bitboard.cpp src/move_ordering.cpp \
                src/datagen.cpp src/nnue.cpp

CXXFLAGS     := -O3 -std=c++20 -march=native -Wall -Wextra -pedantic -DNDEBUG -flto

CXX          := clang++
SUFFIX       :=

PGO := true

LLVM_PROF_CMD = llvm-profdata

ifeq ($(native),1)
    CXXFLAGS += -march=native

    ifeq (,$(shell where llvm-profdata))
        override PGO := off
    endif
endif

# Detect Windows
ifeq ($(OS), Windows_NT)
    SUFFIX   := .exe
    CXXFLAGS += -static
    CXXFLAGS += -fuse-ld=lld
else

    DETECTED_OS := $(shell uname -s)
    ifneq (,$(findstring clang,$(shell $(CXX) --version)))
        ifneq ($(DETECTED_OS), Darwin)
            CXXFLAGS += -fuse-ld=lld

            ifeq (,$(shell which llvm-profdata))
                override PGO := false
            endif
        else
            LLVM_PROF_CMD = xcrun llvm-profdata
        endif
    else
        override PGO := false
    endif
    CXXFLAGS += -pthread

endif

OUT := $(EXE)$(SUFFIX)

make:

ifeq ($(PGO), true)

    $(CXX) $(CXXFLAGS) -fprofile-instr-generate -o $(OUT) $(SOURCES)

ifeq ($(OS), Windows_NT)
    $(OUT) bench
else
    ./$(OUT) bench
endif

    $(LLVM_PROF_CMD) merge -output="Altair.profdata" *.profraw
    $(CXX) $(CXXFLAGS) -o $(OUT) $(SOURCES) -fprofile-instr-use="Altair.profdata"
    rm "Altair.profdata"
    rm *.profraw

else
    $(CXX) $(CXXFLAGS) -o $(OUT) $(SOURCES)
endif

basic:
    $(CXX) $(CXXFLAGS) -o $(OUT) $(SOURCES)

clean:
    rm -rf *.o