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

autodiff macro fails to compile when used on functions defined within other functions #184

Open
sYgbpNA5UEVufjsHNwF3Xvf9ANZi5bNs opened this issue Nov 3, 2024 · 1 comment

Comments

@sYgbpNA5UEVufjsHNwF3Xvf9ANZi5bNs

output of rustc +enzyme --version --verbose:

rustc 1.84.0-nightly (1203575 2024-10-30)
binary: rustc
commit-hash: 1203575
commit-date: 2024-10-30
host: x86_64-unknown-linux-gnu
release: 1.84.0-nightly
LLVM version: 19.1.1

an example:

#![feature(autodiff)]
use std::autodiff::autodiff;

fn main() {
    #[autodiff(d_inner, Forward, Dual, DualOnly)]
    fn inner(x: f32) -> f32 {
        x * x
    }
}

build results in the error message (with the first line with the path manually removed)

error: autodiff must be applied to function
 --> src/main.rs:6:5
  |
6 | /     fn inner(x: f32) -> f32 {
7 | |         x * x
8 | |     }
  | |_____^

error: could not compile `enzyme-test` (bin "enzyme-test") due to 1 previous error
@ZuseZ4
Copy link
Member

ZuseZ4 commented Nov 3, 2024

Thanks for the issue report! I'm a bit short on time till Nov 15, but will look at it afterwards.
That being said it's a frontend error, and those are usually easy to fix.
Here is the PR where I merged the frontend logic: https://github.com/rust-lang/rust/pull/129458/files#diff-548c9b1b2ceb2091452377c3716d4fe1b707295b33705834a97ce4274eb82afa
The error should be in compiler/rustc_builtin_macros/src/autodiff.rs, you probably need to look at the match statements which as fallback lead to this error and add the one case that matches this inner function (and is currently not getting matched).
But otherwise I can also add handling for it after my deadlines.

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

2 participants