Skip to content

Commit 75a4f91

Browse files
committed
Auto merge of rust-lang#140799 - EnzymeAD:enzyme-static, r=<try>
[DO NOT MERGE] build Enzyme as archive r? ghost try-job: dist-aarch64-apple
2 parents 1973872 + 8102bba commit 75a4f91

File tree

6 files changed

+28
-28
lines changed

6 files changed

+28
-28
lines changed

src/bootstrap/src/core/build_steps/compile.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1192,7 +1192,7 @@ pub fn rustc_cargo(
11921192

11931193
if let Some(llvm_config) = builder.llvm_config(builder.config.build) {
11941194
let llvm_version_major = llvm::get_llvm_version_major(builder, &llvm_config);
1195-
cargo.rustflag("-l").rustflag(&format!("Enzyme-{llvm_version_major}"));
1195+
cargo.rustflag("-l").rustflag(&format!("EnzymeStatic-{llvm_version_major}"));
11961196
}
11971197
}
11981198

@@ -2065,15 +2065,15 @@ impl Step for Assemble {
20652065
let enzyme_install = builder.ensure(llvm::Enzyme { target: build_compiler.host });
20662066
let llvm_config = builder.llvm_config(builder.config.build).unwrap();
20672067
let llvm_version_major = llvm::get_llvm_version_major(builder, &llvm_config);
2068-
let lib_ext = std::env::consts::DLL_EXTENSION;
2069-
let libenzyme = format!("libEnzyme-{llvm_version_major}");
2068+
let archive_ext = "a";
2069+
let libenzyme = format!("libEnzymeStatic-{llvm_version_major}");
20702070
let src_lib =
2071-
enzyme_install.join("build/Enzyme").join(&libenzyme).with_extension(lib_ext);
2071+
enzyme_install.join("build/Enzyme").join(&libenzyme).with_extension(archive_ext);
20722072
let libdir = builder.sysroot_target_libdir(build_compiler, build_compiler.host);
20732073
let target_libdir =
20742074
builder.sysroot_target_libdir(target_compiler, target_compiler.host);
2075-
let dst_lib = libdir.join(&libenzyme).with_extension(lib_ext);
2076-
let target_dst_lib = target_libdir.join(&libenzyme).with_extension(lib_ext);
2075+
let dst_lib = libdir.join(&libenzyme).with_extension(archive_ext);
2076+
let target_dst_lib = target_libdir.join(&libenzyme).with_extension(archive_ext);
20772077
builder.copy_link(&src_lib, &dst_lib, FileType::NativeLibrary);
20782078
builder.copy_link(&src_lib, &target_dst_lib, FileType::NativeLibrary);
20792079
}

src/bootstrap/src/core/build_steps/llvm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,6 @@ impl Step for Llvm {
536536
}
537537
};
538538

