Skip to content

Add IBM Z (s390x) support#1307

Open
Andreas-Krebbel wants to merge 2 commits intoxtensor-stack:masterfrom
Andreas-Krebbel:s390x-support
Open

Add IBM Z (s390x) support#1307
Andreas-Krebbel wants to merge 2 commits intoxtensor-stack:masterfrom
Andreas-Krebbel:s390x-support

Conversation

@Andreas-Krebbel
Copy link
Copy Markdown

This PR adds support for IBM Z. It leverages the compiler intrinsics available with GCC and Clang:
https://www.ibm.com/docs/en/open-xl-c-cpp-zos/2.2.0?topic=reference-vector-programming-support

The intrinsics are similar to what is available for IBM Power with altivec (VSX). I've started with an initial version of my patch before VSX has been added to XSIMD. However, while refreshing my changes to the latest upstream level I've used the VSX implementation as a base.

I've tested the patch on an IBM z17 (latest machine generation) with GCC and Clang:

[100%] Built target test_xsimd
[doctest] doctest version is "2.4.9"
[doctest] run with "--help" for options
===============================================================================
[doctest] test cases:     363 |     363 passed | 0 failed | 0 skipped
[doctest] assertions: 1681618 | 1681618 passed | 0 failed |
[doctest] Status: SUCCESS!
[100%] Built target xtest

@serge-sans-paille
Copy link
Copy Markdown
Contributor

We need to setup CI for this. @Andreas-Krebbel could you do that, probably based on how it's done for vsx?

@Andreas-Krebbel
Copy link
Copy Markdown
Author

We need to setup CI for this. @Andreas-Krebbel could you do that, probably based on how it's done for vsx?

I can give it a try. Yes.

@Andreas-Krebbel
Copy link
Copy Markdown
Author

I have tested the workflow locally and it seems to work fine. I see less testcases being executed though:

| [doctest] doctest version is "2.4.9"
| [doctest] run with "--help" for options
| ===============================================================================
| [doctest] test cases:  83 |  83 passed | 0 failed | 0 skipped
| [doctest] assertions: 781 | 781 passed | 0 failed |
| [doctest] Status: SUCCESS!

Copy link
Copy Markdown
Contributor

@serge-sans-paille serge-sans-paille left a comment

Choose a reason for hiding this comment

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

Some nit picking, just missing the runtime detection and we're good.

It also means we should improve CI to detect that...

template <>
struct builtin_scalar<char>
{
using type = unsigned char;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

could be using type = typename std::conditional<std::is_signed<char>::value, signed char, unsigned char>::type and that would avoid the #ifdef, right?

template <class A, class T_in, class T_out>
XSIMD_INLINE batch<T_out, A> bitwise_cast(batch<T_in, A> const& self, batch<T_out, A> const&, requires_arch<vxe>) noexcept
{
return (typename batch<T_out, A>::register_type)(self.data);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: could be a static_cast, but we're not very diligent on this, so feel free to ignore.

template <class A>
XSIMD_INLINE batch<float, A> complex_low(batch<std::complex<float>, A> const& self, requires_arch<vxe>) noexcept
{
uv16qi perm = (uv16qi) { 0, 1, 2, 3, 16, 17, 18, 19, 4, 5, 6, 7, 20, 21, 22, 23 };
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

gcc constructor expression. that's a gnu extension, but I guess it's fine. I've been using it for PowerPC too.

}
// round
// vec_round rounds ties to even instead of zero
#if defined __has_builtin && __has_builtin(__builtin_s390_vfi)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This seems to be supported on modern clang, good.

ARCH_FIELD_EX(detail::rvv<128>, rvv128)
ARCH_FIELD(wasm)
ARCH_FIELD(vsx)
ARCH_FIELD(vxe)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

you should also add a piece of code for runtime detection. See how it's done for power there: https://github.com/xtensor-stack/xsimd/blob/master/include/xsimd/config/xsimd_cpu_features_ppc.hpp

// equivalent types.
XSIMD_DECLARE_SIMD_BOOL_VXE_REGISTER(signed char, signed char, char);
XSIMD_DECLARE_SIMD_BOOL_VXE_REGISTER(unsigned char, unsigned char, char);
#ifdef __CHAR_UNSIGNED__
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If you could avoid using a macro using a type alais instead, that would be cool.

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