578 Commits

Author SHA1 Message Date
Matthijs Douze
c0052c1533 IndexFlatCodes: a single parent for all flat codecs (#2132)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2132

This diff adds the class IndexFlatCodes that becomes the parent of all "flat" encodings.
IndexPQ
IndexFlat
IndexAdditiveQuantizer
IndexScalarQuantizer
IndexLSH
Index2Layer

The other changes are:
- for IndexFlat, there is no vector<float> with the data anymore. It is replaced with a `get_xb()` function. This broke quite a few external codes, that this diff also attempts to fix.
- I/O functions needed to be adapted. This is done without changing the I/O format for any index.
- added a small contrib function to get the data from the IndexFlat
- the functionality has been made uniform, for example remove_ids and add are now in the parent class.

Eventually, we may support generic storage for flat indexes, similar to `InvertedLists`, eg to memmap the data, but this will again require a big change.

Reviewed By: wickedfoo

Differential Revision: D32646769

fbshipit-source-id: 04a1659173fd51b130ae45d345176b72183cae40
2021-12-07 01:31:07 -08:00
Sugosh Nagavara Ravindra
253c7a6070 Update train_type_t enum to support all combinations of flags
Summary:
It looks like loading FAISS codecs which have the flag set fails in dev mode since it builds in ASAN and nothing in the code checks for that.
The error is not present in opt mode, however the sandcastle test fails
For best practice, this diff introduces combination of train_type_t flags as enums

Reviewed By: mdouze

Differential Revision: D32746904

fbshipit-source-id: f20820350e0b07b35e04c965dee01b790194e6f3
2021-12-01 23:55:01 -08:00
Matthijs Douze
bef12cf51b Implement LCC's RCQ + ITQ in Faiss (#2123)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2123

One of the encodings used by LCC is based on a RCQ coarse quantizer and a "payload" of ITQ. The codes are compared with Hamming distances.

The index type `IndexIVFSpectralHash` can be re-purposed to perfrorm this type of index.

This diff contains a small demo demo_rcq_itq script in python to show how:
* the RCQ + ITQ are trained
* the RCQ + ITQ index add and search work (with a very inefficient python implementation)
* they can be transferred to an `IndexIVFSpectralHash`
* the python implementation and `IndexIVFSpectralHash` give the same results

The advantage of using to an `IndexIVFSpectralHash` is that in C++ it offers an `InvertedListScanner` object that can be used to compute query to code distances with its `distance_to_code` method. This is generic and will generalize to  other types of encodings and coarse quantizers.

What is missing is an index_factory to make instanciation easier.

Reviewed By: sc268

Differential Revision: D32642900

fbshipit-source-id: 284f3029d239b7946bbca44a748def4e058489bd
2021-11-25 15:59:18 -08:00
Matthijs Douze
c659dd2dc9 Support 2 concatenated codecs (#2117)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2117

This supports 2 concatenated codecs. It is based on IndexRefine, that already does this but did not have a standalone codec interface.
The main use case for now is a residual quantizer + ITQ.
The test below demonstrates how to instantiate that.
The advantage is that the index_factory parser already exists.
The IndexRefine decoder just uses the second index decoder, that is supposed to be more accurate than the first.

Reviewed By: beauby

Differential Revision: D32569997

fbshipit-source-id: 3fe9cd02eaa7d1cfe23b0f1168cc034821f1c362
2021-11-23 09:58:55 -08:00
Check Deng
6c99782f7c Fix unorder bug in NSG (#2086)
Summary:
The results returned by `NSG::search` are already sorted. Calling `maxheap_reorder` will make the results unorder.

Fixed https://github.com/facebookresearch/faiss/issues/2081.

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

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

Reviewed By: beauby

Differential Revision: D32593924

Pulled By: mdouze

fbshipit-source-id: 794b94681610657bd2f305f7e3d6cd5d25c6bdba
2021-11-22 11:41:01 -08:00
ptaylor
fbf6b4a439 Compress CUDA device code in libfaiss.so (#2091)
Summary:
Pass `-Xfatbin=-compress-all` to `nvcc` so device code is compressed when embedded in `libfaiss.so`.

In our testing[[1]](0a0d3b48e8/results.txt), compressing device code has negligible (or no) impact on compile, load, or run times, but significantly reduces the library size on disk:

```bash
# cmake -GNinja -B build -S . \
#  -DBUILD_SHARED_LIBS=ON -DBUILD_TESTING=OFF \
#  -DFAISS_ENABLE_GPU=ON -DFAISS_ENABLE_PYTHON=OFF \
#  -DCMAKE_CUDA_ARCHITECTURES="60-real;70-real;75-real;80-real;86"

# v1.7.0:
$ du -Shc build/faiss/libfaiss.so
318M	build/faiss/libfaiss.so

# this PR:
$ du -Shc build/faiss/libfaiss.so
160M	build/faiss/libfaiss.so
```

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

Reviewed By: mdouze

Differential Revision: D32597803

Pulled By: wickedfoo

fbshipit-source-id: a2adb43aea0fa24a9581abe14a7d90a6e98523ce
2021-11-22 10:51:07 -08:00
Matthijs Douze
b598f5558c Add an epsilon to avoid numerical instability in PCA whiteneing
Summary:
PCA whitening implies to multiply eigenvectors with 1/sqrt(singular values of convariance matrix). The singular values are sometimes 0 (because the vector subspace is not full-rank) or negative (because of numerical issues).
Therefore, this diff adds an epsilon to the denominator above (default 0).

Reviewed By: edpizzi

Differential Revision: D31725075

fbshipit-source-id: dae68bda9f7452220785d76e30ce4b2ac8582413
2021-10-19 01:02:21 -07:00
Chengqi Deng
26abede812 Non-uniform quantization of vector norms (#2037)
Summary:
This diff implemented non-uniform quantization of vector norms in additive quantizers. index_factory and I/O are supported.

index_factory:  `XXX_Ncqint{nbits}` where `nbits` is the number of bits to quantize vector norm.

For 8 bits code, it is almost the same as 8-bit uniform quantization. It will slightly improve the accuracy if the code size is less than 8 bits.
```
RQ4x8_Nqint8:  R@1 0.1116
RQ4x8_Ncqint8: R@1 0.1117

RQ4x8_Nqint4:  R@1 0.0901
RQ4x8_Ncqint4: R@1 0.0989
```

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

Test Plan:
buck test //faiss/tests/:test_clustering -- TestClustering1D
buck test //faiss/tests/:test_lsq -- test_index_accuracy_cqint
buck test //faiss/tests/:test_residual_quantizer -- test_norm_cqint
buck test //faiss/tests/:test_residual_quantizer -- test_search_L2

Reviewed By: beauby

Differential Revision: D31083476

Pulled By: mdouze

fbshipit-source-id: f34c3dafc4eb1c6f44a63e68137158911aa4a2f4
2021-10-11 14:13:16 -07:00
Jeff Johnson
312d823494 Faiss GPU large transpose fix (#2075)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2075

This is a fix for https://github.com/facebookresearch/faiss/pull/1996

namely, that large transposition jobs (where one of the dimensions is > 65535) will still work by performing a loop over the gridDim.y

Reviewed By: mdouze

Differential Revision: D31481494

fbshipit-source-id: af35af36cce27ce7d44128d95cc229dd5c4b4b56
2021-10-11 12:36:00 -07:00
Lucas Hosseini
79e74fe307 Generate python docstrings from doxygen comments. (#1969)
Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1969

Reviewed By: mdouze

Differential Revision: D31084784

Pulled By: beauby

fbshipit-source-id: 32b152f10fde9a0f5299909b8fd5c855fe738996
2021-10-10 22:14:48 -07:00
Alexander Andreev
14ddbc2911 Add faiss_pairwise_L2sqr_with_defaults into C_API (#2067)
Summary:
fixes https://github.com/facebookresearch/faiss/issues/2060

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

Reviewed By: beauby

Differential Revision: D31228802

Pulled By: mdouze

fbshipit-source-id: 1cb7df125ad47ccfa5169a10504d588b52eacdf7
2021-10-07 03:43:57 -07:00
Matthijs Douze
b813ba805e Reduce mem usage + improve performance for sequential search imlementation
Summary:
Following up on issue https://github.com/facebookresearch/faiss/issues/2054 it seems that this code crashes Faiss (instead of just leaking memory).

Findings:

- when running in MT mode, each search in an indexflat used as coarse quantizer consumes some memory
- this mem consumption does not appear in single-thread mode or with few threads
- in gdb it appears that even when the nb of queries is 1, each search spawns max_threads threads (80 on the test machine)

This diff:

- adds a C++ test that checks how much mem is used when repeatedly searching a vector
- adjusts the number of search threads to the number of query vectors. This is especially useful for single-vector queries.

Reviewed By: beauby

Differential Revision: D31142383

fbshipit-source-id: 134ddaf141e7c52a854cea398f5dbf89951a7ff8
2021-10-05 15:54:04 -07:00
Kent Gauen
3ca4fe5b6a Error Checking Typo (#2055)
Summary:
I am correcting a minor typo in the error checking.

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

Reviewed By: beauby, wickedfoo

Differential Revision: D31052509

Pulled By: mdouze

fbshipit-source-id: 36063107503afa5c37a98a0ae0d62df8bc8832e8
2021-09-20 09:29:35 -07:00
Chengqi Deng
eba1cb1a90 Support LSQ on GPU (#1978)
Summary:
## Description

This PR added support for LSQ on GPU. Only the encoding part is running on GPU and the others are still running on CPU.

Multi-GPU is also supported.

## Usage

``` python
lsq = faiss.LocalSearchQuantizer(d, M, nbits)
ngpus = faiss.get_num_gpus()
lsq.icm_encoder_factory = faiss.GpuIcmEncoderFactory(ngpus)  # we use all gpus

lsq.train(xt)
codes = lsq.compute_codes(xb)
decoded = lsq.decode(codes)
```

## Performance on SIFT1M

On 1 GPU:
```
===== lsq-gpu:
        mean square error = 17337.878528
        training time: 40.9857234954834 s
        encoding time: 27.12640070915222 s
```

On 2 GPUs:
```
===== lsq-gpu:
        mean square error = 17364.658176
        training time: 25.832106113433838 s
        encoding time: 14.879548072814941 s
```

On CPU:
```
===== lsq:
        mean square error = 17305.880576
        training time: 152.57522344589233 s
        encoding time: 110.01779270172119 s
```

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

Test Plan: buck test mode/dev-nosan //faiss/gpu/test/:test_gpu_index_py -- TestLSQIcmEncoder

Reviewed By: wickedfoo

Differential Revision: D29609763

Pulled By: mdouze

fbshipit-source-id: b6ffa2a3c02bf696a4e52348132affa0dd838870
2021-09-09 09:13:15 -07:00
Alexander Andreev
8a2860c1dc Improve meta indexes (#1982)
Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1982

Reviewed By: beauby

Differential Revision: D30762188

Pulled By: mdouze

fbshipit-source-id: 55b92f7829a417195a42870940c158373ed98bc1
2021-09-08 10:02:47 -07:00
Arvin Qin
9c4d6262b3 MOD: add some cpp feature, like distance/norm/inner prod computations (#2036)
Summary:
I want to invoke norm  computations by using CGO, but I find some functions which have been implemented in cpp are not exported in c api, so I commit the PR to solve the problem.

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

Reviewed By: beauby

Differential Revision: D30762172

Pulled By: mdouze

fbshipit-source-id: 097b32f29658c1864bd794734daaef0dd75d17ef
2021-09-06 09:07:12 -07:00
Matthijs Douze
a3fae15e66 Fix training of complex quantizer (#2035)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2035

Relates to issue

https://github.com/facebookresearch/faiss/issues/2019

This diff fixes the issue and adds a test

Reviewed By: beauby

Differential Revision: D30749000

fbshipit-source-id: 3a03fa347a40bde04162981a5e0b153b4f7b9d66
2021-09-06 08:53:29 -07:00
Lucas Hosseini
b4eb51dae8 Change default branch references from master to main. (#2029)
Summary:
This is required for the renaming of the default branch from `master` to `main`, in accordance with the new Facebook OSS guidelines.

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

Reviewed By: mdouze

Differential Revision: D30672862

Pulled By: beauby

fbshipit-source-id: 0b6458a4ff02a12aae14cf94057e85fdcbcbff96
2021-09-01 09:26:20 -07:00
Matthijs Douze
151e3d7be5 fix centroids_norms storage for ResidualCoarseQuantizer (#2018)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2018

The centroids norms table was not reconstructed correctly after being stored in RCQ.

Reviewed By: Sugoshnr

Differential Revision: D30484389

fbshipit-source-id: 9f618a3939c99dc987590c07eda8e76e19248b08
2021-08-25 06:37:33 -07:00
Matthijs Douze
760cce7f3a Support for additive quantizer search (#1961)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1961

This diff implements LUT-based search for additive quantizers.
It also further merges code for LSQ and the RedisualQuantizer.

The documentation + evaluation is on github:

https://github.com/facebookresearch/faiss/wiki/Additive-quantizers

Reviewed By: wickedfoo

Differential Revision: D29395079

fbshipit-source-id: b8a24a647bbdc4cda2a699e791ffdb2a12bfa9c6
2021-08-20 01:00:10 -07:00
Jayasruthi Vr
b78e21aaab Replace ScopeDeleter with unique_ptr in IndexIVFFlat.cpp
Summary: Replaced ScopeDeleter with std::unique_ptr in IndexIVFFlat.cpp

Reviewed By: beauby

Differential Revision: D29776444

fbshipit-source-id: 5a62a2318759bf891a4c1e5a9e990dfeed768bb3
2021-07-26 15:11:36 -07:00
Sugosh Nagavara Ravindra
f1fdcd0e33 Include ResidualCoarseQuantizer in clone_index (#1983)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1983

Add clone_index support to ResidualCoarseQuantizer to enable GPU training. Similar to D28614996

Reviewed By: mdouze

Differential Revision: D29605169

fbshipit-source-id: bf9cc32b60061a42310506058ebb45d5f2cea8d8
2021-07-13 17:36:19 -07:00
Check Deng
48ae55348a Update codebooks with double type (#1975)
Summary:
## Description

The process of updating the codebook in LSQ may be unstable if the data is not zero-centering. This diff fixed it by using `double` instead of `float` during codebook updating. This would not affect the performance since the update process is quite fast.

Users could switch back to `float` mode by setting `update_codebooks_with_double = False`

## Changes

1. Support `double` during codebook updating.
2. Add a unit test.
3. Add `__init__.py` under `contrib/` to avoid warnings.

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

Reviewed By: wickedfoo

Differential Revision: D29565632

Pulled By: mdouze

fbshipit-source-id: 932d7932ae9725c299cd83f87495542703ad6654
2021-07-07 03:29:49 -07:00
Matthijs Douze
1829aa92a1 three small fixes (#1972)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1972

This fixes a few issues that I ran into + adds tests:

- range_search_max_results with IP search

- a few missing downcasts for VectorTRansforms

- ResultHeap supports max IP search

Reviewed By: wickedfoo

Differential Revision: D29525093

fbshipit-source-id: d4ff0aff1d83af9717ff1aaa2fe3cda7b53019a3
2021-07-01 16:08:45 -07:00
Alexander Andreev
7cce100c92 C_API: Improve PreTransformIndex (#1945)
Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1945

Reviewed By: beauby

Differential Revision: D29257935

Pulled By: mdouze

fbshipit-source-id: 1cf355389251646cdea5d1dff8e416506f92ea2a
2021-06-23 07:06:20 -07:00
Alexander Andreev
f6d2efd1df Cover more types for C_API (#1917)
Summary:
Exported some global variables and statistics.
Supported downcast for IndexIDMap and IndexIDMap2 from faiss::Index
Fixes https://github.com/facebookresearch/faiss/issues/1863

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

Reviewed By: beauby

Differential Revision: D28834039

Pulled By: mdouze

fbshipit-source-id: c1f7739dcdc23055780ebc665082609641dff861
2021-06-08 15:34:05 -07:00
Chengqi Deng
fed61e6d95 Add ARM to CI (#1914)
Summary:
This PR added a CI job for ARM.

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

Reviewed By: beauby

Differential Revision: D28833987

Pulled By: mdouze

fbshipit-source-id: 4977585ea1a0715547ed34f400cf0a3646fca667
2021-06-08 14:53:02 -07:00
Lucas Hosseini
b2b129980e Fix release packages being overwritten by nightlies. (#1935)
Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1935

Reviewed By: mdouze

Differential Revision: D28932003

Pulled By: beauby

fbshipit-source-id: f6149697a270c07cfef789e7e7f22ba58cb9627c
2021-06-07 09:24:10 -07:00
H. Vetinari
6c2e59cd14 Small build fixes for 1.7.1 (#1933)
Summary:
Some small fixes from https://github.com/conda-forge/faiss-split-feedstock/pull/46; some missing (and unsorted) headers like in https://github.com/facebookresearch/faiss/issues/1666, and a missing `<algorithm>` include like in  https://github.com/facebookresearch/faiss/issues/1895

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

Reviewed By: mdouze

Differential Revision: D28931009

Pulled By: beauby

fbshipit-source-id: c8a9e52a9237dc0bb87664441a76a5db47cc821a
2021-06-07 08:40:47 -07:00
Y.Imaizumi
e5fa6cf58b Fix Conda CI (#1884)
Summary:
Currently CI jobs using conda are failed due to conflict packages.
This PR fixes this.

- use newer `numpy` to build `faiss-cpu`
- install `pytorch` when testing `faiss-cpu`
    - to find correct `pytorch` package, `pytorch` channel is set at `conda build`

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

Reviewed By: mdouze

Differential Revision: D28777447

Pulled By: beauby

fbshipit-source-id: 82a1ce076abe6bbbba9415e8935ed57b6104b6c3
2021-05-31 00:04:42 -07:00
Lucas Hosseini
cff072b78e Prepare for release v1.7.1. (#1915)
Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1915

Reviewed By: mdouze

Differential Revision: D28749880

Pulled By: beauby

fbshipit-source-id: 4dcb0a5eac8f84d26570a0fb6f3e357bc2f1151c
v1.7.1
2021-05-27 10:49:37 -07:00
Matthijs Douze
a7d62b39b4 Fix GPU nighties test (#1901)
Summary:
This should fix the GPU nighties.

The rationale for the cp is that there is a shared file between the CPU and GPU tests.

Ideally, this file should probably moved to contrib at some point.

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

Reviewed By: beauby

Differential Revision: D28680898

Pulled By: mdouze

fbshipit-source-id: b9d0e1969103764ecb6f1e047c9ed4bd4a76aaba
2021-05-26 09:41:31 -07:00
Matthijs Douze
8eab15eca3 LUT based search for additive quantizers (#1908)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1908

To search the best combination of codebooks, the method that was implemented so far is via a beam search.

It is possible to make this faster for a query vector q by precomputing look-up tables in the form of

LUT_m = <q, cent_m>

where cent_m is the set of centroids for quantizer m=0..M-1.

The LUT can then be used as

inner_prod = sum_m LUT_m[c_m]

and

L2_distance = norm_q + norm_db - 2 * inner_prod

This diff implements this computation by:

- adding the LUT precomputation

- storing an exhaustive table of all centroid norms (when using L2)

This is only practical for small additive quantizers, eg. when a residual vector quantizer is used as coarse quantizer (ResidualCoarseQuantizer).

This diff is based on AdditiveQuantizer diff because it applies equally to other quantizers (eg. the LSQ).

Reviewed By: sc268

Differential Revision: D28467746

fbshipit-source-id: 82611fe1e4908c290204d4de866338c622ae4148
2021-05-25 01:54:53 -07:00
Sugosh Nagavara Ravindra
0825eaf8d3 Include IndexResidual in clone_index
Summary:
Moving index from cpu to gpu is failing with error message `RuntimeError: Error in virtual faiss::Index *faiss::Cloner::clone_Index(const faiss::Index *) at faiss/clone_index.cpp:144: clone not supported for this type of Index`
This diff support IndexResidual clone and unblocks gpu training

Reviewed By: sc268, mdouze

Differential Revision: D28614996

fbshipit-source-id: 9b1e5e7c5dd5da6d55f02594b062691565a86f49
2021-05-24 20:05:23 -07:00
Giuseppe Ottaviano
d5a1bf3e9b Expose query_to_code in SQDistanceComputer
Summary: This is necessary to share a `SQDistanceComputer` instance among multiple thread, when the codes are not stored in a faiss index. The function is `const` and thread-safe.

Reviewed By: philippv, mdouze

Differential Revision: D28623897

fbshipit-source-id: e527d98231bf690dc01191dcc597ee800b5e57a9
2021-05-24 11:01:01 -07:00
Lucas Hosseini
cd6909004f Add packages for CUDA 11.3. (#1902)
Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1902

Reviewed By: mdouze

Differential Revision: D28566993

Pulled By: beauby

fbshipit-source-id: f560130c874bad355377b88b4519519af1e5d9f1
2021-05-21 07:47:37 -07:00
Chengqi Deng
c087f87730 Add LocalSearchQuantizer (#1906)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1906

This PR implemented LSQ/LSQ++, a vector quantization technique described in the following two papers:

1. Revisiting additive quantization
2. LSQ++: Lower running time and higher recall in multi-codebook quantization

Here is a benchmark running on SIFT1M for 64 bits encoding:
```
===== lsq:
        mean square error = 17335.390208
        training time: 312.729779958725 s
        encoding time: 244.6277096271515 s
===== pq:
        mean square error = 23743.004672
        training time: 1.1610801219940186 s
        encoding time: 2.636141061782837 s
===== rq:
        mean square error = 20999.737344
        training time: 31.813055515289307 s
        encoding time: 307.51959800720215 s
```

Changes:

1. Add LocalSearchQuantizer object
2. Fix an out of memory bug in ResidualQuantizer
3. Add a benchmark for evaluating quantizers
4. Add tests for LocalSearchQuantizer

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

Test Plan:
```
buck test //faiss/tests/:test_lsq

buck run mode/opt //faiss/benchs/:bench_quantizer -- lsq pq rq
```

Reviewed By: beauby

Differential Revision: D28376369

Pulled By: mdouze

fbshipit-source-id: 2a394d38bf75b9de0a1c2cd6faddf7dd362a6fa8
2021-05-21 01:33:55 -07:00
Chengqi Deng
d7f2dff589 Add tests for avx2 building (#1905)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1905

This PR added some tests to make sure the building with AVX2 works as we expected in Linux.

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

Test Plan: buck test //faiss/tests/:test_fast_scan -- test_PQ4_speed

Reviewed By: beauby

Differential Revision: D27435796

Pulled By: mdouze

fbshipit-source-id: 901a1d0abd9cb45ccef541bd7a570eb2bd8aac5b
2021-05-20 22:16:06 -07:00
Y.Imaizumi
e52f5d81f8 Workaround for vshl/vshr on aarch64 GCC (#1882)
Summary:
related: https://github.com/facebookresearch/faiss/issues/1815,  https://github.com/facebookresearch/faiss/issues/1880

`vshl` / `vshr` of ARM NEON requires immediate (compiletime constant) value as shift parameter.
However, the implementations of those intrinsics on GCC can receive runtime value.
Current faiss implementation depends on this, so some correct-behavioring compilers like Clang can't build faiss for aarch64.
This PR fix this issue; thus faiss applied this PR can be built with Clang for aarch64 machines like M1 Mac.

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

Reviewed By: beauby

Differential Revision: D28465563

Pulled By: mdouze

fbshipit-source-id: e431dfb3b27c9728072f50b4bf9445a3f4a5ac43
2021-05-20 14:55:37 -07:00
Lucas Hosseini
ef33daae92 Add CUDA compute capability 8.6 for CUDA 11 packages. (#1899)
Summary:
Also remove support for deprecated compute capabilities 3.5 and 5.2 in
CUDA 11.

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

Reviewed By: mdouze

Differential Revision: D28539826

Pulled By: beauby

fbshipit-source-id: 6e8265f2bfd991ff3d14a6a5f76f9087271f3f75
2021-05-19 12:58:50 -07:00
Lucas Hosseini
1223e68688 Avoid OOM in Linux CPU CI jobs. (#1900)
Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1900

Reviewed By: mdouze

Differential Revision: D28539987

Pulled By: beauby

fbshipit-source-id: 2e44755e48bd45233578ce0ba75836fc533afe35
2021-05-19 12:36:05 -07:00
Lucas Hosseini
797bc88566 Add missing includes for std::min/std::max. (#1895)
Summary:
Closes https://github.com/facebookresearch/faiss/issues/1876.

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

Reviewed By: mdouze

Differential Revision: D28511225

Pulled By: beauby

fbshipit-source-id: 6dc6d0662983fdac7eef516f41fea1368195fb3e
2021-05-18 10:42:09 -07:00
Lucas Hosseini
77825c52bd Fix conda recipes. (#1894)
Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1894

Reviewed By: wickedfoo

Differential Revision: D28510244

Pulled By: beauby

fbshipit-source-id: 32983b7eeab497b8d576caaadd56e13a2134a4ab
2021-05-18 09:10:54 -07:00
vorj
67a8070d7d Suppress -Wpedantic (#1888)
Summary:
Current `faiss` contains some codes which will be warned by compilers when we will add some compile options like `-Wall -Wextra` .
IMHO, warning codes in `.cpp` and `.cu` doesn't need to be fixed if the policy of this project allows warning.
However, I think that it is better to fix the codes in `.h` and `.cuh` , which are also referenced by `faiss` users.

Currently it makes a error to `#include` some faiss headers like `#include<faiss/IndexHNSW.h>` when we compile the codes with `-pedantic-errors` .
This PR fix this problem.
In this PR, for the reasons above, we fixed `-Wpedantic` codes only in `.h` .

This PR doesn't change `faiss` behavior.

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

Reviewed By: wickedfoo

Differential Revision: D28506963

Pulled By: beauby

fbshipit-source-id: cbdf0506a95890c9c1b829cb89ee60e69cf94a79
2021-05-18 08:49:50 -07:00
Matthijs Douze
3eb82e32dc Range search bug
Summary:
This diff fixes a serious bug in the range search implementation.

During range search in a flat index, (exhaustive_L2sqr_seq and exhaustive_inner_product_seq) when running in multiple threads, the per-thread results are collected into RangeSearchPartialResult structures.

When the computation is finished, they are aggregated into a RangeSearchResult. In the previous version of the code, this loop was nested into a second loop that is used to check for KeyboardInterrupts. Thus, at each iteration, the results were overwritten.

The fix removes the outer loop. It is most likely useless anyways because the sequential code is called only for a small number of queries, for a larger number the BLAS version is used.

Reviewed By: wickedfoo

Differential Revision: D28486415

fbshipit-source-id: 89a52b17f6ca1ef68fc5e758f0e5a44d0df9fe38
2021-05-17 23:10:20 -07:00
Alexander Andreev
a87930111e Classes inherited from VectorTransform for c_api (#1869)
Summary:
inherite from  LinearTransform doesn't work here.

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

Reviewed By: beauby

Differential Revision: D28345866

Pulled By: mdouze

fbshipit-source-id: 277dd421213a91c07ed41d7b23002840cc5cfa1f
2021-05-12 07:34:39 -07:00
Y.Imaizumi
d7f9c0ce95 Implement peel loop for fvec_L2sqr, fvec_inner_product, and fvec_norm_L2sqr on aarch64 (#1878)
Summary:
In the current `faiss` implementation for x86, `fvec_L2sqr` , `fvec_inner_product` , and `fvec_norm_L2sqr` are [optimized for any dimensionality](e86bf8cae1/faiss/utils/distances_simd.cpp (L404-L432)).

On the other hand, the functions for aarch64 are optimized [**only** if `d` is multiple for 4](e86bf8cae1/faiss/utils/distances_simd.cpp (L583-L584)); thus, they are not much fast for vectors with `d % 4 != 0` .
This PR has accelerated the above three functions for any input size on aarch64.

Kind regards,

![peel-loop](https://user-images.githubusercontent.com/40021161/117810705-b36e7380-b29a-11eb-9096-91babc27a03d.png)
- Evaluated on an AWS EC2 ARM instance (c6g.4xlarge)
- sift1m127 is the dataset with dropped trailing elements of sift1m
    - Therefore, the vector length of sift1m127 is 127 that is not multiple of 4
    - "optimized" runs 2.45-2.77 times faster than "original" with sift1m127
- Two methods, "original" and "optimized", are expected to achieve the same level of performance for sift1m
    - And actually there is almost no significant difference

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

Reviewed By: beauby

Differential Revision: D28376329

Pulled By: mdouze

fbshipit-source-id: c68f13b4c426e56681d81efd8a27bd7bead819de
2021-05-12 07:15:56 -07:00
CodemodService FBSourceClangFormatLinterBot
b4c320a671 Daily arc lint --take CLANGFORMAT
Reviewed By: zertosh

Differential Revision: D28319469

fbshipit-source-id: 8295597a8ee16b2fef3f7aacdd6c892cb22db988
2021-05-10 03:38:52 -07:00
Matthijs Douze
2d380e992b Add manifold check for size 0 (#1867)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1867

Merging code for the 1T photodna index seems to fail at

https://www.internalfb.com/phabricator/paste/view/P412975011?lines=174

with
```
terminate called after throwing an instance of 'facebook::manifold::blobstore::StorageException'
  what():  [400] Begin offset and/or length were invalid -- Begin offset must be positive and length must be non-negative. Received: offset = 2642410612, length = 0
Aborted (core dumped)
```
traces back to

https://www.internalfb.com/intern/diffusion/FBS/browsefile/master/fbcode/manifold/blobstore/BlobstoreThriftHandler.cpp?lines=671%2C700%2C732

There is a single case where we don't check if the read or write size is 0. So let's try this fix.

In the process I realized that the Manifold tests were non functional due to a name collision on common.py. Also fix this in all dependent files.

Differential Revision: D28231710

fbshipit-source-id: 700ffa6ca0c82c49e7d1eae9e76549ec5ff16332
2021-05-09 22:30:31 -07:00
Matthijs Douze
441ccebbff Make more Residual quantizer more memory efficient (#1865)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1865

This diff chunks vectors to encode to make it more memory efficient.

Reviewed By: sc268

Differential Revision: D28234424

fbshipit-source-id: c1afd2aaff953d4ecd339800d5951ae1cae4789a
2021-05-07 02:12:27 -07:00