Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions o/opensearch-project-k-nn/build_info.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
{
"maintainer": "Prachi.Gaonkar@ibm.com",
"maintainer": "Balavva.Mirji@ibm.com",
"package_name": "opensearch-project-k-nn",
"github_url": "https://github.com/opensearch-project/k-NN",
"version": "3.3.0.0",
"required_versions":{"Releases": ["*"], "Tags": ["*"]},
"version": "3.5.0.0",
"required_versions":{"Releases": ["*"], "Tags": ["3.5.0.0"]},
"default_branch": "main",
"package_dir": "o/opensearch-project-k-nn",
"build_script": "opensearch-project-k-NN_3.3.0.0_ubi_9.6.sh",
"build_script": "opensearch-project-k-NN_3.5.0.0_ubi_9.6.sh",
"validate_build_script": true,
"use_non_root_user": true,
"docker_build": false,
"3.5.0.0": {
"build_script": "opensearch-project-k-NN_3.5.0.0_ubi_9.6.sh"
},
"3.3.0.0": {
"build_script": "opensearch-project-k-NN_3.3.0.0_ubi_9.6.sh"
},
Expand Down
53 changes: 53 additions & 0 deletions o/opensearch-project-k-nn/k-NN-3.5.0.0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
diff --git a/jni/cmake/init-faiss.cmake b/jni/cmake/init-faiss.cmake
index 7e9622a9..42d3cc9a 100644
--- a/jni/cmake/init-faiss.cmake
+++ b/jni/cmake/init-faiss.cmake
@@ -126,7 +126,7 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL Windows OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "a
elseif(${CMAKE_SYSTEM_NAME} STREQUAL Linux AND AVX512_SPR_ENABLED)
set(FAISS_OPT_LEVEL avx512_spr)
set(TARGET_LINK_FAISS_LIB faiss_avx512_spr)
- string(PREPEND LIB_EXT "_avx512_spr")
+ string(PREPEND LIB_EXT "")
elseif(${CMAKE_SYSTEM_NAME} STREQUAL Linux AND AVX512_ENABLED)
set(FAISS_OPT_LEVEL avx512) # Keep optimization level as avx512 to improve performance on Linux. This is not present on mac systems, and presently not supported on Windows OS.
set(TARGET_LINK_FAISS_LIB faiss_avx512)
diff --git a/jni/cmake/init-simd.cmake b/jni/cmake/init-simd.cmake
index a5167e74..12ecfa96 100644
--- a/jni/cmake/init-simd.cmake
+++ b/jni/cmake/init-simd.cmake
@@ -2,6 +2,12 @@
# Copyright OpenSearch Contributors
# SPDX-License-Identifier: Apache-2.0
#
+# Force disable AVX512 on unsupported architectures (ppc64le)
+set(ENABLE_AVX512 OFF CACHE BOOL "" FORCE)
+set(ENABLE_AVX512_FP16 OFF CACHE BOOL "" FORCE)
+set(ENABLE_AVX2 OFF CACHE BOOL "" FORCE)
+set(ENABLE_AVX OFF CACHE BOOL "" FORCE)
+set(SIMD_OPT NONE CACHE STRING "" FORCE)

include(CheckCXXSourceCompiles)

@@ -117,7 +123,7 @@ elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux" AND AVX512_ENABLED)
add_definitions(-DKNN_HAVE_AVX512)
message(STATUS "[SIMD] AVX512 + F16C supported by compiler.")
else()
- message(FATAL_ERROR "[SIMD] AVX512 + FP16 was explicitly enabled, but compiler does not support it.")
+ # message(FATAL_ERROR "[SIMD] AVX512 + FP16 was explicitly enabled, but compiler does not support it.")
endif()

else()
diff --git a/jni/external/faiss b/jni/external/faiss
index 5616caad..a5b1a5bd 160000
--- a/jni/external/faiss
+++ b/jni/external/faiss
@@ -1 +1 @@
-Subproject commit 5616caad4cea4e8326cdef90aa177bd618af8531
+Subproject commit a5b1a5bdfdbedd10fca6ee3cf1a8327762e71801-dirty
diff --git a/jni/external/nmslib b/jni/external/nmslib
index a2d6624e..7a998c73 160000
--- a/jni/external/nmslib
+++ b/jni/external/nmslib
@@ -1 +1 @@
-Subproject commit a2d6624e1315402662025debfdd614b505d9c3ef
+Subproject commit 7a998c73839a0a45e8c0ac7895d388200836f463-dirty
112 changes: 112 additions & 0 deletions o/opensearch-project-k-nn/k-NN-faiss-3.5.0.0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
diff --git a/faiss/CMakeLists.txt b/faiss/CMakeLists.txt
index 90041291a..142b0ce38 100644
--- a/faiss/CMakeLists.txt
+++ b/faiss/CMakeLists.txt
@@ -241,9 +241,34 @@ if(NOT WIN32)
list(APPEND FAISS_HEADERS invlists/OnDiskInvertedLists.h)
endif()

+# Detect the architecture and apply appropriate flags
+execute_process(COMMAND uname -m OUTPUT_VARIABLE ARCHITECTURE)
+string(STRIP ${ARCHITECTURE} ARCHITECTURE)
+
+# Check if the system is Power architecture (e.g., ppc64le)
+if(ARCHITECTURE STREQUAL "ppc64le" OR ARCHITECTURE STREQUAL "powerpc64le")
+ message(STATUS "Building for PowerPC architecture, disabling AVX flags")
+
+ # Remove AVX flags if the architecture is PowerPC
+ string(REPLACE "-mavx2" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
+ string(REPLACE "-mfma" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
+ string(REPLACE "-mavx512f" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
+ string(REPLACE "-mavx512cd" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
+ string(REPLACE "-mavx512vl" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
+ string(REPLACE "-mavx512dq" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
+ string(REPLACE "-mavx512bw" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
+ string(REPLACE "-mpopcnt" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
+endif()
+
# Export FAISS_HEADERS variable to parent scope.
set(FAISS_HEADERS ${FAISS_HEADERS} PARENT_SCOPE)

+# Check for the architecture and adjust optimization level
+if(CMAKE_SYSTEM_PROCESSOR STREQUAL "ppc64le" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "powerpc64le")
+ # Disable AVX2/AVX512-specific optimizations on non-x86 architectures
+ set(FAISS_OPT_LEVEL "generic")
+endif()
+
add_library(faiss ${FAISS_SRC})

add_library(faiss_avx2 ${FAISS_SRC})
@@ -251,7 +276,13 @@ if(NOT FAISS_OPT_LEVEL STREQUAL "avx2" AND NOT FAISS_OPT_LEVEL STREQUAL "avx512"
set_target_properties(faiss_avx2 PROPERTIES EXCLUDE_FROM_ALL TRUE)
endif()
if(NOT WIN32)
- target_compile_options(faiss_avx2 PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-mavx2 -mfma -mf16c -mpopcnt>)
+ # target_compile_options(faiss_avx2 PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-mavx2 -mfma -mf16c -mpopcnt>)
+ # Only enable AVX2/AVX512 compile options if the architecture supports them
+ if(FAISS_OPT_LEVEL STREQUAL "avx2")
+ target_compile_options(faiss_avx2 PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-mavx2 -mfma -mf16c -mpopcnt>)
+ elseif(FAISS_OPT_LEVEL STREQUAL "avx512")
+ target_compile_options(faiss_avx2 PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-mavx2 -mfma -mf16c -mavx512f -mavx512cd -mavx512vl -mavx512dq -mavx512bw -mpopcnt>)
+ endif()
else()
# MSVC enables FMA with /arch:AVX2; no separate flags for F16C, POPCNT
# Ref. FMA (under /arch:AVX2): https://docs.microsoft.com/en-us/cpp/build/reference/arch-x64
@@ -269,7 +300,11 @@ endif()
if(NOT WIN32)
# All modern CPUs support F, CD, VL, DQ, BW extensions.
# Ref: https://en.wikipedia.org/wiki/AVX512
- target_compile_options(faiss_avx512 PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-mavx2 -mfma -mf16c -mavx512f -mavx512cd -mavx512vl -mavx512dq -mavx512bw -mpopcnt>)
+ # Ref: https://en.wikipedia.org/wiki/AVX512
+ # Only enable AVX512 compile options if the architecture supports them
+ if(FAISS_OPT_LEVEL STREQUAL "avx512")
+ target_compile_options(faiss_avx512 PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-mavx512f -mavx512cd -mavx512vl -mavx512dq -mavx512bw -mfma -mf16c -mpopcnt>)
+ endif()
else()
target_compile_options(faiss_avx512 PRIVATE $<$<COMPILE_LANGUAGE:CXX>:/arch:AVX512>)
# we need bigobj for the swig wrapper
@@ -283,7 +318,12 @@ endif()
if(NOT WIN32)
# Architecture mode to support AVX512 extensions available since Intel(R) Sapphire Rapids.
# Ref: https://networkbuilders.intel.com/solutionslibrary/intel-avx-512-fp16-instruction-set-for-intel-xeon-processor-based-products-technology-guide
- target_compile_options(faiss_avx512_spr PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-march=sapphirerapids -mtune=sapphirerapids>)
+ if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_SYSTEM_PROCESSOR MATCHES "amd64")
+ # Architecture mode to support AVX512 extensions available since Intel(R) Sapphire Rapids.
+ target_compile_options(faiss_avx512_spr PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-march=sapphirerapids -mtune=sapphirerapids>)
+ else()
+ message(STATUS "Skipping -march=sapphirerapids flags: unsupported architecture (${CMAKE_SYSTEM_PROCESSOR})")
+ endif()
else()
target_compile_options(faiss_avx512_spr PRIVATE $<$<COMPILE_LANGUAGE:CXX>:/arch:AVX512>)
# we need bigobj for the swig wrapper
@@ -294,6 +334,30 @@ add_library(faiss_sve ${FAISS_SRC})
if(NOT FAISS_OPT_LEVEL STREQUAL "sve")
set_target_properties(faiss_sve PROPERTIES EXCLUDE_FROM_ALL TRUE)
endif()
+
+if(NOT WIN32)
+ # Only enable SVE compile options if the architecture supports them
+ if(FAISS_OPT_LEVEL STREQUAL "sve")
+ target_compile_options(faiss_sve PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-msve>)
+ endif()
+else()
+ # Windows-specific compiler flags for SVE (if supported by MSVC)
+ target_compile_options(faiss_sve PRIVATE $<$<COMPILE_LANGUAGE:CXX>:/arch:SVE>)
+ add_compile_options(/bigobj)
+endif()
+
+if(NOT WIN32)
+ target_compile_options(faiss_avx2 PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-mavx2 -mfma -mf16c -mpopcnt>)
+else()
+ # MSVC enables FMA with /arch:AVX2; no separate flags for F16C, POPCNT
+ # Ref. FMA (under /arch:AVX2): https://docs.microsoft.com/en-us/cpp/build/reference/arch-x64
+ # Ref. F16C (2nd paragraph): https://walbourn.github.io/directxmath-avx2/
+ # Ref. POPCNT: https://docs.microsoft.com/en-us/cpp/intrinsics/popcnt16-popcnt-popcnt64
+ target_compile_options(faiss_avx2 PRIVATE $<$<COMPILE_LANGUAGE:CXX>:/arch:AVX2>)
+ # we need bigobj for the swig wrapper
+ add_compile_options(/bigobj)
+endif()
+
if(NOT WIN32)
if("${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG} " MATCHES "(^| )-march=native")
# Do nothing, expect SVE to be enabled by -march=native
13 changes: 13 additions & 0 deletions o/opensearch-project-k-nn/k-NN-nmslib-3.5.0.0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/similarity_search/CMakeLists.txt b/similarity_search/CMakeLists.txt
index 03a3275..440355a 100644
--- a/similarity_search/CMakeLists.txt
+++ b/similarity_search/CMakeLists.txt
@@ -36,7 +36,7 @@ endif()
#message(FATAL_ERROR "stopping... compiler version is: ${CMAKE_CXX_COMPILER_ID} ${CXX_COMPILER_VERSION}")

if(NOT NMSLIB_SIMD_FLAGS)
- set(NMSLIB_SIMD_FLAGS "-march=native" CACHE STRING "SIMD compile flags for NMSLIB" FORCE)
+ set(NMSLIB_SIMD_FLAGS "-mcpu=native" CACHE STRING "SIMD compile flags for NMSLIB" FORCE)
endif()

set(WARN_FLAGS "-Wall -Wunreachable-code -Wcast-align")
Loading
Loading