Skip to content

Commit

Permalink
Apply custom patch only once by comparing the last patch id
Browse files Browse the repository at this point in the history
Signed-off-by: Heemin Kim <[email protected]>
  • Loading branch information
heemin32 committed Jul 16, 2024
1 parent 48478b4 commit 5e54810
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 12 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 by comparing the last patch id [#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
22 changes: 18 additions & 4 deletions jni/cmake/init-faiss.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,25 @@ if (NOT EXISTS ${FAISS_REPO_DIR})
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)
# Get the last patch file name
file(GLOB PATCH_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/patches/faiss/*")
list(SORT PATCH_FILE_LIST ORDER DESCENDING)
list(GET PATCH_FILE_LIST 0 LAST_PATCH_FILE)
message(STATUS "Last patch file: ${PATCH_FILE_LIST}")

# If it exists, apply patches
if (EXISTS ${PATCH_FILE})
# Get patch id of the last patch
execute_process(COMMAND sh -c "cat ${LAST_PATCH_FILE} | git patch-id --stable" OUTPUT_VARIABLE PATCH_ID_OUTPUT)
string(REPLACE " " ";" PATCH_ID_LIST ${PATCH_ID_OUTPUT})
list(GET PATCH_ID_LIST 0 PATCH_ID)
message(STATUS "Extracted patch ID: ${PATCH_ID}")

# Get patch id of the last commit
execute_process(COMMAND sh -c "git --no-pager show HEAD | git patch-id --stable" OUTPUT_VARIABLE PATCH_ID_OUTPUT_FROM_COMMIT WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/external/faiss)
string(REPLACE " " ";" PATCH_ID_LIST_FROM_COMMIT ${PATCH_ID_OUTPUT_FROM_COMMIT})
list(GET PATCH_ID_LIST_FROM_COMMIT 0 PATCH_ID_FROM_COMMIT)
message(STATUS "Extracted patch ID from commit: ${PATCH_ID_FROM_COMMIT}")

if (NOT ${PATCH_ID} STREQUAL ${PATCH_ID_FROM_COMMIT})
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 Down
22 changes: 18 additions & 4 deletions jni/cmake/init-nmslib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,25 @@ if (NOT EXISTS ${NMS_REPO_DIR})
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)
# Get the last patch file name
file(GLOB PATCH_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/patches/nmslib/*")
list(SORT PATCH_FILE_LIST ORDER DESCENDING)
list(GET PATCH_FILE_LIST 0 LAST_PATCH_FILE)
message(STATUS "Last patch file: ${LAST_PATCH_FILE}")

# If it exists, apply patches
if (EXISTS ${PATCH_FILE})
# Get patch id of the last patch
execute_process(COMMAND sh -c "cat ${LAST_PATCH_FILE} | git patch-id --stable" OUTPUT_VARIABLE PATCH_ID_OUTPUT)
string(REPLACE " " ";" PATCH_ID_LIST ${PATCH_ID_OUTPUT})
list(GET PATCH_ID_LIST 0 PATCH_ID)
message(STATUS "Extracted patch ID: ${PATCH_ID}")

# Get patch id of the last commit
execute_process(COMMAND sh -c "git --no-pager show HEAD | git patch-id --stable" OUTPUT_VARIABLE PATCH_ID_OUTPUT_FROM_COMMIT WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/external/nmslib)
string(REPLACE " " ";" PATCH_ID_LIST_FROM_COMMIT ${PATCH_ID_OUTPUT_FROM_COMMIT})
list(GET PATCH_ID_LIST_FROM_COMMIT 0 PATCH_ID_FROM_COMMIT)
message(STATUS "Extracted patch ID from commit: ${PATCH_ID_FROM_COMMIT}")

if (NOT ${PATCH_ID} STREQUAL ${PATCH_ID_FROM_COMMIT})
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)
Expand Down

0 comments on commit 5e54810

Please sign in to comment.