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

Examples do not compile #71

Closed
OwenTrokeBillard opened this issue Jan 4, 2024 · 9 comments
Closed

Examples do not compile #71

OwenTrokeBillard opened this issue Jan 4, 2024 · 9 comments

Comments

@OwenTrokeBillard
Copy link

The examples do not compile.

I followed the build instructions for Linux and attempted to run one of the examples: cargo +enzyme run --example rosenbrock_fwd_iter. There are four compilation errors:

error: cannot find attribute `dup` in this scope
 --> examples/rosenbrock_fwd_iter.rs:4:17
  |
4 | fn rosenbrock(#[dup] x: &[f64; 2]) -> f64 {
  |                 ^^^
error[E0659]: `autodiff` is ambiguous
 --> examples/rosenbrock_fwd_iter.rs:3:3
  |
3 | #[autodiff(d_rosenbrock, Forward, DuplicatedNoNeed)]
  |   ^^^^^^^^ ambiguous name
  |
  = note: ambiguous because of a name conflict with a builtin attribute
  = note: `autodiff` could refer to a built-in attribute
note: `autodiff` could also refer to the attribute macro imported here
 --> examples/rosenbrock_fwd_iter.rs:1:5
  |
1 | use autodiff::autodiff;
  |     ^^^^^^^^^^^^^^^^^^
  = help: use `crate::autodiff` to refer to this attribute macro unambiguously
error[E0425]: cannot find function `d_rosenbrock` in this scope
  --> examples/rosenbrock_fwd_iter.rs:18:17
   |
4  | fn rosenbrock(#[dup] x: &[f64; 2]) -> f64 {
   | ----------------------------------------- similarly named function `rosenbrock` defined here
...
18 |     let df_dx = d_rosenbrock(&x, &[1.0, 0.0]);
   |                 ^^^^^^^^^^^^ help: a function with a similar name exists: `rosenbrock`
error[E0425]: cannot find function `d_rosenbrock` in this scope
  --> examples/rosenbrock_fwd_iter.rs:19:17
   |
4  | fn rosenbrock(#[dup] x: &[f64; 2]) -> f64 {
   | ----------------------------------------- similarly named function `rosenbrock` defined here
...
19 |     let df_dy = d_rosenbrock(&x, &[0.0, 1.0]);
   |                 ^^^^^^^^^^^^ help: a function with a similar name exists: `rosenbrock`

The second error states there are two definitions of the autodiff attribute:

  • One builtin, since the toolchain was built with Enzyme.
  • One in the current project, since the autodiff attribute is also defined in /src/lib.rs.

Two competing definitions of the attribute suggests a configuration issue. Am I missing a step?

@ZuseZ4
Copy link
Member

ZuseZ4 commented Jan 5, 2024

That's not you, this branch is just a bit dated and unfortunately ended up having both the old (src/lib) and the new (builtin) autodiff frontend. The new branch is macro2, I will push a few more of my local changes after cleaning up. The new branch compiles and should today be ready to be tested on windows to resolve potential path issues, but for the examples to fully work I will need a bit more time to Cherry-pick all the changes from my last branch.

@OwenTrokeBillard
Copy link
Author

All good. Thanks for your quick response. I'll wait for your changes to merge and then I'll resume my efforts to get it working on Windows. No rush.

@ZuseZ4
Copy link
Member

ZuseZ4 commented Jan 5, 2024

I just pushed a change to macro2 which now successfully builds and links Enzyme on Linux, so that should be a nice mwe to get it to work on windows, if you want to try. It uses / as path separator, but that's also done by the original code around it, so I assume it is not the reason for failing on windows.
I will now work on getting the intermediate glue code ready.

@ZuseZ4
Copy link
Member

ZuseZ4 commented Jan 8, 2024

By now what's remaining is moving from the syn/quote/parse usage in library/autodiff/src to the rustc ast::MetaItem walking in compiler/rustc_builtin_macros/src/autodiff.rs, the rest should be ported over. I will try to get a first small example to work this evening.

@ZuseZ4
Copy link
Member

ZuseZ4 commented Jan 9, 2024

basic examples now indeed get expanded, the span metadata seems to still be wrong though, since it fails to compile with gibberish error messages. I'll have another look at it next week, after traveling.

fn rosenbrock(x: &[f64; 2]) -> f64 {
    let mut res = 0.0;
    for i in 0..(x.len() - 1) {
        let a = x[i + 1] - x[i] * x[i];
        let b = x[i] - 1.0;
        res += 100.0 * a * a + b * b;
    }
    res
}
fn d_rosenbrock(x: &[f64; 2], dx: &mut [f64; 2]) -> f64 {
    std::hint::black_box(rosenbrock(x), dx);
    std::hint::black_box(unsafe { std::mem::zeroed() })
}

@motabbara
Copy link

As an aside, src/bootstrap/src/core/build_steps/compile.rs wants to copy enzyme libs but assumes the library names have an .so extension, failing on Windows and macOS. I'll see if I can make a PR for it.

@ZuseZ4
Copy link
Member

ZuseZ4 commented Feb 6, 2024

@motabbara Ping in case that you have time to fix and test the extension on another system :)

@ZuseZ4
Copy link
Member

ZuseZ4 commented Feb 6, 2024

Also the macro2 branch is slowly getting in shape to replace the current main branch. I hope to get to it this weekend.

@ZuseZ4
Copy link
Member

ZuseZ4 commented Feb 27, 2024

Closing since the new macro implementation is now on Master and at least some examples compile in debug mode.
It would be nice to port over old examples from #75 at some point.

@ZuseZ4 ZuseZ4 closed this as completed Feb 27, 2024
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