Pointer to aligned memory
Asked Answered
S

1

19

I often use compiler-based vectorization, e.g., for AVX. I am trying to come up with a cleaner way without relying on compiler-based extensions (such as Intel's #pragma vector aligned) by relying on C++11 alignment features. If you consider the code below, e.g., aligned::array<double,48> my_array; allows me to declare an array in stack with proper alignment, and if it is used in the same translation unit compilers seem to recognize this.

My question now concerns how to declare a function with aligned parameters. My most successful attempt is, e.g., aligned::ptr<double>, as used in the function f() below.

gcc compiles this without warnings (use -std=c++0x -O3), and the loop is vectorized. Intel's icc however, gives a warning and does not vectorize properly (warning #3463: alignas does not apply here; using type alignas(64) = T;).

Who is correct? Is there something wrong with my usage of alignas? Is there a better way to accomplish this?

namespace aligned {
  template <class T, int N>
    using array alignas(64) = T[N];

  template <class T>
    using type alignas(64) = T;

  template <class T>
    using ptr = type<T> *;
}

#ifdef __ICC
#define IVDEP "ivdep"
#else
#define IVDEP "GCC ivdep"
#endif

void f(aligned::ptr<double> x, const aligned::ptr<double> y) {
  _Pragma(IVDEP)
  for(int i=0; i<4; i++)
    x[i] = x[i]*y[i];
}
Scuppernong answered 4/5, 2015 at 7:12 Comment(3)
shouldn't it be using array = alignas(64) T[N] ?Substitute
@RichardHodges No, that does not work, see also hereScuppernong
Interesting, thank you.Substitute
N
4

It seems like a bug to me. Your syntax is perfectly correct and accepted by newest versions of GCC and Clang.

First of all, it is important what version of Intel C++ Compiler you currently use.

According to this document:

3.2 New and Changed Features

C++ Composer XE 2015 now contains Intel® C++ Compiler XE 15.0. The following features are new or significantly enhanced in this version:

  • [...]
  • Full C++11 language support (includes these feature new to 15.0) (/Qstd=c++11):

    • value categories (N3055)
    • alignas and alignof (N2341)
    • decltype extensions (N3049, N3276)
    • inheriting constructors (N2540)
    • user defined literals (N2765)
    • thread_local (N2659)

First of all, notice the presence of alignas on the list - you can assume full (or at least "improved comparing with previous version") support of these features starting from ICC 15.0. Secondly, "new or significantly enhanced" is not equal to "fully supported", if you ask me.

This summary also confirms support of alignment features in this version.

It notes, however, that:

Full C++11 support requires gcc 4.8 environment or newer on Linux.

I also encountered this, which may suggest, that not everything works properly yet.


As @Simon has found out, this is a confirmed issue (or, to be more precise, lack of support) and has been reported. Tracker number is DPD200361116. More info can be found in this thread. If anyone else will encounter this problem, I suggest to track updates on this page, they will be posted for sure.

Newsman answered 4/5, 2015 at 7:38 Comment(4)
I was indeed using ICC 15.0.Scuppernong
As you can see, technically, everything is fine. But true level of support seems to be lower than Intel claims. Perhaps posting this on Intel forum would provide clear answer?Newsman
Ok, I just did, I'll keep you updated on any results... I still got two other open issues in that forum, though ;)Scuppernong
I now got an reply in the Intel forum, pointing me to this thread where it had been reported before, and was accepted with tracker number DPD200361116. There was no update since Sept. 2014. Accepting this as an answer, therefore.Scuppernong

© 2022 - 2024 — McMap. All rights reserved.