1065 Commits

Author SHA1 Message Date
Alexander Andreev
513f895b7c Add get,set verbose for Index in c_api (#1790)
Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1790

Reviewed By: beauby

Differential Revision: D27904738

Pulled By: mdouze

fbshipit-source-id: 31e8881996ee558c42206b9bf7ce1f9057595133
2021-04-22 05:16:55 -07:00
Lucas Hosseini
bde7c00271 Update OSX version in CircleCI. (#1833)
Summary:
This should fix the HomeBrew failures we see.

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

Reviewed By: mdouze

Differential Revision: D27880386

Pulled By: beauby

fbshipit-source-id: 5895dfc79a9c66c88283fd5170d2827f63bdd224
2021-04-20 05:50:52 -07:00
Y.Imaizumi
fe777d8010 Improve IndexPQFastScan and IndexIVFPQFastScan performance for aarch64 devices (#1815)
Summary:
related: https://github.com/facebookresearch/faiss/issues/1812

This PR improves the performance of `IndexPQFastScan` and `IndexIVFPQFastScan` on aarch64 devices, e.g., 60x faster on an AWS Arm instance with the SIFT1M dataset.
The contents of this PR are below:

- Add `simdlib_neon.h`
    - `simdlib_neon.h` has `simdlib` compatible API, and they are implemented with Arm NEON intrinsics.
    - `simdlib.h` includes `simdlib_neon.h` if `__aarch64__` is defined.
- Move `geteven` , `getodd` , `getlow128` , and `gethigh128` from `distances_simd.cpp` to `simdlib_avx2.h` .
- Port `geteven` , `getodd` , `getlow128` , and `gethigh128` for non-AVX2 environments.
    - These codes are implemented with AVX2 intrinsics, so they have prevented to implement `compute_PQ_dis_tables_dsub2` for non-AVX2 environments.
    - Now `simdlib_avx2.h` , `simdlib_emulated.h` , and `simdlib_neon.h` all have those functions.
- Enable `compute_PQ_dis_tables_dsub2` on aarch64
    - Above change makes `compute_PQ_dis_tables_dsub2` independent from `geteven` and so on.
    - `compute_PQ_dis_tables_dsub2` implemented with `simdlib_neon.h` is little faster than current implementation, so enabling that.
        - In contrast, `compute_PQ_dis_tables_dsub2` implemented with `simdlib_emulated.h` is slower than current implementation, so we have not enabled it in our PR.

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

Reviewed By: beauby

Differential Revision: D27760259

Pulled By: mdouze

fbshipit-source-id: 5df6168ac35ae0174bedf04508dbaf19f11fab3f
2021-04-16 00:43:35 -07:00
Y.Imaizumi
b85b4308f2 Make simdlib_emulated.h faster (#1814)
Summary:
related: https://github.com/facebookresearch/faiss/issues/1812

This PR improves the performance of contents in `simdlib_emulated.h` .
`IndexPQFastScan` and `IndexIVFPQFastScan` will become faster on non-AVX2 environments, e.g., 4x faster on SIFT1M.
This PR contains below changes:

- Use `template` instead of `std::function` on argument of `unary_func` and `binary_func`
    - Because `std::function` hinders some optimizations like function inlining
- Use `const T&` instead of `T` for vector classes like `simd16uint16` on argument of functions
    - Vector classes on `simdlib_emulated.h` has the data member as array, so the runtime cost for copying is not so low.
    - Passing by const lvalue-ref prevents copy.

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

Reviewed By: beauby

Differential Revision: D27760072

Pulled By: mdouze

fbshipit-source-id: cbc5a14658d1960b24ce55a395e71c80998742dc
2021-04-16 00:24:44 -07:00
Chengqi Deng
c62ab3a696 Use BLAS to compute sdc table (#1809)
Summary:
This PR used BLAS to compute sdc table in ProductQuantizer.

Here is the time of computing sdc tables:

```
nbits=8, d=128 (this commit)
M: 2, sdc: 0.0001361370086669922s
M: 4, sdc: 8.273124694824219e-05s
M: 8, sdc: 7.867813110351562e-05s
M: 16, sdc: 0.0001227855682373047s
M: 32, sdc: 0.0001697540283203125s
M: 64, sdc: 0.0007395744323730469s
```

```
nbits=8, d=128 (master)
M: 2,  sdc: 0.0055773258209228516s
M: 4,  sdc: 0.005366802215576172s
M: 8,  sdc: 0.0050809383392333984s
M: 16, sdc: 0.005639791488647461s
M: 32, sdc: 0.006036281585693359s
M: 64, sdc: 0.009720802307128906s
```

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

Reviewed By: beauby

Differential Revision: D27706249

Pulled By: mdouze

fbshipit-source-id: 102ae0c1c157e244e40557656934062f537b74d4
2021-04-16 00:17:51 -07:00
Alexander Andreev
1ddb517bbd Add IndexScalarQuantizer for c_api (#1802)
Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1802

Reviewed By: beauby

Differential Revision: D27706399

Pulled By: mdouze

fbshipit-source-id: 61ac99f61e9e44b2fca8e3de45357ee4c0a0b9d7
2021-04-15 23:04:49 -07:00
Chengqi Deng
6f6e90162b Fix typo in bench_index_flat (#1810)
Summary:
This PR fixed the typo in `bench_index_flat.py`.

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

Reviewed By: beauby

Differential Revision: D27706115

Pulled By: mdouze

fbshipit-source-id: 35515450be8eb45d6a2e98c7372333d98fc0f7b4
2021-04-15 22:58:42 -07:00
Matthijs Douze
7559cf5c5b add ResidualQuantizer
Summary:
This diff includes:
- progressive dimension k-means.
- the ResidualQuantizer object
- GpuProgressiveDimIndexFactory so that it can be trained on GPU
- corresponding tests
- reference Python implementation of the same in scripts/matthijs/LCC_encoding

Reviewed By: wickedfoo

Differential Revision: D27608029

fbshipit-source-id: 9a8cf3310c8439a93641961ca8b042941f0f4249
2021-04-14 13:11:54 -07:00
Jeff Johnson
50534d76cc remove GPU half select implementations (#1817)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1817

There were instantiations of the k-selection templates that operated on float16 data. These are no longer needed as instead Faiss will process all data in float32 (though input data can still be in float16), so removing them to speed compilation time.

Reviewed By: beauby

Differential Revision: D27742889

fbshipit-source-id: a3cf72a10df15f335d18d1e7709ffe269024121d
2021-04-13 12:40:13 -07:00
Jeff Johnson
b544db24a8 Raw all-pairwise distance function on GPU
Summary:
This diff implements brute-force all-pairwise distances between two different sets of vectors using any of the Faiss supported metrics on the GPU (L2, IP, L1, Lp, Linf, etc).

It is implemented using the same C++ interface as `bfKnn`, except when `k == -1`, all pairwise distances will be returned (no k-selection is made). A restriction exists at present where the entire output data must be able to reside on the same GPU which may be lifted at a subsequent point.

This interface is available in python via `faiss.pairwise_distance_gpu(res, xq, xb, D, metric)` with both numpy and pytorch support which will return all of the distances in D.

Also cleaned up CUDA stream usage a little bit in Distance.cu/Distance.cuh in the C++ implementation.

Reviewed By: mdouze

Differential Revision: D27686773

fbshipit-source-id: 8de6a699cda5d7077f0ab583e9ce76e630f0f687
2021-04-13 12:06:04 -07:00
Alexander Andreev
d77169173e Add getters for c_api IndexIVFFlat (#1787)
Summary:
ref https://github.com/facebookresearch/faiss/issues/1756

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

Reviewed By: beauby

Differential Revision: D27619587

Pulled By: mdouze

fbshipit-source-id: 0a9bb12f27b48c1b21025957e26c7453ab64a78d
2021-04-08 03:01:53 -07:00
Chengqi Deng
213ab22b71 Parallelize add_with_id of IndexIVFFlat and IndexIVFFlatDedup (#1805)
Summary:
This PR parallelized the `add_with_ids` methods of `IndexIVFFlat` and `IndexIVFFlatDedup`. Related to https://github.com/facebookresearch/faiss/issues/1617.

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

Reviewed By: wickedfoo

Differential Revision: D27619557

Pulled By: mdouze

fbshipit-source-id: 74e0d74c7c51870534372a7ddf6fa0badba2686c
2021-04-07 08:09:38 -07:00
Lucas Hosseini
267edb120b Increase timeout for conda packages jobs. (#1801)
Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1801

Reviewed By: mdouze

Differential Revision: D27536458

Pulled By: beauby

fbshipit-source-id: ca2e693a7ac98d543fe1fe2ee2031389244e3c84
2021-04-02 09:43:50 -07:00
H. Vetinari
9c58ae00f1 Portable SWIG Vectors (#1742)
Summary:
After initial positive feedback to the idea in https://github.com/facebookresearch/faiss/issues/1741 from mdouze, here are the patches
I currently have as a basis for discussion.

Matthijs suggests to not bother with the deprecation warnings at all, which is fine for me
as well, though I would normally still advocate to provide users with _some_ advance notice
before removing parts of an interface.

Fixes https://github.com/facebookresearch/faiss/issues/1741

PS. The deprecation warning is only shown once per session (per class)
PPS. I have tested in https://github.com/conda-forge/faiss-split-feedstock/pull/32 that the respective
classes remain available both through `import faiss` and `from faiss import *`.

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

Reviewed By: mdouze

Differential Revision: D26978886

Pulled By: beauby

fbshipit-source-id: b52e2b5b5b0117af7cd95ef5df3128e9914633ad
2021-04-02 07:11:47 -07:00
Lucas Hosseini
06f1ef86ac Use larger instances for GPU builds. (#1794)
Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1794

Reviewed By: mdouze

Differential Revision: D27439445

Pulled By: beauby

fbshipit-source-id: 12a936766ccb49a27767ab3a36ffd37fec2e1bfc
2021-04-01 03:35:41 -07:00
Lucas Hosseini
c65f670523 Add separate targets for libfaiss/libfaiss_avx2. (#1772)
Summary:
This should fix the conda builds.

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

Reviewed By: mdouze

Differential Revision: D27365772

Pulled By: beauby

fbshipit-source-id: 12b9d488d475842030feb1a0452acf26dbe6ac01
2021-03-26 14:28:16 -07:00
Check Deng
c37c2fa393 Support I/O and clone for NSG (#1766)
Summary:
This PR added IO and clone support to NSG.

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

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

Reviewed By: beauby

Differential Revision: D27189414

Pulled By: mdouze

fbshipit-source-id: c35c253d043c711d09a675f4ba5c3317b9423b5b
2021-03-23 09:18:15 -07:00
Check Deng
885d87f712 Support NSG in the index factory (#1758)
Summary:
## Description
This PR added NSG into the index factory. Here are the supported index strings:
1. `NSG{0}` or `NSG{0},Flat`: Create an IndexNSGFlat with `R = {0}`.
2. `IVF{0}_NSG{1},{2}`: Create an IndexIVF using NSG as a coarse quantizer where `ncentroids = {0}`, `R = {1}` and `{2}` is the second level quantizer.

These two types of indexes may be the most useful ones. Other composite indexes could be supported in the future.

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

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

Reviewed By: beauby

Differential Revision: D27189479

Pulled By: mdouze

fbshipit-source-id: b60000f985c490ef2e7bc561b4e209f9f61c3cc8
2021-03-23 07:28:20 -07:00
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