Skip to content

[SYCL] Add code examples for all SYCL FPGA loop attributes #2764

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 16, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 119 additions & 0 deletions clang/include/clang/Basic/AttrDocs.td
Original file line number Diff line number Diff line change
Expand Up @@ -2380,6 +2380,22 @@ is unspecified and is therefore considered infinite.
In case of ivdep being applied both w/o an array variable and for a particular
array, the array variables that were not designated a separate ivdep will receive
the no-array ivdep's safelen, with the correspondent treatment by the backend.

.. code-block:: c++

void foo() {
int a[10];
[[intel::ivdep]] for (int i = 0; i != 10; ++i) { }
[[intel::ivdep(2)]] for (int i = 0; i != 10; ++i) { }
[[intel::ivdep(a)]] for (int i = 0; i != 10; ++i) { }
[[intel::ivdep(a, 2)]] for (int i = 0; i != 10; ++i) { }
}

template<int N>
void bar() {
[[intel::ivdep(N)]] for(;;) { }
}

}];
}

Expand All @@ -2390,6 +2406,19 @@ def SYCLIntelFPGAIIAttrDocs : Documentation {
This attribute applies to a loop. Indicates that the loop should be pipelined
with an initiation interval of N. N must be a positive integer. Cannot be
applied multiple times to the same loop.

.. code-block:: c++

void foo() {
int var = 0;
[[intel::ii(4)]] for (int i = 0; i < 10; ++i) var++;
}

template<int N>
void bar() {
[[intel::ii(N)]] for(;;) { }
}

}];
}

Expand All @@ -2401,6 +2430,19 @@ This attribute applies to a loop. Indicates that the loop should allow no more
than N threads or iterations to execute it simultaneously. N must be a non
negative integer. '0' indicates the max_concurrency case to be unbounded. Cannot
be applied multiple times to the same loop.

.. code-block:: c++

void foo() {
int a[10];
[[intel::max_concurrency(2)]] for (int i = 0; i != 10; ++i) a[i] = 0;
}

template<int N>
void bar() {
[[intel::max_concurrency(N)]] for(;;) { }
}

}];
}

Expand All @@ -2412,6 +2454,34 @@ This attribute applies to a loop. Indicates that the loop nest should be
coalesced into a single loop without affecting functionality. Parameter N is
optional. If specified, it shall be a positive integer, and indicates how many
of the nested loop levels should be coalesced.

.. code-block:: c++

void foo() {
int a[10];
[[intel::loop_coalesce]] for (int i = 0; i != 10; ++i) a[i] = 0;
}

template<int N>
void loop_coalesce() {
int j = 0, n = 48;
[[intel::loop_coalesce(N)]]
while (j < n) {
if (j % 4) {
++j;
continue;
}
}
j = 0;
[[intel::loop_coalesce]]
while (j < n) {
if (j % 6) {
++j;
continue;
}
}
}

}];
}

Expand All @@ -2423,6 +2493,14 @@ This attribute applies to a loop. Disables pipelining of the loop data path,
causing the loop to be executed serially. Cannot be used on the same loop in
conjunction with max_interleaving, speculated_iterations, max_concurrency, ii
or ivdep.

.. code-block:: c++

void foo() {
int var = 0;
[[intel::disable_loop_pipelining] for (int i = 0; i < 10; ++i) var++;
}

}];
}

Expand All @@ -2436,6 +2514,19 @@ mean that this attribute can only be applied to inner loops in user code - outer
loops in user code may still be contained in an implicit loop due to NDRange).
Parameter N is mandatory, and shall be non-negative integer. Cannot be
used on the same loop in conjunction with disable_loop_pipelining.

.. code-block:: c++

void foo() {
int a[10];
[[intel::max_interleaving(4)]] for (int i = 0; i != 10; ++i) a[i] = 0;
}

template<int N>
void bar() {
[[intel::max_interleaving(N)]] for(;;) { }
}

}];
}

Expand All @@ -2448,6 +2539,19 @@ iterations that will be in flight for a loop invocation (i.e. the exit
condition for these iterations will not have been evaluated yet).
Parameter N is mandatory, and may either be 0, or a positive integer. Cannot be
used on the same loop in conjunction with disable_loop_pipelining.

.. code-block:: c++

void foo() {
int var = 0;
[[intel::speculated_iterations(4)]] for (int i = 0; i < 10; ++i) var++;
}

template<int N>
void bar() {
[[intel::speculated_iterations(N)]] for(;;) { }
}

}];
}

Expand All @@ -2457,6 +2561,21 @@ def SYCLIntelFPGANofusionAttrDocs : Documentation {
let Content = [{
This attribute applies to a loop. Indicates that the annotated
loop should not be fused with any adjacent loop.

.. code-block:: c++

void foo() {
[[intel::nofusion]] for (int i=0; i<10;++i) { }
}

void nofusion() {
int a1[10];
for (int i = 0; i < 10; ++i) {
[[intel::nofusion]] for (int j = 0; j < 10; ++j) {
a1[i] += a1[j];
}
}

}];
}

Expand Down