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

cpu_x86.h dependency for runtime instruction set checks with MSVC #405

Closed
alxvth opened this issue Aug 26, 2022 · 5 comments
Closed

cpu_x86.h dependency for runtime instruction set checks with MSVC #405

alxvth opened this issue Aug 26, 2022 · 5 comments

Comments

@alxvth
Copy link
Contributor

alxvth commented Aug 26, 2022

Does the runtime check for SSE and AVX with MSVC at

#include "cpu_x86.h"

currently require to use Mysticial/FeatureDetector?

If that is intentional, it would be good to mention that somewhere but otherwise it'd be nicer to not have that dependency and just go with

//#include "cpu_x86.h"
void cpuid(int32_t out[4], int32_t eax, int32_t ecx) {
    __cpuidex(out, eax, ecx);
}
@yurymalkov
Copy link
Member

Hi @alxvth,

I am do not think it requires external dependencies and the windows build tests pass.
Do you have a different experience?

@alxvth
Copy link
Contributor Author

alxvth commented Aug 28, 2022

Yes, for me it does not build on Windows with a MSVC compiler since that compiler does not know any cpu_x86.h

Have a look at this godbolt example. I think this problem does not show in the CI since MSVC does not set USE_AVX but instead defines __AVX__. It also does not set anything equivalent for SSE, see here. As far as I know there is no march=native equivalent for MSVC, but SSE2 compiler intrinsics are active by default. All that's why I guess the problematic #include "cpu_x86.h" is never actually reached in the windows build tests.
Removing that include will have the code run nicely in the example above.

@alxvth
Copy link
Contributor Author

alxvth commented Aug 29, 2022

I just noticed that not all I wrote above made too much sense, I somehow overlooked the USE_SSE definition in the first lines of hnswlib.h. Anyways, the main problem remains in that MCVS does not define __SSE__. To cover both x86 and x64 msvc compilers I'd suggest to use this (a little bit more verbose) check instead of just checking for __SSE__

#if (defined(__SSE__) || _M_IX86_FP > 0 || defined(_M_AMD64) || defined(_M_X64))
#define USE_SSE
#endif

I guess then the build test on windows also run into the #include "cpu_x86.h" problem.

@yurymalkov
Copy link
Member

Thank you! Will take a look at the PR!

@alxvth
Copy link
Contributor Author

alxvth commented Sep 22, 2022

Fixed with 1f49ffe

@alxvth alxvth closed this as completed Sep 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants