-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Implement autodiff using intrinsics #142640
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
base: master
Are you sure you want to change the base?
Conversation
WARNING: ad function defined in traits are broken
_ if tcx.has_attr(def_id, sym::rustc_autodiff) => { | ||
// NOTE(Sa4dUs): This is a hacky way to get the autodiff items | ||
// so we can focus on the lowering of the intrinsic call | ||
|
||
// `diff_items` is empty even when autodiff is enabled, and if we're here, | ||
// it's because some function was marked as intrinsic and had the `rustc_autodiff` attr | ||
let diff_items = tcx.collect_and_partition_mono_items(()).autodiff_items; | ||
|
||
// this shouldn't happen? | ||
if diff_items.is_empty() { | ||
bug!("no autodiff items found for {def_id:?}"); | ||
} | ||
|
||
// TODO(Sa4dUs): generate the enzyme call itself, based on the logic in `builder.rs` | ||
|
||
// Just gen the fallback body for now | ||
return Err(ty::Instance::new_raw(def_id, instance.args)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this is the part you got stuck on?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kinda. I tried to use the collect_and_partition_mono_items
just as a hacky way of getting autodiff_items, so i can focus on the declaration. Once that was working, I would focus on how to get that information in the best way possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for context, during yesterday's meeting, we came to the conclusion that, for the time being, it's acceptable to copy and paste the collector logic from within the provider's code, just to focus on the declaration, but still nice to have feedback since, in some moment, we'll need to get to AutoDiffItems
in a decent way. collect_and_partition_mono_items(()).autodiff_items
being []
in autodiff code seems weird, so it would be nice to know why it's happening, or if it is some kind of bug.
@Sa4dUs Can you provide the motivation in the PR desc for context? |
This PR aims to handle derivatives generated by autodiff as compiler intrinsics, using the
#[rustc_intrinsic]
attr, so we can get rid of a lot of our frontend code, and in the backend, just lower it into a declaration.