Skip to content

What does @unroll and @unroll(n) do? #482

Locked Answered by weiweichen
cjohnson318 asked this question in Q&A
Discussion options

You must be logged in to vote

These are two loop decorators to tell the compiler to unroll a loop (https://en.wikipedia.org/wiki/Loop_unrolling). This doesn't impact the functionality of the loops, but potentially can help for better performance since it opens possibility for further compiler optimizations.

The syntax to use them is something like

# Fully unroll the loop's 10 iterations into 10 `do_something` calls and remove the for-loop.
@unroll 
for i in range(10):
  do_something(i)

or

# Unroll every 2 iterations and loop over 5 times.
@unroll(2)
for i in range (10):
  do_something(i)

This decorator can be attached to while statement too.
Note that currently the compiler can only unroll a loop, when:

  • Its lower b…

Replies: 2 comments 7 replies

Comment options

You must be logged in to vote
7 replies
@iamtimdavis
Comment options

@cjohnson318
Comment options

@leandrolcampos
Comment options

@gryznar
Comment options

@weiweichen
Comment options

Answer selected by cjohnson318
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
7 participants