539-
// FIXME(ZuseZ4): Do we need that for Enzyme too?
540539
// When building LLVM with LLVM_LINK_LLVM_DYLIB for macOS, an unversioned
541540
// libLLVM.dylib will be built. However, llvm-config will still look
542541
// for a versioned path like libLLVM-14.dylib. Manually create a symbolic
@@ -970,6 +969,7 @@ impl Step for Enzyme {
970969
.env("LLVM_CONFIG_REAL", &llvm_config)
971970
.define("LLVM_ENABLE_ASSERTIONS", "ON")
972971
.define("ENZYME_EXTERNAL_SHARED_LIB", "ON")
972+
.define("ENZYME_STATIC_LIB", "ON")
973973
.define("LLVM_DIR", builder.llvm_out(target));
974974

975975
cfg.build();

src/ci/docker/host-aarch64/dist-aarch64-linux/Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ ENV RUST_CONFIGURE_ARGS \
8989
--set llvm.thin-lto=true \
9090
--set llvm.libzstd=true \
9191
--set llvm.ninja=false \
92+
--set llvm.enzyme=true \
9293
--set rust.debug-assertions=false \
9394
--set rust.jemalloc \
9495
--set rust.use-lld=true \

src/ci/github-actions/jobs.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ auto:
382382
- name: dist-x86_64-apple
383383
env:
384384
SCRIPT: ./x.py dist bootstrap --include-default-paths --host=x86_64-apple-darwin --target=x86_64-apple-darwin
385-
RUST_CONFIGURE_ARGS: --enable-full-tools --enable-sanitizers --enable-profiler --set rust.jemalloc --set rust.lto=thin --set rust.codegen-units=1
385+
RUST_CONFIGURE_ARGS: --enable-full-tools --enable-sanitizers --enable-profiler --set rust.jemalloc --set rust.lto=thin --set llvm.enzyme=true --set rust.codegen-units=1
386386
RUSTC_RETRY_LINKER_ON_SEGFAULT: 1
387387
# Ensure that host tooling is built to support our minimum support macOS version.
388388
MACOSX_DEPLOYMENT_TARGET: 10.12
@@ -400,7 +400,7 @@ auto:
400400
SCRIPT: ./x.py dist bootstrap --include-default-paths --host='' --target=aarch64-apple-ios,x86_64-apple-ios,aarch64-apple-ios-sim,aarch64-apple-ios-macabi,x86_64-apple-ios-macabi
401401
# Mac Catalyst cannot currently compile the sanitizer:
402402
# https://github.com/rust-lang/rust/issues/129069
403-
RUST_CONFIGURE_ARGS: --enable-sanitizers --enable-profiler --set rust.jemalloc --set target.aarch64-apple-ios-macabi.sanitizers=false --set target.x86_64-apple-ios-macabi.sanitizers=false
403+
RUST_CONFIGURE_ARGS: --enable-sanitizers --enable-profiler --set rust.jemalloc --set target.aarch64-apple-ios-macabi.sanitizers=false --set llvm.enzyme=true --set target.x86_64-apple-ios-macabi.sanitizers=false
404404
RUSTC_RETRY_LINKER_ON_SEGFAULT: 1
405405
# Ensure that host tooling is built to support our minimum support macOS version.
406406
# FIXME(madsmtm): This might be redundant, as we're not building host tooling here (?)
@@ -432,6 +432,7 @@ auto:
432432
--enable-profiler
433433
--set rust.jemalloc
434434
--set llvm.ninja=false
435+
--set llvm.enzyme=true
435436
--set rust.lto=thin
436437
--set rust.codegen-units=1
437438
RUSTC_RETRY_LINKER_ON_SEGFAULT: 1

src/tools/enzyme

Submodule enzyme updated 122 files

tests/codegen/autodiffv2.rs renamed to tests/codegen/autodiff/autodiffv2.rs

+16-18
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,13 @@
1818
// but each shadow argument is `width` times larger (thus 16 and 20 elements here).
1919
// `d_square3` instead takes `width` (4) shadow arguments, which are all the same size as the
2020
// original function arguments.
21-
//
22-
// FIXME(autodiff): We currently can't test `d_square1` and `d_square3` in the same file, since they
23-
// generate the same dummy functions which get merged by LLVM, breaking pieces of our pipeline which
24-
// try to rewrite the dummy functions later. We should consider to change to pure declarations both
25-
// in our frontend and in the llvm backend to avoid these issues.
2621

2722
#![feature(autodiff)]
2823

2924
use std::autodiff::autodiff;
3025

3126
#[no_mangle]
32-
//#[autodiff(d_square1, Forward, Dual, Dual)]
27+
#[autodiff(d_square1, Forward, Dual, Dual)]
3328
#[autodiff(d_square2, Forward, 4, Dualv, Dualv)]
3429
#[autodiff(d_square3, Forward, 4, Dual, Dual)]
3530
fn square(x: &[f32], y: &mut [f32]) {
@@ -42,6 +37,9 @@ fn square(x: &[f32], y: &mut [f32]) {
4237
y[4] = 1.0 * x[0] + 2.0 * x[1] + 3.0 * x[2] + 4.0 * x[3];
4338
}
4439

40+
// FIXME
41+
// CHECK: start:
42+
4543
fn main() {
4644
let x1 = std::hint::black_box(vec![0.0, 1.0, 2.0, 3.0]);
4745

@@ -78,25 +76,25 @@ fn main() {
7876
let mut dy3_4 = std::hint::black_box(vec![0.0; 5]);
7977

8078
// scalar.
81-
//d_square1(&x1, &z1, &mut y1, &mut dy1_1);
82-
//d_square1(&x1, &z2, &mut y2, &mut dy1_2);
83-
//d_square1(&x1, &z3, &mut y3, &mut dy1_3);
84-
//d_square1(&x1, &z4, &mut y4, &mut dy1_4);
79+
d_square1(&x1, &z1, &mut y1, &mut dy1_1);
80+
d_square1(&x1, &z2, &mut y2, &mut dy1_2);
81+
d_square1(&x1, &z3, &mut y3, &mut dy1_3);
82+
d_square1(&x1, &z4, &mut y4, &mut dy1_4);
8583

8684
// assert y1 == y2 == y3 == y4
87-
//for i in 0..5 {
88-
// assert_eq!(y1[i], y2[i]);
89-
// assert_eq!(y1[i], y3[i]);
90-
// assert_eq!(y1[i], y4[i]);
91-
//}
85+
for i in 0..5 {
86+
assert_eq!(y1[i], y2[i]);
87+
assert_eq!(y1[i], y3[i]);
88+
assert_eq!(y1[i], y4[i]);
89+
}
9290

9391
// batch mode A)
9492
d_square2(&x1, &z5, &mut y5, &mut dy2);
9593

9694
// assert y1 == y2 == y3 == y4 == y5
97-
//for i in 0..5 {
98-
// assert_eq!(y1[i], y5[i]);
99-
//}
95+
for i in 0..5 {
96+
assert_eq!(y1[i], y5[i]);
97+
}
10098

10199
// batch mode B)
102100
d_square3(&x1, &z1, &z2, &z3, &z4, &mut y6, &mut dy3_1, &mut dy3_2, &mut dy3_3, &mut dy3_4);

0 commit comments

Comments
 (0)