Skip to content

Commit b8a6f7e

Browse files
authored
Fix benchmarks failing and adjust compilation flags (#118)
1 parent c3be472 commit b8a6f7e

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

asv.conf.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
"/usr/bin/sed -i '$ a\include voyager/version.py' {build_dir}/python/MANIFEST.in",
1212
"in-dir={build_dir}/python python -m build",
1313
"/usr/bin/cp -r {build_dir}/python/dist/. {build_cache_dir}"
14-
],
14+
],
15+
"install_command": [
16+
"in-dir={env_dir} python -mpip install {wheel_file} numpy"
17+
],
1518
"benchmark_dir": "benchmarks",
1619
"env_dir": ".asv/env",
1720
"results_dir": ".asv/results",

java/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ ifeq ($(UNAME_S),Linux)
1717
CXX := g++
1818
JAVA_INC := $(JAVA_HOME)/include $(JAVA_HOME)/include/linux
1919
ALL_OBJS := target/classes/linux-x64/$(LINUX_SOBJ) target/classes/linux-aarch64/$(LINUX_SOBJ)
20-
CXXFLAGS := -I. -lc -shared -std=c++17 -I ./include $(addprefix -I,$(JAVA_INC)) -I $(CPP_SRC_DIR) -fPIC -O3
20+
CXXFLAGS := -I. -lc -shared -std=c++17 -I ./include $(addprefix -I,$(JAVA_INC)) -I $(CPP_SRC_DIR) -fPIC -O3 -fassociative-math -fno-signaling-nans -fno-trapping-math -fno-signed-zeros -freciprocal-math -fno-math-errno
2121
PREBUILD_COMMAND := sudo apt-get update && sudo apt-get install -y ca-certificates-java openjdk-11-jre-headless; { curl https://dlcdn.apache.org/maven/maven-3/3.9.2/binaries/apache-maven-3.9.2-bin.tar.gz | sudo tar -xvzf - -C /opt ; }; export M2_HOME=/opt/apache-maven-3.9.2 && export PATH=\"${M2_HOME}/bin:${PATH}\"
2222
else ifeq ($(UNAME_S),Darwin)
2323
CXX := clang++
2424
JAVA_INC := $(JAVA_HOME)/include $(JAVA_HOME)/include/darwin
2525
ALL_OBJS := target/classes/mac-x64/$(MAC_SOBJ) target/classes/mac-aarch64/$(MAC_SOBJ)
26-
CXXFLAGS := -I. -lc++ -shared -std=c++17 -I ./include $(addprefix -I,$(JAVA_INC)) -I $(CPP_SRC_DIR) -fPIC -O3
26+
CXXFLAGS := -I. -lc++ -shared -std=c++17 -I ./include $(addprefix -I,$(JAVA_INC)) -I $(CPP_SRC_DIR) -fPIC -O3 -fassociative-math -fno-signaling-nans -fno-trapping-math -fno-signed-zeros -freciprocal-math -fno-math-errno
2727
else ifdef OS # Windows:
2828
CXX := cl.exe
2929
JAVA_INC := $(JAVA_HOME)/include $(JAVA_HOME)/include/win32

python/CMakeLists.txt

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ else()
3131
set(DEV_MODULE Development.Module)
3232
endif()
3333

34+
set(IS_UNIX ${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
35+
set(IS_WINDOWS ${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
36+
3437
find_package(Python 3.8 COMPONENTS Interpreter ${DEV_MODULE})
3538

3639
# Import nanobind through CMake's find_package mechanism
@@ -48,18 +51,33 @@ execute_process(
4851
OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE nanobind_ROOT)
4952
find_package(nanobind CONFIG REQUIRED)
5053

54+
# Allow for some math optimization on unix but not -ffast-math
55+
# See: https://simonbyrne.github.io/notes/fastmath/#flushing_subnormals_to_zero
56+
if (IS_UNIX)
57+
add_compile_options(-fassociative-math -fno-signaling-nans -fno-trapping-math -fno-signed-zeros -freciprocal-math -fno-math-errno)
58+
endif()
59+
60+
# Relase build with all optimizations
61+
if (CMAKE_BUILD_TYPE STREQUAL "Release" AND IS_UNIX)
62+
add_compile_options(-O3)
63+
elseif (CMAKE_BUILD_TYPE STREQUAL "Release" AND IS_WINDOWS)
64+
add_compile_options(/Ox)
65+
endif()
66+
67+
5168
# Check the USE_ASAN environment variable, and if set to 1, enable AddressSanitizer
5269
if (DEFINED ENV{USE_ASAN} AND "$ENV{USE_ASAN}" STREQUAL "1")
53-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
54-
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
70+
add_compile_options(-fsanitize=address -fno-omit-frame-pointer)
71+
add_link_options(-fsanitize=address)
5572
endif()
5673

74+
5775
nanobind_add_module(
5876
voyager_ext
5977
# Target the stable ABI for Python 3.12+, which reduces
6078
# the number of binary wheels that must be built. This
6179
# does nothing on older Python versions
62-
NB_STATIC STABLE_ABI LTO FREE_THREADED
80+
NB_STATIC STABLE_ABI LTO FREE_THREADED NOMINSIZE
6381
# Sources:
6482
src/bindings.cpp
6583
)

0 commit comments

Comments
 (0)