adding a working rlib autodiff test
This commit is contained in:
parent
0dfdb6c3da
commit
2d1fc63101
4 changed files with 94 additions and 0 deletions
7
tests/run-make/autodiff/rlib/dep.rs
Normal file
7
tests/run-make/autodiff/rlib/dep.rs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
pub fn f(x: f64, y: f64) -> f64 {
|
||||
2.0 * x + y
|
||||
}
|
||||
|
||||
pub fn g(x: f64) -> f64 {
|
||||
2.0 * x
|
||||
}
|
||||
13
tests/run-make/autodiff/rlib/lib.rs
Normal file
13
tests/run-make/autodiff/rlib/lib.rs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#![feature(autodiff)]
|
||||
extern crate simple_dep;
|
||||
use std::autodiff::*;
|
||||
|
||||
#[inline(never)]
|
||||
pub fn f2(x: f64) -> f64 {
|
||||
x.sin()
|
||||
}
|
||||
|
||||
#[autodiff_forward(df1_lib, Dual, Dual)]
|
||||
pub fn _f1(x: f64) -> f64 {
|
||||
simple_dep::f(x, x) * f2(x)
|
||||
}
|
||||
8
tests/run-make/autodiff/rlib/main.rs
Normal file
8
tests/run-make/autodiff/rlib/main.rs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
extern crate foo;
|
||||
|
||||
fn main() {
|
||||
//dbg!("Running main.rs");
|
||||
let enzyme_y1_lib = foo::df1_lib(1.5, 1.0);
|
||||
println!("output1: {:?}", enzyme_y1_lib.0);
|
||||
println!("output2: {:?}", enzyme_y1_lib.1);
|
||||
}
|
||||
66
tests/run-make/autodiff/rlib/rmake.rs
Normal file
66
tests/run-make/autodiff/rlib/rmake.rs
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
//@ needs-enzyme
|
||||
//@ ignore-cross-compile
|
||||
|
||||
use run_make_support::{cwd, run, rustc};
|
||||
|
||||
fn main() {
|
||||
// Build the dependency crate.
|
||||
rustc()
|
||||
.input("dep.rs")
|
||||
.arg("-Zautodiff=Enable")
|
||||
.arg("--edition=2024")
|
||||
.arg("-Copt-level=3")
|
||||
.arg("--crate-name=simple_dep")
|
||||
.arg("-Clinker-plugin-lto")
|
||||
.arg("--crate-type=lib")
|
||||
.emit("dep-info,metadata,link")
|
||||
.run();
|
||||
|
||||
let cwd = cwd();
|
||||
let cwd_str = cwd.to_string_lossy();
|
||||
|
||||
let mydep = format!("-Ldependency={cwd_str}");
|
||||
|
||||
let simple_dep_rlib =
|
||||
format!("--extern=simple_dep={}", cwd.join("libsimple_dep.rlib").to_string_lossy());
|
||||
|
||||
// Build the main library that depends on `simple_dep`.
|
||||
rustc()
|
||||
.input("lib.rs")
|
||||
.arg("-Zautodiff=Enable")
|
||||
.arg("--edition=2024")
|
||||
.arg("-Copt-level=3")
|
||||
.arg("--crate-name=foo")
|
||||
.arg("-Clinker-plugin-lto")
|
||||
.arg("--crate-type=lib")
|
||||
.emit("dep-info,metadata,link")
|
||||
.arg(&mydep)
|
||||
.arg(&simple_dep_rlib)
|
||||
.run();
|
||||
|
||||
let foo_rlib = format!("--extern=foo={}", cwd.join("libfoo.rlib").to_string_lossy());
|
||||
|
||||
// Build the final binary linking both rlibs.
|
||||
rustc()
|
||||
.input("main.rs")
|
||||
.arg("-Zautodiff=Enable")
|
||||
.arg("--edition=2024")
|
||||
.arg("-Copt-level=3")
|
||||
.arg("--crate-name=foo")
|
||||
.arg("-Clto=fat")
|
||||
.arg("--crate-type=bin")
|
||||
.emit("dep-info,link")
|
||||
.arg(&mydep)
|
||||
.arg(&foo_rlib)
|
||||
.arg(&simple_dep_rlib)
|
||||
.run();
|
||||
|
||||
// Run the binary and check its output.
|
||||
let binary = run("foo");
|
||||
assert!(binary.status().success(), "binary failed to run");
|
||||
|
||||
let binary_out = binary.stdout();
|
||||
let output = String::from_utf8_lossy(&binary_out);
|
||||
assert!(output.contains("output1: 4.488727439718245"));
|
||||
assert!(output.contains("output2: 3.3108023673168265"));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue