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

Support closures in kernels #114

Open
RianGoossens opened this issue Sep 10, 2024 · 0 comments
Open

Support closures in kernels #114

RianGoossens opened this issue Sep 10, 2024 · 0 comments

Comments

@RianGoossens
Copy link
Contributor

Currently it's not possible to write a closure like so:

#[cube(launch_unchecked)]
fn gelu_array<F: Float>(input: &Array<F>, output: &mut Array<F>) {
    if ABSOLUTE_POS < input.len() {
        let f = |x: F| x * F::erf(x / F::new(2.0f32.sqrt()) + F::new(1.0)) / F::new(2.0);
        output[ABSOLUTE_POS] = f(input[ABSOLUTE_POS]);
    }
}

I'm not sure if this is even possible, though I could see it working in limited circumstances. I haven't written many proc macros, so there might be a reason this is infeasible, but a way to tackle this could be by inlining them.

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

1 participant