Skip to content

[DO NOT MERGE] build Enzyme as archive #140799

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 6 additions & 6 deletions src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,7 @@ pub fn rustc_cargo(

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

Expand Down Expand Up @@ -2065,15 +2065,15 @@ impl Step for Assemble {
let enzyme_install = builder.ensure(llvm::Enzyme { target: build_compiler.host });
let llvm_config = builder.llvm_config(builder.config.build).unwrap();
let llvm_version_major = llvm::get_llvm_version_major(builder, &llvm_config);
let lib_ext = std::env::consts::DLL_EXTENSION;
let libenzyme = format!("libEnzyme-{llvm_version_major}");
let archive_ext = "a";
let libenzyme = format!("libEnzymeStatic-{llvm_version_major}");
let src_lib =
enzyme_install.join("build/Enzyme").join(&libenzyme).with_extension(lib_ext);
enzyme_install.join("build/Enzyme").join(&libenzyme).with_extension(archive_ext);
let libdir = builder.sysroot_target_libdir(build_compiler, build_compiler.host);
let target_libdir =
builder.sysroot_target_libdir(target_compiler, target_compiler.host);
let dst_lib = libdir.join(&libenzyme).with_extension(lib_ext);
let target_dst_lib = target_libdir.join(&libenzyme).with_extension(lib_ext);
let dst_lib = libdir.join(&libenzyme).with_extension(archive_ext);
let target_dst_lib = target_libdir.join(&libenzyme).with_extension(archive_ext);
builder.copy_link(&src_lib, &dst_lib, FileType::NativeLibrary);
builder.copy_link(&src_lib, &target_dst_lib, FileType::NativeLibrary);
}
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/build_steps/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,6 @@ impl Step for Llvm {
}
};

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

cfg.build();
Expand Down
1 change: 1 addition & 0 deletions src/ci/docker/host-aarch64/dist-aarch64-linux/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ ENV RUST_CONFIGURE_ARGS \
--set llvm.thin-lto=true \
--set llvm.libzstd=true \
--set llvm.ninja=false \
--set llvm.enzyme=true \
--set rust.debug-assertions=false \
--set rust.jemalloc \
--set rust.use-lld=true \
Expand Down
5 changes: 3 additions & 2 deletions src/ci/github-actions/jobs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ auto:
- name: dist-x86_64-apple
env:
SCRIPT: ./x.py dist bootstrap --include-default-paths --host=x86_64-apple-darwin --target=x86_64-apple-darwin
RUST_CONFIGURE_ARGS: --enable-full-tools --enable-sanitizers --enable-profiler --set rust.jemalloc --set rust.lto=thin --set rust.codegen-units=1
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
RUSTC_RETRY_LINKER_ON_SEGFAULT: 1
# Ensure that host tooling is built to support our minimum support macOS version.
MACOSX_DEPLOYMENT_TARGET: 10.12
Expand All @@ -394,7 +394,7 @@ auto:
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
# Mac Catalyst cannot currently compile the sanitizer:
# https://github.com/rust-lang/rust/issues/129069
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
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
RUSTC_RETRY_LINKER_ON_SEGFAULT: 1
# Ensure that host tooling is built to support our minimum support macOS version.
# FIXME(madsmtm): This might be redundant, as we're not building host tooling here (?)
Expand Down Expand Up @@ -426,6 +426,7 @@ auto:
--enable-profiler
--set rust.jemalloc
--set llvm.ninja=false
--set llvm.enzyme=true
--set rust.lto=thin
--set rust.codegen-units=1
RUSTC_RETRY_LINKER_ON_SEGFAULT: 1
Expand Down
2 changes: 1 addition & 1 deletion src/tools/enzyme
Submodule enzyme updated 122 files
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,13 @@
// but each shadow argument is `width` times larger (thus 16 and 20 elements here).
// `d_square3` instead takes `width` (4) shadow arguments, which are all the same size as the
// original function arguments.
//
// FIXME(autodiff): We currently can't test `d_square1` and `d_square3` in the same file, since they
// generate the same dummy functions which get merged by LLVM, breaking pieces of our pipeline which
// try to rewrite the dummy functions later. We should consider to change to pure declarations both
// in our frontend and in the llvm backend to avoid these issues.

#![feature(autodiff)]

use std::autodiff::autodiff;

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

// FIXME
// CHECK: start:

fn main() {
let x1 = std::hint::black_box(vec![0.0, 1.0, 2.0, 3.0]);

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

// scalar.
//d_square1(&x1, &z1, &mut y1, &mut dy1_1);
//d_square1(&x1, &z2, &mut y2, &mut dy1_2);
//d_square1(&x1, &z3, &mut y3, &mut dy1_3);
//d_square1(&x1, &z4, &mut y4, &mut dy1_4);
d_square1(&x1, &z1, &mut y1, &mut dy1_1);
d_square1(&x1, &z2, &mut y2, &mut dy1_2);
d_square1(&x1, &z3, &mut y3, &mut dy1_3);
d_square1(&x1, &z4, &mut y4, &mut dy1_4);

// assert y1 == y2 == y3 == y4
//for i in 0..5 {
// assert_eq!(y1[i], y2[i]);
// assert_eq!(y1[i], y3[i]);
// assert_eq!(y1[i], y4[i]);
//}
for i in 0..5 {
assert_eq!(y1[i], y2[i]);
assert_eq!(y1[i], y3[i]);
assert_eq!(y1[i], y4[i]);
}

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

// assert y1 == y2 == y3 == y4 == y5
//for i in 0..5 {
// assert_eq!(y1[i], y5[i]);
//}
for i in 0..5 {
assert_eq!(y1[i], y5[i]);
}

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