mirror of
https://github.com/facebookresearch/faiss.git
synced 2026-10-11 22:50:00 +00:00
Select OpenBLAS OMP build in conda for AArch64 + Linux (#5669)
Summary: - The current Faiss conda recipe does not specify the OpenBLAS threading variant. - On Linux AArch64, the dependency solver selects the pthreads build. - This causes problems when Faiss calls BLAS from within an existing OpenMP parallel region due to nested threading - As a result, the benchmark below (with an OOB conda install of faiss) only yields 7% of the throughput reachable when an OMP build of OpenBLAS is selected (what this PR does) - This PR fixes the issue, and as a result accelerates affected workloads by ~ 14x ``` # SPDX-FileCopyrightText: Copyright 2026 Arm Limited and/or its affiliates <[email protected]> # SPDX-License-Identifier: MIT import ctypes import statistics import time import faiss import numpy as np rng = np.random.default_rng(1234) d = 128 nlist = 4096 nq = 40_000 quantizer = faiss.IndexFlatL2(d) quantizer.add(rng.random((nlist, d), dtype=np.float32)) index = faiss.IndexIVFPQFastScan(quantizer, d, nlist, 128, 4) # index is empty - this only triggeres the course quantizer index.is_trained = True index.nprobe = 64 xq = rng.random((nq, d), dtype=np.float32) openblas = ctypes.CDLL("libopenblas.so.0") openblas.openblas_get_parallel.restype = ctypes.c_int openblas.openblas_get_num_threads.restype = ctypes.c_int print(f"nq={nq:,}, d={d}, nlist={nlist}, nprobe={index.nprobe}") print(f"OpenMP threads={faiss.omp_get_max_threads()}") print( f"OpenBLAS parallel={openblas.openblas_get_parallel()}, " f"threads={openblas.openblas_get_num_threads()}" ) print(f"BLAS threshold={faiss.cvar.distance_compute_blas_threshold}") index.search(xq, 10) times = [] for _ in range(20): start = time.perf_counter() index.search(xq, 10) times.append(time.perf_counter() - start) elapsed = statistics.median(times) print(f"median={elapsed:.6f}s, throughput={nq / elapsed:,.0f} QPS") ``` Pull Request resolved: https://github.com/facebookresearch/faiss/pull/5669 Reviewed By: weixianghong Differential Revision: D124380509 Pulled By: mnorris11 fbshipit-source-id: 16e1521e7aaf7d65c6a4ce8e404a47bdb26c1198
This commit is contained in:
committed by
meta-codesync[bot]
parent
44afa7729d
commit
39079668a8
@@ -1,4 +1,5 @@
|
||||
# Copyright (c) Facebook, Inc. and its affiliates.
|
||||
# Copyright 2026 Arm Limited and/or its affiliates <[email protected]>
|
||||
#
|
||||
# This source code is licensed under the MIT license found in the
|
||||
# LICENSE file in the root directory of this source tree.
|
||||
@@ -61,14 +62,14 @@ outputs:
|
||||
host:
|
||||
- _openmp_mutex =4.5=2_kmp_llvm # [x86_64]
|
||||
- mkl >=2024.2.2,<2026 # [x86_64]
|
||||
- openblas =0.3.34 # [not x86_64]
|
||||
- openblas =0.3.34 openmp_* # [not x86_64]
|
||||
- libcuvs =26.06
|
||||
- cuda-version {{ cuda_constraints }}
|
||||
- libsvs-runtime =0.4.0 # [x86_64 and linux]
|
||||
run:
|
||||
- _openmp_mutex =4.5=2_kmp_llvm # [x86_64]
|
||||
- mkl >=2024.2.2,<2026 # [x86_64]
|
||||
- openblas =0.3.34 # [not x86_64]
|
||||
- openblas =0.3.34 openmp_* # [not x86_64]
|
||||
- cuda-cudart {{ cuda_constraints }}
|
||||
- libcublas {{ libcublas_constraints }}
|
||||
- libcuvs =26.06
|
||||
@@ -83,6 +84,7 @@ outputs:
|
||||
- test -f $PREFIX/lib/libfaiss_avx2$SHLIB_EXT # [x86_64 and not win]
|
||||
- conda inspect linkages -p $PREFIX $PKG_NAME # [not win]
|
||||
- conda inspect objects -p $PREFIX $PKG_NAME # [osx]
|
||||
- python -c "import ctypes; lib = ctypes.CDLL('libopenblas.so.0'); assert lib.openblas_get_parallel() == 2" # [linux and not x86_64]
|
||||
|
||||
- name: faiss-gpu-cuvs
|
||||
script: build-pkg.sh # [x86_64 and not win and not osx]
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
# Copyright (c) Facebook, Inc. and its affiliates.
|
||||
# Copyright 2026 Arm Limited and/or its affiliates <[email protected]>
|
||||
#
|
||||
# This source code is licensed under the MIT license found in the
|
||||
# LICENSE file in the root directory of this source tree.
|
||||
@@ -60,11 +61,11 @@ outputs:
|
||||
- cuda-toolkit {{ cudatoolkit }}
|
||||
host:
|
||||
- mkl >=2024.2.2,<2026 # [x86_64]
|
||||
- openblas =0.3.34 # [not x86_64]
|
||||
- openblas =0.3.34 openmp_* # [not x86_64]
|
||||
- libsvs-runtime =0.4.0 # [x86_64 and linux]
|
||||
run:
|
||||
- mkl >=2024.2.2,<2026 # [x86_64]
|
||||
- openblas =0.3.34 # [not x86_64]
|
||||
- openblas =0.3.34 openmp_* # [not x86_64]
|
||||
- cuda-cudart {{ cuda_constraints }}
|
||||
- libcublas {{ libcublas_constraints }}
|
||||
- libsvs-runtime =0.4.0 # [x86_64 and linux]
|
||||
@@ -76,6 +77,7 @@ outputs:
|
||||
- test -f $PREFIX/lib/libfaiss_avx2$SHLIB_EXT # [x86_64 and not win]
|
||||
- conda inspect linkages -p $PREFIX $PKG_NAME # [not win]
|
||||
- conda inspect objects -p $PREFIX $PKG_NAME # [osx]
|
||||
- python -c "import ctypes; lib = ctypes.CDLL('libopenblas.so.0'); assert lib.openblas_get_parallel() == 2" # [linux and not x86_64]
|
||||
|
||||
- name: faiss-gpu
|
||||
script: build-pkg.sh # [x86_64 and not win and not osx]
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
# Copyright (c) Facebook, Inc. and its affiliates.
|
||||
# Copyright 2026 Arm Limited and/or its affiliates <[email protected]>
|
||||
#
|
||||
# This source code is licensed under the MIT license found in the
|
||||
# LICENSE file in the root directory of this source tree.
|
||||
@@ -69,7 +70,7 @@ outputs:
|
||||
- mkl >=2024.2.2,<2026 # [x86_64 and win]
|
||||
- python_abi =3.12
|
||||
{% endif %}
|
||||
- openblas =0.3.34 # [linux and not x86_64]
|
||||
- openblas =0.3.34 openmp_* # [linux and not x86_64]
|
||||
- libopenblas =0.3.34 # [osx]
|
||||
run:
|
||||
- python {{ python }}
|
||||
@@ -83,7 +84,7 @@ outputs:
|
||||
- mkl >=2024.2.2,<2026 # [x86_64 and win]
|
||||
- python_abi =3.12
|
||||
{% endif %}
|
||||
- openblas =0.3.34 # [linux and not x86_64]
|
||||
- openblas =0.3.34 openmp_* # [linux and not x86_64]
|
||||
- libopenblas =0.3.34 # [osx]
|
||||
test:
|
||||
requires:
|
||||
@@ -95,6 +96,7 @@ outputs:
|
||||
- test -f $PREFIX/lib/MetalDistance.metallib # [osx and arm64]
|
||||
- conda inspect linkages -p $PREFIX $PKG_NAME # [not win]
|
||||
- conda inspect objects -p $PREFIX $PKG_NAME # [osx]
|
||||
- python -c "import ctypes; lib = ctypes.CDLL('libopenblas.so.0'); assert lib.openblas_get_parallel() == 2" # [linux and not x86_64]
|
||||
|
||||
- name: faiss-cpu
|
||||
script: build-pkg.sh # [x86_64 and not win and not osx]
|
||||
|
||||
Reference in New Issue
Block a user