Summary:
Legacy __print__ statements are syntax errors in Python 3 but __print()__ function works as expected in both Python 2 and Python 3.
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1443
Reviewed By: LowikC
Differential Revision: D24157415
Pulled By: mdouze
fbshipit-source-id: 4ec637aa26b61272e5337d47b7796a330ce25bad
Summary:
This diff removes a long-standing limitation with GpuIndexIVFPQ, in that only a limited number of dimensions per sub-quantizer were supported when not using precomputed codes. This is part of the general cleanup and extension/optimization that I am performing of the GPU PQ code.
Now, we keep the same old specialized distance computations, but if we attempt to use a number of dimensions per sub-Q that are not specialized, we fall back to a general implementation based on batch matrix multiplication for computing PQ distances per code.
The batch MM PQ distance computation is enabled automatically if you use an odd number of dimensions per sub-quantizer (say, 7, 11, 53, ...). It can also be manually enabled via the `useMMCodeDistance` option in `GpuIndexIVFPQConfig` for testing purposes, though the result should be within some epsilon of the other implementation.
This diff also removes the iterated GEMM wrapper. I don't honestly know why I was using this instead of `cublasGemmStridedBatchedEx`, maybe I couldn't find that or this was originally implemented in a much older version of CUDA. The iterated GEMM call was used in a few other places (e.g., precomputed code computation). Now, this (and the PQ distance computation) use batch MM which is a single CUDA call.
This diff also adds stream synchronization to the temporary memory manager, as the fallback PQ distance computation needs to use temporary memory, and there were too many buffers for these to pre-allocate.
It also fixes the bug in https://github.com/facebookresearch/faiss/issues/1421.
Reviewed By: mdouze
Differential Revision: D24130629
fbshipit-source-id: 1c8bc53c86d0523832ad89c8bd4fa4b5fc187cae
Summary:
This diff contains the following changes:
- adds support for an alternative IVFPQ memory layout, where the codes are interleaved by vector in groups of 32 rather than sub-quantizer, in order to support a variety of SIMD-like optimizations for PQ lookup kernels (eg like SCANN or other techniques that use in-register storage). This internal GPU-only format is transparent to the rest of the code, and attempts to copy an index to/from CPU deal with the difference in layout. The feature is enabled using `GpuIndexIVFPQConfig::alternativeLayout` upon index construction, which is not intended for general use yet, though it is functional.
This is the difference in layout explained:
```
/// The default memory layout is [vector][PQ component]:
/// (v0 d0) (v0 d1) ... (v0 dD-1) (v1 d0) (v1 d1) ...
///
/// An alternative memory layout (layoutBy32) is
/// [vector / 32][PQ component][vector % 32] with padding:
/// (v0 d0) (v1 d0) ... (v31 d0) (v0 d1) (v1 d1) ... (v31 dD-1) (v31 dD-1) (v33
/// d0) ...
/// so the list length is always a multiple of numSubQuantizers * 32
```
- adds kernels to support IVFPQ query using this format. These new kernels are naive implementations that do not use register or shared memory at all to store the code distance information, however unlike the prior GPU IVFPQ code, they support arbitrary-sized PQ encodings (arbitrary dimensions per sub-quantizer and arbitrary number of sub-quantizers per vector). This is enabled for both precomputed and normal codes. It is my intention that I will eventually remove the restriction on dimensions per sub-Q / number of sub-Qs in the GPU code so that it functions more like the CPU code, though due to the necessity of implementation specialization, it will be likely that a small number of choices will be optimized, leaving the rest to use slower fallback implementations.
It is likely that this will eventually become the default / only format supported by the GPU, but the optimized kernels have not yet been developed using this layout. This diff is being checked in first in order to checkpoint the development. The existing lookup kernels and storage have not been affected.
Furthermore, it may be likely that IVFFlat and IVFSQ eventually change to this interleaved format as they offer some advantages in implementation.
- Unifies the IVF handling and copy code more between IVFFlat, IVFPQ and IVFScalarQuantizer on the GPU. There was a lot of copy pasta/duplicated code between the three implementations which was also divergent. This code is now all handled by the IVFBase and GpuIndexIVF classes.
- Adds a logging feature to StandardGpuResources which allows for printing all memory allocation/deallocation requests to the console as they happen in real time. This is useful for debugging.
Reviewed By: mdouze
Differential Revision: D24064745
fbshipit-source-id: 434fb4ec39aaba32271742ba7a40460847386141
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1432
The contrib function knn_ground_truth does not provide exactly the same resutls on GPU and CPU (but relative accuracy is still 1e-7). This diff relaxes the constraint on CPU and added test on GPU.
Reviewed By: wickedfoo
Differential Revision: D24012199
fbshipit-source-id: aaa20dbdf42b876b3ed7da34028646dbb20833d3
Summary:
This diff fixes https://github.com/facebookresearch/faiss/issues/1412
There were various inconsistencies in how the shard and replica wrappers updated their internal state as the sub-indices were updated. This makes the two container classes work in the same way with similar synchronization functionality.
Reviewed By: beauby
Differential Revision: D23974186
fbshipit-source-id: c688c0c9124f823e4239aa2ff617b007b4564859
Summary:
if `ils = dynamic_cast<ArrayInvertedLists *> (index_ivf->invlists)` failed, `ils` would be `nullptr`.
so check if `ils` is `nullptr` before use it.
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1410
Reviewed By: beauby
Differential Revision: D23985814
Pulled By: mdouze
fbshipit-source-id: f62a3988e74b4de1f1c9a127475368302a35d4a5
Summary:
For some obscure reason Lua support depends on python2, which is going to be removed.
https://fb.workplace.com/groups/311767668871855/permalink/4219593711422545/
Since the Lua interface is not used in any active code it seems, it's easier to just remove the Lua interface.
It also removes the Faiss Lua dep in the few occurrences where it is used (omry see recog-eval).
Reviewed By: wickedfoo
Differential Revision: D23865458
fbshipit-source-id: 4149517af18acce29179d04152c7364c2548efa0
Summary:
This PR paves the way for nightly builds.
+ Get rid of cmake 3.17 manual install as cmake 3.18 is now available
in conda.
+ Update docker files for conda packages.
+ Specify CUDA architectures via CMake's `CMAKE_CUDA_ARCHITECTURES`.
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1422
Reviewed By: mdouze
Differential Revision: D23870447
Pulled By: beauby
fbshipit-source-id: 40ae7517e83356443a007a43261713e7e3a140d4
Summary:
there was a dynamic allocation on a std::string from multiple threads. Instead of adding a mutex in perfromance sensitive code, I use a statically allocated string instead.
The stress test crashed before, now it runs fine.
Reviewed By: wickedfoo
Differential Revision: D23702154
fbshipit-source-id: 5dd37f1c151d8ce7f756f54a059235d8673cdabc
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1407
When Inverted list reading throws an exception, it is propagated until it reaches the openmp loop, which crashes the caller.
This diff catches the exception and properly propagates it to the caller in Python.
It should be possible to test it with an ondisk instead of relying on Manifold.
Reviewed By: MDSilber
Differential Revision: D23688968
fbshipit-source-id: 0943fac41d4e9b8b86535439e3fdee18ce96d4a5
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1406
I appear to have broken this with the rework of float16 support in Faiss GPU, though I cannot figure out why the tests only started failing recently.
cuBLAS does not support a f16 x f32 = f32 matrix multiplication. With a f16 coarse quantizer and IVFPQ precomputed codes, we were attempting to perform such a multiplication.
Now, in the precomputed code calculation, we intercept this and change it to a f32 x f32 = f32 computation.
The test when run by itself was also failing separately, though when run in series with the other test_gpu_index_ivfpq tests it was succeeding, due to the fact that the seed is only initialized once. The epsilon needed to change a slight bit.
Reviewed By: mdouze
Differential Revision: D23687070
fbshipit-source-id: 14a535407ed433eeaef3bc77cb0d6f5909c55b9f
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1402
in C++03 there was no way to get the min value that is portable between int and float types (for float min returns the lowests strictly positive value). For C++11 this is lowest, so let's use it in the heap funcs.
Reviewed By: beauby
Differential Revision: D23622612
fbshipit-source-id: d3e3b2b7f695d971866f7b45bfc41986cd6b9bf4
Summary:
Fix to https://github.com/facebookresearch/faiss/issues/1385, set the value during cuBLAS handle construction.
Also the tensor core option is deprecated for CUDA 11+.
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1388
Test Plan: Unable to test numerical results, but builds on GCP A100 instance with CUDA 11.
Reviewed By: mdouze
Differential Revision: D23427285
Pulled By: wickedfoo
fbshipit-source-id: d9487559035175ec7e06600dcd8f6a307f50abad
Summary:
The pytorch interop code was in a test until now. However, it is better if people can rely on it to be updated when the API is updated. Therefore, we move it into contrib.
Also added a README.md
Reviewed By: wickedfoo
Differential Revision: D23392962
fbshipit-source-id: 9b7c0e388a7ea3c0b73dc0018322138f49191673
Summary:
This diff adds an object for a few useful dataset in faiss.contrib.
This includes synthetic datasets and the classic ones.
It is intended to work on:
- the FAIR cluster
- gluster
- manifold
Reviewed By: wickedfoo
Differential Revision: D23378763
fbshipit-source-id: 2437a7be9e712fd5ad1bccbe523cc1c936f7ab35
Summary:
`long` is 32 bits on windows and so is the default int type for numpy (eg. the one used for `np.arange`).
This diff explicitly specifies 64-bit ints for all occurrences where it matters.
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1381
Reviewed By: wickedfoo
Differential Revision: D23371232
Pulled By: mdouze
fbshipit-source-id: 220262cd70ee70379f83de93561a4eae71c94b04
Summary: Properties on swig sources must be set prior to the `swig_add_library()` call.
Reviewed By: mdouze
Differential Revision: D23338668
fbshipit-source-id: 71fdd1221ef0fabbd5597eff5e71d36e26435304
Summary:
Precomputing code does not make sense for IP search (it is useful only for L2). Previously, this throwed an exception. This diff just prints a warning.
Another error showed up that I am not sure how to fix:
https://www.internalfb.com/intern/testinfra/testconsole/testrun/1407375052636748/
Reviewed By: wickedfoo
Differential Revision: D23314697
fbshipit-source-id: e11b2ded43f9579d637963a142499693f5c15b71
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1359
The declaration is in distances.h, which utils.cpp does not include,
confusing the linker on Windows.
Test Plan: Imported from OSS
Reviewed By: mdouze
Differential Revision: D23311999
Pulled By: beauby
fbshipit-source-id: 6ebf26248a4376abc9dd90996e5dc43fa343e0b4