A while whose condition is a plain bool does not compile inside a kernel:
#[kernel]
fn f(n: i32, x: Varying<f32>) -> Varying<f32> {
let mut acc = x;
let mut i = 0;
while i < n {
acc = acc + 1.0;
i += 1;
}
acc
}
Two errors:
error[E0308]: mismatched types
| while i < n {
| ----- ^^^ expected `Mask<i32, N>`, found `bool`
error[E0277]: cannot assign to a value of type `i32` under execution context `VMask<N>`
| i += 1;
The first is the condition slot of Exec::enter_loop. The second is more
fundamental: rewrite.rs:390 rebinds __exec to the loop mask inside the body,
so the loop counter is a uniform write under a varying mask — deliberately not
implemented, since every lane would race on one location.
Both workarounds already exist and are used by the benchmark kernels:
for i in 0..n { ... }
loop { if !c { break; } ... }
A
whilewhose condition is a plainbooldoes not compile inside a kernel:Two errors:
The first is the condition slot of
Exec::enter_loop. The second is morefundamental:
rewrite.rs:390rebinds__execto the loop mask inside the body,so the loop counter is a uniform write under a varying mask — deliberately not
implemented, since every lane would race on one location.
Both workarounds already exist and are used by the benchmark kernels: