Skip to content

Commit 6b95820

Browse files
authored
[SYCL] Add code examples for all SYCL FPGA loop attributes (#2764)
This is a followup in #2715 (comment). This patch improves the documentation by adding code examples for all FPGA loop attributes that we did not have before. Signed-off-by: Soumi Manna <[email protected]>
1 parent 1ce46c9 commit 6b95820

File tree

1 file changed

+119
-0
lines changed

1 file changed

+119
-0
lines changed

clang/include/clang/Basic/AttrDocs.td

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2397,6 +2397,22 @@ is unspecified and is therefore considered infinite.
23972397
In case of ivdep being applied both w/o an array variable and for a particular
23982398
array, the array variables that were not designated a separate ivdep will receive
23992399
the no-array ivdep's safelen, with the correspondent treatment by the backend.
2400+
2401+
.. code-block:: c++
2402+
2403+
void foo() {
2404+
int a[10];
2405+
[[intel::ivdep]] for (int i = 0; i != 10; ++i) { }
2406+
[[intel::ivdep(2)]] for (int i = 0; i != 10; ++i) { }
2407+
[[intel::ivdep(a)]] for (int i = 0; i != 10; ++i) { }
2408+
[[intel::ivdep(a, 2)]] for (int i = 0; i != 10; ++i) { }
2409+
}
2410+
2411+
template<int N>
2412+
void bar() {
2413+
[[intel::ivdep(N)]] for(;;) { }
2414+
}
2415+
24002416
}];
24012417
}
24022418

@@ -2407,6 +2423,19 @@ def SYCLIntelFPGAIIAttrDocs : Documentation {
24072423
This attribute applies to a loop. Indicates that the loop should be pipelined
24082424
with an initiation interval of N. N must be a positive integer. Cannot be
24092425
applied multiple times to the same loop.
2426+
2427+
.. code-block:: c++
2428+
2429+
void foo() {
2430+
int var = 0;
2431+
[[intel::ii(4)]] for (int i = 0; i < 10; ++i) var++;
2432+
}
2433+
2434+
template<int N>
2435+
void bar() {
2436+
[[intel::ii(N)]] for(;;) { }
2437+
}
2438+
24102439
}];
24112440
}
24122441

@@ -2418,6 +2447,19 @@ This attribute applies to a loop. Indicates that the loop should allow no more
24182447
than N threads or iterations to execute it simultaneously. N must be a non
24192448
negative integer. '0' indicates the max_concurrency case to be unbounded. Cannot
24202449
be applied multiple times to the same loop.
2450+
2451+
.. code-block:: c++
2452+
2453+
void foo() {
2454+
int a[10];
2455+
[[intel::max_concurrency(2)]] for (int i = 0; i != 10; ++i) a[i] = 0;
2456+
}
2457+
2458+
template<int N>
2459+
void bar() {
2460+
[[intel::max_concurrency(N)]] for(;;) { }
2461+
}
2462+
24212463
}];
24222464
}
24232465

@@ -2429,6 +2471,34 @@ This attribute applies to a loop. Indicates that the loop nest should be
24292471
coalesced into a single loop without affecting functionality. Parameter N is
24302472
optional. If specified, it shall be a positive integer, and indicates how many
24312473
of the nested loop levels should be coalesced.
2474+
2475+
.. code-block:: c++
2476+
2477+
void foo() {
2478+
int a[10];
2479+
[[intel::loop_coalesce]] for (int i = 0; i != 10; ++i) a[i] = 0;
2480+
}
2481+
2482+
template<int N>
2483+
void loop_coalesce() {
2484+
int j = 0, n = 48;
2485+
[[intel::loop_coalesce(N)]]
2486+
while (j < n) {
2487+
if (j % 4) {
2488+
++j;
2489+
continue;
2490+
}
2491+
}
2492+
j = 0;
2493+
[[intel::loop_coalesce]]
2494+
while (j < n) {
2495+
if (j % 6) {
2496+
++j;
2497+
continue;
2498+
}
2499+
}
2500+
}
2501+
24322502
}];
24332503
}
24342504

@@ -2440,6 +2510,14 @@ This attribute applies to a loop. Disables pipelining of the loop data path,
24402510
causing the loop to be executed serially. Cannot be used on the same loop in
24412511
conjunction with max_interleaving, speculated_iterations, max_concurrency, ii
24422512
or ivdep.
2513+
2514+
.. code-block:: c++
2515+
2516+
void foo() {
2517+
int var = 0;
2518+
[[intel::disable_loop_pipelining] for (int i = 0; i < 10; ++i) var++;
2519+
}
2520+
24432521
}];
24442522
}
24452523

@@ -2453,6 +2531,19 @@ mean that this attribute can only be applied to inner loops in user code - outer
24532531
loops in user code may still be contained in an implicit loop due to NDRange).
24542532
Parameter N is mandatory, and shall be non-negative integer. Cannot be
24552533
used on the same loop in conjunction with disable_loop_pipelining.
2534+
2535+
.. code-block:: c++
2536+
2537+
void foo() {
2538+
int a[10];
2539+
[[intel::max_interleaving(4)]] for (int i = 0; i != 10; ++i) a[i] = 0;
2540+
}
2541+
2542+
template<int N>
2543+
void bar() {
2544+
[[intel::max_interleaving(N)]] for(;;) { }
2545+
}
2546+
24562547
}];
24572548
}
24582549

@@ -2465,6 +2556,19 @@ iterations that will be in flight for a loop invocation (i.e. the exit
24652556
condition for these iterations will not have been evaluated yet).
24662557
Parameter N is mandatory, and may either be 0, or a positive integer. Cannot be
24672558
used on the same loop in conjunction with disable_loop_pipelining.
2559+
2560+
.. code-block:: c++
2561+
2562+
void foo() {
2563+
int var = 0;
2564+
[[intel::speculated_iterations(4)]] for (int i = 0; i < 10; ++i) var++;
2565+
}
2566+
2567+
template<int N>
2568+
void bar() {
2569+
[[intel::speculated_iterations(N)]] for(;;) { }
2570+
}
2571+
24682572
}];
24692573
}
24702574

@@ -2474,6 +2578,21 @@ def SYCLIntelFPGANofusionAttrDocs : Documentation {
24742578
let Content = [{
24752579
This attribute applies to a loop. Indicates that the annotated
24762580
loop should not be fused with any adjacent loop.
2581+
2582+
.. code-block:: c++
2583+
2584+
void foo() {
2585+
[[intel::nofusion]] for (int i=0; i<10;++i) { }
2586+
}
2587+
2588+
void nofusion() {
2589+
int a1[10];
2590+
for (int i = 0; i < 10; ++i) {
2591+
[[intel::nofusion]] for (int j = 0; j < 10; ++j) {
2592+
a1[i] += a1[j];
2593+
}
2594+
}
2595+
24772596
}];
24782597
}
24792598

0 commit comments

Comments
 (0)