|
| 1 | +#![feature(rustc_attrs)] |
| 2 | +#![feature(prelude_import)] |
| 3 | +#![feature(panic_internals)] |
| 4 | +#![no_std] |
| 5 | +//@ needs-enzyme |
| 6 | +#![feature(autodiff)] |
| 7 | +#[prelude_import] |
| 8 | +use ::std::prelude::rust_2015::*; |
| 9 | +#[macro_use] |
| 10 | +extern crate std; |
| 11 | +//@ pretty-mode:expanded |
| 12 | +//@ pretty-compare-only |
| 13 | +//@ pp-exact:batching.pp |
| 14 | + |
| 15 | + |
| 16 | +// Test that forward mode ad macros are expanded correctly. |
| 17 | +use std::arch::asm; |
| 18 | +use std::autodiff::autodiff; |
| 19 | + |
| 20 | +#[no_mangle] |
| 21 | +#[rustc_autodiff] |
| 22 | +#[inline(never)] |
| 23 | +fn square(x: &f32) -> f32 { |
| 24 | + x * x |
| 25 | +} |
| 26 | +#[rustc_autodiff(Forward, 4, Dual, Dual)] |
| 27 | +#[inline(never)] |
| 28 | +fn d_square1(x: &f32, bx_0: &f32, bx_1: &f32, bx_2: &f32, bx_3: &f32) -> [f32; 5usize] { |
| 29 | + unsafe { |
| 30 | + asm!("NOP", options(nomem)); |
| 31 | + }; |
| 32 | + ::core::hint::black_box(square(x)); |
| 33 | + ::core::hint::black_box((bx_0, bx_1, bx_2, bx_3)); |
| 34 | + ::core::hint::black_box(<[f32; 5usize]>::default()) |
| 35 | +} |
| 36 | +#[rustc_autodiff(Forward, 4, Dual, DualOnly)] |
| 37 | +#[inline(never)] |
| 38 | +fn d_square2(x: &f32, bx_0: &f32, bx_1: &f32, bx_2: &f32, bx_3: &f32) -> [f32; 4usize] { |
| 39 | + unsafe { |
| 40 | + asm!("NOP", options(nomem)); |
| 41 | + }; |
| 42 | + ::core::hint::black_box(square(x)); |
| 43 | + ::core::hint::black_box((bx_0, bx_1, bx_2, bx_3)); |
| 44 | + ::core::hint::black_box(<[f32; 4usize]>::default()) |
| 45 | +} |
| 46 | + |
| 47 | + |
| 48 | +fn main() {} |
0 commit comments