#pragma omp declare simd

Forum for the public review of the OpenMP 4.0 API Release Candidates. (Read Only)
Forum rules
This forum is now closed.

#pragma omp declare simd

Postby jakub » Mon Feb 25, 2013 10:42 am

From the 2.7.2 text it isn't obvious to me where exactly in the C/C++ grammar should #pragma omp declare simd be specified or what should happen if it is a function declaration with multiple declared functions.
What is supposed to happen for
#pragma omp declare simd
int foo (int), bar (), baz (double);
? Shall it be handled as if there were 3 separate function declarations, with 3 #pragma omp declare simd directives before each?
What about:
#pragma omp declare simd
int foo (int), var;
? Shall this be an error?

And, for function templates, shall #pragma omp declare simd go after template <...> or before it?
template <int N>
#pragma omp declare simd
int foo (int);
or
#pragma omp declare simd
template <int N>
int foo (int);
?

I also wonder about the: "The function declaration or definition shall not have an exception specification." restriction, does that mean that even
#pragma omp declare simd
int foo (int) throw ();
or
#pragma omp declare simd
double bar () noexcept (true);
or
#pragma omp declare simd
int baz () noexcept;
are not allowed? Is that desirable?

And, as has been raised before, I think it is undesirable to restrict just a single simdlen directive, often it is desirable to have one function compiled for more than one simdlen (e.g. one version that would use 128-bit vectors, one that would use 256-bit vectors, etc.). Then some callers could use just the 128-bit vector variant, if used in SIMD loops with lower safelen in one place and in SIMD loops with higher safelen in another place (or in say -msse4 vs. -mavx2 compiled code).
jakub
 
Posts: 74
Joined: Fri Oct 26, 2007 3:19 am

Re: #pragma omp declare simd

Postby aduran » Tue Feb 26, 2013 1:04 pm

For the first question, the directive is intended to be applied to only one function declaration.

For the second, the syntax would be:

#pragma omp declare simd
template <int N>
int foo (int);

For the third one, I guess right now it reads as you say but as you say we might want to allow an empty exception specification. We'll see to fix it.

As for the last one, you'll see support for not just different simdlen but also for other variants in the upcoming RC2.
aduran
 
Posts: 12
Joined: Wed Oct 24, 2007 8:33 am
Location: Barcelona, Spain

Re: #pragma omp declare simd

Postby jakub » Thu May 02, 2013 7:24 am

For #pragma omp declare simd, the spec lists reduction as an allowed clause? What is it useful for? From what I understand, reductions on #pragma omp simd are supposed to be treated like any other private variables, except that immediately before the loop they are constructed resp. initialized from the reduction initializer clause or builtin reduction initializer, and after the simd loop combined. But how is it useful to tell that fact to the elemental function? If the elemental function were to update the reduction vars, either it would need to be done by passing them by reference resp. address of the var, or by returning it from the elemental function.

If there is a reason for reduction clauses to be allowed, then guess the spec should make it clear that the reduction clause should only refer to arguments (i.e. have argument-list rather than list), and:
"Each argument can appear in at most one uniform or linear clause." should probably also include "or reduction" too.
jakub
 
Posts: 74
Joined: Fri Oct 26, 2007 3:19 am

Re: #pragma omp declare simd

Postby jakub » Mon May 06, 2013 3:21 am

Also, regarding the syntax where #pragma omp declare simd comes before template, are the parameter names in the uniform/linear/aligned/reduction (for reduction see previous comment) clauses the only things that is parsed actually after processing the function declaration? I mean:
Code: Select all
char *a;
short *b;
const int N = 1;

#pragma omp declare simd simdlen (N * 4) aligned (a : sizeof (*a) * 16) linear (b : sizeof (*b) * N * 16)
template <int N>
void foo (int *a, long long *b);

template <>
void foo <4> (int *, long long *);


Currently in the parsing code I'm working, this adds simdlen (4) aligned (1st argument of foo <4> : 16) linear (2nd argument of foo <4> : 32), i.e. while a and b in the clauses variable list are looked up after parsing the fn decl,
the expressions N * 4, sizeof (*a) * 16 and sizeof (*b) * N * 16 are parsed in the context where the #pragma omp declare simd line is written. Is that right, or do you expect to defer parsing the expressions somehow (guess that would be quite hard)
and parse the expressions only later on when the template parameter N and parameters a and b are in scope?
jakub
 
Posts: 74
Joined: Fri Oct 26, 2007 3:19 am


Return to OpenMP 4.0 Public Review Release Candidates

Who is online

Users browsing this forum: Google [Bot] and 0 guests