From 4dffdfedbe3a6082fdd6b5208a780221d131baa5 Mon Sep 17 00:00:00 2001 From: Andy Lee Date: Tue, 2 Sep 2025 14:27:06 -0700 Subject: [PATCH] feat: Add ARM64 Linux wheel support for leann-backend-hnsw (#83) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: Add ARM64 Linux wheel support for leann-backend-hnsw * fix: Use OpenBLAS for ARM64 Linux builds instead of Intel MKL * fix: Configure Faiss with SVE optimization for ARM64 builds - Set FAISS_OPT_LEVEL to "sve" for ARM64 architecture - Disable x86-specific SIMD instructions (AVX2, AVX512, SSE4.1) - Use ARM64-native SVE optimization as per Faiss conda build scripts - Add architecture detection and proper configuration messages Fixes compilation error: "xmmintrin.h: No such file or directory" on ubuntu-24.04-arm runners. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude * fix: Apply ARM64 compatibility fix directly to Faiss submodule - Modify faiss/impl/pq.cpp to use x86-specific preprocessor conditions - Remove patch file approach in favor of direct submodule modification - Update CMakeLists.txt to reflect the submodule changes - Fixes ARM64 Linux compilation by preventing x86 SIMD header inclusion This resolves the "xmmintrin.h: No such file or directory" error when building ARM64 Linux wheels for Docker compatibility. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude * chore: Update Faiss submodule to include ARM64 compatibility fix - Points to commit ed96ff7d with x86-specific preprocessor conditions - Enables successful ARM64 Linux wheel builds 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude * retrigger ci * fix: Use different optimization levels for ARM64 based on platform - Use SVE optimization only for ARM64 Linux - Use generic optimization for ARM64 macOS to avoid clang SVE issues - Fixes macOS ARM64 compilation errors with SVE instructions 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude * feat: Update DiskANN submodule with OpenBLAS fallback support - Points to commit 5c396c4 with ARM64 Linux OpenBLAS support - Enables DiskANN to build on ARM64 Linux using standard BLAS libraries - Resolves Intel MKL dependency issues for Docker ARM64 deployments 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude * fix: Update DiskANN submodule with ZeroMQ polling configuration - Points to commit 3a1016e with explicit polling method setup - Resolves ZeroMQ autodetection issues on ARM64 Linux - Ensures stable cross-platform ZeroMQ builds 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude * retrigger ci * fix: Update DiskANN submodule with ARM64 compiler flags fix - Points to commit a0dc600 with architecture-specific compiler flags - Removes x86 SIMD flags on ARM64 Linux to fix compilation errors - Enables successful ARM64 Linux wheel builds 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude * fix: Update DiskANN submodule with ARM64 compiler flags fix - Points to commit 0921664 with architecture-specific compiler flags - Removes x86 SIMD flags on ARM64 Linux to fix compilation errors - Enables successful ARM64 Linux wheel builds 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude * retrigger ci * fix: Update DiskANN submodule with cross-platform prefetch support - Points to commit 39192d6 with unified prefetch macros - Replaces all Intel-specific _mm_prefetch calls with cross-platform macros - Enables ARM64 Linux compatibility while maintaining x86 performance - Resolves all remaining compilation errors for ARM64 builds 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude * fix: Update DiskANN submodule with corrected ARM64 compatibility fixes - Points to commit 3cb87a8 with proper x86 platform detection - Includes ARM64 fallback for AVXDistanceInnerProductFloat function - Resolves all remaining '__m256 was not declared' compilation errors - Enables successful ARM64 Linux wheel builds for Docker compatibility 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude * fix: Update DiskANN submodule with template type handling fix - Points to commit d396bc3 with corrected template type handling - Fixes DistanceInnerProduct template instantiation for int8_t/uint8_t types - Resolves 'cannot convert const signed char* to const float*' error - Completes ARM64 Linux compilation compatibility 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude * fix: Update DiskANN submodule with DistanceFastL2::norm template fix - Points to commit 69d9a99 with corrected template type handling - Fixes DistanceFastL2::norm template instantiation for int8_t/uint8_t types - Resolves another 'cannot convert const signed char* to const float*' error - Continues ARM64 Linux compilation compatibility improvements 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude * fix: Update DiskANN submodule with LAPACKE header detection - Points to commit 64a9e01 with LAPACKE header path configuration - Adds pkg-config based detection for LAPACKE include directories - Resolves 'lapacke.h: No such file or directory' compilation error - Completes OpenBLAS integration for ARM64 Linux builds 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude * fix: Update DiskANN submodule with enhanced LAPACKE header detection - Points to commit 18d0721 with fallback LAPACKE header search paths - Checks multiple standard locations for lapacke.h on various systems - Improves ARM64 Linux compatibility for OpenBLAS builds - Should resolve 'lapacke.h: No such file or directory' errors 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude * fix: Add liblapacke-dev package for ARM64 Linux builds - Add liblapacke-dev to ARM64 dependencies alongside libopenblas-dev - Provides lapacke.h header file needed for LAPACK C interface - Fixes 'lapacke.h: No such file or directory' compilation error - Enables complete OpenBLAS + LAPACKE support for ARM64 wheel builds 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude * fix: Update DiskANN submodule with cosine_similarity.h x86 intrinsics fix - Points to commit dbb17eb with corrected conditional compilation - Fixes immintrin.h inclusion for ARM64 compatibility in cosine_similarity.h - Resolves 'immintrin.h: No such file or directory' error - Continues systematic ARM64 Linux compilation fixes 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude * fix: Update DiskANN submodule with LAPACKE library linking fix - Points to commit 19f9603 with explicit LAPACKE library discovery and linking - Resolves 'undefined symbol: LAPACKE_sgesdd' runtime error on ARM64 Linux - Completes ARM64 Linux wheel build compatibility for Docker deployments 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --------- Co-authored-by: Claude --- .github/workflows/build-reusable.yml | 58 ++++++++++++++++--- .../leann-backend-diskann/third_party/DiskANN | 2 +- packages/leann-backend-hnsw/CMakeLists.txt | 21 ++++++- packages/leann-backend-hnsw/third_party/faiss | 2 +- 4 files changed, 73 insertions(+), 10 deletions(-) diff --git a/.github/workflows/build-reusable.yml b/.github/workflows/build-reusable.yml index f0b7b24..d0bfb16 100644 --- a/.github/workflows/build-reusable.yml +++ b/.github/workflows/build-reusable.yml @@ -54,6 +54,17 @@ jobs: python: '3.12' - os: ubuntu-22.04 python: '3.13' + # ARM64 Linux builds + - os: ubuntu-24.04-arm + python: '3.9' + - os: ubuntu-24.04-arm + python: '3.10' + - os: ubuntu-24.04-arm + python: '3.11' + - os: ubuntu-24.04-arm + python: '3.12' + - os: ubuntu-24.04-arm + python: '3.13' - os: macos-14 python: '3.9' - os: macos-14 @@ -108,13 +119,46 @@ jobs: pkg-config libabsl-dev libaio-dev libprotobuf-dev \ patchelf - # Install Intel MKL for DiskANN - wget -q https://registrationcenter-download.intel.com/akdlm/IRC_NAS/79153e0f-74d7-45af-b8c2-258941adf58a/intel-onemkl-2025.0.0.940.sh - sudo sh intel-onemkl-2025.0.0.940.sh -a --components intel.oneapi.lin.mkl.devel --action install --eula accept -s - source /opt/intel/oneapi/setvars.sh - echo "MKLROOT=/opt/intel/oneapi/mkl/latest" >> $GITHUB_ENV - echo "LD_LIBRARY_PATH=/opt/intel/oneapi/compiler/latest/linux/compiler/lib/intel64_lin" >> $GITHUB_ENV - echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/intel/oneapi/mkl/latest/lib/intel64" >> $GITHUB_ENV + # Debug: Show system information + echo "🔍 System Information:" + echo "Architecture: $(uname -m)" + echo "OS: $(uname -a)" + echo "CPU info: $(lscpu | head -5)" + + # Install math library based on architecture + ARCH=$(uname -m) + echo "🔍 Setting up math library for architecture: $ARCH" + + if [[ "$ARCH" == "x86_64" ]]; then + # Install Intel MKL for DiskANN on x86_64 + echo "📦 Installing Intel MKL for x86_64..." + wget -q https://registrationcenter-download.intel.com/akdlm/IRC_NAS/79153e0f-74d7-45af-b8c2-258941adf58a/intel-onemkl-2025.0.0.940.sh + sudo sh intel-onemkl-2025.0.0.940.sh -a --components intel.oneapi.lin.mkl.devel --action install --eula accept -s + source /opt/intel/oneapi/setvars.sh + echo "MKLROOT=/opt/intel/oneapi/mkl/latest" >> $GITHUB_ENV + echo "LD_LIBRARY_PATH=/opt/intel/oneapi/compiler/latest/linux/compiler/lib/intel64_lin" >> $GITHUB_ENV + echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/intel/oneapi/mkl/latest/lib/intel64" >> $GITHUB_ENV + echo "✅ Intel MKL installed for x86_64" + + # Debug: Check MKL installation + echo "🔍 MKL Installation Check:" + ls -la /opt/intel/oneapi/mkl/latest/ || echo "MKL directory not found" + ls -la /opt/intel/oneapi/mkl/latest/lib/ || echo "MKL lib directory not found" + + elif [[ "$ARCH" == "aarch64" ]]; then + # Use OpenBLAS for ARM64 (MKL installer not compatible with ARM64) + echo "📦 Installing OpenBLAS for ARM64..." + sudo apt-get install -y libopenblas-dev liblapack-dev liblapacke-dev + echo "✅ OpenBLAS installed for ARM64" + + # Debug: Check OpenBLAS installation + echo "🔍 OpenBLAS Installation Check:" + dpkg -l | grep openblas || echo "OpenBLAS package not found" + ls -la /usr/lib/aarch64-linux-gnu/openblas/ || echo "OpenBLAS directory not found" + fi + + # Debug: Show final library paths + echo "🔍 Final LD_LIBRARY_PATH: $LD_LIBRARY_PATH" - name: Install system dependencies (macOS) if: runner.os == 'macOS' diff --git a/packages/leann-backend-diskann/third_party/DiskANN b/packages/leann-backend-diskann/third_party/DiskANN index c593831..19f9603 160000 --- a/packages/leann-backend-diskann/third_party/DiskANN +++ b/packages/leann-backend-diskann/third_party/DiskANN @@ -1 +1 @@ -Subproject commit c593831474afb26bf167b077c2f0956ddbc54603 +Subproject commit 19f9603c728f51ff4a37df78805a3bb183e9870d diff --git a/packages/leann-backend-hnsw/CMakeLists.txt b/packages/leann-backend-hnsw/CMakeLists.txt index 12e19ef..87d4592 100644 --- a/packages/leann-backend-hnsw/CMakeLists.txt +++ b/packages/leann-backend-hnsw/CMakeLists.txt @@ -49,9 +49,28 @@ set(BUILD_TESTING OFF CACHE BOOL "" FORCE) set(FAISS_ENABLE_C_API OFF CACHE BOOL "" FORCE) set(FAISS_OPT_LEVEL "generic" CACHE STRING "" FORCE) -# Disable additional SIMD versions to speed up compilation +# Disable x86-specific SIMD optimizations (important for ARM64 compatibility) set(FAISS_ENABLE_AVX2 OFF CACHE BOOL "" FORCE) set(FAISS_ENABLE_AVX512 OFF CACHE BOOL "" FORCE) +set(FAISS_ENABLE_SSE4_1 OFF CACHE BOOL "" FORCE) + +# ARM64-specific configuration +if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm64") + message(STATUS "Configuring Faiss for ARM64 architecture") + + if(CMAKE_SYSTEM_NAME STREQUAL "Linux") + # Use SVE optimization level for ARM64 Linux (as seen in Faiss conda build) + set(FAISS_OPT_LEVEL "sve" CACHE STRING "" FORCE) + message(STATUS "Setting FAISS_OPT_LEVEL to 'sve' for ARM64 Linux") + else() + # Use generic optimization for other ARM64 platforms (like macOS) + set(FAISS_OPT_LEVEL "generic" CACHE STRING "" FORCE) + message(STATUS "Setting FAISS_OPT_LEVEL to 'generic' for ARM64 ${CMAKE_SYSTEM_NAME}") + endif() + + # ARM64 compatibility: Faiss submodule has been modified to fix x86 header inclusion + message(STATUS "Using ARM64-compatible Faiss submodule") +endif() # Additional optimization options from INSTALL.md set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE) diff --git a/packages/leann-backend-hnsw/third_party/faiss b/packages/leann-backend-hnsw/third_party/faiss index a036185..ed96ff7 160000 --- a/packages/leann-backend-hnsw/third_party/faiss +++ b/packages/leann-backend-hnsw/third_party/faiss @@ -1 +1 @@ -Subproject commit a0361858fc9cbc95239ef304d9c85d48bb2701c8 +Subproject commit ed96ff7dbaea0562b994f8ce7823af41884b1010