Skip to content

Commit

Permalink
make setup.py win+avx2 compatible (#1682)
Browse files Browse the repository at this point in the history
Summary:
While working on conda-forge/faiss-split-feedstock#27, it turned out I needed
to patch `setup.py` anyway. In order to unify how the extension of the built lib is set, I fell back
to another patch that would/will become necessary if faiss ever wants to support PyPy
(see discussion in conda-forge/faiss-split-feedstock#22).

It would be nice if this was done natively by CMake, but as far as I can tell from
https://gitlab.kitware.com/cmake/cmake/-/issues/21070, cmake is not likely to do that right away.

I didn't particularly expect this patch to be upstreamed (especially if there is no interest for PyPy support, for example),
but beauby [invited](conda-forge/faiss-split-feedstock#27 (comment))
me to post it so here goes (plus necessary adaptations to the conda recipes)

Related to #1600, #1680, #1681

PS. I thought about using `logger.INFO` in case of an import failure for AVX2, but since it's a setup file,
I thought `print` would actually be more useful. Happy to change or remove if desired.

Pull Request resolved: #1682

Reviewed By: wickedfoo

Differential Revision: D26484393

Pulled By: beauby

fbshipit-source-id: 6cd2598838c4070dbf83d6f27ce15ce9faa6bf20
  • Loading branch information
h-vetinari authored and facebook-github-bot committed Feb 17, 2021
1 parent 7ef4b03 commit d0ad3d7
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions faiss/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@
shutil.copyfile("__init__.py", "faiss/__init__.py")
shutil.copyfile("loader.py", "faiss/loader.py")
shutil.copyfile("swigfaiss.py", "faiss/swigfaiss.py")
if platform.system() == 'Windows':
shutil.copyfile("Release/_swigfaiss.pyd", "faiss/_swigfaiss.pyd")

else:
shutil.copyfile("_swigfaiss.so", "faiss/_swigfaiss.so")
try:
shutil.copyfile("swigfaiss_avx2.py", "faiss/swigfaiss_avx2.py")
shutil.copyfile("_swigfaiss_avx2.so", "faiss/_swigfaiss_avx2.so")
except:
pass
ext = ".pyd" if platform.system() == 'Windows' else ".so"
prefix = "Release/" * (platform.system() == 'Windows')
shutil.copyfile(f"{prefix}_swigfaiss{ext}", f"faiss/_swigfaiss{ext}")

try:
shutil.copyfile("swigfaiss_avx2.py", "faiss/swigfaiss_avx2.py")
shutil.copyfile(f"{prefix}_swigfaiss_avx2{ext}", f"faiss/_swigfaiss_avx2{ext}")
except Exception as e:
print(f"Could not move swigfaiss_avx2.py / {prefix}_swigfaiss_avx2{ext} due to:\n{e!r}")
pass

long_description="""
Faiss is a library for efficient similarity search and clustering of dense
Expand Down

0 comments on commit d0ad3d7

Please sign in to comment.