diff --git a/F/Faiss/Faiss/build_tarballs.jl b/F/Faiss/Faiss/build_tarballs.jl new file mode 100644 index 00000000000..c97b12f289e --- /dev/null +++ b/F/Faiss/Faiss/build_tarballs.jl @@ -0,0 +1,10 @@ +# 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" + +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"7") diff --git a/F/Faiss/Faiss_GPU/build_tarballs.jl b/F/Faiss/Faiss_GPU/build_tarballs.jl new file mode 100644 index 00000000000..06298710fdc --- /dev/null +++ b/F/Faiss/Faiss_GPU/build_tarballs.jl @@ -0,0 +1,35 @@ +# 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_GPU" + +cuda_versions = ["11.8", "12.1"] # 11.8 to have SM 87;89;90 support. Conda GPU packages build on 11.4 and 12.1: https://github.com/facebookresearch/faiss/blob/v1.8.0/.circleci/config.yml#L358 + +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) + +# 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 diff --git a/F/Faiss/bundled/patches/faiss-mingw32.patch b/F/Faiss/bundled/patches/faiss-mingw32.patch new file mode 100644 index 00000000000..1d825e0d7ce --- /dev/null +++ b/F/Faiss/bundled/patches/faiss-mingw32.patch @@ -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 + #include + +-#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 + +@@ -91,6 +92,8 @@ inline int __builtin_clzll(uint64_t x) { + #define __F16C__ 1 + #endif + ++#endif // _MSC_VER ++ + #define FAISS_ALWAYS_INLINE __forceinline + + #else diff --git a/F/Faiss/common.jl b/F/Faiss/common.jl new file mode 100644 index 00000000000..3a0e7911ec5 --- /dev/null +++ b/F/Faiss/common.jl @@ -0,0 +1,80 @@ +version = v"1.8.0" + +# Collection of sources required to complete build +sources = [ + GitSource("https://github.com/facebookresearch/faiss.git", "22f2292be4aa98559797e1dd6e45f12386b06099"), + 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.patch + +cmake_extra_args=() + +if [[ $bb_full_target == *cuda* ]]; then + export CUDACXX=$prefix/cuda/bin/nvcc + cmake_extra_args+=( + -DFAISS_ENABLE_GPU=ON + -DCUDAToolkit_ROOT=$prefix/cuda + -DCMAKE_CUDA_ARCHITECTURES="60" + -DCUDA_CUDART_LIBRARY=$prefix/cuda/lib64/libcudart.$dlext + ) +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 +""" + +# 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("i686", "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[ + 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")), +]