Debian Codegraph @

.github/actions/build_cmake/action.yml

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