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 SSE inclusion conditional for target features #526

Merged
merged 4 commits into from Jul 16, 2021

Conversation

mbargull
Copy link
Contributor

Since 0.12.3/gh-295 the underlying library gets compiled with SSE4.1/SSE4.2/PCLMUL instructions unconditionally.
This prevents building the library for backwards compatible binaries, e.g., for target-cpu=nocona you'd want a binary without SSE4 instructions.
With the changes proposed here, one still can freely build for target-cpu=nehalem (or target-cpu=westmere to get PCLMUL), or just target-cpu=native given a recent enough machine and for local deployment. And additionally target-cpu=nocona would yield the desired compatible build.

(Context here is that rust-rocksdb is used by some programs we distribute as binaries for Bioconda and currently/usually target older CPU architectures there.)

config.flag_if_supported("-msse4.2");
let target_feature = env::var("CARGO_CFG_TARGET_FEATURE").unwrap();
let target_features: Vec<_> = target_feature.split(",").collect();
if target_features.contains(&"sse2") {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it change the behavior to not enable sse2 etc by default? If that's the case, CHANGELOG.md should be updated accordingly so developers are aware about the performance degradation once they upgrade the rocksdb crate.

Copy link
Contributor Author

@mbargull mbargull Jul 13, 2021

Choose a reason for hiding this comment

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

I believe SSE2 is in the set of default features for x86-64, at least it is for me if I run

# rustc --print=cfg 
debug_assertions
target_arch="x86_64"
target_endian="little"
target_env="gnu"
target_family="unix"
target_feature="fxsr"
target_feature="sse"
target_feature="sse2"
target_os="linux"
target_pointer_width="64"
target_vendor="unknown"
unix

It is, however, a change in behavior for SSE4.2 etc. since those are not always enable by default. The user should of course use -C target-cpu=<native-or-other-appropriate-arch> to make sure they get accelerated/compatible binaries.
Should we amend the changelog regarding SSE4.2 et al? Do you have a suggestion for the wording?

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe something like "RocksDB is not compiled with SSE4 instructions anymore unless the corresponding features are enabled in rustc"?

Copy link
Member

@aleksuss aleksuss left a comment

Choose a reason for hiding this comment

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

Overall LGTM 👍🏻

config.flag_if_supported("-msse4.1");
config.flag_if_supported("-msse4.2");
let target_feature = env::var("CARGO_CFG_TARGET_FEATURE").unwrap();
let target_features: Vec<_> = target_feature.split(",").collect();
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
let target_features: Vec<_> = target_feature.split(",").collect();
let target_features: Vec<_> = target_feature.split(',').collect();

Of course, it's not critical here. But I think the better way to use char rather than &str as a pattern when you use one character for splitting.

@aleksuss aleksuss merged commit 81a9ede into rust-rocksdb:master Jul 16, 2021
mbargull added a commit to mbargull/rust-bio-tools that referenced this pull request Aug 14, 2021
- SSE instructions are used according to the target CPU specifications
- via rust-rocksdb/rust-rocksdb#526
- fixes bioconda/bioconda-recipes#28719
johanneskoester pushed a commit to rust-bio/rust-bio-tools that referenced this pull request Aug 17, 2021
- SSE instructions are used according to the target CPU specifications
- via rust-rocksdb/rust-rocksdb#526
- fixes bioconda/bioconda-recipes#28719
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

Successfully merging this pull request may close these issues.

None yet

4 participants