Skip to content
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

adding rust ADBench version #1797

Closed
wants to merge 90 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
9770ceb
adding gmm
ZuseZ4 Mar 19, 2024
9f05ff8
working C too
ZuseZ4 Mar 25, 2024
4da9910
Delete enzyme/benchmarks/ReverseMode/gmmrs/src/main.rs2
ZuseZ4 Mar 26, 2024
0f68ce8
rust setup
wsmoses Mar 28, 2024
7995eb3
add files
wsmoses Mar 28, 2024
069e3cb
improve makefile and fix c ffi
ZuseZ4 Mar 29, 2024
be54358
maybe needed? pthread for cmake
ZuseZ4 Mar 30, 2024
4423222
bench gmm: use path relative to Makefile
jedbrown Mar 30, 2024
7b5a24c
Fix byref issue for rust abi
wsmoses Mar 31, 2024
ea03750
Add primal bench/test
wsmoses Mar 31, 2024
77a130f
fix math
ZuseZ4 Mar 31, 2024
4abf2bf
write into return var
ZuseZ4 Mar 31, 2024
5cde3d7
Cleanup gmm config
wsmoses Mar 31, 2024
af6583d
bench gmm: make cmath::lgamma with libm as an optional feature
jedbrown Mar 31, 2024
48c2e1f
oxidize - more noalias
ZuseZ4 Mar 31, 2024
ba75484
reduce caching
ZuseZ4 Mar 31, 2024
9394028
bench gmm: makefile dep on Cargo.toml, split targets
jedbrown Mar 31, 2024
814eb62
revert cmake pthread since only needed for Rust
ZuseZ4 Mar 31, 2024
41157fa
bench gmm: fix primal (sqnorm length matters)
jedbrown Mar 31, 2024
114f236
bench gmm: quash rust warnings
jedbrown Mar 31, 2024
012cf4c
adding ba benchmark
ZuseZ4 Mar 31, 2024
0430e44
Benchmark ba
wsmoses Apr 1, 2024
4b0062b
fix ba primal
ZuseZ4 Apr 2, 2024
1f27479
adding unsafe gmm version
ZuseZ4 Apr 4, 2024
af3e078
Add FFT and LSTM benchmark for Rust Enzyme
bytesnake Apr 4, 2024
c8bcfe9
adding unsafe Rust fft version (how to run?)
ZuseZ4 Apr 4, 2024
cad4221
imprv safe rus tto work like c++
ZuseZ4 Apr 4, 2024
f0bf16b
unsafe version not crashing
ZuseZ4 Apr 4, 2024
12e9a4a
fix lstm makefile
ZuseZ4 Apr 4, 2024
688721d
adding unsafe rust lstm version
ZuseZ4 Apr 4, 2024
7ca8092
run full fft tests
ZuseZ4 Apr 4, 2024
73f8075
Delete enzyme/benchmarks/ReverseMode/lstm/src/main.rs
ZuseZ4 Apr 5, 2024
ba3aa5d
cleanup and correctness
ZuseZ4 Apr 6, 2024
2737734
initial (compiling) rust ode version
ZuseZ4 May 6, 2024
1ffbaaa
cleanups
ZuseZ4 May 6, 2024
8bd316a
fix ba bench
ZuseZ4 May 22, 2024
c769dac
bench gmm: move allocation of scratch space outside AD'd function
jedbrown May 23, 2024
c5e1f19
bench gmm: switch scratch from Const to Duplicated
jedbrown May 23, 2024
947852c
bench gmm: match C++ performance by asserting sizes of work slices
jedbrown May 23, 2024
cb9d403
bench gmm: shed unused import (warning)
jedbrown May 23, 2024
dbffef6
bench lstm: optimize using length assertions
jedbrown May 23, 2024
0174227
adding unsafe ba version
ZuseZ4 May 24, 2024
629f87c
smaller perf improvements
ZuseZ4 Jun 2, 2024
c6f44b3
small improvment
ZuseZ4 Jun 2, 2024
fb6df5b
clean up ode-real example (not building)
ZuseZ4 Jun 3, 2024
a6d4a7c
add ba.cpp version without restrict
ZuseZ4 Jul 20, 2024
d08142b
add gmm version without restrict
ZuseZ4 Jul 20, 2024
d6b35b3
add lstm version without restrict
ZuseZ4 Jul 20, 2024
55a76b9
Revert "smaller perf improvements"
ZuseZ4 Jul 22, 2024
de87081
adding lstm primal cxx overhead benchmark
ZuseZ4 Jul 22, 2024
5d9b026
Merge branch 'main' into rust-bench
ZuseZ4 Sep 18, 2024
7d70dc5
fix ode-real example, correct results, faster than c++, without dupno…
ZuseZ4 Sep 19, 2024
fdb0d09
remove boost leftovers
ZuseZ4 Sep 19, 2024
747e4f9
fix makefiles to use new rustflags
ZuseZ4 Oct 1, 2024
05d3e87
add tanh support for llvm19+
ZuseZ4 Oct 2, 2024
1fe64c0
fix safe fft performance
ZuseZ4 Oct 2, 2024
7f26f43
fix (mostly) safe lstm perf
ZuseZ4 Oct 2, 2024
7ecd27b
make lstm benchmark fair by running c++ with O3
ZuseZ4 Oct 24, 2024
aaef8b3
make ba bench fair by running c++ with O3
ZuseZ4 Oct 24, 2024
51ef17a
make ode-real/bruss fair by adjusting both
ZuseZ4 Oct 24, 2024
9c9f276
equalize benchmark configs and move over to new use std::autodiff::au…
ZuseZ4 Oct 27, 2024
5ebcd1e
move Rust to DuplicatedOnly
ZuseZ4 Oct 27, 2024
aeed32d
cleanup makefiles
ZuseZ4 Oct 28, 2024
1542a38
update fft-tapenade to be correct but segfault
ZuseZ4 Oct 28, 2024
047f121
add mayalias/unsafe ode-real/BRUSS benchmark versions
ZuseZ4 Oct 30, 2024
3d25858
fix safe fft performance
ZuseZ4 Oct 30, 2024
2d04892
cleanup fft
ZuseZ4 Oct 30, 2024
a273bdf
bench fft: more idiomatic safe Rust
jedbrown Oct 31, 2024
65e1eaf
bench fft: use size_t in C++ for parity with Rust usize
jedbrown Oct 31, 2024
609bf4d
bench fft: move from i+=2 to ii++ in loop increments
jedbrown Oct 31, 2024
b722c87
move rust fft to use i32 for isign
ZuseZ4 Oct 31, 2024
a7943f0
safe rust fft without bounds checking
ZuseZ4 Nov 1, 2024
59f866b
Add -fno-math-errno to each makefile for fairness
ZuseZ4 Nov 1, 2024
119c2ac
Merge branch 'main' into rust-bench
jedbrown Nov 1, 2024
6460848
bench fft: __builtin_sin not necessary with -fno-math-errno
jedbrown Nov 1, 2024
3b174ea
move c++ lstm to also use size_t, since Rust uses usize
ZuseZ4 Nov 6, 2024
8945897
adjust gmm, but breaks tapenade
ZuseZ4 Nov 7, 2024
a73a1ad
Revert "move c++ lstm to also use size_t, since Rust uses usize"
ZuseZ4 Nov 9, 2024
dca82bb
fix single gmm size for benchmarking
ZuseZ4 Nov 9, 2024
f7c75a2
safe lstm without alias info
ZuseZ4 Nov 9, 2024
06b135f
use new flag to keep const ptr/ref while still not emitting noalias
ZuseZ4 Nov 9, 2024
74a3784
make safe fft safe again
ZuseZ4 Nov 9, 2024
ba7cf82
bench fft: cleaner to use step_by(2)
jedbrown Nov 9, 2024
d5bd596
bench gmm: fix Tapenade
jedbrown Nov 13, 2024
4d78820
bench gmm: fix C++ primal (negative size_t)
jedbrown Nov 13, 2024
13ef016
bench fft: avoid bounds checks in safe Rust
jedbrown Nov 1, 2024
9f67bd1
update fft to make benchmarking more reliable, make safe rust version…
ZuseZ4 Nov 15, 2024
88feab6
improve lstm output, makefiles
ZuseZ4 Nov 15, 2024
31fd712
bench fft: closer C++ code to Rust and use -fno-plt
jedbrown Nov 15, 2024
abf2a26
more numactl
ZuseZ4 Nov 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 25 additions & 24 deletions enzyme/benchmarks/ReverseMode/fft/src/safe.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
use std::slice;
use std::f64::consts::PI;
use std::autodiff::autodiff;
use std::f64::consts::PI;
use std::slice;

