547 Commits

Author SHA1 Message Date
Lucas Hosseini
d67689c8f7 Use larger instance for AVX2 CI. (#1768)
Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1768

Reviewed By: mdouze

Differential Revision: D27164105

Pulled By: beauby

fbshipit-source-id: a80c8581ae28ef415ead90e709e97b64bff8e168
2021-03-18 14:34:31 -07:00
Alexander Andreev
fe7b06197e IndexIVFFlat inherited from Index for c_api (#1764)
Summary:
ref https://github.com/facebookresearch/faiss/issues/1756

Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1764

Reviewed By: beauby

Differential Revision: D27152915

Pulled By: mdouze

fbshipit-source-id: 5e4ed9e861ff63fc95f92644f58ee8c7f98ca052
2021-03-18 02:36:51 -07:00
Check Deng
6977d72b1d Fix compile errors in NSG (#1752)
Summary:
## Description

This PR fixed following two compile errors in NSG and one warning in PolysemousTraining:

In [Linux(conda)](https://app.circleci.com/pipelines/github/facebookresearch/faiss/1369/workflows/701ac434-3ad7-48b8-bd5b-a41fed7716a2/jobs/4512) building:
```
/opt/conda/conda-bld/faiss-pkg_1615417553875/work/faiss/IndexNSG.cpp:279:25: error: expected ')' before 'PRId64'
                 "has %" PRId64 " invalid entries\n",
                         ^~~~~~
```

In [Windows](https://app.circleci.com/pipelines/github/facebookresearch/faiss/1369/workflows/701ac434-3ad7-48b8-bd5b-a41fed7716a2/jobs/4514) building:
```
swigfaissPYTHON_wrap.obj : error LNK2019: unresolved external symbol "public: static int const faiss::NSG::EMPTY_ID" (?EMPTY_ID@NSG@faiss@2HB) referenced in function Swig_var_NSG_EMPTY_ID_get [C:\tools\miniconda3\conda-bld\faiss-pkg_1615417741685\work\_build_python_3.7\swigfaiss.vcxproj]
```

In [Linux(AVX2)](https://app.circleci.com/pipelines/github/facebookresearch/faiss/1376/workflows/7ed0ebd1-9dec-48c8-b6ba-75efe5e80eec/jobs/4546) building:
```
/home/circleci/project/faiss/impl/PolysemousTraining.cpp:978:1: warning: control reaches end of non-void function [-Wreturn-type]
  978 | }
      | ^
```

## Changed
1. Replaced all `inttypes.h` by `cinttypes`.
2. Removed the constant static member in NSG.
3. Return a default value in `PolysemousTraining::memory_usage_per_thread`.

Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1752

Reviewed By: mdouze

Differential Revision: D27013008

Pulled By: beauby

fbshipit-source-id: 0f0d307b59209e5ca4292764e208267fe4e97339
2021-03-13 14:14:21 -08:00
Check Deng
096b4b5b0e Fix building with -DFAISS_OPT_LEVEL=avx2 (#1746)
Summary:
As stated in https://github.com/facebookresearch/faiss/issues/1743, `_swigfaiss.so` will not exist if compiled with `-DFAISS_OPT_LEVEL=avx2`. This diff added a conditional statement before copying it.

Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1746

Reviewed By: mdouze

Differential Revision: D26978739

Pulled By: beauby

fbshipit-source-id: 34250c29585fca28677849c9734f6a421661f108
2021-03-11 15:28:15 -08:00
Check Deng
b35103a138 Add NSG (#1707)
Summary:
## Description:
This diff implemented Navigating Spreading-out Graph (NSG) which accepts a KNN graph as input.
Here is the interface of building an NSG graph:
``` c++
void IndexNSG::build(idx_t n, const float *x, idx_t *knn_graph, int GK);
```
where `GK` is the nb of neighbors per node and `knn_graph[i * GK + j]` is the j-th neighbor of node i.

The `add` method is not implemented yet.

The unit tests could be found in `tests/test_nsg.cpp`.

mdouze beauby Maybe I need some advice on how to design the interface and support python.

Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1707

Test Plan: buck test //faiss/tests/:test_index -- TestNSG

Reviewed By: beauby

Differential Revision: D26748498

Pulled By: mdouze

fbshipit-source-id: 3280f705fb1b5f9c8cc5efeba63b904c3b832544
2021-03-10 15:03:00 -08:00
Lucas Hosseini
5e54fb57d8 Add missing copyright header. (#1751)
Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1751

Reviewed By: LowikC

Differential Revision: D26954273

Pulled By: beauby

fbshipit-source-id: f3e4cb825283a7571ec44b123146ebc06d4a3a9c
2021-03-10 13:49:49 -08:00
Lucas Hosseini
dd85e7a167 Add test for CPU dispatch in conda packages. (#1724)
Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1724

Reviewed By: mdouze

Differential Revision: D26814141

Pulled By: beauby

fbshipit-source-id: 11f32c6e04a7d78dab9dae48b8d951dd80c11353
2021-03-09 01:18:22 -08:00
generatedunixname89002005325676
3e10769abb Daily arc lint --take CLANGFORMAT
Reviewed By: zertosh

Differential Revision: D26879724

fbshipit-source-id: 0e2dd4c5f7ba96e97e7cbc078184aed2a034ad2c
2021-03-08 03:48:11 -08:00
Check Deng
1f9ddec353 Fix the include header for PRId64 (#1745)
Summary:
This diff fixed the error in [Linux nightlies
](https://app.circleci.com/pipelines/github/facebookresearch/faiss/1325/workflows/e3c09d68-9fbe-4215-a3df-f901a1a5c08e/jobs/4245)

Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1745

Reviewed By: mdouze

Differential Revision: D26870628

Pulled By: beauby

fbshipit-source-id: fd2f5e66fff478565e59a6590dafdb50d4280b25
2021-03-08 00:46:37 -08:00
H. Vetinari
ee701b9bff add a subsection for installation from conda-forge (#1740)
Summary:
After existing for close to a year and considering the quality (IMO) of the collaboration since then,
I believe it would be reasonable to also mention the conda-forge packages in `INSTALL.md`.

WDYT mdouze beauby?

Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1740

Reviewed By: mdouze

Differential Revision: D26870699

Pulled By: beauby

fbshipit-source-id: 17465cd5c9f138f041d394d61fccd086bcafc3c7
2021-03-08 00:32:31 -08:00
Matthijs Douze
189aecb224 Fix polysemous OOM
Summary: Polysemous training can OOM because it uses tables of size n^2 with n is 2**nbit of the PQ. This throws and exception when the table threatens to become too large. It also reduces the number of threads when this would make it possible to fit the computation within max_memory bytes.

Reviewed By: wickedfoo

Differential Revision: D26856747

fbshipit-source-id: bd98e60293494e2f4b2b6d48eb1200efb1ce683c
2021-03-06 00:40:05 -08:00
Matthijs Douze
f2464141a7 Add docstrings for most of the replaced index methods
Summary:
This adds docstrings for most of the replaced methods.
This will make the doc visible in notebooks.

Reviewed By: wickedfoo

Differential Revision: D26856664

fbshipit-source-id: da05cf8ac8380ee06a94a380d2547991b0c0a3be
2021-03-05 17:19:17 -08:00
H. Vetinari
0e968b5295 do not overload __builtin_ctz for win + cuda>=11 (#1737)
Summary:
Apparently, this is now being supplied by CUDA libs. Without this patch, CUDA builds
on 11.1 & 11.2 give the following kind of warnings:
```
Compiling CUDA source file ..\..\faiss\gpu\GpuIndex.cu...
[...]/faiss/impl/platform_macros.h(42): warning : declaration overloads built-in function "__builtin_ctz"
[...]/faiss/impl/platform_macros.h(42): warning : declaration overloads built-in function "__builtin_ctz"
[...]/faiss/impl/platform_macros.h(42): warning : declaration overloads built-in function "__builtin_ctz"
```

Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1737

Reviewed By: wickedfoo

Differential Revision: D26855669

Pulled By: mdouze

fbshipit-source-id: 9447ce20d5db76936c2fb8037560ae910f12b87f
2021-03-05 15:49:43 -08:00
H. Vetinari
42c6175535 fix warning about deprecate assertEquals (#1738)
Summary:
There's an annoying warning on every test run that I'd like to fix
```
=============================== warnings summary ===============================
tests/test_index_accuracy.py::TestRefine::test_IP
tests/test_index_accuracy.py::TestRefine::test_L2
  $SRC_DIR/tests/test_index_accuracy.py:726: DeprecationWarning: Please use assertEqual instead.
    self.assertEquals(recall1, recall2)
```

I've tried sneaking this into https://github.com/facebookresearch/faiss/issues/1704 & https://github.com/facebookresearch/faiss/issues/1717 already, but the first needs more time and
in the second, beauby asked me to keep this separate, so here's a new PR. :)

Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1738

Reviewed By: wickedfoo

Differential Revision: D26855644

Pulled By: mdouze

fbshipit-source-id: 1198a9d9b3a79dfeb1d69513a61229fb45924f89
2021-03-05 13:46:35 -08:00
H. Vetinari
e8ad7272e2 fix int32 vs int64 issue for GPU test on windows (#1739)
Summary:
Part of the work towards https://github.com/facebookresearch/faiss/issues/1586; I already mentioned this diff as necessary for a passing
GPU test suite on windows [here](https://github.com/facebookresearch/faiss/issues/1586#issuecomment-782084250)

Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1739

Reviewed By: wickedfoo

Differential Revision: D26855633

Pulled By: mdouze

fbshipit-source-id: 96d3e627034ccbbe3a32cc4f2310a721e8ea0a69
2021-03-05 13:43:27 -08:00
Prabhat Roy
f2f014de50 Added C API(GPU) to CMake and CircleCI (#1700)
Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1700

Reviewed By: mdouze

Differential Revision: D26814446

Pulled By: beauby

fbshipit-source-id: 654e0297be929afd42bcfbaf790c5d87f04f5193
2021-03-04 05:04:00 -08:00
generatedunixname89002005325676
a9429aa86f Daily arc lint --take CLANGFORMAT
Reviewed By: zertosh

Differential Revision: D26811509

fbshipit-source-id: c3ebd530e50d50744467e615549eafaebb04e948
2021-03-04 04:29:12 -08:00
H. Vetinari
0d7e5a8ba5 Fix swig vs. AVX2 (#1717)
Summary:
Towards https://github.com/facebookresearch/faiss/issues/1711. There's still a test [error](https://github.com/facebookresearch/faiss/issues/1711#issuecomment-787509873) that won't be picked up unless an AVX2-specific CI run is added.

Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1717

Reviewed By: mdouze

Differential Revision: D26814113

Pulled By: beauby

fbshipit-source-id: c3e64a04c3afd1d354439a2c4a2edd611d2c6af8
2021-03-04 03:46:39 -08:00
Lucas Hosseini
4314c5baa6 Add CI job for AVX2 builds. (#1723)
Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1723

Reviewed By: mdouze

Differential Revision: D26814122

Pulled By: beauby

fbshipit-source-id: ef7ea57b497e314960319c695ea46f22de208054
2021-03-04 03:43:11 -08:00
Dikpal Reddy
2b1194a3fa Ensure that invalid k/nprobe search input parameters to Faiss / Faiss GPU don't crash
Summary: Checking for invalid parameters (number of nearest neighbors and number of probes where applicable) in the indices and throwing. Along with unit tests.

Reviewed By: wickedfoo

Differential Revision: D26582467

fbshipit-source-id: e345635d2f0f44ddcecc3f3314b2b9113359a787
2021-03-03 21:17:28 -08:00
Matthijs Douze
949dacf258 Fix concurrency bug in random generator in NNdescent
Summary: Remove the shared mutable random generator, instead re-instanciate the rng everytime it's needed from a random_seed field. For each occurrence, the random_seed is multiplied by a prime number to generate some diveristy.

Reviewed By: beauby

Differential Revision: D26726888

fbshipit-source-id: 58ef99f522bc4adb8233b94f9b9ad9b9d0e1df0b
2021-03-03 10:51:03 -08:00
Lucas Hosseini
4e5fa635ac Add CircleCI job to check format through clang-format. (#1710)
Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1710

Reviewed By: mdouze

Differential Revision: D26691243

Pulled By: beauby

fbshipit-source-id: ddaa2f3e28a23bbc9652aee0c3f8e6927918bdf2
2021-03-03 06:49:10 -08:00
Ivan Murashko
53f08c5c3a Enable clang-format for .cuh (CUDA headers) (#1726)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1726

The diff enables clang-format for CUDA headers and applies it for fbsource

Reviewed By: zertosh

Differential Revision: D26695628

fbshipit-source-id: 30e53bfd6ad8aedd93c1b18076c5bd0a104a893f
2021-03-03 04:17:27 -08:00
Matthijs Douze
64dcdbed95 Fix inefficient float / binary conversion
Summary: A test was timing out but the culprit was not the functionality being tested but instead a very slow list comprehension. Also relaxed the test very slightly as it failed from time to time.

Reviewed By: wickedfoo

Differential Revision: D26727507

fbshipit-source-id: 5b3352674fbef1f0cb6155452e4a93adc631d6a7
2021-03-01 21:43:31 -08:00
Check Deng
a144b4cf6a Remove warnings in format printing (#1715)
Summary:
This diff fixed some warnings in [Windows building](https://app.circleci.com/pipelines/github/facebookresearch/faiss/1267/workflows/d3147265-becc-4a9b-9ab4-854ec13b89d8/jobs/3976).

The warnings are caused by the incompatibility between `int64_t` and `%ld`.

Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1715

Reviewed By: wickedfoo

Differential Revision: D26727122

Pulled By: mdouze

fbshipit-source-id: 84c33bb4af2b1115d1bacecd4cb15350e16a4903
2021-03-01 12:38:28 -08:00
Facebook Community Bot
a081c85b7d
Re-sync with internal repository (#1714)
Co-authored-by: Facebook Community Bot <6422482+facebook-github-bot@users.noreply.github.com>
2021-02-26 15:25:44 +01:00
generatedunixname89002005325676
d1f4a68157 Daily arc lint --take CLANGFORMAT
Reviewed By: zertosh

Differential Revision: D26685857

fbshipit-source-id: 4440e6ccba44740197a71ba05ca0ee85282c2403
2021-02-26 04:00:18 -08:00
Check Deng
d6535a3d87 Add NNDescent to faiss (#1654)
Summary:
As discussed in https://github.com/facebookresearch/faiss/issues/685, I'm going to add an NSG index to faiss. This PR which adds an NNDescent index is the first step as I commented [here ](https://github.com/facebookresearch/faiss/issues/685#issuecomment-760608431).

**Changes:**
1. Add an `IndexNNDescent` and an `IndexNNDescentFlat` which allow users to construct a KNN graph on a million scale dataset using CPU and search NN on it. The implementation part is put under `faiss/impl`.
2. Add compilation entries to `CMakeLists.txt` for C++ and `swigfaiss.swig` for Python. `IndexNNDescentFlat` could be directly called by users in C++ and Python.
3. `VisitedTable` struct in `HNSW.h` is moved into `AuxIndexStructures.h`.
3. Add a demo `demo_nndescent.cpp` to demonstrate the effectiveness.

**TODO**
1. Support index factor.
2. Implement `IndexNNDescentPQ` and `IndexNNDescentSQ`
3. More comments in the code.

Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1654

Test Plan:
buck test //faiss/tests/:test_index_accuracy -- TestNNDescent

buck test //faiss/tests/:test_build_blocks -- TestNNDescentKNNG

Reviewed By: wickedfoo

Differential Revision: D26309716

Pulled By: mdouze

fbshipit-source-id: 2abade9708d29023f8bccbf77143e8eea14f66c4
2021-02-25 16:48:28 -08:00
Matthijs Douze
3f2ebf4b1c Add preassigned functions to contrib
Summary:
Adds the preassigned add and search python wrappers to contrib.
Adds the preassigned search for the binary case (was missing before).
Also adds a real test for that functionality.

Reviewed By: beauby

Differential Revision: D26560021

fbshipit-source-id: 330b715a9ed0073cfdadbfbcb1c23b10bed963a5
2021-02-25 11:39:07 -08:00
Lucas Hosseini
e86bf8cae1 Enable clang-format + autofix.
Summary: Format whole codebase with clang-format.

Reviewed By: mdouze

Differential Revision: D22891341

fbshipit-source-id: 673032b2444d61026d1e2c3fa2c5659f178cf58b
2021-02-25 04:46:10 -08:00
Lucas Hosseini
6d51766607 Fix unused variables in python
Reviewed By: mdouze

Differential Revision: D26633983

fbshipit-source-id: 32b9f95ed9647716f65b93f2713a8d5bad6abe78
2021-02-24 11:52:18 -08:00
Check Deng
55c93f3cde Handle the situation where nprobe > nlist in IndexBinaryIVF (#1695)
Summary:
## Description

It is the same as https://github.com/facebookresearch/faiss/pull/1673 but for `IndexBinaryIVF`. Ensure that `nprobe` is no more than `nlist`.

## Changes
1. Replace `nprobe` with `min(nprobe, nlist)`
2. Replace `long` with `idx_t` in `IndexBinaryIVF.cpp`
3. Add a unit test
4. Fix a small bug in https://github.com/facebookresearch/faiss/pull/1673, `index` should be replaced by `gt_index`

Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1695

Reviewed By: wickedfoo

Differential Revision: D26603278

Pulled By: mdouze

fbshipit-source-id: a4fb79bdeb975e9d8ec507177596c36da1195646
2021-02-23 12:20:37 -08:00
Lucas Hosseini
dfae5457b9 Configure linter to avoid warning about ambiguous variable name I.
Summary: This warning has been making a lot of noise for diffs touching python files in Faiss, as we commonly use `D, I = index.search(...)`.

Reviewed By: mdouze

Differential Revision: D26576006

fbshipit-source-id: 67bde4faa85b5eea2240fd4310d8e186084ca8e6
2021-02-22 02:19:07 -08:00
Matthijs Douze
96b740abed function to override coarse centroids for all IVF indexes
Summary: This diff standardizes the `add_core` function that makes it possible to override the centroids for all types of IVF indexes. This was already more or less supported for some types of indexes.

Reviewed By: wickedfoo

Differential Revision: D26543509

fbshipit-source-id: 2706ee4796707423b6af95de57466150ed619f3d
2021-02-19 12:11:52 -08:00
Matthijs Douze
57e29a5cb7 Implement serialization of indexes
Summary: add getstate / setstate to serialize indexes. Seems to work properly with object ownership etc.

Reviewed By: wickedfoo

Differential Revision: D26521228

fbshipit-source-id: ebbe08cfe2c15af2aa5b7ea1fc1bf87546066c23
2021-02-19 12:08:27 -08:00
H. Vetinari
1afaddbb28 Windows: portable intrinsics (#1684)
Summary:
Trying to compile windows for AVX2 in https://github.com/conda-forge/faiss-split-feedstock/pull/27
(after https://github.com/facebookresearch/faiss/issues/1600) surfaced a bunch of things (https://github.com/facebookresearch/faiss/issues/1680, https://github.com/facebookresearch/faiss/issues/1681, https://github.com/facebookresearch/faiss/issues/1682), but the most voluminous problem
was MSVC being much worse at dealing with operator overloads and casts around `__m128` / `__m256`.

This lead to loads of errors that looked as follows:
```
[...]\faiss\utils\distances_simd.cpp(411): error C2676: binary '+=': '__m128' does not define this operator or a conversion to a type acceptable to the predefined operator
[...]\faiss\utils\distances_simd.cpp(440): error C2676: binary '-': '__m256' does not define this operator or a conversion to a type acceptable to the predefined operator
[...]\faiss\utils\distances_simd.cpp(441): error C2676: binary '*': 'const __m256' does not define this operator or a conversion to a type acceptable to the predefined operator
[...]\faiss\utils\distances_simd.cpp(446): error C2676: binary '+=': '__m128' does not define this operator or a conversion to a type acceptable to the predefined operator
[...]\faiss\utils\distances_simd.cpp(451): error C2676: binary '-': '__m128' does not define this operator or a conversion to a type acceptable to the predefined operator
[...]\faiss\utils\distances_simd.cpp(452): error C2676: binary '*': 'const __m128' does not define this operator or a conversion to a type acceptable to the predefined operator
[...]\faiss\utils\distances_simd.cpp(459): error C2676: binary '-': '__m128' does not define this operator or a conversion to a type acceptable to the predefined operator
[...]\faiss\utils\distances_simd.cpp(460): error C2676: binary '*': '__m128' does not define this operator or a conversion to a type acceptable to the predefined operator
[...]\faiss\utils\distances_simd.cpp(471): error C2440: '<function-style-cast>': cannot convert from '__m256i' to '__m256'
```

I've followed https://software.intel.com/sites/landingpage/IntrinsicsGuide/ to try to replace everything correctly,
but this will surely require close review, because I'm not sure how well these code-paths are checked by the
test suite.

In any case, with the commits from https://github.com/facebookresearch/faiss/issues/1600 #1666 https://github.com/facebookresearch/faiss/issues/1680 #1681 https://github.com/facebookresearch/faiss/issues/1682, I was able to build `libfaiss` & `faiss`
for AVX2 on windows (while remaining "green" on linux/osx, both with & without AVX2).

Sidenote: the issues in the last commit (26fc7cf139)
were uncovered by adding the `__SSE3__` compat macros in https://github.com/facebookresearch/faiss/issues/1681.

Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1684

Test Plan: buck test //faiss/tests/...

Reviewed By: beauby

Differential Revision: D26454443

Pulled By: mdouze

fbshipit-source-id: 70df0818e357f1ecea6a056d619618df0236e0eb
2021-02-18 11:28:47 -08:00
H. Vetinari
d0ad3d71f4 make setup.py win+avx2 compatible (#1682)
Summary:
While working on https://github.com/conda-forge/faiss-split-feedstock/pull/27, it turned out I needed
to patch `setup.py` anyway. In order to unify how the extension of the built lib is set, I fell back
to another patch that would/will become necessary if faiss ever wants to support PyPy
(see discussion in https://github.com/conda-forge/faiss-split-feedstock/pull/22).

It would be nice if this was done natively by CMake, but as far as I can tell from
https://gitlab.kitware.com/cmake/cmake/-/issues/21070, cmake is not likely to do that right away.

I didn't particularly expect this patch to be upstreamed (especially if there is no interest for PyPy support, for example),
but beauby [invited](https://github.com/conda-forge/faiss-split-feedstock/pull/27#issuecomment-777291797)
me to post it so here goes (plus necessary adaptations to the conda recipes)

Related to https://github.com/facebookresearch/faiss/issues/1600, https://github.com/facebookresearch/faiss/issues/1680, https://github.com/facebookresearch/faiss/issues/1681

PS. I thought about using `logger.INFO` in case of an import failure for AVX2, but since it's a setup file,
I thought `print` would actually be more useful. Happy to change or remove if desired.

Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1682

Reviewed By: wickedfoo

Differential Revision: D26484393

Pulled By: beauby

fbshipit-source-id: 6cd2598838c4070dbf83d6f27ce15ce9faa6bf20
2021-02-17 15:09:04 -08:00
H. Vetinari
7ef4b030ee add msvc-compatible AVX2 switch in CMakeLists.txt (#1680)
Summary:
Upstreaming patches from https://github.com/conda-forge/faiss-split-feedstock/pull/27, follow-up (sorta) to https://github.com/facebookresearch/faiss/issues/1600.

Not sure if there are more CMake-native tricks to use here, but given that the flags don't have
an equivalent on the MSVC side, I think this approach is reasonable.

Without this patch, we would get:
```
cl : Command line warning D9002: ignoring unknown option '-mavx2'
cl : Command line warning D9002: ignoring unknown option '-mfma'
cl : Command line warning D9002: ignoring unknown option '-mf16c'
cl : Command line warning D9002: ignoring unknown option '-mpopcnt'
```

Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1680

Reviewed By: wickedfoo

Differential Revision: D26484347

Pulled By: beauby

fbshipit-source-id: 2803132f2d81fe37dc494fc4c824b6e240ae973b
2021-02-17 14:06:54 -08:00
Lucas Hosseini
442c4317a0 Avoid building packages for compute_86 with CUDA 11.0. (#1694)
Summary:
Compute capability 86 is only available from CUDA 11.1 onwards, for
which Anaconda does not have a `cudatoolkit` package yet.

Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1694

Reviewed By: wickedfoo

Differential Revision: D26482788

Pulled By: beauby

fbshipit-source-id: c0c84e0433ea9d9b04a1572001bd7c0d2ee82988
2021-02-17 09:53:24 -08:00
H. Vetinari
6d8afffadd Win+AVX2 compat (#1681)
Summary:
Upstreaming patches from conda-forge/faiss-split-feedstock#27, follow-up (sorta) to https://github.com/facebookresearch/faiss/issues/1600.

All these should be fairly uncontroversial, I think (mostly just oversights or stuff that never got
triggered on windows due to not having https://github.com/facebookresearch/faiss/issues/1680 so far).

Things work without `#include <faiss/impl/platform_macros.h>`, but I preferred to be explicit here,
because the `__SSEx__` macros (that are used in the affected files) are only defined there for windows.

Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1681

Reviewed By: beauby

Differential Revision: D26454427

Pulled By: mdouze

fbshipit-source-id: 345e0ef45888f338e71bba004454a701572f9afb
2021-02-17 08:05:55 -08:00
Jeff Johnson
96d0d331a7 Fix CircleCI IVFPQ GPU tests (#1690)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1690

The GPU and CPU were trained separately in the failing test, leading to fairly different PQ centroids. Instead, just train on the GPU and copy to the CPU like other tests.

Also silences the not enough centroids warnings.

Reviewed By: beauby

Differential Revision: D26470199

fbshipit-source-id: 1f7c036671c03ed4a97c8c4a44d3c5b9767019cb
2021-02-16 16:03:48 -08:00
Chengqi Deng
b4a0a9c617 Handle the situation where nprobe > nlist in IndexIVF (#1673)
Summary:
## Description

Fix the bug mentioned in https://github.com/facebookresearch/faiss/issues/1010. When `nprobe` is greater than `nlist` in `IndexIVF`, the program will crash because the index will ask the quantizer to return more centroids than it owns.

## Changes:
1. Set `nprobe` as `nlist` if it is greater than `nlist` during searching.
2. Add one test to detect this bug.
3. Fix typo in `IndexPQ.cpp`.

Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1673

Reviewed By: wickedfoo

Differential Revision: D26454420

Pulled By: mdouze

fbshipit-source-id: d1d0949e30802602e975a94ba873f9db29abd5ab
2021-02-16 09:54:23 -08:00
Lucas Hosseini
2a01135127 Add missing copyright headers. (#1689)
Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1689

Reviewed By: mdouze

Differential Revision: D26460606

Pulled By: beauby

fbshipit-source-id: ad35dd2ea3fb23a0b87bc04597a8fbc38393c997
2021-02-16 09:11:30 -08:00
Lucas Hosseini
0336293fec Update INSTALL.md. (#1686)
Summary:
Add detailed information about installing/building/testing.

Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1686

Reviewed By: mdouze

Differential Revision: D26453860

Pulled By: beauby

fbshipit-source-id: a64f1ad46648d5576911459e833699ea37819c9d
2021-02-16 06:52:56 -08:00
Lucas Hosseini
6f271490e8 Add CHANGELOG.md. (#1688)
Summary:
The file follows the format described in
https://keepachangelog.com/en/1.0.0/.

Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1688

Reviewed By: mdouze

Differential Revision: D26454197

Pulled By: beauby

fbshipit-source-id: 16bafed43897479c7e87fae202b08e95107c6658
2021-02-16 06:31:22 -08:00
Prabhat Roy
7a289d5418 Added C API to CMake and CircleCI (#1678)
Summary:
This supersedes https://github.com/facebookresearch/faiss/issues/1390 and https://github.com/facebookresearch/faiss/issues/1141.

Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1678

Reviewed By: mdouze

Differential Revision: D26428986

Pulled By: beauby

fbshipit-source-id: 1e2718f457c1aca18c19edc2436d6baf9b627a60
2021-02-15 12:41:31 -08:00
Matthijs Douze
961dd8bfb8 Fix a few warnings with gcc
Summary: GCC flags a few more warnings than clang.

Reviewed By: wickedfoo

Differential Revision: D26421696

fbshipit-source-id: 3706ede205c03352667c1e483f014ca498666878
2021-02-15 03:55:00 -08:00
Matthijs Douze
13e3039d5e Fix copy construction of AlignedTable
Summary: Copy construction of Aligned table was wrong, which crashed cloning of IVFPQ.

Reviewed By: wickedfoo

Differential Revision: D26426400

fbshipit-source-id: 1d43ea6309d0a56eb592f9d6c5b52282f494e653
2021-02-15 00:13:50 -08:00
H. Vetinari
97ed48291a log success messages and errors in loader.py (#1683)
Summary:
This patch is to provide log information in case of failing to load the AVX2-enabled lib,
and also to log the successful loading of the libraries.

Otherwise, the programmatic detection of which library was loaded also needs to take
into account which other log statements were executed, if the original import failed due to an exception,
cf. the tests in https://github.com/conda-forge/faiss-split-feedstock/pull/27

Finally, this reduces the number of import statements by one - one non-AVX2 fallback is enough.

Related to https://github.com/facebookresearch/faiss/issues/1600, https://github.com/facebookresearch/faiss/issues/1680, https://github.com/facebookresearch/faiss/issues/1681, https://github.com/facebookresearch/faiss/issues/1682.

Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1683

Reviewed By: mdouze

Differential Revision: D26424333

Pulled By: beauby

fbshipit-source-id: 16beddec7e0c098b913a7f5420cbb02d1cf515ad
2021-02-12 10:59:32 -08:00
Jeff Johnson
43ce2c93a4 CUDA 11 fixes + PQ training on the GPU
Summary:
This diff exposes the ProductQuantizer `pq` object to the user for manipulation in Python just as `IndexIVFPQ` does.

If no clustering index object is provided in `pq`, we create a `GpuIndexFlatL2` in order to perform the PQ training on the GPU as well.

Also raises the error threshold a bit in some tests, as the previous ones seem to be triggered on a V100 GPU.

Fixes an issue with AddException + (CUDA 11 and/or V100 GPUs) as well, where a `cudaMalloc` failure now seems to set state that is returned by `cudaGetLastError`. This we now clear before continuing.

Fixes an issue (possible cuBLAS bug, following up with Nvidia):

cublasSgemmEx in libcublas.so.11.1.0.229 returning CUBLAS_STATUS_NOT_SUPPORTED but would work fine in CUDA 9.2 (V100 GPU)

cublasSgemmEx(handle, CUBLAS_OP_T, CUBLAS_OP_N,
64, 8, 64,
&alpha,
A, CUDA_R_16F, 64,
B, CUDA_R_16F, 64,
&beta,
C, CUDA_R_32F, 64);

Using cublasGemmEx with CUBLAS_COMPUTE_32F and CUBLAS_GEMM_DEFAULT would also fail, but using CUBLAS_COMPUTE_32F_PEDANTIC with cublasGemmEx succeeds. Using PEDANTIC for CUDA 11 + f16 arguments for now.

Reviewed By: mdouze

Differential Revision: D26331887

fbshipit-source-id: c65448c4c79b58dd49b0220b393056e431ef53c0
2021-02-10 15:22:51 -08:00