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

Support disabling of extensions #101

Open
c0d1f1ed opened this issue Jan 15, 2020 · 3 comments
Open

Support disabling of extensions #101

c0d1f1ed opened this issue Jan 15, 2020 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@c0d1f1ed
Copy link

To test all code paths of apps that use cpu_features to select between different implementations of an algorithm, it would be useful to be able to mock having a CPU with fewer features than actually supported.

While this can be done in wrapper layer which uses cpu_features to query the real feature set, little prevents direct use of cpu_features functions that would break the purpose of the wrapper. Hence I think it would be useful if this was a core feature of cpu_features itself.

One complication is that for tests to be able to run concurrently this would have to be thread-local (assuming the tests are single-threaded). For multi-threaded tests a global mutex could be used to prevent concurrent execution from the point where cpu_features is provided with override options, to the point where they're removed.

Multiple users of cpu_features have to deal with this themselves currently, so having it as a core feature instead avoids duplicate effort and incompatible solutions which might have subtle bugs that are best fixed centrally.

@Mizux Mizux added the enhancement New feature or request label Jan 15, 2020
@gchatelet
Copy link
Collaborator

Thx for the suggestion @c0d1f1ed. I think it's a great idea.
Let me think about how to implement it.

@gchatelet gchatelet self-assigned this Jan 16, 2020
gchatelet added a commit that referenced this issue Jan 17, 2020
@gchatelet
Copy link
Collaborator

gchatelet commented Jan 17, 2020

@c0d1f1ed would something along the lines of eb59787 work for you? Do you see any shortcomings?

@c0d1f1ed
Copy link
Author

One minor concern (or rather a follow-up feature request) is that it's non-trivial to know which set of extensions is supported by each CPU micro-architecture. Even just the mix of SSE4.1, SSE4.2, SSE4a, POPCNT, and LZCNT one can end up with in practice gets confusing quite quickly (https://en.wikipedia.org/wiki/SSE4#Supporting_CPUs). It's common for software to check for one of these features and end up using instructions from the other sets. Sometimes that's valid, sometimes it's not.

Likewise even when we disable all features not supported by a certain micro-architecture, when new extensions come along those would remain enabled unless we (and all other cpu_features users that use mocking) update our code.

So it would be super helpful if cpu_features can mock specific micro-architectures (or an intersection of the features of the CPU we're running on and the one we're trying to not exceed its feature set), and keep that up to date.

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

No branches or pull requests

4 participants
@gchatelet @c0d1f1ed @Mizux and others