Skip to content

Commit

Permalink
Make custom patch to get applied only once after sub module is checke…
Browse files Browse the repository at this point in the history
…d out

Signed-off-by: Heemin Kim <[email protected]>
  • Loading branch information
heemin32 committed Jul 16, 2024
1 parent 48478b4 commit 4a96b99
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 18 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ jobs:
steps:
- name: Checkout k-NN
uses: actions/checkout@v1
with:
submodules: true

# Setup git user so that patches for native libraries can be applied and committed
- name: Setup git user
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/test_security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ jobs:
steps:
- name: Checkout k-NN
uses: actions/checkout@v1
with:
submodules: true
# Setup git user so that patches for native libraries can be applied and committed
- name: Setup git user
run: |
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
* Release memory properly for an array type [#1820](https://github.com/opensearch-project/k-NN/pull/1820)
* FIX Same Suffix Cause Recall Drop to zero [#1802](https://github.com/opensearch-project/k-NN/pull/1802)
### Infrastructure
* Apply custom patch only once after submodule is checked out [#1833](https://github.com/opensearch-project/k-NN/pull/1833)
### Documentation
* Update dev guide to fix clang linking issue on arm [#1746](https://github.com/opensearch-project/k-NN/pull/1746)
### Maintenance
Expand Down
8 changes: 1 addition & 7 deletions jni/cmake/init-faiss.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,7 @@ find_path(FAISS_REPO_DIR NAMES faiss PATHS ${CMAKE_CURRENT_SOURCE_DIR}/external/
if (NOT EXISTS ${FAISS_REPO_DIR})
message(STATUS "Could not find faiss. Pulling updated submodule.")
execute_process(COMMAND git submodule update --init -- external/faiss WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
endif ()

# Check if patch exist, this is to skip git apply during CI build. See CI.yml with ubuntu.
find_path(PATCH_FILE NAMES 0001-Custom-patch-to-support-multi-vector.patch 0002-Enable-precomp-table-to-be-shared-ivfpq.patch 0003-Custom-patch-to-support-range-search-params.patch 0004-Custom-patch-to-support-binary-vector.patch PATHS ${CMAKE_CURRENT_SOURCE_DIR}/patches/faiss NO_DEFAULT_PATH)

# If it exists, apply patches
if (EXISTS ${PATCH_FILE})
message(STATUS "Applying custom patches.")
execute_process(COMMAND git ${GIT_PATCH_COMMAND} --3way --ignore-space-change --ignore-whitespace ${CMAKE_CURRENT_SOURCE_DIR}/patches/faiss/0001-Custom-patch-to-support-multi-vector.patch WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/external/faiss ERROR_VARIABLE ERROR_MSG RESULT_VARIABLE RESULT_CODE)
execute_process(COMMAND git ${GIT_PATCH_COMMAND} --3way --ignore-space-change --ignore-whitespace ${CMAKE_CURRENT_SOURCE_DIR}/patches/faiss/0002-Enable-precomp-table-to-be-shared-ivfpq.patch WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/external/faiss ERROR_VARIABLE ERROR_MSG RESULT_VARIABLE RESULT_CODE)
Expand All @@ -25,7 +19,7 @@ if (EXISTS ${PATCH_FILE})
if(RESULT_CODE)
message(FATAL_ERROR "Failed to apply patch:\n${ERROR_MSG}")
endif()
endif()
endif ()

if (${CMAKE_SYSTEM_NAME} STREQUAL Darwin)
if(CMAKE_C_COMPILER_ID MATCHES "Clang\$")
Expand Down
8 changes: 1 addition & 7 deletions jni/cmake/init-nmslib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,14 @@ find_path(NMS_REPO_DIR NAMES similarity_search PATHS ${CMAKE_CURRENT_SOURCE_DIR}
if (NOT EXISTS ${NMS_REPO_DIR})
message(STATUS "Could not find nmslib. Pulling updated submodule.")
execute_process(COMMAND git submodule update --init -- external/nmslib WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
endif ()

# Check if patch exist, this is to skip git apply during CI build. See CI.yml with ubuntu.
find_path(PATCH_FILE NAMES 0001-Initialize-maxlevel-during-add-from-enterpoint-level.patch 0002-Adds-ability-to-pass-ef-parameter-in-the-query-for-h.patch PATHS ${CMAKE_CURRENT_SOURCE_DIR}/patches/nmslib NO_DEFAULT_PATH)

# If it exists, apply patches
if (EXISTS ${PATCH_FILE})
message(STATUS "Applying custom patches.")
execute_process(COMMAND git ${GIT_PATCH_COMMAND} --3way --ignore-space-change --ignore-whitespace ${CMAKE_CURRENT_SOURCE_DIR}/patches/nmslib/0001-Initialize-maxlevel-during-add-from-enterpoint-level.patch WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/external/nmslib ERROR_VARIABLE ERROR_MSG RESULT_VARIABLE RESULT_CODE)
execute_process(COMMAND git ${GIT_PATCH_COMMAND} --3way --ignore-space-change --ignore-whitespace ${CMAKE_CURRENT_SOURCE_DIR}/patches/nmslib/0002-Adds-ability-to-pass-ef-parameter-in-the-query-for-h.patch WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/external/nmslib ERROR_VARIABLE ERROR_MSG RESULT_VARIABLE RESULT_CODE)

if(RESULT_CODE)
message(FATAL_ERROR "Failed to apply patch:\n${ERROR_MSG}")
endif()
endif()
endif ()

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/external/nmslib/similarity_search)
7 changes: 7 additions & 0 deletions scripts/windowsScript.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@
#

git submodule update --init -- jni/external/nmslib
git -C jni/external/nmslib apply --3way --ignore-space-change --ignore-whitespace ../../patches/nmslib/0001-Initialize-maxlevel-during-add-from-enterpoint-level.patch
git -C jni/external/nmslib apply --3way --ignore-space-change --ignore-whitespace ../../patches/nmslib/0002-Adds-ability-to-pass-ef-parameter-in-the-query-for-h.patch

git submodule update --init -- jni/external/faiss
git -C jni/external/faiss apply --3way --ignore-space-change --ignore-whitespace ../../patches/faiss/0001-Custom-patch-to-support-multi-vector.patch
git -C jni/external/faiss apply --3way --ignore-space-change --ignore-whitespace ../../patches/faiss/0002-Enable-precomp-table-to-be-shared-ivfpq.patch
git -C jni/external/faiss apply --3way --ignore-space-change --ignore-whitespace ../../patches/faiss/0003-Custom-patch-to-support-range-search-params.patch
git -C jni/external/faiss apply --3way --ignore-space-change --ignore-whitespace ../../patches/faiss/0004-Custom-patch-to-support-binary-vector.patch

# _MSC_VER is a predefined macro which defines the version of Visual Studio Compiler
# As we are using x86_64-w64-mingw32-gcc compiler we need to replace this macro with __MINGW32__
Expand Down

0 comments on commit 4a96b99

Please sign in to comment.