1
Fork 0

remove outdated *First autodiff variants for higher-order ad

This commit is contained in:
Manuel Drehwald 2025-02-10 01:35:53 -05:00
parent 1221cff551
commit 061abbc369
3 changed files with 6 additions and 22 deletions

View file

@ -30,14 +30,6 @@ pub enum DiffMode {
Forward, Forward,
/// The target function, to be created using reverse mode AD. /// The target function, to be created using reverse mode AD.
Reverse, Reverse,
/// The target function, to be created using forward mode AD.
/// This target function will also be used as a source for higher order derivatives,
/// so compute it before all Forward/Reverse targets and optimize it through llvm.
ForwardFirst,
/// The target function, to be created using reverse mode AD.
/// This target function will also be used as a source for higher order derivatives,
/// so compute it before all Forward/Reverse targets and optimize it through llvm.
ReverseFirst,
} }
/// Dual and Duplicated (and their Only variants) are getting lowered to the same Enzyme Activity. /// Dual and Duplicated (and their Only variants) are getting lowered to the same Enzyme Activity.
@ -92,10 +84,10 @@ pub struct AutoDiffAttrs {
impl DiffMode { impl DiffMode {
pub fn is_rev(&self) -> bool { pub fn is_rev(&self) -> bool {
matches!(self, DiffMode::Reverse | DiffMode::ReverseFirst) matches!(self, DiffMode::Reverse)
} }
pub fn is_fwd(&self) -> bool { pub fn is_fwd(&self) -> bool {
matches!(self, DiffMode::Forward | DiffMode::ForwardFirst) matches!(self, DiffMode::Forward)
} }
} }
@ -106,8 +98,6 @@ impl Display for DiffMode {
DiffMode::Source => write!(f, "Source"), DiffMode::Source => write!(f, "Source"),
DiffMode::Forward => write!(f, "Forward"), DiffMode::Forward => write!(f, "Forward"),
DiffMode::Reverse => write!(f, "Reverse"), DiffMode::Reverse => write!(f, "Reverse"),
DiffMode::ForwardFirst => write!(f, "ForwardFirst"),
DiffMode::ReverseFirst => write!(f, "ReverseFirst"),
} }
} }
} }
@ -125,12 +115,12 @@ pub fn valid_ret_activity(mode: DiffMode, activity: DiffActivity) -> bool {
match mode { match mode {
DiffMode::Error => false, DiffMode::Error => false,
DiffMode::Source => false, DiffMode::Source => false,
DiffMode::Forward | DiffMode::ForwardFirst => { DiffMode::Forward => {
activity == DiffActivity::Dual activity == DiffActivity::Dual
|| activity == DiffActivity::DualOnly || activity == DiffActivity::DualOnly
|| activity == DiffActivity::Const || activity == DiffActivity::Const
} }
DiffMode::Reverse | DiffMode::ReverseFirst => { DiffMode::Reverse => {
activity == DiffActivity::Const activity == DiffActivity::Const
|| activity == DiffActivity::Active || activity == DiffActivity::Active
|| activity == DiffActivity::ActiveOnly || activity == DiffActivity::ActiveOnly
@ -166,10 +156,10 @@ pub fn valid_input_activity(mode: DiffMode, activity: DiffActivity) -> bool {
return match mode { return match mode {
DiffMode::Error => false, DiffMode::Error => false,
DiffMode::Source => false, DiffMode::Source => false,
DiffMode::Forward | DiffMode::ForwardFirst => { DiffMode::Forward => {
matches!(activity, Dual | DualOnly | Const) matches!(activity, Dual | DualOnly | Const)
} }
DiffMode::Reverse | DiffMode::ReverseFirst => { DiffMode::Reverse => {
matches!(activity, Active | ActiveOnly | Duplicated | DuplicatedOnly | Const) matches!(activity, Active | ActiveOnly | Duplicated | DuplicatedOnly | Const)
} }
}; };
@ -200,8 +190,6 @@ impl FromStr for DiffMode {
"Source" => Ok(DiffMode::Source), "Source" => Ok(DiffMode::Source),
"Forward" => Ok(DiffMode::Forward), "Forward" => Ok(DiffMode::Forward),
"Reverse" => Ok(DiffMode::Reverse), "Reverse" => Ok(DiffMode::Reverse),
"ForwardFirst" => Ok(DiffMode::ForwardFirst),
"ReverseFirst" => Ok(DiffMode::ReverseFirst),
_ => Err(()), _ => Err(()),
} }
} }

View file

@ -52,8 +52,6 @@ fn generate_enzyme_call<'ll>(
let mut ad_name: String = match attrs.mode { let mut ad_name: String = match attrs.mode {
DiffMode::Forward => "__enzyme_fwddiff", DiffMode::Forward => "__enzyme_fwddiff",
DiffMode::Reverse => "__enzyme_autodiff", DiffMode::Reverse => "__enzyme_autodiff",
DiffMode::ForwardFirst => "__enzyme_fwddiff",
DiffMode::ReverseFirst => "__enzyme_autodiff",
_ => panic!("logic bug in autodiff, unrecognized mode"), _ => panic!("logic bug in autodiff, unrecognized mode"),
} }
.to_string(); .to_string();

View file

@ -916,8 +916,6 @@ fn autodiff_attrs(tcx: TyCtxt<'_>, id: DefId) -> Option<AutoDiffAttrs> {
let mode = match mode.as_str() { let mode = match mode.as_str() {
"Forward" => DiffMode::Forward, "Forward" => DiffMode::Forward,
"Reverse" => DiffMode::Reverse, "Reverse" => DiffMode::Reverse,
"ForwardFirst" => DiffMode::ForwardFirst,
"ReverseFirst" => DiffMode::ReverseFirst,
_ => { _ => {
span_bug!(mode.span, "rustc_autodiff attribute contains invalid mode"); span_bug!(mode.span, "rustc_autodiff attribute contains invalid mode");
} }