Can't compile internal While loop or For loop with break
See original GitHub issueHi,
I used Aparapi before for GPU calculations Java on GPU: Pricing options with Monte Carlo simulation. I was excited to hear about Torando VM and wanted to repeat my calculations on FPGA.
I noticed an issue when moving from Aparapi to Tornado VM. I have a Monte Carlo simulation (n elements with m calculations/simulations per each). Seems that Tornado can’t compile simulations with breaks (while loop or for loop with break).
Maybe Tornado thinks that I modify incoming arrays, but this isn’t the case.
Do you have any suggestion about how to fix or debug this issue, please?
public static void mapCalcMc(float[] arrS, float[] arrB, int iterPerElement, int logicIterNum, float[] results) {
int arrLength = arrS.length;
int currentIter = 0;
for (@Parallel int i = 0; i < arrLength; i++) {
for (@Parallel int j = 0; j < iterPerElement; j++) {
int k = 0;
float curA = arrS[i];
float b = arrB[i];
while (k < logicIterNum
&& curA > b//Condition that can't be compiled
) {
k++;
}
results[currentIter] = 0.0f;
currentIter++;
}
}
}
UPD:
- I run code on AMD 4Gb GPU locally. Tornado works for me both on CPU and GPU with other tasks.
- Code above is “Minimum Breaking Example”. I tried to remove all non-essential logic.
- Here is the code to trigger task:
TaskSchedule task = new TaskSchedule("s0")
.task("map", MonteCarloTornadoGPU::mapCalcMc, new float[10], new float[10],
10,
100, // It looks crazy but if I replace 100 wit 10 code works.
// This param is used for number of iterations in no-op loop
new float[100])
.streamOut(gpuInterimMapResults);
task.execute();
I found a strange behavior, when I increase number of iterations in no-op while loop, app crashes (see comment to task code).
Attaching kernel out. kernel.txt
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:7 (4 by maintainers)
Top Results From Across the Web
If inside a while loop, can't break out of the while loop
"break" can only get you out of 1 loop. Your most fundamental problem is the infinite loops. To have one infinite loop is...
Read more >Can't break the while loop bash - Unix & Linux Stack Exchange
1 Answer. Save this answer. Show activity on this post. Since the value of var is never modified over the course of the...
Read more >Using Break and Continue Statements When Working with ...
While both loops iterate 5 times, each has a conditional if statement with a break statement. The outer loop will break if the...
Read more >JavaScript break Statement - W3Schools
In in a loop, it breaks out of the loop and continues executing the code after the loop (if any). Using Lables. The...
Read more >Break statement in Java - GeeksforGeeks
Using break, we can force immediate termination of a loop, bypassing the conditional expression and any remaining code in the body of the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m sorry, seems I didn’t provide enough information in my original post. I extended post with extra details.
@AlexeyPirogov
Thank you for reporting this. It looks that this issue is now solved.
The kernel Tornado generates is printed below:
I will close this issue for now. If anything else shows up, please let us know with a new issue.