Skip to content

Commit f72d7e3

Browse files
committed
Rename intrinsic from enzyme_autodiff to autodiff
1 parent ff7594a commit f72d7e3

File tree

10 files changed

+42
-50
lines changed

10 files changed

+42
-50
lines changed

compiler/rustc_builtin_macros/src/autodiff.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ mod llvm_enzyme {
197197
/// }
198198
/// #[rustc_autodiff(Reverse, Duplicated, Active)]
199199
/// fn cos_box(x: &Box<f32>, dx: &mut Box<f32>, dret: f32) -> f32 {
200-
/// std::intrinsics::enzyme_autodiff(sin::<>, cos_box::<>, (x, dx, dret))
200+
/// std::intrinsics::autodiff(sin::<>, cos_box::<>, (x, dx, dret))
201201
/// }
202202
/// ```
203203
/// FIXME(ZuseZ4): Once autodiff is enabled by default, make this a doc comment which is checked
@@ -493,11 +493,11 @@ mod llvm_enzyme {
493493
ty
494494
}
495495

496-
// Generate `enzyme_autodiff` intrinsic call
496+
// Generate `autodiff` intrinsic call
497497
// ```
498-
// std::intrinsics::enzyme_autodiff(source, diff, (args))
498+
// std::intrinsics::autodiff(source, diff, (args))
499499
// ```
500-
fn call_enzyme_autodiff(
500+
fn call_autodiff(
501501
ecx: &ExtCtxt<'_>,
502502
primal: Ident,
503503
diff: Ident,
@@ -523,7 +523,7 @@ mod llvm_enzyme {
523523
.into(),
524524
);
525525

526-
let enzyme_path_idents = ecx.std_path(&[sym::intrinsics, sym::enzyme_autodiff]);
526+
let enzyme_path_idents = ecx.std_path(&[sym::intrinsics, sym::autodiff]);
527527
let enzyme_path = ecx.path(span, enzyme_path_idents);
528528
let call_expr = ecx.expr_call(
529529
span,
@@ -603,10 +603,10 @@ mod llvm_enzyme {
603603
let new_decl_span = d_sig.span;
604604

605605
// Add a call to the primal function to prevent it from being inlined
606-
// and call `enzyme_autodiff` intrinsic (this also covers the return type)
606+
// and call `autodiff` intrinsic (this also covers the return type)
607607
let body = ecx.block(
608608
span,
609-
thin_vec![call_enzyme_autodiff(
609+
thin_vec![call_autodiff(
610610
ecx,
611611
primal,
612612
diff_ident,

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
194194
&[ptr, args[1].immediate()],
195195
)
196196
}
197-
sym::enzyme_autodiff => {
198-
codegen_enzyme_autodiff(self, tcx, instance, args, result);
197+
sym::autodiff => {
198+
codegen_autodiff(self, tcx, instance, args, result);
199199
return Ok(());
200200
}
201201
sym::is_val_statically_known => {
@@ -1122,7 +1122,7 @@ fn get_rust_try_fn<'a, 'll, 'tcx>(
11221122
rust_try
11231123
}
11241124

1125-
fn codegen_enzyme_autodiff<'ll, 'tcx>(
1125+
fn codegen_autodiff<'ll, 'tcx>(
11261126
bx: &mut Builder<'_, 'll, 'tcx>,
11271127
tcx: TyCtxt<'tcx>,
11281128
instance: ty::Instance<'tcx>,

compiler/rustc_hir_analysis/src/check/intrinsic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: LocalDefId) -> hi
135135
| sym::round_ties_even_f32
136136
| sym::round_ties_even_f64
137137
| sym::round_ties_even_f128
138-
| sym::enzyme_autodiff
138+
| sym::autodiff
139139
| sym::const_eval_select => hir::Safety::Safe,
140140
_ => hir::Safety::Unsafe,
141141
};
@@ -199,7 +199,7 @@ pub(crate) fn check_intrinsic_type(
199199
let safety = intrinsic_operation_unsafety(tcx, intrinsic_id);
200200
let n_lts = 0;
201201
let (n_tps, n_cts, inputs, output) = match intrinsic_name {
202-
sym::enzyme_autodiff => (4, 0, vec![param(0), param(1), param(2)], param(3)),
202+
sym::autodiff => (4, 0, vec![param(0), param(1), param(2)], param(3)),
203203
sym::abort => (0, 0, vec![], tcx.types.never),
204204
sym::unreachable => (0, 0, vec![], tcx.types.never),
205205
sym::breakpoint => (0, 0, vec![], tcx.types.unit),

compiler/rustc_monomorphize/src/collector.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ use rustc_span::source_map::{Spanned, dummy_spanned, respan};
237237
use rustc_span::{DUMMY_SP, Span};
238238
use tracing::{debug, instrument, trace};
239239

240-
use crate::collector::autodiff::collect_enzyme_autodiff_fn;
240+
use crate::collector::autodiff::collect_autodiff_fn;
241241
use crate::errors::{
242242
self, EncounteredErrorWhileInstantiating, EncounteredErrorWhileInstantiatingGlobalAsm,
243243
NoOptimizedMir, RecursionLimit,
@@ -914,7 +914,7 @@ fn visit_instance_use<'tcx>(
914914
return;
915915
}
916916
if let Some(intrinsic) = tcx.intrinsic(instance.def_id()) {
917-
collect_enzyme_autodiff_fn(tcx, instance, intrinsic, output);
917+
collect_autodiff_fn(tcx, instance, intrinsic, output);
918918

919919
if let Some(_requirement) = ValidityRequirement::from_intrinsic(intrinsic.name) {
920920
// The intrinsics assert_inhabited, assert_zero_valid, and assert_mem_uninitialized_valid will

compiler/rustc_monomorphize/src/collector/autodiff.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ use rustc_middle::ty::{self, GenericArg, IntrinsicDef, TyCtxt};
44
use crate::collector::{MonoItems, create_fn_mono_item};
55

66
// Here, we force both primal and diff function to be collected in
7-
// mono so this does not interfere in `enzyme_autodiff` intrinsics
7+
// mono so this does not interfere in `autodiff` intrinsics
88
// codegen process. If they are unused, they will be removed later and
99
// won't be present at LLVM-IR.
10-
pub(crate) fn collect_enzyme_autodiff_fn<'tcx>(
10+
pub(crate) fn collect_autodiff_fn<'tcx>(
1111
tcx: TyCtxt<'tcx>,
1212
instance: ty::Instance<'tcx>,
1313
intrinsic: IntrinsicDef,
1414
output: &mut MonoItems<'tcx>,
1515
) {
16-
if intrinsic.name != rustc_span::sym::enzyme_autodiff {
16+
if intrinsic.name != rustc_span::sym::autodiff {
1717
return;
1818
};
1919

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ symbols! {
917917
enumerate_method,
918918
env,
919919
env_CFG_RELEASE: env!("CFG_RELEASE"),
920-
enzyme_autodiff,
920+
autodiff,
921921
eprint_macro,
922922
eprintln_macro,
923923
eq,

library/core/src/intrinsics/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3169,7 +3169,7 @@ pub const unsafe fn copysignf128(x: f128, y: f128) -> f128;
31693169
/// - `T`: A tuple of arguments passed to `df`.
31703170
/// - `R`: The return type of the derivative function.
31713171
///
3172-
/// This shows where the `enzyme_autodiff` intrinsic is used during macro expansion:
3172+
/// This shows where the `autodiff` intrinsic is used during macro expansion:
31733173
///
31743174
/// ```rust,ignore (macro example)
31753175
/// #[autodiff_forward(df1, Dual, Const, Dual)]
@@ -3188,12 +3188,12 @@ pub const unsafe fn copysignf128(x: f128, y: f128) -> f128;
31883188
/// }
31893189
/// #[rustc_autodiff(Forward, 1, Dual, Const, Dual)]
31903190
/// pub fn df1(x: &[f64], bx_0: &[f64], y: f64) -> (f64, f64) {
3191-
/// ::core::intrinsics::enzyme_autodiff(f1::<>, df1::<>, (x, bx_0, y))
3191+
/// ::core::intrinsics::autodiff(f1::<>, df1::<>, (x, bx_0, y))
31923192
/// }
31933193
/// ```
31943194
#[rustc_nounwind]
31953195
#[rustc_intrinsic]
3196-
pub const fn enzyme_autodiff<F, G, T: crate::marker::Tuple, R>(f: F, df: G, args: T) -> R;
3196+
pub const fn autodiff<F, G, T: crate::marker::Tuple, R>(f: F, df: G, args: T) -> R;
31973197

31983198
/// Inform Miri that a given pointer definitely has a certain alignment.
31993199
#[cfg(miri)]

tests/pretty/autodiff/autodiff_forward.pp

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,46 +36,43 @@
3636
}
3737
#[rustc_autodiff(Forward, 1, Dual, Const, Dual)]
3838
pub fn df1(x: &[f64], bx_0: &[f64], y: f64) -> (f64, f64) {
39-
::core::intrinsics::enzyme_autodiff(f1::<>, df1::<>, (x, bx_0, y))
39+
::core::intrinsics::autodiff(f1::<>, df1::<>, (x, bx_0, y))
4040
}
4141
#[rustc_autodiff]
4242
pub fn f2(x: &[f64], y: f64) -> f64 {
4343
::core::panicking::panic("not implemented")
4444
}
4545
#[rustc_autodiff(Forward, 1, Dual, Const, Const)]
4646
pub fn df2(x: &[f64], bx_0: &[f64], y: f64) -> f64 {
47-
::core::intrinsics::enzyme_autodiff(f2::<>, df2::<>, (x, bx_0, y))
47+
::core::intrinsics::autodiff(f2::<>, df2::<>, (x, bx_0, y))
4848
}
4949
#[rustc_autodiff]
5050
pub fn f3(x: &[f64], y: f64) -> f64 {
5151
::core::panicking::panic("not implemented")
5252
}
5353
#[rustc_autodiff(Forward, 1, Dual, Const, Const)]
5454
pub fn df3(x: &[f64], bx_0: &[f64], y: f64) -> f64 {
55-
::core::intrinsics::enzyme_autodiff(f3::<>, df3::<>, (x, bx_0, y))
55+
::core::intrinsics::autodiff(f3::<>, df3::<>, (x, bx_0, y))
5656
}
5757
#[rustc_autodiff]
5858
pub fn f4() {}
5959
#[rustc_autodiff(Forward, 1, None)]
60-
pub fn df4() -> () {
61-
::core::intrinsics::enzyme_autodiff(f4::<>, df4::<>, ())
62-
}
60+
pub fn df4() -> () { ::core::intrinsics::autodiff(f4::<>, df4::<>, ()) }
6361
#[rustc_autodiff]
6462
pub fn f5(x: &[f64], y: f64) -> f64 {
6563
::core::panicking::panic("not implemented")
6664
}
6765
#[rustc_autodiff(Forward, 1, Const, Dual, Const)]
6866
pub fn df5_y(x: &[f64], y: f64, by_0: f64) -> f64 {
69-
::core::intrinsics::enzyme_autodiff(f5::<>, df5_y::<>, (x, y, by_0))
67+
::core::intrinsics::autodiff(f5::<>, df5_y::<>, (x, y, by_0))
7068
}
7169
#[rustc_autodiff(Forward, 1, Dual, Const, Const)]
7270
pub fn df5_x(x: &[f64], bx_0: &[f64], y: f64) -> f64 {
73-
::core::intrinsics::enzyme_autodiff(f5::<>, df5_x::<>, (x, bx_0, y))
71+
::core::intrinsics::autodiff(f5::<>, df5_x::<>, (x, bx_0, y))
7472
}
7573
#[rustc_autodiff(Reverse, 1, Duplicated, Const, Active)]
7674
pub fn df5_rev(x: &[f64], dx_0: &mut [f64], y: f64, dret: f64) -> f64 {
77-
::core::intrinsics::enzyme_autodiff(f5::<>, df5_rev::<>,
78-
(x, dx_0, y, dret))
75+
::core::intrinsics::autodiff(f5::<>, df5_rev::<>, (x, dx_0, y, dret))
7976
}
8077
struct DoesNotImplDefault;
8178
#[rustc_autodiff]
@@ -84,53 +81,50 @@
8481
}
8582
#[rustc_autodiff(Forward, 1, Const)]
8683
pub fn df6() -> DoesNotImplDefault {
87-
::core::intrinsics::enzyme_autodiff(f6::<>, df6::<>, ())
84+
::core::intrinsics::autodiff(f6::<>, df6::<>, ())
8885
}
8986
#[rustc_autodiff]
9087
pub fn f7(x: f32) -> () {}
9188
#[rustc_autodiff(Forward, 1, Const, None)]
9289
pub fn df7(x: f32) -> () {
93-
::core::intrinsics::enzyme_autodiff(f7::<>, df7::<>, (x,))
90+
::core::intrinsics::autodiff(f7::<>, df7::<>, (x,))
9491
}
9592
#[no_mangle]
9693
#[rustc_autodiff]
9794
fn f8(x: &f32) -> f32 { ::core::panicking::panic("not implemented") }
9895
#[rustc_autodiff(Forward, 4, Dual, Dual)]
9996
fn f8_3(x: &f32, bx_0: &f32, bx_1: &f32, bx_2: &f32, bx_3: &f32)
10097
-> [f32; 5usize] {
101-
::core::intrinsics::enzyme_autodiff(f8::<>, f8_3::<>,
98+
::core::intrinsics::autodiff(f8::<>, f8_3::<>,
10299
(x, bx_0, bx_1, bx_2, bx_3))
103100
}
104101
#[rustc_autodiff(Forward, 4, Dual, DualOnly)]
105102
fn f8_2(x: &f32, bx_0: &f32, bx_1: &f32, bx_2: &f32, bx_3: &f32)
106103
-> [f32; 4usize] {
107-
::core::intrinsics::enzyme_autodiff(f8::<>, f8_2::<>,
104+
::core::intrinsics::autodiff(f8::<>, f8_2::<>,
108105
(x, bx_0, bx_1, bx_2, bx_3))
109106
}
110107
#[rustc_autodiff(Forward, 1, Dual, DualOnly)]
111108
fn f8_1(x: &f32, bx_0: &f32) -> f32 {
112-
::core::intrinsics::enzyme_autodiff(f8::<>, f8_1::<>, (x, bx_0))
109+
::core::intrinsics::autodiff(f8::<>, f8_1::<>, (x, bx_0))
113110
}
114111
pub fn f9() {
115112
#[rustc_autodiff]
116113
fn inner(x: f32) -> f32 { x * x }
117114
#[rustc_autodiff(Forward, 1, Dual, Dual)]
118115
fn d_inner_2(x: f32, bx_0: f32) -> (f32, f32) {
119-
::core::intrinsics::enzyme_autodiff(inner::<>, d_inner_2::<>,
120-
(x, bx_0))
116+
::core::intrinsics::autodiff(inner::<>, d_inner_2::<>, (x, bx_0))
121117
}
122118
#[rustc_autodiff(Forward, 1, Dual, DualOnly)]
123119
fn d_inner_1(x: f32, bx_0: f32) -> f32 {
124-
::core::intrinsics::enzyme_autodiff(inner::<>, d_inner_1::<>,
125-
(x, bx_0))
120+
::core::intrinsics::autodiff(inner::<>, d_inner_1::<>, (x, bx_0))
126121
}
127122
}
128123
#[rustc_autodiff]
129124
pub fn f10<T: std::ops::Mul<Output = T> + Copy>(x: &T) -> T { *x * *x }
130125
#[rustc_autodiff(Reverse, 1, Duplicated, Active)]
131126
pub fn d_square<T: std::ops::Mul<Output = T> +
132127
Copy>(x: &T, dx_0: &mut T, dret: T) -> T {
133-
::core::intrinsics::enzyme_autodiff(f10::<T>, d_square::<T>,
134-
(x, dx_0, dret))
128+
::core::intrinsics::autodiff(f10::<T>, d_square::<T>, (x, dx_0, dret))
135129
}
136130
fn main() {}

tests/pretty/autodiff/autodiff_reverse.pp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,34 +29,32 @@
2929
}
3030
#[rustc_autodiff(Reverse, 1, Duplicated, Const, Active)]
3131
pub fn df1(x: &[f64], dx_0: &mut [f64], y: f64, dret: f64) -> f64 {
32-
::core::intrinsics::enzyme_autodiff(f1::<>, df1::<>, (x, dx_0, y, dret))
32+
::core::intrinsics::autodiff(f1::<>, df1::<>, (x, dx_0, y, dret))
3333
}
3434
#[rustc_autodiff]
3535
pub fn f2() {}
3636
#[rustc_autodiff(Reverse, 1, None)]
37-
pub fn df2() { ::core::intrinsics::enzyme_autodiff(f2::<>, df2::<>, ()) }
37+
pub fn df2() { ::core::intrinsics::autodiff(f2::<>, df2::<>, ()) }
3838
#[rustc_autodiff]
3939
pub fn f3(x: &[f64], y: f64) -> f64 {
4040
::core::panicking::panic("not implemented")
4141
}
4242
#[rustc_autodiff(Reverse, 1, Duplicated, Const, Active)]
4343
pub fn df3(x: &[f64], dx_0: &mut [f64], y: f64, dret: f64) -> f64 {
44-
::core::intrinsics::enzyme_autodiff(f3::<>, df3::<>, (x, dx_0, y, dret))
44+
::core::intrinsics::autodiff(f3::<>, df3::<>, (x, dx_0, y, dret))
4545
}
4646
enum Foo { Reverse, }
4747
use Foo::Reverse;
4848
#[rustc_autodiff]
4949
pub fn f4(x: f32) { ::core::panicking::panic("not implemented") }
5050
#[rustc_autodiff(Reverse, 1, Const, None)]
51-
pub fn df4(x: f32) {
52-
::core::intrinsics::enzyme_autodiff(f4::<>, df4::<>, (x,))
53-
}
51+
pub fn df4(x: f32) { ::core::intrinsics::autodiff(f4::<>, df4::<>, (x,)) }
5452
#[rustc_autodiff]
5553
pub fn f5(x: *const f32, y: &f32) {
5654
::core::panicking::panic("not implemented")
5755
}
5856
#[rustc_autodiff(Reverse, 1, DuplicatedOnly, Duplicated, None)]
5957
pub unsafe fn df5(x: *const f32, dx_0: *mut f32, y: &f32, dy_0: &mut f32) {
60-
::core::intrinsics::enzyme_autodiff(f5::<>, df5::<>, (x, dx_0, y, dy_0))
58+
::core::intrinsics::autodiff(f5::<>, df5::<>, (x, dx_0, y, dy_0))
6159
}
6260
fn main() {}

tests/pretty/autodiff/inherent_impl.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
}
3232
#[rustc_autodiff(Reverse, 1, Const, Active, Active)]
3333
fn df(&self, x: f64, dret: f64) -> (f64, f64) {
34-
::core::intrinsics::enzyme_autodiff(Self::f::<>, Self::df::<>,
34+
::core::intrinsics::autodiff(Self::f::<>, Self::df::<>,
3535
(self, x, dret))
3636
}
3737
}

0 commit comments

Comments
 (0)