diff options
author | Robert Blake <blake14@llnl.gov> | 2022-11-18 12:43:41 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-18 21:43:41 +0100 |
commit | 1db914f567d8294c9d1b2dad9e0db576d1989802 (patch) | |
tree | 40ee86e6242bc509374ccfba5cc0af770cb79ca1 | |
parent | 688dae70583c6a66ad79cf689c260143c70687cf (diff) | |
download | spack-1db914f567d8294c9d1b2dad9e0db576d1989802.tar.gz spack-1db914f567d8294c9d1b2dad9e0db576d1989802.tar.bz2 spack-1db914f567d8294c9d1b2dad9e0db576d1989802.tar.xz spack-1db914f567d8294c9d1b2dad9e0db576d1989802.zip |
Updating faiss with new versions (#33983)
Co-authored-by: Massimiliano Culpo <massimiliano.culpo@gmail.com>
-rw-r--r-- | var/spack/repos/builtin/packages/faiss/fixes-in-v1.7.2.patch | 49 | ||||
-rw-r--r-- | var/spack/repos/builtin/packages/faiss/package.py | 80 |
2 files changed, 117 insertions, 12 deletions
diff --git a/var/spack/repos/builtin/packages/faiss/fixes-in-v1.7.2.patch b/var/spack/repos/builtin/packages/faiss/fixes-in-v1.7.2.patch new file mode 100644 index 0000000000..478abeabd9 --- /dev/null +++ b/var/spack/repos/builtin/packages/faiss/fixes-in-v1.7.2.patch @@ -0,0 +1,49 @@ +diff --git a/faiss/python/CMakeLists.txt b/faiss/python/CMakeLists.txt +index e403065..be3736f 100644 +--- a/faiss/python/CMakeLists.txt ++++ b/faiss/python/CMakeLists.txt +@@ -68,7 +68,7 @@ swig_add_library(swigfaiss + LANGUAGE python + SOURCES swigfaiss.swig + ) +-set_property(TARGET swigfaiss PROPERTY SWIG_COMPILE_OPTIONS -doxygen) ++set_property(TARGET swigfaiss PROPERTY SWIG_COMPILE_OPTIONS) + + set_property(SOURCE swigfaiss_avx2.swig + PROPERTY SWIG_MODULE_NAME swigfaiss_avx2) +@@ -77,7 +77,7 @@ swig_add_library(swigfaiss_avx2 + LANGUAGE python + SOURCES swigfaiss_avx2.swig + ) +-set_property(TARGET swigfaiss_avx2 PROPERTY SWIG_COMPILE_OPTIONS -doxygen) ++set_property(TARGET swigfaiss_avx2 PROPERTY SWIG_COMPILE_OPTIONS) + if(NOT FAISS_OPT_LEVEL STREQUAL "avx2") + set_target_properties(swigfaiss_avx2 PROPERTIES EXCLUDE_FROM_ALL TRUE) + endif() +diff --git a/faiss/python/setup.py b/faiss/python/setup.py +index 9ef3a03..5ff9585 100644 +--- a/faiss/python/setup.py ++++ b/faiss/python/setup.py +@@ -21,9 +21,11 @@ prefix = "Release/" * (platform.system() == 'Windows') + + swigfaiss_generic_lib = f"{prefix}_swigfaiss{ext}" + swigfaiss_avx2_lib = f"{prefix}_swigfaiss_avx2{ext}" ++callbacks_lib = f"{prefix}libfaiss_python_callbacks{ext}" + + found_swigfaiss_generic = os.path.exists(swigfaiss_generic_lib) + found_swigfaiss_avx2 = os.path.exists(swigfaiss_avx2_lib) ++found_callbacks = os.path.exists(callbacks_lib) + + assert (found_swigfaiss_generic or found_swigfaiss_avx2), \ + f"Could not find {swigfaiss_generic_lib} or " \ +@@ -39,6 +41,10 @@ if found_swigfaiss_avx2: + shutil.copyfile("swigfaiss_avx2.py", "faiss/swigfaiss_avx2.py") + shutil.copyfile(swigfaiss_avx2_lib, f"faiss/_swigfaiss_avx2{ext}") + ++if found_callbacks: ++ print(f"Copying {callbacks_lib}") ++ shutil.copyfile(callbacks_lib, f"faiss/{callbacks_lib}") ++ + long_description=""" + Faiss is a library for efficient similarity search and clustering of dense + vectors. It contains algorithms that search in sets of vectors of any size, diff --git a/var/spack/repos/builtin/packages/faiss/package.py b/var/spack/repos/builtin/packages/faiss/package.py index 0ff22a6c96..f26a1023dd 100644 --- a/var/spack/repos/builtin/packages/faiss/package.py +++ b/var/spack/repos/builtin/packages/faiss/package.py @@ -8,7 +8,7 @@ import os from spack.package import * -class Faiss(AutotoolsPackage, CudaPackage): +class Faiss(AutotoolsPackage, CMakePackage, CudaPackage): """Faiss is a library for efficient similarity search and clustering of dense vectors. @@ -22,26 +22,34 @@ class Faiss(AutotoolsPackage, CudaPackage): homepage = "https://github.com/facebookresearch/faiss" url = "https://github.com/facebookresearch/faiss/archive/v1.6.3.tar.gz" - maintainers = ["bhatiaharsh"] + maintainers = ["bhatiaharsh", "rblake-llnl"] + build_system( + conditional("cmake", when="@1.7:"), conditional("autotools", when="@:1.6"), default="cmake" + ) + + version("1.7.2", sha256="d49b4afd6a7a5b64f260a236ee9b2efb760edb08c33d5ea5610c2f078a5995ec") version("1.6.3", sha256="e1a41c159f0b896975fbb133e0240a233af5c9286c09a28fde6aefff5336e542") version("1.5.3", sha256="b24d347b0285d01c2ed663ccc7596cd0ea95071f3dd5ebb573ccfc28f15f043b") variant("python", default=False, description="Build Python bindings") + variant("shared", default=False, description="Build shared library") variant("tests", default=False, description="Build Tests") conflicts("+tests", when="~python", msg="+tests must be accompanied by +python") + depends_on("cmake@3.17:", when="build_system=cmake", type="build") + + extends("python", when="+python") depends_on("python@3.7:", when="+python", type=("build", "run")) depends_on("py-pip", when="+python", type="build") depends_on("py-wheel", when="+python", type="build") + depends_on("py-setuptools", when="+python", type="build") depends_on("py-numpy", when="+python", type=("build", "run")) - depends_on("py-scipy", when="+tests", type=("build", "run")) + depends_on("swig@4", when="+python", type="build") + depends_on("py-scipy", when="+python+tests", type=("build", "run")) depends_on("blas") - depends_on("python", type="build") - depends_on("py-setuptools", when="+python", type="build") - depends_on("swig", when="+python", type="build") # patch for v1.5.3 # faiss assumes that the "source directory" will always @@ -56,12 +64,64 @@ class Faiss(AutotoolsPackage, CudaPackage): # also, some include paths in gpu/tests/Makefile are missing patch("fixes-in-v1.6.3.patch", when="@1.6.3") + # patch for v1.7.2 + # a shared object is missing in the python/setup.py + # https://github.com/facebookresearch/faiss/issues/2063 + # https://github.com/facebookresearch/faiss/pull/2062 + # a header is missing in a test file + # https://github.com/facebookresearch/faiss/issues/2300 + patch("fixes-in-v1.7.2.patch", when="@1.7.2") + + def setup_run_environment(self, env): + if "+python" in self.spec: + env.prepend_path("PYTHONPATH", python_platlib) + + +class CMakeBuilder(spack.build_systems.cmake.CMakeBuilder): + def cmake_args(self): + spec = self.spec + args = [ + self.define_from_variant("BUILD_SHARED_LIBS", "shared"), + self.define_from_variant("FAISS_ENABLE_PYTHON", "python"), + self.define_from_variant("FAISS_ENABLE_GPU", "cuda"), + self.define_from_variant("BUILD_TESTING", "tests"), + self.define("FAISS_OPT_LEVEL", "generic"), + ] + if "+python" in spec: + pyexe = spec["python"].command.path + args.append(self.define("Python_EXECUTABLE", pyexe)) + + if "+cuda" in spec: + key = "CMAKE_CUDA_ARCHITECTURES" + args.append(self.define_from_variant(key, "cuda_arch")) + # args.append(self.define_from_variant( + # 'CMAKE_CUDA_STANDARD', 'cudastd')) + return args + + def install(self, pkg, spec, prefix): + super().install(pkg, spec, prefix) + if "+python" in spec: + + class CustomPythonPipBuilder(spack.build_systems.python.PythonPipBuilder): + def __init__(self, pkg, build_dirname): + spack.build_systems.python.PythonPipBuilder.__init__(self, pkg) + self.build_dirname = build_dirname + + @property + def build_directory(self): + return os.path.join(self.pkg.stage.path, self.build_dirname, "faiss", "python") + + customPip = CustomPythonPipBuilder(pkg, self.build_dirname) + customPip.install(pkg, spec, prefix) + + +class AutotoolsBuilder(spack.build_systems.autotools.AutotoolsBuilder): def configure_args(self): args = [] args.extend(self.with_or_without("cuda", activation_value="prefix")) return args - def build(self, spec, prefix): + def build(self, pkg, spec, prefix): make() @@ -81,7 +141,7 @@ class Faiss(AutotoolsPackage, CudaPackage): make("build") # target added by the patch make("demo_ivfpq_indexing_gpu") - def install(self, spec, prefix): + def install(self, pkg, spec, prefix): make("install") @@ -123,7 +183,3 @@ class Faiss(AutotoolsPackage, CudaPackage): # spack injects its own optimization flags makefile = FileFilter("makefile.inc") makefile.filter("CPUFLAGS = -mavx2 -mf16c", "#CPUFLAGS = -mavx2 -mf16c") - - def setup_run_environment(self, env): - if "+python" in self.spec: - env.prepend_path("PYTHONPATH", python_platlib) |