fn bitreversal_perm<T>(data: &mut [T]) {
let len = data.len() / 2;
let mut j = 1;

let mut i = 1;
while i < 2*len {
while i < 2 * len {
if j > i {
//dbg!(&i, &j);
//data.swap(j-1, i-1);
//data.swap(j, i);
unsafe {data.swap_unchecked(j-1, i-1);}
unsafe {data.swap_unchecked(j, i);}
unsafe {
data.swap_unchecked(j - 1, i - 1);
}
unsafe {
data.swap_unchecked(j, i);
}
}

let mut m = len;
Expand All @@ -27,37 +31,35 @@ fn bitreversal_perm<T>(data: &mut [T]) {
}
}

fn radix2(data: &mut [f64], i_sign: f64, n: usize) {
fn radix2(data: &mut [f64], i_sign: f64) {
let n = data.len() / 2;
if n == 1 {
return;
}

let (a,b) = data.split_at_mut(n);
radix2(a, i_sign, n/2);
radix2(b, i_sign, n/2);
let (a, b) = data.split_at_mut(n);
radix2(a, i_sign);
radix2(b, i_sign);

let wtemp = i_sign * (PI / n as f64).sin();
let wpi = -i_sign * (2.0 * PI / n as f64).sin();
let wpr = -2.0 * wtemp * wtemp;
let mut wr = 1.0;
let mut wi = 0.0;

assert_eq!(data.len(), 2*n);
for i in (0..n).step_by(2) {
let in_n = i + n;
let tempr = data[in_n] * wr - data[in_n + 1] * wi;
let tempi = data[in_n] * wi + data[in_n + 1] * wr;
for i in (0..n).step_by(2) {
let tempr = b[i] * wr - b[i + 1] * wi;
let tempi = b[i] * wi + b[i + 1] * wr;

data[in_n] = data[i] - tempr;
data[in_n + 1] = data[i + 1] - tempi;
data[i] += tempr;
data[i + 1] += tempi;
b[i] = a[i] - tempr;
b[i + 1] = a[i + 1] - tempi;
a[i] += tempr;
a[i + 1] += tempi;

let wtemp_new = wr;
wr += wr * wpr - wi * wpi;
wi += wi * wpr + wtemp_new * wpi;
}

}
Copy link
Collaborator

@jedbrown jedbrown Oct 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ZuseZ4 Let me know if you don't like this and I'll remove it. (Other changes in this commit are just rustfmt/whitespace.)


fn rescale(data: &mut [f64], scale: usize) {
Expand All @@ -69,12 +71,12 @@ fn rescale(data: &mut [f64], scale: usize) {

fn fft(data: &mut [f64]) {
bitreversal_perm(data);
radix2(data, 1.0, data.len() / 2);
radix2(data, 1.0);
}

fn ifft(data: &mut [f64]) {
bitreversal_perm(data);
radix2(data, -1.0, data.len() / 2);
radix2(data, -1.0);
rescale(data, data.len() / 2);
}

Expand All @@ -86,15 +88,14 @@ pub fn foobar(data: &mut [f64]) {

#[no_mangle]
pub extern "C" fn rust_dfoobar(n: usize, data: *mut f64, ddata: *mut f64) {

let (data, ddata) = unsafe {
(
slice::from_raw_parts_mut(data, n * 2),
slice::from_raw_parts_mut(ddata, n * 2)
slice::from_raw_parts_mut(ddata, n * 2),
)
};

unsafe {dfoobar(data, ddata)};
unsafe { dfoobar(data, ddata) };
}

#[no_mangle]
Expand Down