-
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 TODO list #2012
Comments
Dear @samuelpmishLLNL, @wsmoses, Is there any preview of the expected API of this I am currently working on my own __enzyme_fwddiff<double>(reinterpret_cast<void*>(f),
enzyme_const, 2., enzyme_dup, 2, 1) into: const auto v = VariableValueAndIncrement<double>{2, 1};
diff(f2, 2., v); where the special type I also plan to implement a auto d2f_dxdy = get_derivative<0, 1>(f); Have you something similar in mind ? |
@thelfer yeah, sorry for the delay, see these for example: https://github.com/EnzymeAD/Enzyme/blob/main/enzyme/test/Integration/ReverseMode/sugar.cpp This essentially adds type checking and other nice things to the current autodiff mechanic. Subsequently we aim to add gradient/jacobian/etc wrappers atop this as well. |
@samuelpmishLLNL can you make a MWE for 1) I just finished adding support for Enzyme to automatically interleave args, which I presume @jandrej will like regardless -- but also enables us to pass in tensors/structs by value without issue. see #2048 |
This may be such an example: https://fwd.gymni.ch/yRcfkC |
sret issues should now be fixed by #2051 |
@wsmoses Thanks for keeping in touch. We currently make progresses on our side: https://github.com/thelfer/TFELMathEnzyme/tree/master/tests We made it worked for our own tensorial library, but it could easily be adapted to work with others, like For example: constexpr auto eps = double{1e-14};
constexpr auto E = double{70e9};
constexpr auto nu = double{0.3};
constexpr auto lambda = computeLambda(E, nu);
constexpr auto mu = computeMu(E, nu);
const auto hooke_potential = [](const Stensor& e) {
return (lambda / 2) * power<2>(trace(e)) + mu * (e | e);
};
// second derivative with respect to the first variable
// m is either REVERSE or FORWARD
const auto stress = getDerivativeFunction<m, 0>(hooke_potential);
// second derivative with respect to the first variable
const auto stiffness = getDerivativeFunction<m, 0, 0>(hooke_potential);
const auto e = Stensor{0.01, 0, 0, 0};
const auto s = stress(e);
const auto K = stiffness(e); We implemented a wrapper around However, the code of the If the objects like Are your examples already in |
yup all of this is on main And yes already the c++ autodiff syntax should abstract out all of the magic constants |
This is one of the main things the C++ interface hopes to address. By communicating the activity (const, duplicated, etc) through the type system, it's possible to write variadic functions that use enzyme under the hood.
There are only a few examples of the C++ interface right now, but I don't think we have a variadic one. |
@wsmoses Perfect ! I'll give it a try and make feed-backs ! |
That's exactly what caused me pain and headaches ! |
@thelfer related, you might want to have a look at https://github.com/mfem/mfem/blob/dfem-coefficient/examples/dfem/dfem.hpp#L1719 |
@jandrej Thanks for the pointer. Have you published anything about this, just to get an overview of the project ? |
Not yet, but feel free to ping me if you want to talk (e.g. MFEM workshop slack) |
I'm writing this issue to capture some of the ideas mentioned in a private discussion with @wsmoses about the future C++ interface. I'm hoping that this will increase visibility and allow other contributors to weigh in with design suggestions and considerations, as well as track progress on these topics.
(fix WIP) Address an issue where C++ functions that return composite types by-value are mishandled aftersret
transformations (and produce error messages that report the functions returnvoid
). This has been observed in some larger projects, but still needs a minimal reproducer.edit: fixed by Sugar: fix sret fwd mode #2051
Add a
make_zero
function for basic types (and allow users to specialize it for custom types), in order to better support differentiation over custom containers.Add higher-level tools for Jacobian, Hessian, JVP, VJP, HVP (actual interface still TBD, maybe look to Julia implementation for inspiration here?)
Support for batch-duplicated arguments (what container / layout should be used to pass the batch?)
Custom Derivative rule interface (likely also requires some effort in front end)
The text was updated successfully, but these errors were encountered: