Skip to content
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

Support static link as a feature #67

Merged
merged 10 commits into from
Aug 23, 2023
Merged

Support static link as a feature #67

merged 10 commits into from
Aug 23, 2023

Conversation

SkyFan2002
Copy link
Contributor

After enabling the static feature, users do not need to download and build faiss, so it can be used out of the box.

Copy link
Owner

@Enet4 Enet4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello! Thank you for this very interesting contribution, It may indeed help some users take advantage of the library.

I have raised some concerns in the comments below, but once they're sorted out we can continue with the review and testing.

.gitmodules Outdated Show resolved Hide resolved
faiss-sys/Cargo.toml Outdated Show resolved Hide resolved
faiss-sys/c_api.h Outdated Show resolved Hide resolved
faiss-sys/gen_bindings.sh Outdated Show resolved Hide resolved
src/index/io.rs Outdated Show resolved Hide resolved
@SkyFan2002
Copy link
Contributor Author

Hello! Thank you for this very interesting contribution, It may indeed help some users take advantage of the library.

I have raised some concerns in the comments below, but once they're sorted out we can continue with the review and testing.

Sorry, I pushed the development of generic io to this branch by mistake, I will solve it

@SkyFan2002 SkyFan2002 requested a review from Enet4 April 28, 2023 08:15
@SkyFan2002
Copy link
Contributor Author

By the way, it seems that due to the update of bindgen, the gen_bindings.sh is no longer valid

$ ./gen_bindings.sh 
fatal: destination path 'faiss' already exists and is not an empty directory.
ls: cannot access 'faiss/c_api/impl/*_c.h': No such file or directory
ls: cannot access 'faiss/c_api/utils/*_c.h': No such file or directory
bindgen --rust-target 1.33 --size_t-is-usize --whitelist-function faiss_.* --whitelist-type idx_t|Faiss.* --opaque-type FILE c_api.h -o src/bindings.rs
error: unexpected argument '--size_t-is-usize' found

  tip: a similar argument exists: '--no-size_t-is-usize'

Usage: bindgen [FLAGS] [OPTIONS] [HEADER] -- [CLANG_ARGS]...

For more information, try '--help'.
bindgen --rust-target 1.33 --size_t-is-usize --whitelist-function faiss_.* --whitelist-type idx_t|Faiss.* --opaque-type FILE c_api.h -o src/bindings_gpu.rs -- -Ifaiss/c_api -I/opt/cuda/include
error: unexpected argument '--size_t-is-usize' found

  tip: a similar argument exists: '--no-size_t-is-usize'

Usage: bindgen [FLAGS] [OPTIONS] [HEADER] -- [CLANG_ARGS]...

For more information, try '--help'.
$ bindgen --version
bindgen 0.65.1

@Enet4
Copy link
Owner

Enet4 commented Apr 28, 2023

By the way, it seems that due to the update of bindgen, the gen_bindings.sh is no longer valid

Hmm, maybe I should have recorded which version of rust-bindgen I was using.
It appears that the behavior size_t is usize has become the default, so the flag --size_t-is-usize can be removed.
The rust-bindgen changelog might help track down the latest changes and know what to update here.

The other errors may have to do with faiss now existing as a git submodule.

@SkyFan2002
Copy link
Contributor Author

SkyFan2002 commented Apr 28, 2023

In fact,--whitelist-function is invalid, eithier.

error: unexpected argument '--whitelist-type' found

  tip: a similar argument exists: '--allowlist-type'

@Enet4
Copy link
Owner

Enet4 commented Apr 28, 2023

It should be a matter of following the changelog and the recommendations from the tool itself until it works. For the record, I last used bindgen in version 0.59.2.

@SkyFan2002
Copy link
Contributor Author

What can I do to have this PR continued? I apologize for may have been impolite before.

Copy link
Owner

@Enet4 Enet4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SkyFan2002 No harm taken at all! I am just trying to help you resolve some of the issues here, as I may not be able to fill in all the gaps. It may also take some time to review and provide feedback, as I cannot commit to a prompt reply for this particular project.


The two major issues I could find right now are:

  • The faiss-sys/faiss submodule should check out branch c_api_head instead of the default branch.
  • gen_bindings.sh will indeed need to be modified so that it does not try to clone and clean up faiss if the git submodule has already been checked out. Another easy way around this is to use a different destination name, although in this case we would be making a redundant version. I added a suggested change for this.
  • Other minor tweaks in the code follow.
  • Updating gen_bindings.sh to support the latest version of bindgen is secondary, but would be OK to introduce here as well.

.gitmodules Show resolved Hide resolved
faiss-sys/build.rs Show resolved Hide resolved
SkyFan2002 and others added 3 commits April 30, 2023 19:00
Co-authored-by: Eduardo Pinho <enet4mikeenet@gmail.com>
Co-authored-by: Eduardo Pinho <enet4mikeenet@gmail.com>
@SkyFan2002
Copy link
Contributor Author

Hi, thanks for your help. I have fixed the repeated clone issue. As for the bindgen version, --size_t-is-usize can be deleted directly, but the --whitelist-function and --whitelist-type has been deprecated, and I don't know if there is an API with similar semantics.
Do you have any idea about this?Or I am glad to try to solve this in anothr PR.

@web3creator
Copy link

@SkyFan2002 Why is this PR closed?I hope to add support for static libraries, but I don't know c language

@SkyFan2002 SkyFan2002 reopened this Jun 1, 2023
@Enet4 Enet4 self-requested a review June 1, 2023 08:48
@Enet4
Copy link
Owner

Enet4 commented Jun 2, 2023

It seems to have compiled seamlessly on my Linux machine. But I wonder, how can one specify more details about the compilation and linking of Faiss without changing the build script? In particular, it should be possible to define some of the options found here, including which BLAS implementation to use, where to find CUDA in case of GPU support, and whether to use the avx2 optimization level.
If there is no way to define these options from outside (maybe specially written environment variables?), we should open a way to do this ourselves at faiss-sys, using environment variables and/or Cargo features.

@jondot
Copy link

jondot commented Aug 23, 2023

https://github.com/rustformers/llm/blob/main/crates/ggml/sys/build.rs

@Enet4 this is a good reference, it shows a similar library, with factors such as CPU/GPU and advanced CPU instruction toggling, as well as logic by-platform.

it should have all kinds of example of toggling flags for upstream libraries.

@jondot
Copy link

jondot commented Aug 23, 2023

@Enet4 I've been playing around (actually pulling hair!) with building an abstraction that depends on faiss-rs, and my impression is that this PR offers a better starting point for dynamic linking and a reasonable static linking experience (I'm on ARM macos so that's already a litmus test). Reasonable being that we can assume that the static linking build -- as it is now in this PR -- does not support advanced options.

All in all, I'm getting a smoother experience with the static build. I've locally updated to 1.7.x with no issues (faiss master), and build went smoothly with a small tweak.

Any thoughts on merging this PR for a starting point for static linking, having that it gives the existing dynamic linking experience an equivalent value?

@SkyFan2002
Copy link
Contributor Author

@Enet4 . Let's merge. I'm willing to help if advanced options are needed by someone in the future.

Copy link
Owner

@Enet4 Enet4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very well, let's do this! There seems to be more anticipation that I predicted. 😅

Thank you @SkyFan2002 for the contribution.

@Enet4 Enet4 merged commit c2838b8 into Enet4:master Aug 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants