-
Notifications
You must be signed in to change notification settings - Fork 108
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++ interface templates appear to be broken #1904
Comments
Yeah it is known that references aren't handled properly in the new interface, help definitely welcome! And yeah tentaitlvely c++17, though obviously earlier support would be nice if possible |
Adding a MFE which used to work in the original PR for the C++ interface https://fwd.gymni.ch/nsKPWF |
@jandrej with #1914 your code compiles with the following minor changes: 62,64c62,63
< return std::tuple<enzyme::Duplicated<decltype(std::get<Is>(args))>...>{
< { std::get<Is>(args), std::get<Is>(shadow_args) }...
< };
---
> return std::tuple_cat(std::make_tuple(
> enzyme::Duplicated<std::remove_cv_t<std::remove_reference_t<decltype(std::get<Is>(args))>>*> {&std::get<Is>(args), &std::get<Is>(shadow_args)})...);
87c86
< enzyme::autodiff<enzyme::Forward>
---
> enzyme::autodiff<enzyme::Forward, enzyme::DuplicatedNoNeed<kf_return_t>>
106,110c105
< std::get<0>(kernel_args) = 3;
< std::get<0>(kernel_shadow_args) = 1;
<
< const auto res = fwddiff_apply_enzyme(func, kernel_args, kernel_shadow_args);
< std::cout << res << " == 6\n";
---
> fwddiff_apply_enzyme(func, kernel_args, kernel_shadow_args); (I've replaced It still doesn't work as intended (prints #include <enzyme/enzyme>
#include <iostream>
double f(const double& x) { return x * x; }
int main() {
double x = 3, dx = 0;
enzyme::autodiff<enzyme::Reverse>(
f, enzyme::Duplicated<const double&>{ x, dx }
);
std::cout << x << ' ' << dx << '\n';
return 0;
} will compile and work meanwhile this: #include <enzyme/enzyme>
#include <iostream>
double f(const double& x) { return x * x; }
int main() {
double x = 3, dx = 0;
enzyme::autodiff<enzyme::Reverse>(
&f, enzyme::Duplicated<const double&>{ x, dx }
);
std::cout << x << ' ' << dx << '\n';
return 0;
} will not:
(nevermind the line numbers, I'm testing everything in a single |
@GregTheMadMonk the issue is that we need to ensure that all the reference passes do not end up creating a copy and thus the autodiff/fwddiff call gets the pointer to the actual reference provided. Re function pointers, they are supported, but when passed directly. (like the top) |
@wsmoses Sorry, I'm not sure I quite follow what you're saying... Do you mean that we need to ensure that the pointer Then there is also the issue that I've written about in the PR comments - but I see you've already read and replied to it :) And I also realize (now) why function pointers can't really be processed (since a function pointer could point to any function really and there is no guarantee it was processed by Enzyme). It seems that the best self-critique arrives after the code has been submitted... It's getting quite late, I won't be replying for a while |
So we can find out what's happening by looking at the generated LLVM. If there's a copy somewhere we'll see a different allocation passed to the underlying It would be nice to do a check at the outermost c++ api level (though we have some internal shenanigans to handle a slightly wider scope). |
@GregTheMadMonk did you check the output values? I only get zeros from the fwddiff in your branch. |
Seemingly resolved. |
Thank you! Sorry for being very inconsistent with GH activity |
Hello! Playing with C++ interface trying to get it to work and this simple program:
doesn't compile with the following errors:
It seems that the interface
std::
stuff with an internalenzyme::tuple
Unless I terribly misunderstand something, this is an error.
If it is, I think I'm going to try and fix it
edit: btw, what version of C++ should I use if editing the headers? C++17, or do you target lower versions too?
The text was updated successfully, but these errors were encountered: