-
Notifications
You must be signed in to change notification settings - Fork 685
Added Faiss #8572
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
Merged
Merged
Added Faiss #8572
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
70c112e
Added Faiss, and Faiss_GPU
stemann 6973362
Renamed Faiss_GPU to Faiss_CUDA
stemann bb5480e
Reduced CUDA archs to "real" archs for CUDA compute capability > 8.0,…
stemann 9fc05ef
Disabled riscv64
stemann a25fdee
Revert "Disabled riscv64"
stemann a138de2
MKL 2025 doesn't support i686
stemann f14a5a8
Replaced superfluous `configure || configure || configure` with just …
stemann e402b5d
Bumped GCC requirement to v"8" to support PowerPC64LE
stemann ce99359
Bumped GCC requirement to v"9" to also support aarch64-linux-gnu
stemann c60ecab
Bumped GCC requirement to v"10"
stemann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # Note that this script can accept some limited command-line arguments, run | ||
| # `julia build_tarballs.jl --help` to see a usage message. | ||
| using BinaryBuilder, Pkg | ||
|
|
||
| name = "Faiss" | ||
| version = v"1.9.0" | ||
|
|
||
| include(joinpath(@__DIR__, "..", "common.jl")) | ||
|
|
||
| # Build the tarballs, and possibly a `build.jl` as well. | ||
| build_tarballs(ARGS, name, version, sources, script, platforms, products, dependencies; | ||
| julia_compat="1.6", | ||
| preferred_gcc_version=v"10", # Not using v"7", since OpenBLAS v0.3.29+ on PowerPC64LE requires libgfortran5, and not using v"8", and v"9" due to internal compiler errors on aarch64-linux-gnu | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| # Note that this script can accept some limited command-line arguments, run | ||
| # `julia build_tarballs.jl --help` to see a usage message. | ||
| using BinaryBuilder, Pkg | ||
|
|
||
| const YGGDRASIL_DIR = "../../.." | ||
| include(joinpath(YGGDRASIL_DIR, "fancy_toys.jl")) | ||
| include(joinpath(YGGDRASIL_DIR, "platforms", "cuda.jl")) | ||
|
|
||
| name = "Faiss_CUDA" | ||
| version = v"1.9.0" | ||
|
|
||
| # Conda GPU packages build on 11.4 and 12.1: https://github.com/facebookresearch/faiss/blob/v1.9.0/.github/workflows/build.yml#L182-L260 | ||
| cuda_versions = [ | ||
| # 11.4 does not provide cuda_profiler_api (used by faiss) | ||
| "11.8", # 11.8 to have cuda_profiler_api, and SM 87;89;90 support. | ||
| "12.1", | ||
| ] | ||
|
|
||
| include(joinpath(@__DIR__, "..", "common.jl")) | ||
|
|
||
| # Override the default platforms | ||
| platforms = CUDA.supported_platforms() | ||
| filter!(p -> arch(p) == "x86_64", platforms) | ||
|
|
||
| filter!(p -> p["cuda"] in cuda_versions, platforms) | ||
|
|
||
| # Override the default products | ||
| products = [ | ||
| products..., | ||
| FileProduct("include/faiss/gpu/GpuIndex.h", :faiss_gpu_gpuindex_h), | ||
| FileProduct("include/faiss/c_api/gpu/GpuIndex_c.h", :faiss_c_api_gpu_gpuindex_c_h), | ||
| ] | ||
|
|
||
| # Build for all supported CUDA toolkits | ||
| for platform in platforms | ||
| should_build_platform(triplet(platform)) || continue | ||
|
|
||
| cuda_deps = CUDA.required_dependencies(platform; static_sdk=true) | ||
|
|
||
| build_tarballs(ARGS, name, version, sources, script, [platform], products, [dependencies; cuda_deps]; | ||
| lazy_artifacts=true, | ||
| julia_compat="1.6", | ||
| preferred_gcc_version=v"7", | ||
| augment_platform_block=CUDA.augment, | ||
| skip_audit=true, | ||
| dont_dlopen=true) | ||
| end | ||
| # trigger yggy |
25 changes: 25 additions & 0 deletions
25
F/Faiss/bundled/patches/faiss-mingw32-InvertedListsIOHook.patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| diff --git a/faiss/invlists/InvertedListsIOHook.cpp b/faiss/invlists/InvertedListsIOHook.cpp | ||
| index 0081c4f9..2c3a6006 100644 | ||
| --- a/faiss/invlists/InvertedListsIOHook.cpp | ||
| +++ b/faiss/invlists/InvertedListsIOHook.cpp | ||
| @@ -13,9 +13,9 @@ | ||
|
|
||
| #include <faiss/invlists/BlockInvertedLists.h> | ||
|
|
||
| -#ifndef _MSC_VER | ||
| +#ifndef _WIN32 | ||
| #include <faiss/invlists/OnDiskInvertedLists.h> | ||
| -#endif // !_MSC_VER | ||
| +#endif // !_WIN32 | ||
|
|
||
| namespace faiss { | ||
|
|
||
| @@ -33,7 +33,7 @@ namespace { | ||
| /// std::vector that deletes its contents | ||
| struct IOHookTable : std::vector<InvertedListsIOHook*> { | ||
| IOHookTable() { | ||
| -#ifndef _MSC_VER | ||
| +#ifndef _WIN32 | ||
| push_back(new OnDiskInvertedListsIOHook()); | ||
| #endif | ||
| push_back(new BlockInvertedListsIOHook()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| diff --git a/faiss/CMakeLists.txt b/faiss/CMakeLists.txt | ||
| index 2871d974..bc017d10 100644 | ||
| --- a/faiss/CMakeLists.txt | ||
| +++ b/faiss/CMakeLists.txt | ||
| @@ -326,6 +326,10 @@ if(WIN32) | ||
| target_compile_definitions(faiss_sve PRIVATE FAISS_MAIN_LIB) | ||
| endif() | ||
|
|
||
| +if(WIN32) | ||
| + set_target_properties(faiss PROPERTIES LINK_FLAGS "-Wl,--export-all-symbols") | ||
| +endif() | ||
| + | ||
| string(FIND "${CMAKE_CXX_FLAGS}" "FINTEGER" finteger_idx) | ||
| if (${finteger_idx} EQUAL -1) | ||
| target_compile_definitions(faiss PRIVATE FINTEGER=int) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| diff --git a/faiss/impl/platform_macros.h b/faiss/impl/platform_macros.h | ||
| index 2aecc512..0c792190 100644 | ||
| --- a/faiss/impl/platform_macros.h | ||
| +++ b/faiss/impl/platform_macros.h | ||
| @@ -11,7 +11,7 @@ | ||
| #include <cstdint> | ||
| #include <cstdio> | ||
|
|
||
| -#ifdef _MSC_VER | ||
| +#ifdef _WIN32 | ||
|
|
||
| /******************************************************* | ||
| * Windows specific macros | ||
| @@ -23,11 +23,11 @@ | ||
| #define FAISS_API __declspec(dllimport) | ||
| #endif // FAISS_MAIN_LIB | ||
|
|
||
| -#ifdef _MSC_VER | ||
| #define strtok_r strtok_s | ||
| -#endif // _MSC_VER | ||
|
|
||
| +#ifdef _MSC_VER | ||
| #define __PRETTY_FUNCTION__ __FUNCSIG__ | ||
| +#endif // _MSC_VER | ||
|
|
||
| #define posix_memalign(p, a, s) \ | ||
| (((*(p)) = _aligned_malloc((s), (a))), *(p) ? 0 : errno) | ||
| @@ -37,6 +37,7 @@ | ||
| #define ALIGNED(x) __declspec(align(x)) | ||
|
|
||
| // redefine the GCC intrinsics with Windows equivalents | ||
| +#ifdef _MSC_VER | ||
|
|
||
| #include <intrin.h> | ||
|
|
||
| @@ -91,6 +92,8 @@ inline int __builtin_clzll(uint64_t x) { | ||
| #define __F16C__ 1 | ||
| #endif | ||
|
|
||
| +#endif // _MSC_VER | ||
| + | ||
| #define FAISS_ALWAYS_INLINE __forceinline | ||
|
|
||
| #else |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| # Collection of sources required to complete build | ||
| sources = [ | ||
| GitSource("https://github.com/facebookresearch/faiss.git", "d243e628880676332263347817b3fe7f474b8b5b"), | ||
| DirectorySource(joinpath(@__DIR__, "bundled")), | ||
| ] | ||
|
|
||
| # Bash recipe for building across all platforms | ||
| script = raw""" | ||
| # Needs CMake >= 3.23.1 provided via HostBuildDependency | ||
| apk del cmake | ||
|
|
||
| cd faiss | ||
|
|
||
| atomic_patch -p1 ../patches/faiss-mingw32-cmake.patch | ||
| atomic_patch -p1 ../patches/faiss-mingw32-InvertedListsIOHook.patch | ||
| atomic_patch -p1 ../patches/faiss-mingw32.patch | ||
|
|
||
| cmake_extra_args=() | ||
|
|
||
| if [[ $bb_full_target == *cuda* ]]; then | ||
| cuda_version=${bb_full_target##*-cuda+} | ||
| if [[ $cuda_version == "11.8" ]]; then | ||
| cuda_archs="60-real;61-real;62-real;70-real;72-real;75-real;80;86-real;87-real;89-real;90" | ||
| elif [[ $cuda_version == "12.1" ]]; then | ||
| cuda_archs="70-real;72-real;75-real;80;86-real;87-real;89-real;90" | ||
| else | ||
| false # Fail for unexpected CUDA version | ||
| fi | ||
|
|
||
| # CUDA compilation can run out of storage | ||
| mkdir $WORKSPACE/tmpdir | ||
| export TMPDIR=$WORKSPACE/tmpdir | ||
|
|
||
| export CUDA_PATH=$prefix/cuda | ||
| ln -s $prefix/cuda/lib $prefix/cuda/lib64 | ||
| cmake_extra_args+=( | ||
| -DFAISS_ENABLE_GPU=ON | ||
| -DCUDAToolkit_ROOT=$CUDA_PATH | ||
| -DCMAKE_CUDA_ARCHITECTURES=$cuda_archs | ||
| ) | ||
| fi | ||
|
|
||
| cmake -B build \ | ||
| -DCMAKE_INSTALL_PREFIX=$prefix \ | ||
| -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TARGET_TOOLCHAIN} \ | ||
| -DCMAKE_BUILD_TYPE=Release \ | ||
| -DFAISS_ENABLE_GPU=OFF \ | ||
| -DFAISS_ENABLE_PYTHON=OFF \ | ||
| -DBUILD_TESTING=OFF \ | ||
| -DBUILD_SHARED_LIBS=ON \ | ||
| -DFAISS_ENABLE_C_API=ON \ | ||
| ${cmake_extra_args[@]} | ||
| cmake --build build --parallel ${nproc} | ||
| cmake --install build | ||
|
|
||
| install -Dvm 755 build/c_api/libfaiss_c.$dlext $libdir/libfaiss_c.$dlext | ||
|
|
||
| if [[ $bb_full_target == *cuda* ]]; then | ||
| unlink $prefix/cuda/lib64 | ||
| fi | ||
| """ | ||
|
|
||
| # These are the platforms we will build for by default, unless further | ||
| # platforms are passed in on the command line | ||
| platforms = supported_platforms() | ||
|
|
||
| mkl_platforms = Platform[ | ||
| Platform("x86_64", "Linux"), | ||
| Platform("x86_64", "MacOS"), | ||
| Platform("x86_64", "Windows"), | ||
| ] | ||
|
|
||
| openblas_platforms = filter(p -> p ∉ mkl_platforms, platforms) | ||
|
|
||
| platforms = expand_cxxstring_abis(platforms) | ||
| mkl_platforms = expand_cxxstring_abis(mkl_platforms) | ||
| openblas_platforms = expand_cxxstring_abis(openblas_platforms) | ||
|
|
||
| # The products that we will ensure are always built | ||
| products = Product[ | ||
| FileProduct("include/faiss/Index.h", :faiss_index_h), | ||
| FileProduct("include/faiss/c_api/faiss_c.h", :faiss_c_api_faiss_c_h), | ||
| LibraryProduct(["libfaiss", "faiss"], :libfaiss), | ||
| LibraryProduct(["libfaiss_c", "faiss_c"], :libfaiss_c), | ||
| ] | ||
|
|
||
| # Dependencies that must be installed before this package can be built | ||
| dependencies = [ | ||
| # For OpenMP we use libomp from `LLVMOpenMP_jll` where we use LLVM as compiler (BSD | ||
| # systems), and libgomp from `CompilerSupportLibraries_jll` everywhere else. | ||
| Dependency(PackageSpec(name="CompilerSupportLibraries_jll", uuid="e66e0078-7015-5450-92f7-15fbd957f2ae"); platforms=filter(!Sys.isbsd, platforms)), | ||
| Dependency(PackageSpec(name="LLVMOpenMP_jll", uuid="1d63c593-3942-5779-bab2-d838dc0a180e"); platforms=filter(Sys.isbsd, platforms)), | ||
| Dependency("LAPACK_jll"; platforms = openblas_platforms), | ||
| Dependency("MKL_jll"; platforms = mkl_platforms), | ||
| BuildDependency("MKL_Headers_jll"; platforms = mkl_platforms), | ||
| Dependency("OpenBLAS32_jll"; platforms = openblas_platforms), | ||
| HostBuildDependency(PackageSpec("CMake_jll", v"3.28.1")), | ||
| ] | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.