diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs index 2e5865e509695..a035f9e10d211 100644 --- a/src/bootstrap/src/core/build_steps/compile.rs +++ b/src/bootstrap/src/core/build_steps/compile.rs @@ -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}")); } } @@ -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); } diff --git a/src/bootstrap/src/core/build_steps/llvm.rs b/src/bootstrap/src/core/build_steps/llvm.rs index 86af956535e5e..98f9dfca43a10 100644 --- a/src/bootstrap/src/core/build_steps/llvm.rs +++ b/src/bootstrap/src/core/build_steps/llvm.rs @@ -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 @@ -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(); diff --git a/src/ci/docker/host-aarch64/dist-aarch64-linux/Dockerfile b/src/ci/docker/host-aarch64/dist-aarch64-linux/Dockerfile index 2b8a3f829c608..b47f91905ac11 100644 --- a/src/ci/docker/host-aarch64/dist-aarch64-linux/Dockerfile +++ b/src/ci/docker/host-aarch64/dist-aarch64-linux/Dockerfile @@ -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 \ diff --git a/src/ci/github-actions/jobs.yml b/src/ci/github-actions/jobs.yml index 88b29d2df56ae..8c56a843c8c6c 100644 --- a/src/ci/github-actions/jobs.yml +++ b/src/ci/github-actions/jobs.yml @@ -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 @@ -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 (?) @@ -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 diff --git a/src/tools/enzyme b/src/tools/enzyme index a35f4f773118c..6ea4cd081e345 160000 --- a/src/tools/enzyme +++ b/src/tools/enzyme @@ -1 +1 @@ -Subproject commit a35f4f773118ccfbd8d05102eb12a34097b1ee55 +Subproject commit 6ea4cd081e345769e7a02450ee4f1474011cfe25 diff --git a/tests/codegen/autodiffv2.rs b/tests/codegen/autodiff/autodiffv2.rs similarity index 82% rename from tests/codegen/autodiffv2.rs rename to tests/codegen/autodiff/autodiffv2.rs index a40d19d3be3a8..af2f3ef49e1a2 100644 --- a/tests/codegen/autodiffv2.rs +++ b/tests/codegen/autodiff/autodiffv2.rs @@ -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]) { @@ -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]); @@ -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);