From 68a509026c79667ec488e04bce0bd1d9aaea36e9 Mon Sep 17 00:00:00 2001 From: Dmitry Yashunin Date: Mon, 8 May 2023 11:33:09 +0400 Subject: [PATCH 1/7] Add macos into CI --- .github/workflows/build.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8cfa469a..d565f8b3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,7 +7,7 @@ jobs: runs-on: ${{matrix.os}} strategy: matrix: - os: [ubuntu-latest, windows-latest] + os: [ubuntu-latest, windows-latest, macos-latest] python-version: ["3.7", "3.8", "3.9", "3.10"] steps: - uses: actions/checkout@v3 @@ -28,7 +28,7 @@ jobs: runs-on: ${{matrix.os}} strategy: matrix: - os: [ubuntu-latest, windows-latest] + os: [ubuntu-latest, windows-latest, macos-latest] steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 @@ -40,10 +40,10 @@ jobs: mkdir build cd build cmake .. - if [ "$RUNNER_OS" == "Linux" ]; then - make - elif [ "$RUNNER_OS" == "Windows" ]; then + if [ "$RUNNER_OS" == "Windows" ]; then cmake --build ./ --config Release + else + make fi shell: bash From 0a6df9bde1c65c50f860f6b0a1d0fe2f58c8666d Mon Sep 17 00:00:00 2001 From: Dmitry Yashunin Date: Mon, 8 May 2023 12:50:00 +0400 Subject: [PATCH 2/7] Fix mac setup --- setup.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/setup.py b/setup.py index 0126585e..c630e876 100644 --- a/setup.py +++ b/setup.py @@ -75,20 +75,14 @@ class BuildExt(build_ext): """A custom build extension for adding compiler-specific options.""" c_opts = { 'msvc': ['/EHsc', '/openmp', '/O2'], - #'unix': ['-O3', '-march=native'], # , '-w' - 'unix': ['-O3'], # , '-w' + 'unix': ['-O3', '-march=native'], # , '-w' } - if not os.environ.get("HNSWLIB_NO_NATIVE"): - c_opts['unix'].append('-march=native') - link_opts = { 'unix': [], 'msvc': [], } if sys.platform == 'darwin': - if platform.machine() == 'arm64': - c_opts['unix'].remove('-march=native') c_opts['unix'] += ['-stdlib=libc++', '-mmacosx-version-min=10.7'] link_opts['unix'] += ['-stdlib=libc++', '-mmacosx-version-min=10.7'] else: @@ -103,6 +97,23 @@ def build_extensions(self): opts.append(cpp_flag(self.compiler)) if has_flag(self.compiler, '-fvisibility=hidden'): opts.append('-fvisibility=hidden') + # check that native flag is available + native_flag = '-march=native' + print('checking avalability of flag:', native_flag) + if not has_flag(self.compiler, native_flag): + print('removing unsupported compiler flag:', native_flag) + opts.remove(native_flag) + # for macos add apple-m1 flag if it's available + if sys.platform == 'darwin': + m1_flag = '-mcpu=apple-m1' + print('checking avalability of flag:', m1_flag) + if has_flag(self.compiler, m1_flag): + print('adding flag:', m1_flag) + opts.append(m1_flag) + else: + print(f'flag: {m1_flag} is not available') + else: + print(f'flag: {native_flag} is available') elif ct == 'msvc': opts.append('/DVERSION_INFO=\\"%s\\"' % self.distribution.get_version()) From 4785406deb11b2a9665c1ba5879628d23e921808 Mon Sep 17 00:00:00 2001 From: Dmitry Yashunin Date: Mon, 8 May 2023 13:26:59 +0400 Subject: [PATCH 3/7] Use macos-13 in CI --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d565f8b3..1fa15c75 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,7 +7,7 @@ jobs: runs-on: ${{matrix.os}} strategy: matrix: - os: [ubuntu-latest, windows-latest, macos-latest] + os: [ubuntu-latest, windows-latest, macos-13] python-version: ["3.7", "3.8", "3.9", "3.10"] steps: - uses: actions/checkout@v3 @@ -28,7 +28,7 @@ jobs: runs-on: ${{matrix.os}} strategy: matrix: - os: [ubuntu-latest, windows-latest, macos-latest] + os: [ubuntu-latest, windows-latest, macos-13] steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 From 3800e238ebc080e233dda39b547ac328645738c6 Mon Sep 17 00:00:00 2001 From: Dmitry Yashunin Date: Wed, 10 May 2023 14:02:59 +0400 Subject: [PATCH 4/7] Allow asserts, fix checkIntegrity --- CMakeLists.txt | 20 ++++++++++++++++---- hnswlib/hnswalg.h | 1 - 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b2aecc8e..14865834 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,7 @@ project(hnswlib LANGUAGES CXX) include(GNUInstallDirs) +include(CheckCXXCompilerFlag) add_library(hnswlib INTERFACE) add_library(hnswlib::hnswlib ALIAS hnswlib) @@ -33,12 +34,23 @@ endif() if(HNSWLIB_EXAMPLES) set(CMAKE_CXX_STANDARD 11) - if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - SET( CMAKE_CXX_FLAGS "-Ofast -DNDEBUG -std=c++11 -DHAVE_CXX0X -openmp -march=native -fpic -ftree-vectorize") + if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") + SET( CMAKE_CXX_FLAGS "-Ofast -std=c++11 -DHAVE_CXX0X -openmp -fpic -ftree-vectorize" ) + check_cxx_compiler_flag("-march=native" COMPILER_SUPPORT_NATIVE_FLAG) + if(COMPILER_SUPPORT_NATIVE_FLAG) + SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native" ) + message("set -march=native flag") + else() + check_cxx_compiler_flag("-mcpu=apple-m1" COMPILER_SUPPORT_M1_FLAG) + if(COMPILER_SUPPORT_M1_FLAG) + SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mcpu=apple-m1" ) + message("set -mcpu=apple-m1 flag") + endif() + endif() elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - SET( CMAKE_CXX_FLAGS "-Ofast -lrt -DNDEBUG -std=c++11 -DHAVE_CXX0X -march=native -fpic -w -fopenmp -ftree-vectorize -ftree-vectorizer-verbose=0" ) + SET( CMAKE_CXX_FLAGS "-Ofast -lrt -std=c++11 -DHAVE_CXX0X -march=native -fpic -w -fopenmp -ftree-vectorize -ftree-vectorizer-verbose=0" ) elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") - SET( CMAKE_CXX_FLAGS "-Ofast -lrt -DNDEBUG -std=c++11 -DHAVE_CXX0X -openmp -march=native -fpic -w -fopenmp -ftree-vectorize" ) + SET( CMAKE_CXX_FLAGS "-Ofast -lrt -std=c++11 -DHAVE_CXX0X -openmp -march=native -fpic -w -fopenmp -ftree-vectorize" ) endif() # examples diff --git a/hnswlib/hnswalg.h b/hnswlib/hnswalg.h index 88de0fa9..68a4f8ef 100644 --- a/hnswlib/hnswalg.h +++ b/hnswlib/hnswalg.h @@ -1246,7 +1246,6 @@ class HierarchicalNSW : public AlgorithmInterface { tableint *data = (tableint *) (ll_cur + 1); std::unordered_set s; for (int j = 0; j < size; j++) { - assert(data[j] > 0); assert(data[j] < cur_element_count); assert(data[j] != i); inbound_connections_num[data[j]]++; From 1b8883425e3bb9b7c4af4a5502f3ec742d51cfc7 Mon Sep 17 00:00:00 2001 From: Dmitry Yashunin Date: Wed, 10 May 2023 14:11:56 +0400 Subject: [PATCH 5/7] Revert macos to latest in CI --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1fa15c75..7d96591b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,7 +7,7 @@ jobs: runs-on: ${{matrix.os}} strategy: matrix: - os: [ubuntu-latest, windows-latest, macos-13] + os: [ubuntu-latest, windows-latest, macos-latest] python-version: ["3.7", "3.8", "3.9", "3.10"] steps: - uses: actions/checkout@v3 From ca1fb7bf2fb9f765f5a94668f7cc001cd1cffb8b Mon Sep 17 00:00:00 2001 From: Dmitry Yashunin Date: Wed, 10 May 2023 14:22:51 +0400 Subject: [PATCH 6/7] Fix CI --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7d96591b..d565f8b3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -28,7 +28,7 @@ jobs: runs-on: ${{matrix.os}} strategy: matrix: - os: [ubuntu-latest, windows-latest, macos-13] + os: [ubuntu-latest, windows-latest, macos-latest] steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 From 5e26ea3f0ba42a3aefd412e1a21e840622e20a34 Mon Sep 17 00:00:00 2001 From: Dmitry Yashunin Date: Wed, 10 May 2023 15:25:22 +0400 Subject: [PATCH 7/7] Windows build warnings --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 14865834..cff0dca7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,7 +50,7 @@ if(HNSWLIB_EXAMPLES) elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") SET( CMAKE_CXX_FLAGS "-Ofast -lrt -std=c++11 -DHAVE_CXX0X -march=native -fpic -w -fopenmp -ftree-vectorize -ftree-vectorizer-verbose=0" ) elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") - SET( CMAKE_CXX_FLAGS "-Ofast -lrt -std=c++11 -DHAVE_CXX0X -openmp -march=native -fpic -w -fopenmp -ftree-vectorize" ) + SET( CMAKE_CXX_FLAGS "/O2 -DHAVE_CXX0X /W1 /openmp /EHsc" ) endif() # examples