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

make setup.py win+avx2 compatible #1682

Closed
wants to merge 4 commits into from

Conversation

h-vetinari
Copy link
Contributor

@h-vetinari h-vetinari commented Feb 12, 2021

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
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.

@h-vetinari h-vetinari changed the title set correct EXT_SUFFIX for swig set uniform EXT_SUFFIX for swig Feb 12, 2021
@h-vetinari h-vetinari changed the title set uniform EXT_SUFFIX for swig set uniform EXT_SUFFIX and make setup.py win+avx2 compatible Feb 12, 2021
@h-vetinari
Copy link
Contributor Author

h-vetinari commented Feb 12, 2021

The failing test seems to be flaky.

@beauby
Copy link
Contributor

beauby commented Feb 12, 2021

For this, I'd be more inclined to keep the CMake config as is, and just deal with it in setup.py. It's not a perfect solution, but it's better than putting the burden of setting the correct EXT_SUFFIX env variable on the user. Thoughts?

@h-vetinari
Copy link
Contributor Author

For this, I'd be more inclined to keep the CMake config as is, and just deal with it in setup.py. It's not a perfect solution, but it's better than putting the burden of setting the correct EXT_SUFFIX env variable on the user. Thoughts?

Understandable. I'd suggest to keep the changes in setup.py, but I've removed the rest for now.

@h-vetinari h-vetinari changed the title set uniform EXT_SUFFIX and make setup.py win+avx2 compatible make setup.py win+avx2 compatible Feb 12, 2021
facebook-github-bot pushed a commit that referenced this pull request Feb 12, 2021
Summary:
This patch is to provide log information in case of failing to load the AVX2-enabled lib,
and also to log the successful loading of the libraries.

Otherwise, the programmatic detection of which library was loaded also needs to take
into account which other log statements were executed, if the original import failed due to an exception,
cf. the tests in conda-forge/faiss-split-feedstock#27

Finally, this reduces the number of import statements by one - one non-AVX2 fallback is enough.

Related to #1600, #1680, #1681, #1682.

Pull Request resolved: #1683

Reviewed By: mdouze

Differential Revision: D26424333

Pulled By: beauby

fbshipit-source-id: 16beddec7e0c098b913a7f5420cbb02d1cf515ad
@h-vetinari
Copy link
Contributor Author

@beauby
Can this pared-down version still be considered? Without it, win+avx2 cannot be successfully installed.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@beauby has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@beauby merged this pull request in d0ad3d7.

@h-vetinari h-vetinari deleted the ext_suffix branch February 17, 2021 23:17
facebook-github-bot pushed a commit that referenced this pull request Feb 18, 2021
Summary:
Trying to compile windows for AVX2 in conda-forge/faiss-split-feedstock#27
(after #1600) surfaced a bunch of things (#1680, #1681, #1682), but the most voluminous problem
was MSVC being much worse at dealing with operator overloads and casts around `__m128` / `__m256`.

This lead to loads of errors that looked as follows:
```
[...]\faiss\utils\distances_simd.cpp(411): error C2676: binary '+=': '__m128' does not define this operator or a conversion to a type acceptable to the predefined operator
[...]\faiss\utils\distances_simd.cpp(440): error C2676: binary '-': '__m256' does not define this operator or a conversion to a type acceptable to the predefined operator
[...]\faiss\utils\distances_simd.cpp(441): error C2676: binary '*': 'const __m256' does not define this operator or a conversion to a type acceptable to the predefined operator
[...]\faiss\utils\distances_simd.cpp(446): error C2676: binary '+=': '__m128' does not define this operator or a conversion to a type acceptable to the predefined operator
[...]\faiss\utils\distances_simd.cpp(451): error C2676: binary '-': '__m128' does not define this operator or a conversion to a type acceptable to the predefined operator
[...]\faiss\utils\distances_simd.cpp(452): error C2676: binary '*': 'const __m128' does not define this operator or a conversion to a type acceptable to the predefined operator
[...]\faiss\utils\distances_simd.cpp(459): error C2676: binary '-': '__m128' does not define this operator or a conversion to a type acceptable to the predefined operator
[...]\faiss\utils\distances_simd.cpp(460): error C2676: binary '*': '__m128' does not define this operator or a conversion to a type acceptable to the predefined operator
[...]\faiss\utils\distances_simd.cpp(471): error C2440: '<function-style-cast>': cannot convert from '__m256i' to '__m256'
```

I've followed https://software.intel.com/sites/landingpage/IntrinsicsGuide/ to try to replace everything correctly,
but this will surely require close review, because I'm not sure how well these code-paths are checked by the
test suite.

In any case, with the commits from #1600 #1666 #1680 #1681 #1682, I was able to build `libfaiss` & `faiss`
for AVX2 on windows (while remaining "green" on linux/osx, both with & without AVX2).

Sidenote: the issues in the last commit (26fc7cf)
were uncovered by adding the `__SSE3__` compat macros in #1681.

Pull Request resolved: #1684

Test Plan: buck test //faiss/tests/...

Reviewed By: beauby

Differential Revision: D26454443

Pulled By: mdouze

fbshipit-source-id: 70df0818e357f1ecea6a056d619618df0236e0eb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants