|
| 1 | +name: Build cmake |
| 2 | +inputs: |
| 3 | + opt_level: |
| 4 | + description: 'Compile options / optimization level.' |
| 5 | + required: false |
| 6 | + default: generic |
| 7 | + gpu: |
| 8 | + description: 'Enable GPU support.' |
| 9 | + required: false |
| 10 | + default: OFF |
| 11 | + cuvs: |
| 12 | + description: 'Enable cuVS support.' |
| 13 | + required: false |
| 14 | + default: OFF |
| 15 | + rocm: |
| 16 | + description: 'Enable ROCm support.' |
| 17 | + required: false |
| 18 | + default: OFF |
| 19 | +runs: |
| 20 | + using: composite |
| 21 | + steps: |
| 22 | + - name: Setup miniconda |
| 23 | + uses: conda-incubator/setup-miniconda@v3 |
| 24 | + with: |
| 25 | + python-version: '3.11' |
| 26 | + miniforge-version: latest # ensures conda-forge channel is used. |
| 27 | + channels: conda-forge |
| 28 | + conda-remove-defaults: 'true' |
| 29 | + # Set to aarch64 if we're on arm64 because there's no miniforge ARM64 package, just aarch64. |
| 30 | + # They are the same thing, just named differently. |
| 31 | + architecture: ${{ runner.arch == 'ARM64' && 'aarch64' || runner.arch }} |
| 32 | + - name: Configure build environment |
| 33 | + shell: bash |
| 34 | + run: | |
| 35 | + # initialize Conda |
| 36 | + conda config --set solver libmamba |
| 37 | + # Ensure starting packages are from conda-forge. |
| 38 | + conda list --show-channel-urls |
| 39 | + conda update -y -q conda |
| 40 | + echo "$CONDA/bin" >> $GITHUB_PATH |
| 41 | +
|
| 42 | + conda install -y -q python=3.11 cmake=3.26 make=4.2 swig=4.0 "numpy<2" scipy=1.14 pytest=7.4 gflags=2.2 |
| 43 | +
|
| 44 | + # install base packages for ARM64 |
| 45 | + if [ "${{ runner.arch }}" = "ARM64" ]; then |
| 46 | + conda install -y -q -c conda-forge openblas=0.3 gxx_linux-aarch64=14.2 sysroot_linux-aarch64=2.17 |
| 47 | + fi |
| 48 | +
|
| 49 | + # install base packages for X86_64 |
| 50 | + if [ "${{ runner.arch }}" = "X64" ]; then |
| 51 | + # TODO: merge this with ARM64 |
| 52 | + conda install -y -q -c conda-forge gxx_linux-64=14.2 sysroot_linux-64=2.17 |
| 53 | + conda install -y -q mkl=2022.2.1 mkl-devel=2022.2.1 |
| 54 | + fi |
| 55 | +
|
| 56 | + # no CUDA needed for ROCm so skip this |
| 57 | + if [ "${{ inputs.rocm }}" = "ON" ]; then |
| 58 | + : |
| 59 | + # regular CUDA for GPU builds |
| 60 | + elif [ "${{ inputs.gpu }}" = "ON" ] && [ "${{ inputs.cuvs }}" = "OFF" ]; then |
| 61 | + conda install -y -q cuda-toolkit=12.4 -c "nvidia/label/cuda-12.4.0" |
| 62 | + # and CUDA from cuVS channel for cuVS builds |
| 63 | + elif [ "${{ inputs.cuvs }}" = "ON" ]; then |
| 64 | + conda install -y -q libcuvs=24.12 'cuda-version>=12.0,<=12.5' cuda-toolkit=12.4.1 gxx_linux-64=12.4 -c rapidsai -c conda-forge |
| 65 | + fi |
| 66 | +
|
| 67 | + # install test packages |
| 68 | + if [ "${{ inputs.rocm }}" = "ON" ]; then |
| 69 | + : # skip torch install via conda, we need to install via pip to get |
| 70 | + # ROCm-enabled version until it's supported in conda by PyTorch |
| 71 | + elif [ "${{ inputs.gpu }}" = "ON" ]; then |
| 72 | + conda install -y -q "pytorch<2.5" pytorch-cuda=12.4 -c pytorch -c "nvidia/label/cuda-12.4.0" |
| 73 | + else |
| 74 | + conda install -y -q "pytorch<2.5" -c pytorch |
| 75 | + fi |
| 76 | + - name: ROCm - Install dependencies |
| 77 | + if: inputs.rocm == 'ON' |
| 78 | + shell: bash |
| 79 | + run: | |
| 80 | + # Update repos and install kmod, wget, gpg |
| 81 | + sudo apt-get -qq update >/dev/null |
| 82 | + sudo apt-get -qq install -y kmod wget gpg >/dev/null |
| 83 | +
|
| 84 | + # Get UBUNTU version name |
| 85 | + UBUNTU_VERSION_NAME=`cat /etc/os-release | grep UBUNTU_CODENAME | awk -F= '{print $2}'` |
| 86 | +
|
| 87 | + # Set ROCm version |
| 88 | + ROCM_VERSION="6.2" |
| 89 | +
|
| 90 | + # Download, prepare, and install the package signing key |
| 91 | + mkdir --parents --mode=0755 /etc/apt/keyrings |
| 92 | + wget https://repo.radeon.com/rocm/rocm.gpg.key -O - | gpg --dearmor | sudo tee /etc/apt/keyrings/rocm.gpg > /dev/null |
| 93 | +
|
| 94 | + # Add rocm repository |
| 95 | + wget -qO - http://repo.radeon.com/rocm/rocm.gpg.key | sudo apt-key add - |
| 96 | + rocm_baseurl="http://repo.radeon.com/rocm/apt/${ROCM_VERSION}" |
| 97 | + echo "deb [arch=amd64] ${rocm_baseurl} ${UBUNTU_VERSION_NAME} main" | sudo tee /etc/apt/sources.list.d/rocm.list |
| 98 | + sudo apt-get -qq update --allow-insecure-repositories >/dev/null |
| 99 | + sudo apt-get -qq install -y --allow-unauthenticated \ |
| 100 | + "rocm-dev${ROCM_VERSION}" "rocm-utils${ROCM_VERSION}" \ |
| 101 | + "rocm-libs${ROCM_VERSION}" >/dev/null |
| 102 | +
|
| 103 | + # Fake presence of MI200-class accelerators |
| 104 | + echo "gfx90a" | sudo tee /opt/rocm/bin/target.lst |
| 105 | +
|
| 106 | + # Cleanup |
| 107 | + sudo apt-get -qq autoclean >/dev/null |
| 108 | + sudo apt-get -qq clean >/dev/null |
| 109 | + sudo rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* |
| 110 | + - name: Symblink system dependencies |
| 111 | + if: inputs.rocm == 'ON' |
| 112 | + shell: bash |
| 113 | + run: | |
| 114 | + # symblink system libraries for HIP compiler |
| 115 | + sudo ln -s /lib/x86_64-linux-gnu/libc.so.6 /lib64/libc.so.6 |
| 116 | + sudo ln -s /lib/x86_64-linux-gnu/libc_nonshared.a /usr/lib64/libc_nonshared.a |
| 117 | + sudo ln -s /usr/lib/x86_64-linux-gnu/libpthread.so.0 /lib64/libpthread.so.0 |
| 118 | + sudo ln -s $HOME/miniconda3/x86_64-conda-linux-gnu/sysroot/usr/lib64/libpthread_nonshared.a /usr/lib64/libpthread_nonshared.a |
| 119 | + - name: Build all targets |
| 120 | + shell: bash |
| 121 | + run: | |
| 122 | + eval "$(conda shell.bash hook)" |
| 123 | + conda activate |
| 124 | + cmake -B build \ |
| 125 | + -DBUILD_TESTING=ON \ |
| 126 | + -DBUILD_SHARED_LIBS=ON \ |
| 127 | + -DFAISS_ENABLE_GPU=${{ inputs.gpu }} \ |
| 128 | + -DFAISS_ENABLE_CUVS=${{ inputs.cuvs }} \ |
| 129 | + -DFAISS_ENABLE_ROCM=${{ inputs.rocm }} \ |
| 130 | + -DFAISS_OPT_LEVEL=${{ inputs.opt_level }} \ |
| 131 | + -DFAISS_ENABLE_C_API=ON \ |
| 132 | + -DPYTHON_EXECUTABLE=$CONDA/bin/python \ |
| 133 | + -DCMAKE_BUILD_TYPE=Release \ |
| 134 | + -DBLA_VENDOR=${{ runner.arch == 'X64' && 'Intel10_64_dyn' || '' }} \ |
| 135 | + -DCMAKE_CUDA_FLAGS=${{ runner.arch == 'X64' && '"-gencode arch=compute_75,code=sm_75"' || '' }} \ |
| 136 | + . |
| 137 | + make -k -C build -j$(nproc) |
| 138 | + - name: C++ tests |
| 139 | + shell: bash |
| 140 | + run: | |
| 141 | + export GTEST_OUTPUT="xml:$(realpath .)/test-results/googletest/" |
| 142 | + make -C build test |
| 143 | + - name: C++ perf benchmarks |
| 144 | + shell: bash |
| 145 | + if: inputs.rocm == 'OFF' |
| 146 | + run: | |
| 147 | + find ./build/perf_tests/ -executable -type f -name "bench*" -exec '{}' -v \; |
| 148 | + - name: Install Python extension |
| 149 | + shell: bash |
| 150 | + working-directory: build/faiss/python |
| 151 | + run: | |
| 152 | + $CONDA/bin/python setup.py install |
| 153 | + - name: ROCm - install ROCm-enabled torch via pip |
| 154 | + if: inputs.rocm == 'ON' |
| 155 | + shell: bash |
| 156 | + run: | |
| 157 | + pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/rocm6.1 |
| 158 | + - name: Python tests (CPU only) |
| 159 | + if: inputs.gpu == 'OFF' |
| 160 | + shell: bash |
| 161 | + run: | |
| 162 | + pytest --junitxml=test-results/pytest/results.xml tests/test_*.py |
| 163 | + pytest --junitxml=test-results/pytest/results-torch.xml tests/torch_*.py |
| 164 | + - name: Python tests (CPU + GPU) |
| 165 | + if: inputs.gpu == 'ON' |
| 166 | + shell: bash |
| 167 | + run: | |
| 168 | + pytest --junitxml=test-results/pytest/results.xml tests/test_*.py |
| 169 | + pytest --junitxml=test-results/pytest/results-torch.xml tests/torch_*.py |
| 170 | + cp tests/common_faiss_tests.py faiss/gpu/test |
| 171 | + pytest --junitxml=test-results/pytest/results-gpu.xml faiss/gpu/test/test_*.py |
| 172 | + pytest --junitxml=test-results/pytest/results-gpu-torch.xml faiss/gpu/test/torch_*.py |
| 173 | + - name: Test avx2 loading |
| 174 | + if: inputs.opt_level == 'avx2' |
| 175 | + shell: bash |
| 176 | + run: | |
| 177 | + FAISS_DISABLE_CPU_FEATURES=AVX2 LD_DEBUG=libs $CONDA/bin/python -c "import faiss" 2>&1 | grep faiss.so |
| 178 | + LD_DEBUG=libs $CONDA/bin/python -c "import faiss" 2>&1 | grep faiss_avx2.so |
| 179 | + - name: Upload test results |
| 180 | + if: always() |
| 181 | + uses: actions/upload-artifact@v4 |
| 182 | + with: |
| 183 | + name: test-results-arch=${{ runner.arch }}-opt=${{ inputs.opt_level }}-gpu=${{ inputs.gpu }}-cuvs=${{ inputs.cuvs }}-rocm=${{ inputs.rocm }} |
| 184 | + path: test-results |
| 185 | + - name: Check installed packages channel |
| 186 | + shell: bash |
| 187 | + run: | |
| 188 | + # Shows that all installed packages are from conda-forge. |
| 189 | + conda list --show-channel-urls |
0 commit comments