Skip to content

Commit

Permalink
Fix test failure in OSX with OpenMP called from multiple threads (#1849)
Browse files Browse the repository at this point in the history
Summary:
Need to add an ssh key to the circleci to be able to debug

For my own ref, how to connect to the job:
```
[matthijs@matthijs-mbp /Users/matthijs/Desktop/faiss_github/circleci_keys] ssh -p 54782 38.39.188.110 -i id_ed25519
```

Pull Request resolved: #1849

Reviewed By: wickedfoo

Differential Revision: D28234897

Pulled By: mdouze

fbshipit-source-id: 6827fa45f24b3e4bf586315bd38f18608d07ecf9
  • Loading branch information
mdouze authored and facebook-github-bot committed May 6, 2021
1 parent 061b68b commit 4dc5b27
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
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
10 changes: 10 additions & 0 deletions 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 @@ -131,6 +139,8 @@ 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

0 comments on commit 4dc5b27

Please sign in to comment.