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

BUG: verify the OS supports avx instruction #10814

Merged
merged 1 commit into from Apr 5, 2018

Conversation

juliantaylor
Copy link
Contributor

On some systems you can disable avx registers but the gcc builtin does
only checks if the cpu has the feature.
Before using avx functions check the OS support with xgetbv.
Closes gh-10787
Closes gh-9534

@juliantaylor juliantaylor added this to the 1.15.0 release milestone Mar 27, 2018
@njsmith
Copy link
Member

njsmith commented Mar 27, 2018

Nice!

Have you filed a bug with gcc? I guess they should fix __builtin_cpu_supports to do this itself...

npy_cpu_supports(const char * feature)
{
#ifdef HAVE___BUILTIN_CPU_SUPPORTS
if (strcmp(feature, "avx2") == 0) {
Copy link
Member

Choose a reason for hiding this comment

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

Why not npy_cpu_supports_avx() and npy_cpu_supports_avx2(), rather than incurring a strcmp?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would probably make sense, but we only use it during module load so performance is not really an issue, with link time optimization the compiler would also fold it away.

@juliantaylor
Copy link
Contributor Author

yes I have filed a GCC bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85100

#endif
}
else if (strcmp(feature, "avx") == 0) {
#ifdef HAVE_ATTRIBUTE_TARGET_AVX
Copy link
Member

Choose a reason for hiding this comment

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

Why repeat this here when it's already used at the call site?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

indeed this is unnecessary, fixed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think they were needed for gcc versions that didn't know about avx/avx2, though those should not be around anymore

On some systems you can disable avx registers but the gcc builtin does
only checks if the cpu has the feature.
Before using avx functions check the OS support with xgetbv.
Closes numpygh-10787
Closes numpygh-9534
@charris charris merged commit e0f8846 into numpy:master Apr 5, 2018
@charris
Copy link
Member

charris commented Apr 5, 2018

Thanks Julian.

@matthew-brett
Copy link
Contributor

GCC bug now fixed, for what it's worth:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85100

#if HAVE_XGETBV
/*
* use bytes for xgetbv to avoid issues with compiler not knowing the
* instruction
Copy link
Member

Choose a reason for hiding this comment

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

This comment doesn't look true?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants