# Loops when writing code for PYNQ

**URL:** <https://discuss.pynq.io/t/loops-when-writing-code-for-pynq/4520>\
**Category:** Support\
**Created:** [August 4, 2022, 5:02pm UTC](https://discuss.pynq.io/t/loops-when-writing-code-for-pynq/4520 "2022-08-04T17:02:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alienflip](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/alienflip/32/3408_2.png) [@alienflip](https://discuss.pynq.io/u/alienflip)\
**Post date:** [August 4, 2022, 5:02pm UTC](https://discuss.pynq.io/t/loops-when-writing-code-for-pynq/4520/1 "2022-08-04T17:02:36Z")

</div>

I am curious as to the looping convention when writing HLS:

```auto
L1:...
    L2:...
        L3:...

```

Why is this done?

E.g: [Vitis\_Accel\_Examples/adder.cpp at 53e7d4fd8e1a8a431b53aff47dfcb6c5d19d9686 · Xilinx/Vitis\_Accel\_Examples · GitHub](https://github.com/Xilinx/Vitis_Accel_Examples/blob/53e7d4fd8e1a8a431b53aff47dfcb6c5d19d9686/cpp_kernels/dataflow_stream/src/adder.cpp#L80)

---

<div class="post-metadata">

**Author:** ![cathalmccabe](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/cathalmccabe/32/3348_2.png) [@cathalmccabe](https://discuss.pynq.io/u/cathalmccabe)\
**Post date:** [August 4, 2022, 7:33pm UTC](https://discuss.pynq.io/t/loops-when-writing-code-for-pynq/4520/2 "2022-08-04T19:33:10Z")

</div>

Why the loops are labelled? This can be useful for identifying a loop when applying HLS optimizations, or understanding how the design has been optimized.

If you are using pragmas, they can be inlined with the loop. Labels are less important.  
However, optimizations can also be applied using Tcl commands which are separate to your code. The optimization needs a way to identify the code or loop in this case.

E.g.  
From here:  
[https://docs.xilinx.com/r/en-US/ug1399-vitis-hls/set\_directive\_loop\_tripcount](https://docs.xilinx.com/r/en-US/ug1399-vitis-hls/set_directive_loop_tripcount)

```auto
set_directive_loop_tripcount -min 12 -max 16 -avg 14 foo/loop_1

```

directive is applied to the loop labelled “loop\_1” in fn foo

Cathal

---

<div class="post-metadata">

**Author:** ![system](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/system/32/2_2.png) [@system](https://discuss.pynq.io/u/system)\
**Post date:** [May 3, 2023, 9:46pm UTC](https://discuss.pynq.io/t/loops-when-writing-code-for-pynq/4520/3 "2023-05-03T21:46:44Z")

</div>

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.
