// Arange operation for i32.
//
// Concatenated after int_saturate.wgsl and int_from_float.wgsl. The store goes
// through numr_f32_to_i32_sat rather than a bare `i32(value)`: WGSL leaves the
// conversion of an out-of-range float implementation-defined, while CPU's
// `Element::from_f64` clamps to the dtype's bounds.
const WORKGROUP_SIZE: u32 = 256u;
struct ArangeParams {
numel: u32,
start: f32,
step: f32,
}
@group(0) @binding(0) var<storage, read_write> arange_out: array<i32>;
@group(0) @binding(1) var<uniform> arange_params: ArangeParams;
@compute @workgroup_size(256)
fn arange_i32(
@builtin(global_invocation_id) gid: vec3<u32>,
@builtin(num_workgroups) nwg: vec3<u32>,
) {
let idx = gid.x + gid.y * nwg.x * WORKGROUP_SIZE;
if (idx < arange_params.numel) {
let value = arange_params.start + arange_params.step * f32(idx);
arange_out[idx] = numr_f32_to_i32_sat(value);
}
}