Skip to content

Commit 394f9c2

Browse files
Enable ROCm in build-only mode (#3713)
Summary: Enable ROCm in CI Differential Revision: D60598458
1 parent b670cb1 commit 394f9c2

File tree

4 files changed

+78
-6
lines changed

4 files changed

+78
-6
lines changed

.github/actions/build_cmake/action.yml

+55-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ inputs:
1212
description: 'Enable RAFT support.'
1313
required: false
1414
default: OFF
15+
rocm:
16+
description: 'Enable ROCm support.'
17+
required: false
18+
default: OFF
1519
runs:
1620
using: composite
1721
steps:
@@ -38,7 +42,11 @@ runs:
3842
# install base packages for X86_64
3943
if [ "${{ runner.arch }}" = "X64" ]; then
4044
# TODO: unpin versions for gxx_linux-64 and sysroot_linux-64 and merge it with ARM64 below
41-
conda install -y -q -c conda-forge gxx_linux-64=11.2 sysroot_linux-64=2.28
45+
if [ "${{ inputs.rocm }}" = "ON" ]; then
46+
conda install -y -q -c conda-forge gxx_linux-64 sysroot_linux-64
47+
else
48+
conda install -y -q -c conda-forge gxx_linux-64=11.2 sysroot_linux-64=2.28
49+
fi
4250
conda install -y -q mkl=2023 mkl-devel=2023
4351
fi
4452
@@ -60,6 +68,48 @@ runs:
6068
else
6169
conda install -y -q pytorch -c pytorch
6270
fi
71+
- name: ROCm - Install dependencies
72+
if: inputs.rocm == 'ON'
73+
shell: bash
74+
run: |
75+
# Update repos and install kmod, wget
76+
sudo apt-get update
77+
sudo apt-get install -y kmod wget
78+
79+
# Get UBUNTU version name
80+
UBUNTU_VERSION_NAME=`cat /etc/os-release | grep UBUNTU_CODENAME | awk -F= '{print $2}'`
81+
82+
# Set ROCm version
83+
ROCM_VERSION="6.1.1"
84+
85+
# Download, prepare, and install the package signing key
86+
mkdir --parents --mode=0755 /etc/apt/keyrings
87+
wget https://repo.radeon.com/rocm/rocm.gpg.key -O - | gpg --dearmor | sudo tee /etc/apt/keyrings/rocm.gpg > /dev/null
88+
89+
# Add rocm repository
90+
wget -qO - http://repo.radeon.com/rocm/rocm.gpg.key | sudo apt-key add -
91+
rocm_baseurl="http://repo.radeon.com/rocm/apt/${ROCM_VERSION}"
92+
echo "deb [arch=amd64] ${rocm_baseurl} ${UBUNTU_VERSION_NAME} main" | sudo tee /etc/apt/sources.list.d/rocm.list
93+
sudo apt-get update --allow-insecure-repositories
94+
sudo apt-get install -y --allow-unauthenticated \
95+
"rocm-dev${ROCM_VERSION}" "rocm-utils${ROCM_VERSION}" "rocm-libs${ROCM_VERSION}"
96+
97+
# Fake presence of MI200-class accelerators
98+
echo "gfx90a" | sudo tee /opt/rocm/bin/target.lst
99+
100+
# Cleanup
101+
sudo apt-get autoclean && sudo apt-get clean
102+
sudo rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
103+
104+
# symblink system libraries for HIP compiler
105+
sudo ln -s /lib/x86_64-linux-gnu/libc.so.6 /lib64/libc.so.6
106+
sudo ln -s /lib/x86_64-linux-gnu/libc_nonshared.a /usr/lib64/libc_nonshared.a
107+
sudo ln -s /usr/lib/x86_64-linux-gnu/libpthread.so.0 /lib64/libpthread.so.0
108+
sudo ln -s /home/runner/miniconda3/x86_64-conda-linux-gnu/sysroot/usr/lib64/libpthread_nonshared.a /usr/lib64/libpthread_nonshared.a
109+
- name: ROCm - Hipify
110+
if: inputs.rocm == 'ON'
111+
shell: bash
112+
run: ./faiss/gpu/hipify.sh
63113
- name: Build all targets
64114
shell: bash
65115
run: |
@@ -70,6 +120,7 @@ runs:
70120
-DBUILD_SHARED_LIBS=ON \
71121
-DFAISS_ENABLE_GPU=${{ inputs.gpu }} \
72122
-DFAISS_ENABLE_RAFT=${{ inputs.raft }} \
123+
-DFAISS_ENABLE_ROCM=${{ inputs.rocm }} \
73124
-DFAISS_OPT_LEVEL=${{ inputs.opt_level }} \
74125
-DFAISS_ENABLE_C_API=ON \
75126
-DPYTHON_EXECUTABLE=$CONDA/bin/python \
@@ -79,6 +130,7 @@ runs:
79130
.
80131
make -k -C build -j$(nproc)
81132
- name: C++ tests
133+
if: inputs.rocm == 'OFF'
82134
shell: bash
83135
run: |
84136
export GTEST_OUTPUT="xml:$(realpath .)/test-results/googletest/"
@@ -95,7 +147,7 @@ runs:
95147
pytest --junitxml=test-results/pytest/results.xml tests/test_*.py
96148
pytest --junitxml=test-results/pytest/results-torch.xml tests/torch_*.py
97149
- name: Python tests (CPU + GPU)
98-
if: inputs.gpu == 'ON'
150+
if: inputs.gpu == 'ON' && inputs.rocm == 'OFF'
99151
shell: bash
100152
run: |
101153
pytest --junitxml=test-results/pytest/results.xml tests/test_*.py
@@ -110,6 +162,7 @@ runs:
110162
FAISS_DISABLE_CPU_FEATURES=AVX2 LD_DEBUG=libs $CONDA/bin/python -c "import faiss" 2>&1 | grep faiss.so
111163
LD_DEBUG=libs $CONDA/bin/python -c "import faiss" 2>&1 | grep faiss_avx2.so
112164
- name: Upload test results
165+
if: inputs.rocm == 'OFF'
113166
uses: actions/upload-artifact@v4
114167
with:
115168
name: test-results-${{ runner.arch }}-${{ inputs.opt_level }}-${{ inputs.gpu }}-${{ inputs.raft }}

.github/workflows/build.yml

+11
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,17 @@ jobs:
8888
with:
8989
gpu: ON
9090
raft: ON
91+
linux-x86_64-GPU-w-ROCm-cmake:
92+
name: Linux x86_64 GPU w/ ROCm (cmake)
93+
needs: linux-x86_64-cmake
94+
runs-on: 4-core-ubuntu
95+
steps:
96+
- name: Checkout
97+
uses: actions/checkout@v4
98+
- uses: ./.github/actions/build_cmake
99+
with:
100+
gpu: ON
101+
rocm: ON
91102
linux-arm64-SVE-cmake:
92103
name: Linux arm64 SVE (cmake)
93104
needs: linux-x86_64-cmake

CMakeLists.txt

+11-4
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ cmake_minimum_required(VERSION 3.24.0 FATAL_ERROR)
2323
set(FAISS_LANGUAGES CXX)
2424

2525
if(FAISS_ENABLE_GPU)
26-
# if ROCm install detected, assume ROCm/HIP is GPU device
27-
if (EXISTS /opt/rocm)
26+
if (FAISS_ENABLE_ROCM)
2827
set(USE_ROCM TRUE)
2928
list(APPEND FAISS_LANGUAGES HIP)
29+
list(PREPEND CMAKE_MODULE_PATH "/opt/rocm/lib/cmake")
30+
list(PREPEND CMAKE_PREFIX_PATH "/opt/rocm")
3031
else()
3132
list(APPEND FAISS_LANGUAGES CUDA)
3233
endif()
@@ -60,6 +61,7 @@ list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
6061
option(FAISS_OPT_LEVEL "" "generic")
6162
option(FAISS_ENABLE_GPU "Enable support for GPU indexes." ON)
6263
option(FAISS_ENABLE_RAFT "Enable RAFT for GPU indexes." OFF)
64+
option(FAISS_ENABLE_ROCM "Enable ROCm for GPU indexes." OFF)
6365
option(FAISS_ENABLE_PYTHON "Build Python extension." ON)
6466
option(FAISS_ENABLE_C_API "Build C API." OFF)
6567

@@ -78,8 +80,13 @@ if(FAISS_ENABLE_GPU)
7880
endif()
7981

8082
if(FAISS_ENABLE_RAFT AND NOT TARGET raft::raft)
81-
find_package(raft COMPONENTS compiled distributed)
82-
endif()
83+
find_package(raft COMPONENTS compiled distributed)
84+
endif()
85+
86+
if(USE_ROCM)
87+
find_package(HIP REQUIRED)
88+
find_package(hipBLAS REQUIRED)
89+
endif()
8390

8491
add_subdirectory(faiss)
8592

tests/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ target_link_libraries(faiss_test PRIVATE
123123
OpenMP::OpenMP_CXX
124124
GTest::gtest_main
125125
$<$<BOOL:${FAISS_ENABLE_RAFT}>:raft::raft>
126+
$<$<BOOL:${FAISS_ENABLE_ROCM}>:hip::host>
126127
)
127128

128129
# Defines `gtest_discover_tests()`.

0 commit comments

Comments
 (0)