Skip to content

cpu_features: add PPC64LE compile-time SIMD feature detection#482

Open
runlevel5 wants to merge 1 commit into
trifectatechfoundation:mainfrom
runlevel5:ppc64le-simd-phase1a
Open

cpu_features: add PPC64LE compile-time SIMD feature detection#482
runlevel5 wants to merge 1 commit into
trifectatechfoundation:mainfrom
runlevel5:ppc64le-simd-phase1a

Conversation

@runlevel5
Copy link
Copy Markdown

Summary

  • Add is_enabled_altivec(), is_enabled_vsx(), and is_enabled_power9() to cpu_features.rs for powerpc64 targets
  • Uses compile-time detection via cfg!(target_feature = ...), following the same pattern as wasm32/simd128

Why?

This is groundwork for PPC64LE SIMD support. The core::arch::powerpc64 intrinsics and is_powerpc64_feature_detected! macro are both nightly-only in Rust (tracked by rust-lang/rust#111145 (rust-lang/rust#111145) and #111191 (rust-lang/rust#111191)), so runtime detection is not possible on stable. Compile-time detection via cfg!(target_feature) is stable and is the same approach used for wasm32.

Users enable PPC64LE SIMD at build time with -C target-feature=+altivec,+vsx or -C target-cpu=pwr8 (or higher).

Testing

  • Verified compilation on host (cargo check)
  • Verified cross-compilation for powerpc64le-unknown-linux-gnu (cargo check --target powerpc64le-unknown-linux-gnu)
  • Verified compilation with SIMD flags (RUSTFLAGS="-C target-feature=+altivec,+vsx" cargo check --target powerpc64le-unknown-linux-gnu)

Future plan

Port features from the C Zlib

Add is_enabled_altivec(), is_enabled_vsx(), and is_enabled_power9()
for powerpc64 targets. These use compile-time detection via
cfg!(target_feature) following the same pattern as wasm32/simd128,
since runtime detection (is_powerpc64_feature_detected!) is not
available on stable Rust.

Users enable PPC64LE SIMD with -C target-feature=+altivec,+vsx
or -C target-cpu=pwr8 (or higher).
@folkertdev
Copy link
Copy Markdown
Member

By itself this is kind of pointless, because this code will never run. We also don't currently test on powerpc64 at all, but you can set that up in the CI file.

So, weirdly, I think that this PR is too small, can you make something that runs end-to-end and actually gets tested in CI?

@folkertdev
Copy link
Copy Markdown
Member

Also, just interested, what makes you want to add powerpc64 support?

@runlevel5
Copy link
Copy Markdown
Author

Also, just interested, what makes you want to add powerpc64 support?

I and many people have been using C zlib-ng to develop softwares for PPC64 for years. Many are now picking up Rust, to me having zlib-rs supporting SIMD would be a big win for Rust adoption in enterprise sector.

@runlevel5
Copy link
Copy Markdown
Author

So, weirdly, I think that this PR is too small, can you make something that runs end-to-end and actually gets tested in CI?

This is just the starter. In the upcoming PR I will port over more features.

@folkertdev
Copy link
Copy Markdown
Member

I and many people have been using C zlib-ng to develop softwares for PPC64 for years. Many are now picking up Rust, to me having zlib-rs supporting SIMD would be a big win for Rust adoption in enterprise sector.

Neat! Now, something that you're already running into here is that much of the PPC64 infrastructure is still unstable. This is mostly due to a (perceived) lack of a need. With modest amounts of funding, these features can actually be stabilized (I speak here also as co-maintainer of rust-lang/stdarch, where the SIMD intrinsics are defined). Contact info is at https://trifectatech.org/about/.

This is just the starter. In the upcoming PR I will port over more features.

Sure, could you at least add CI support in this PR? I think you can base that on the s390x code here

# s390x-unknown-linux-gnu
CARGO_TARGET_S390X_UNKNOWN_LINUX_GNU_LINKER: s390x-linux-gnu-gcc
CARGO_TARGET_S390X_UNKNOWN_LINUX_GNU_RUNNER: qemu-s390x -L /usr/s390x-linux-gnu

and

- target: "s390x-unknown-linux-gnu"
os: ubuntu-latest
codecov: false
packages: gcc-s390x-linux-gnu g++-s390x-linux-gnu qemu-user qemu-user-static

@runlevel5
Copy link
Copy Markdown
Author

@folkertdev could you please apply for a native runner from IBM? Please see https://github.com/IBM/actionspz, IMHO it is way faster than cross-compilation

@runlevel5
Copy link
Copy Markdown
Author

Neat! Now, something that you're already running into here is that much of the PPC64 infrastructure is still unstable. This is mostly due to a (perceived) lack of a need. With modest amounts of funding, these features can actually be stabilized (I speak here also as co-maintainer of rust-lang/stdarch, where the SIMD intrinsics are defined). Contact info is at https://trifectatech.org/about/.

To be fair it is going to take some time for the enterprise customers to onboard with Rust, atm all I could see is traditional stack like Java, C, C++, Python ...COBOL, FORTRAN. So I hope by working with Rust folks to lay a good foundation, it would encourage more adoption and hopefully more funding from those firms in Rust-based techs.

@folkertdev
Copy link
Copy Markdown
Member

Cross-compilation with rust is plenty fast in our experience. Let's see first how far we get with that.

So I hope by working with Rust folks to lay a good foundation, it would encourage more adoption and hopefully more funding from those firms in Rust-based techs.

Well now you know that the option exists. By default powerpc64 rarely makes it to the top of the to-do list, but it could with relatively small amounts of funding.

@folkertdev
Copy link
Copy Markdown
Member

I've just added CI support. However, I'd actually like to see the followup that actually uses altivec/vsx before merging this, otherwise there is a risk of having a bunch of code that just never gets used.

@runlevel5
Copy link
Copy Markdown
Author

I've just added CI support. However, I'd actually like to see the followup that actually uses altivec/vsx before merging this, otherwise there is a risk of having a bunch of code that just never gets used.

Sure I could add them into this same PR if you are okay with a bigger size PR

@folkertdev
Copy link
Copy Markdown
Member

sure let's do that. I'd rather have something that works start-to-finish.

@folkertdev
Copy link
Copy Markdown
Member

friendly ping?

@runlevel5
Copy link
Copy Markdown
Author

@folkertdev I am still here, I will resume this work once I am back from my holiday

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.

2 participants