Skip to content

Commit bd70be1

Browse files
committed
Add TypeTree tests for scalar types
- Add specific tests for f32, f64, i32, f16, f128 TypeTree generation - Verify correct enzyme_type metadata for each scalar type - Ensure TypeTree metadata matches expected Enzyme format Signed-off-by: Karan Janthe <[email protected]>
1 parent acbf6a9 commit bd70be1

File tree

15 files changed

+154
-0
lines changed

15 files changed

+154
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
; Check that f128 TypeTree metadata is correctly generated
2+
; f128 maps to Unknown in our current implementation since CConcreteType doesn't have DT_F128
3+
4+
CHECK: define{{.*}}"enzyme_type"={{.*}}@test_f128{{.*}}"enzyme_type"="{[]:Pointer}"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//@ needs-enzyme
2+
//@ ignore-cross-compile
3+
4+
use run_make_support::{llvm_filecheck, rfs, rustc};
5+
6+
fn main() {
7+
// Compile with TypeTree enabled and emit LLVM IR
8+
rustc().input("test.rs").arg("-Zautodiff=Enable").emit("llvm-ir").run();
9+
10+
// Check that f128 TypeTree metadata is correctly generated
11+
llvm_filecheck().patterns("f128.check").stdin_buf(rfs::read("test.ll")).run();
12+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#![feature(autodiff, f128)]
2+
3+
use std::autodiff::autodiff_reverse;
4+
5+
#[autodiff_reverse(d_test, Duplicated, Active)]
6+
#[no_mangle]
7+
fn test_f128(x: &f128) -> f128 {
8+
*x * *x
9+
}
10+
11+
fn main() {
12+
let x = 2.0_f128;
13+
let mut dx = 0.0_f128;
14+
let _result = d_test(&x, &mut dx, 1.0);
15+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
; Check that f16 TypeTree metadata is correctly generated
2+
; Should show Half for f16 values and Pointer for references
3+
4+
CHECK: define{{.*}}"enzyme_type"={{.*}}@test_f16{{.*}}"enzyme_type"="{[]:Pointer}"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//@ needs-enzyme
2+
//@ ignore-cross-compile
3+
4+
use run_make_support::{llvm_filecheck, rfs, rustc};
5+
6+
fn main() {
7+
// Compile with TypeTree enabled and emit LLVM IR
8+
rustc().input("test.rs").arg("-Zautodiff=Enable").emit("llvm-ir").run();
9+
10+
// Check that f16 TypeTree metadata is correctly generated
11+
llvm_filecheck().patterns("f16.check").stdin_buf(rfs::read("test.ll")).run();
12+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#![feature(autodiff, f16)]
2+
3+
use std::autodiff::autodiff_reverse;
4+
5+
#[autodiff_reverse(d_test, Duplicated, Active)]
6+
#[no_mangle]
7+
fn test_f16(x: &f16) -> f16 {
8+
*x * *x
9+
}
10+
11+
fn main() {
12+
let x = 2.0_f16;
13+
let mut dx = 0.0_f16;
14+
let _result = d_test(&x, &mut dx, 1.0);
15+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
; Check that f32 TypeTree metadata is correctly generated
2+
; Should show Float@float for f32 values and Pointer for references
3+
4+
CHECK: define{{.*}}"enzyme_type"="{[]:Float@float}"{{.*}}@test_f32{{.*}}"enzyme_type"="{[]:Pointer}"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//@ needs-enzyme
2+
//@ ignore-cross-compile
3+
4+
use run_make_support::{llvm_filecheck, rfs, rustc};
5+
6+
fn main() {
7+
// Compile with TypeTree enabled and emit LLVM IR
8+
rustc().input("test.rs").arg("-Zautodiff=Enable").emit("llvm-ir").run();
9+
10+
// Check that f32 TypeTree metadata is correctly generated
11+
llvm_filecheck().patterns("f32.check").stdin_buf(rfs::read("test.ll")).run();
12+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#![feature(autodiff)]
2+
3+
use std::autodiff::autodiff_reverse;
4+
5+
#[autodiff_reverse(d_test, Duplicated, Active)]
6+
#[no_mangle]
7+
fn test_f32(x: &f32) -> f32 {
8+
x * x
9+
}
10+
11+
fn main() {
12+
let x = 2.0_f32;
13+
let mut dx = 0.0_f32;
14+
let _result = d_test(&x, &mut dx, 1.0);
15+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
; Check that f64 TypeTree metadata is correctly generated
2+
; Should show Float@double for f64 values and Pointer for references
3+
4+
CHECK: define{{.*}}"enzyme_type"="{[]:Float@double}"{{.*}}@test_f64{{.*}}"enzyme_type"="{[]:Pointer}"

0 commit comments

Comments
 (0)