-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Support CAGRA in FAISS C API #4508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Hi @QingyangYinUber! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
| DEFINE_GETTER(GpuIndexConfig, int, device) | ||
|
|
||
| int faiss_index_gpu_to_cpu_new(const FaissIndex* gpu_index, FaissIndex** p_out) { | ||
| int result = faiss_index_gpu_to_cpu(gpu_index, p_out); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would be the difference between faiss_index_gpu_to_cpu_new and faiss_index_gpu_to_cpu? If these function are to ever have a different behavior, then that should probably be documented.
|
Hi @QingyangYinUber , seems like the build has errors, are you able to see the logs and update? |
|
Hi @mnorris11 , I have updated the code to follow the clang-format. For the build error, I modified the "How to Test" section, adding the conda environment and the needed packages to build. |
| auto cpu_index = faiss::gpu::index_gpu_to_cpu( | ||
| reinterpret_cast<const Index*>(gpu_index)); | ||
| *p_out = reinterpret_cast<FaissIndex*>(cpu_index); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it is nullptr, this just casts null to null right? Is there a problem with it on your consumer side?
| int device, | ||
| const FaissIndex* index, | ||
| FaissGpuIndex** p_out) { | ||
| return faiss_index_cpu_to_gpu(provider, device, index, p_out); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't quite understand why we need the _new if it just wraps this function?
|
This is the cmake run by the first initial job: It fails because it tries to build the c api but there is no cublas as Can tests/test_gpu_cagra_c_api.cpp instead be under the gpu/tests directory? You can try it and see if it builds |
Description
This pull request introduces support for the CAGRA index in the FAISS C API. This enables downstream projects that use the C API, such as Lucene, to leverage GPU-accelerated indexing with CAGRA. The key changes include:
New C interface for CAGRA: Exposes CAGRA index functionality through the C API.
CPU/GPU Index Conversion: Adds C interfaces to convert a GPU-based CAGRA index to a CPU-based HNSW index and vice-versa. This is necessary because CAGRA indexes cannot be directly saved to disk. The current workaround is to convert the index to HNSW for saving and convert it back to CAGRA upon loading.
Motivation
The primary motivation is to unblock the use of CAGRA in Lucene. A recently merged PR in Lucene (apache/lucene#14178) introduced a FAISS codec for k-NN search using the Panama FFI. However, it cannot use CAGRA because the FAISS C API lacks the necessary support, which this PR now provides.
How to Test
The new functionality can be tested using the newly added C++ example:
tests/test_gpu_cagra_c_api.cpp. To run the project, first create a Conda environment and install the required packages. Then, build the project and execute the tests as shown below.