Skip to content
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

Other kinds of for loops #191

Closed
rachitnigam opened this issue May 6, 2019 · 5 comments
Closed

Other kinds of for loops #191

rachitnigam opened this issue May 6, 2019 · 5 comments

Comments

@rachitnigam
Copy link
Member

Two common patterns of for loops I've encountered in PolyBench:

  1. Loops instantiated with other loop variables (same as Initialize loops using other iterators #72).
for(let j = k + 1; j < PB_J; j++) // k is another loop bounds and PB_J is compile time constant
  1. Loops range ends with other loop variables
for(let j = 0; j < k; j++) // k is another loop bounds
  1. Non-1 steps for for loops
for(j = 0; j < PB_J; j += 2)

There might be interesting type system things we can do for these loops. Every other for loop should just be turned into a while loop.

For (3), we can do something of the form where only some of the banks are consumed since not all of them are touched.

Don't know what to do for (1) and (2).

@sampsyo
Copy link
Contributor

sampsyo commented May 6, 2019

Would it work to implement (1) and (2) by using prefix or suffix views and then iterating over those? We would, of course, need to figure out what it means to take a view using an index type…

@rachitnigam
Copy link
Member Author

Well normally, the other loops wouldn't be unrolled so the iterator would be treated as "just" a dynamic number for slicing purposes.

I still don't know of a way to unroll the outer loop without doing the equivalent of the suggestion in #72...

The Jason Cong paper seems to recommend having the inner loop unrolled with a static bound while the outer (controller) loops has a dynamic bound.

@rachitnigam
Copy link
Member Author

I don't think having a prefix view for (2) helps (unless I missed something). What we need is loops with dynamic bounds:

for (let i = 0..j) 

Right now, the compiler restricts j to be a syntactic number. The obvious implementation is allowing dynamic bounds and disallowing unrolling of these loops.

As a bonus, we can transitively calculate the TRIPCOUNTs for each of the variables if j or one of its initializers is a static integers. It seems like having the bounds check pass statically calculate the bounds for each expression is the right thing to do in the limit.

@sampsyo
Copy link
Contributor

sampsyo commented May 7, 2019

I suppose I was implicitly suggesting that loops might be written to use the size of an array for their bounds—sort of like a "foreach" loop. Then, you would do this by first taking a view on the array and then iterating over the entire array. This proposal doesn't really solve the problem; it just moves it into the view creation instead of the iteration…

@rachitnigam
Copy link
Member Author

Yeah, I don't know if that fixes it. See the example in #193 which tries to use both the underlying array and the view together.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants