Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test failure in OSX with OpenMP called from multiple threads #1849

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ jobs:
OMP_NUM_THREADS: 10
steps:
- checkout
- add_ssh_keys:
fingerprints:
- "ea:af:e4:cc:96:1b:87:11:e2:88:88:80:8d:b4:cc:5c"
- run:
name: Install Homebrew packages
command: |
Expand Down
2 changes: 1 addition & 1 deletion faiss/IndexIVFPQR.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct IndexIVFPQR : IndexIVFPQ {
idx_t n,
const float* x,
const idx_t* xids,
const idx_t* precomputed_idx = nullptr);
const idx_t* precomputed_idx) override;

void reconstruct_from_offset(int64_t list_no, int64_t offset, float* recons)
const override;
Expand Down
11 changes: 11 additions & 0 deletions tests/test_index_binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"""this is a basic test script for simple indices work"""
from __future__ import absolute_import, division, print_function, unicode_literals

import sys
import numpy as np
import unittest
import faiss
Expand Down Expand Up @@ -351,6 +352,13 @@ def test_replicas(self):

Dref, Iref = index_ref.search(xq, 10)

# there is a OpenMP bug in this configuration, so disable threading
if sys.platform == "darwin" and "Clang 12" in sys.version:
nthreads = faiss.omp_get_max_threads()
faiss.omp_set_num_threads(1)
else:
nthreads = None

nrep = 5
index = faiss.IndexBinaryReplicas()
for _i in range(nrep):
Expand All @@ -371,6 +379,9 @@ def test_replicas(self):
index2.add(xb)
D2, I2 = index2.search(xq, 10)

if nthreads is not None:
faiss.omp_set_num_threads(nthreads)

self.assertTrue((Dref == D2).all())
self.assertTrue((Iref == I2).all())

Expand Down
12 changes: 11 additions & 1 deletion tests/test_meta_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

# translation of test_meta_index.lua

import sys
import numpy as np
import faiss
import unittest
Expand Down Expand Up @@ -86,6 +87,13 @@ def test_shards(self):
_Dref, Iref = ref_index.search(xq, k)
print(Iref[:5, :6])

# there is a OpenMP bug in this configuration, so disable threading
if sys.platform == "darwin" and "Clang 12" in sys.version:
nthreads = faiss.omp_get_max_threads()
faiss.omp_set_num_threads(1)
else:
nthreads = None

shard_index = faiss.IndexShards(d)
shard_index_2 = faiss.IndexShards(d, True, False)

Expand Down Expand Up @@ -130,7 +138,9 @@ def test_shards(self):

print('%d / %d differences' % (ndiff, nq * k))
assert(ndiff < nq * k / 1000.)


if nthreads is not None:
faiss.omp_set_num_threads(nthreads)

class Merge(unittest.TestCase):

Expand Down