Skip to content

Commit

Permalink
cmakelist update
Browse files Browse the repository at this point in the history
  • Loading branch information
Disservin committed May 30, 2024
1 parent 8f51a65 commit d239b16
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
40 changes: 39 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.0)

project(training_data_loader)
project(training_data_loader CXX)

if(NOT DEFINED CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RelWithDebInfo)
Expand All @@ -13,6 +13,44 @@ set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g -O3 -march=native -DNDEBUG")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED 17)

include(CheckCXXCompilerFlag)

# Function to check if the CPU is AMD and not older than family 25
function(check_amd_family_25_or_newer)
execute_process(
COMMAND awk "/^vendor_id/{{print \$3; exit}}" /proc/cpuinfo
OUTPUT_VARIABLE VENDOR_ID
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND awk "/^cpu family/{{print \$4; exit}}" /proc/cpuinfo
OUTPUT_VARIABLE CPU_FAMILY
OUTPUT_STRIP_TRAILING_WHITESPACE
)

if(VENDOR_ID STREQUAL "AuthenticAMD" AND CPU_FAMILY GREATER_EQUAL "25")
set(CPU_AMD_FAMILY_25_OR_NEWER TRUE PARENT_SCOPE)
else()
set(CPU_AMD_FAMILY_25_OR_NEWER FALSE PARENT_SCOPE)
endif()
endfunction()

# Call the function to check if the CPU is AMD and not older than family 25
check_amd_family_25_or_newer()

# Check for BMI2 support
check_cxx_compiler_flag("-mbmi2" COMPILER_SUPPORTS_BMI2)
if(COMPILER_SUPPORTS_BMI2)
if(CPU_AMD_FAMILY_25_OR_NEWER OR NOT VENDOR_ID STREQUAL "AuthenticAMD")
message(STATUS "Adding BMI2 support")
add_definitions(-DHAS_BMI2)
else()
message(STATUS "CPU is older than AMD family 25, not adding BMI2 support")
endif()
else()
message(FATAL_ERROR "Compiler does not support BMI2")
endif()

add_library(training_data_loader SHARED training_data_loader.cpp)

find_package(Threads REQUIRED)
Expand Down
4 changes: 2 additions & 2 deletions lib/nnue_training_data_formats.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <mutex>
#include <random>

#ifdef __BMI2__
#ifdef HAS_BMI2
#include <immintrin.h> // _pdep_u64
#endif

Expand Down Expand Up @@ -267,7 +267,7 @@ namespace chess

inline int nthSetBitIndex(std::uint64_t v, std::uint64_t n)
{
#ifdef __BMI2__
#ifdef HAS_BMI2
return intrin::msb(_pdep_u64(1ULL << n, v));
#endif

Expand Down

0 comments on commit d239b16

Please sign in to comment.