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

C++20 non-type template parameter wrapper not working for lambdas with captures #1685

Open
alecjacobson opened this issue Feb 9, 2024 · 2 comments

Comments

@alecjacobson
Copy link

I was trying to follow the examples and probably misunderstood the documentation. I guess the documentation is ambiguous whether "Using a similar wrapper with non-type template parameter (requires C++20)" will work for lambdas that capture.

This little examples seems to show that it won't: https://enzyme.mit.edu/explorer/

Could anyone please confirm?

@alecjacobson alecjacobson changed the title C++20 not working for lambdas with captures C++20 non-type template parameter wrapper not working for lambdas with captures Feb 9, 2024
@wsmoses
Copy link
Member

wsmoses commented Feb 10, 2024

Ah, so we definitely should improve those docs (PR's welcome and cc'ing @samuelpmish @samuelpmishLLNL).

Lambda's that capture essentially can be thought of as a function that doesn't capture, followed by that passes in the lambda data as the first argument. As a result, the lambda with data requires a marking for enzyme_const, enzyme_dup, enzyme_out, etc.

The example in the doc with c++20 may work if the data in the lambda is a compile time constant, but otherwise you can't push runtime data through a template argument. It is resolvable (like mentioned above), but that specific wrapper would need some modification.

We have been meaning to add better overall syntactic sugar for C++ (akin to the Julia ones https://enzyme.mit.edu/julia which have type wrappers and automatically handle closures/members, etc), but we've recently been distracted by things like auto sparsity :)

@samuelpmishLLNL
Copy link
Collaborator

hi @alecjacobson -- I'm a fan of your work on TetWild!


Thanks for finding this mistake. For reference, here's the relevant bit of the documentation if you have any other corrections or contributions. A coworker of mine recently found a small syntax mistake in one of the code snippets on that page, so I should probably fix that one too.

I assumed that stateful lambdas as nontype template args were valid C++20 (unrelated to enzyme), and gcc agrees but clang doesn't: https://godbolt.org/z/8xTs8sfTx. Ultimately, clang's opinion is the only one that counts here!

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

3 participants