Files
Fadi Arafeh 39079668a8 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
2026-10-09 11:27:04 -07:00
..