Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2b6b22c

Browse files
ZuseZ4bytesnake
andcommittedOct 11, 2024
Single commit implementing the enzyme/autodiff frontend
Co-authored-by: Lorenz Schmidt <bytesnake@mailbox.org>
1 parent 7fdd545 commit 2b6b22c

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed
 

‎core/src/lib.rs

+9
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,15 @@ pub mod assert_matches {
278278
pub use crate::macros::{assert_matches, debug_assert_matches};
279279
}
280280

281+
// We don't export this through #[macro_export] for now, to avoid breakage.
282+
#[cfg(not(bootstrap))]
283+
#[unstable(feature = "autodiff", issue = "124509")]
284+
/// Unstable module containing the unstable `autodiff` macro.
285+
pub mod autodiff {
286+
#[unstable(feature = "autodiff", issue = "124509")]
287+
pub use crate::macros::builtin::autodiff;
288+
}
289+
281290
#[unstable(feature = "cfg_match", issue = "115585")]
282291
pub use crate::macros::cfg_match;
283292

‎core/src/macros/mod.rs

+18
Original file line numberDiff line numberDiff line change
@@ -1539,6 +1539,24 @@ pub(crate) mod builtin {
15391539
($file:expr $(,)?) => {{ /* compiler built-in */ }};
15401540
}
15411541

1542+
/// Automatic Differentiation macro which allows generating a new function to compute
1543+
/// the derivative of a given function. It may only be applied to a function.
1544+
/// The expected usage syntax is
1545+
/// `#[autodiff(NAME, MODE, INPUT_ACTIVITIES, OUTPUT_ACTIVITY)]`
1546+
/// where:
1547+
/// NAME is a string that represents a valid function name.
1548+
/// MODE is any of Forward, Reverse, ForwardFirst, ReverseFirst.
1549+
/// INPUT_ACTIVITIES consists of one valid activity for each input parameter.
1550+
/// OUTPUT_ACTIVITY must not be set if we implicitely return nothing (or explicitely return
1551+
/// `-> ()`. Otherwise it must be set to one of the allowed activities.
1552+
#[unstable(feature = "autodiff", issue = "124509")]
1553+
#[allow_internal_unstable(rustc_attrs)]
1554+
#[rustc_builtin_macro]
1555+
#[cfg(not(bootstrap))]
1556+
pub macro autodiff($item:item) {
1557+
/* compiler built-in */
1558+
}
1559+
15421560
/// Asserts that a boolean expression is `true` at runtime.
15431561
///
15441562
/// This will invoke the [`panic!`] macro if the provided expression cannot be

‎std/src/lib.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@
267267
#![allow(unused_features)]
268268
//
269269
// Features:
270+
#![cfg_attr(not(bootstrap), feature(autodiff))]
270271
#![cfg_attr(test, feature(internal_output_capture, print_internals, update_panic_count, rt))]
271272
#![cfg_attr(
272273
all(target_vendor = "fortanix", target_env = "sgx"),
@@ -627,7 +628,13 @@ pub mod simd {
627628
#[doc(inline)]
628629
pub use crate::std_float::StdFloat;
629630
}
630-
631+
#[cfg(not(bootstrap))]
632+
#[unstable(feature = "autodiff", issue = "124509")]
633+
/// This module provides support for automatic differentiation.
634+
pub mod autodiff {
635+
/// This macro handles automatic differentiation.
636+
pub use core::autodiff::autodiff;
637+
}
631638
#[stable(feature = "futures_api", since = "1.36.0")]
632639
pub mod task {
633640
//! Types and Traits for working with asynchronous tasks.

0 commit comments

Comments
 (0)
Failed to load comments.