Skip to content

Uniform (bool) while conditions do not compile in a kernel #4

Description

@byeongjee

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; } ... }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions