public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: Determining maximum vector length supported by the CPU?
@ 2019-05-22  8:36 Martin Reinecke
  2019-05-22  9:18 ` Richard Biener
  0 siblings, 1 reply; 7+ messages in thread
From: Martin Reinecke @ 2019-05-22  8:36 UTC (permalink / raw)
  To: gcc; +Cc: m.kretz 

Hi Matthias!

> I agree, we need more information from the compiler. Esp. whether the user 
> specified `-mprefer-avx128` or `-mprefer-vector-width=none/128/256/512`.
> OTOH `-msve-vector-bits=N` is reported as __ARM_FEATURE_SVE_BITS. So that's 
> covered.

Almost ... except that I'd need a platform-agnostic definition. The
point is that the code does not care about the underlying hardware at
all, only for the vector length supported by it.

> Related: PR83875 - because while we're adding things in that area, it'd be 
> nice if they worked with target clones as well.

Yes, this is a problem I've come across as well in the past.
(https://gcc.gnu.org/ml/gcc-help/2018-10/msg00118.html)

> Are you aware of std::experimental::simd? It didn't make GCC 9.1, but you 
> can easily patch your (installed) libstdc++ using https://github.com/VcDevel/
> std-simd.

This looks extremely interesting! I have to look at it in more detail,
but this might be the way to go in the future.
However, the code I'm working on may be incorporated into numpy/scipy at
some point, and the minimum required compilers for these packages are
pretty old. I can't expect more than vanilla C++11 support there.

Cheers,
  Martin

^ permalink raw reply	[flat|nested] 7+ messages in thread
* Determining maximum vector length supported by the CPU?
@ 2019-05-22  6:39 Martin Reinecke
  2019-05-22  8:09 ` Matthias Kretz
  0 siblings, 1 reply; 7+ messages in thread
From: Martin Reinecke @ 2019-05-22  6:39 UTC (permalink / raw)
  To: gcc

[Disclaimer: I sent this to gcc-help two weeks ago, but didn't get an
answer. Maybe the topic is more suited for the main gcc list ... I
really think the feature in question would be extremely useful to have,
and easy to add!]

Hi,

I'm currently writing an FFT library which tries to make use of SIMD
instructions and uses a lot of variables with
 __attribute__ ((vector_size (xyz))

The resulting source is nicely portable and architecture-independent -
except for the one place where I need to determine the maximum
hardware-supported vector length on the target CPU.

This currently looks like

#if defined(__AVX__)
constexpr int veclen=32;
#elif defined(__SSE2__)
constexpr int veclen=16;
[...]

This approach requires me to add an #ifdef for many architectures, most
of which I cannot really test on ... and new architectures will be
unsupported by default.

Hence my question: is there a way in gcc to determine the hardware
vector length for the architecture the compiler is currently targeting?
Some predefined macro like

HARDWARE_VECTOR_LENGTH_IN_BYTES

which is 32 for AVX, 16 for SSE2, and has proper values for Neon, VPX
etc. etc.

If this is not provided at the moment, would it bo possible to add this
in the future? This could massively simplify writing and maintaining
multi-platform SIMD code.

Thanks,
  Martin

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-05-22  9:37 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-22  8:36 Determining maximum vector length supported by the CPU? Martin Reinecke
2019-05-22  9:18 ` Richard Biener
2019-05-22  9:27   ` Martin Reinecke
2019-05-22  9:37     ` Matthias Kretz
2019-05-22  9:27   ` Matthias Kretz
  -- strict thread matches above, loose matches on Subject: below --
2019-05-22  6:39 Martin Reinecke
2019-05-22  8:09 ` Matthias Kretz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).