diff --git a/.github/actions/build_cmake/action.yml b/.github/actions/build_cmake/action.yml index ad3811f473..2e32dc1578 100644 --- a/.github/actions/build_cmake/action.yml +++ b/.github/actions/build_cmake/action.yml @@ -101,10 +101,6 @@ runs: sudo apt-get -qq autoclean >/dev/null sudo apt-get -qq clean >/dev/null sudo rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* - - name: ROCm - Hipify - if: inputs.rocm == 'ON' - shell: bash - run: ./faiss/gpu/hipify.sh - name: Symblink system dependencies if: inputs.raft == 'ON' || inputs.rocm == 'ON' shell: bash diff --git a/CMakeLists.txt b/CMakeLists.txt index c4fea46a3d..03d2b496eb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,6 +72,7 @@ if(FAISS_ENABLE_GPU) find_package(HIP REQUIRED) find_package(hipBLAS REQUIRED) set(GPU_EXT_PREFIX "hip") + execute_process(COMMAND ${PROJECT_SOURCE_DIR}/faiss/gpu/hipify.sh) else () set(CMAKE_CUDA_HOST_COMPILER ${CMAKE_CXX_COMPILER}) enable_language(CUDA) diff --git a/INSTALL.md b/INSTALL.md index d4e2326ffb..e6d3f33fb8 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -147,9 +147,7 @@ Several options can be passed to CMake, among which: to build against (see [CUDA docs](https://developer.nvidia.com/cuda-gpus) to determine which architecture(s) you should pick), - `-DFAISS_ENABLE_ROCM=ON` in order to enable building GPU indices for AMD GPUs. - The hipify script must be executed before using this option. - Invoke `./faiss/gpu/hipify.sh` to execute. `-DFAISS_ENABLE_GPU` must be `ON` - when using this option. (possible values are `ON` and `OFF`), + `-DFAISS_ENABLE_GPU` must be `ON` when using this option. (possible values are `ON` and `OFF`), - python-related options: - `-DPython_EXECUTABLE=/path/to/python3.7` in order to build a python interface for a different python than the default one (see diff --git a/faiss/gpu/hipify.sh b/faiss/gpu/hipify.sh index c8d75bf2fa..2b65854205 100755 --- a/faiss/gpu/hipify.sh +++ b/faiss/gpu/hipify.sh @@ -4,101 +4,87 @@ # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. -# go one level up from faiss/gpu -top=$(dirname "${BASH_SOURCE[0]}")/.. -echo "top=$top" -cd "$top" || exit -echo "pwd=$(pwd)" +function hipify_dir() +{ + # print dir name + cd "$1" || exit + echo "Hipifying $(pwd)" -# create all destination directories for hipified files into sibling 'gpu-rocm' directory -while IFS= read -r -d '' src -do - dst="${src//gpu/gpu-rocm}" - echo "Creating $dst" - mkdir -p "$dst" -done < <(find ./gpu -type d -print0) - -# run hipify-perl against all *.cu *.cuh *.h *.cpp files, no renaming -# run all files in parallel to speed up -for ext in cu cuh h cpp -do + # create all destination directories for hipified files into sibling 'gpu-rocm' directory while IFS= read -r -d '' src do - dst="${src//\.\/gpu/\.\/gpu-rocm}" - hipify-perl -o="$dst.tmp" "$src" & - done < <(find ./gpu -name "*.$ext" -print0) -done -wait + dst="${src//gpu/gpu-rocm}" -# rename all hipified *.cu files to *.hip -while IFS= read -r -d '' src -do - dst=${src%.cu.tmp}.hip.tmp - mv "$src" "$dst" -done < <(find ./gpu-rocm -name "*.cu.tmp" -print0) + if [ -d $dst ]; then + #Clearing out any leftover files and directories + echo "Removing old $dst" + rm -rf "$dst" + fi -# replace header include statements "@#include @' "$src" - sed -i 's@#include @#include @' "$src" - done < <(find ./gpu-rocm -name "*.$ext.tmp" -print0) -done + #Making directories + echo "Creating $dst" + mkdir -p "$dst" + done < <(find ./gpu -type d -print0) -# hipify was run in parallel above -# don't copy the tmp file if it is unchanged -for ext in hip cuh h cpp -do + # run hipify-perl against all *.cu *.cuh *.h *.cpp files, no renaming + # run all files in parallel to speed up + for ext in cu cuh h cpp c + do + while IFS= read -r -d '' src + do + dst="${src//\.\/gpu/\.\/gpu-rocm}" + hipify-perl -o="$dst.tmp" "$src" & + done < <(find ./gpu -name "*.$ext" -print0) + done + wait + + # rename all hipified *.cu files to *.hip while IFS= read -r -d '' src do - dst=${src%.tmp} - if test -f "$dst" - then - if diff -q "$src" "$dst" >& /dev/null + dst=${src%.cu.tmp}.hip.tmp + mv "$src" "$dst" + done < <(find ./gpu-rocm -name "*.cu.tmp" -print0) + + # replace header include statements "@#include @' "$src" + sed -i 's@#include @#include @' "$src" + done < <(find ./gpu-rocm -name "*.$ext.tmp" -print0) + done + + # hipify was run in parallel above + # don't copy the tmp file if it is unchanged + for ext in hip cuh h cpp c + do + while IFS= read -r -d '' src + do + dst=${src%.tmp} + if test -f "$dst" then - echo "$dst [unchanged]" - rm "$src" + if diff -q "$src" "$dst" >& /dev/null + then + echo "$dst [unchanged]" + rm "$src" + else + echo "$dst" + mv "$src" "$dst" + fi else echo "$dst" mv "$src" "$dst" fi - else - echo "$dst" - mv "$src" "$dst" - fi - done < <(find ./gpu-rocm -name "*.$ext.tmp" -print0) -done - -# copy over CMakeLists.txt -while IFS= read -r -d '' src -do - dst="${src//\.\/gpu/\.\/gpu-rocm}" - if test -f "$dst" - then - if diff -q "$src" "$dst" >& /dev/null - then - echo "$dst [unchanged]" - else - echo "$dst" - cp "$src" "$dst" - fi - else - echo "$dst" - cp "$src" "$dst" - fi -done < <(find ./gpu -name "CMakeLists.txt" -print0) + done < <(find ./gpu-rocm -name "*.$ext.tmp" -print0) + done -# Copy over other files -other_exts="py" -for ext in $other_exts -do + # copy over CMakeLists.txt while IFS= read -r -d '' src do dst="${src//\.\/gpu/\.\/gpu-rocm}" @@ -115,102 +101,36 @@ do echo "$dst" cp "$src" "$dst" fi - done < <(find ./gpu -name "*.$ext" -print0) -done - -################################################################################### -# C_API Support -################################################################################### - -# Now get the c_api dir -# This points to the faiss/c_api dir -top_c_api=$(dirname "${BASH_SOURCE[0]}")/../../c_api -echo "top=$top_c_api" -cd "../$top_c_api" || exit -echo "pwd=$(pwd)" - - -# create all destination directories for hipified files into sibling 'gpu-rocm' directory -while IFS= read -r -d '' src -do - dst="${src//gpu/gpu-rocm}" - echo "Creating $dst" - mkdir -p "$dst" -done < <(find ./gpu -type d -print0) + done < <(find ./gpu -name "CMakeLists.txt" -print0) -# run hipify-perl against all *.cu *.cuh *.h *.cpp files, no renaming -# run all files in parallel to speed up -for ext in cu cuh h cpp c -do - while IFS= read -r -d '' src - do - dst="${src//\.\/gpu/\.\/gpu-rocm}" - hipify-perl -o="$dst.tmp" "$src" & - done < <(find ./gpu -name "*.$ext" -print0) -done -wait - -# rename all hipified *.cu files to *.hip -while IFS= read -r -d '' src -do - dst=${src%.cu.tmp}.hip.tmp - mv "$src" "$dst" -done < <(find ./gpu-rocm -name "*.cu.tmp" -print0) - -# replace header include statements "@#include @' "$src" - sed -i 's@#include @#include @' "$src" - done < <(find ./gpu-rocm -name "*.$ext.tmp" -print0) -done - -# hipify was run in parallel above -# don't copy the tmp file if it is unchanged -for ext in hip cuh h cpp c -do - while IFS= read -r -d '' src - do - dst=${src%.tmp} - if test -f "$dst" - then - if diff -q "$src" "$dst" >& /dev/null + while IFS= read -r -d '' src + do + dst="${src//\.\/gpu/\.\/gpu-rocm}" + if test -f "$dst" then - echo "$dst [unchanged]" - rm "$src" + if diff -q "$src" "$dst" >& /dev/null + then + echo "$dst [unchanged]" + else + echo "$dst" + cp "$src" "$dst" + fi else echo "$dst" - mv "$src" "$dst" + cp "$src" "$dst" fi - else - echo "$dst" - mv "$src" "$dst" - fi - done < <(find ./gpu-rocm -name "*.$ext.tmp" -print0) -done + done < <(find ./gpu -name "*.$ext" -print0) + done +} -# copy over CMakeLists.txt -while IFS= read -r -d '' src -do - dst="${src//\.\/gpu/\.\/gpu-rocm}" - if test -f "$dst" - then - if diff -q "$src" "$dst" >& /dev/null - then - echo "$dst [unchanged]" - else - echo "$dst" - cp "$src" "$dst" - fi - else - echo "$dst" - cp "$src" "$dst" - fi -done < <(find ./gpu -name "CMakeLists.txt" -print0) +# Convert the faiss/gpu dir +dir_name=$(dirname "${BASH_SOURCE[0]}")/.. +hipify_dir $dir_name + +# Convert the faiss/c_api dir +dir_name=$(dirname "${BASH_SOURCE[0]}")/../../c_api +hipify_dir $dir_name