diff options
| author | bors <bors@rust-lang.org> | 2025-02-22 10:30:06 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-02-22 10:30:06 +0000 |
| commit | 8dac72bb1d12b2649acd0c190e41524f83da5683 (patch) | |
| tree | 23cadee493bbc328f4d7227e66212847c17388ba /src | |
| parent | b6d3be4948e92fce0236cbbe22b55c55f6950269 (diff) | |
| parent | 49e9630641e44756b679187bfeefa85b06dfc86f (diff) | |
| download | rust-8dac72bb1d12b2649acd0c190e41524f83da5683.tar.gz rust-8dac72bb1d12b2649acd0c190e41524f83da5683.zip | |
Auto merge of #136428 - EnzymeAD:enable-autodiff, r=oli-obk
test building enzyme in CI 1) This PR fixes a significant compile-time regression, by only running the expensive autodiff pipeline, if the users pass the newly introduced Enable value to the `-Zautodiff=` flag. It updates the test(s) accordingly. It gives a nice error if users forget that. 2) It fixes macos support by explicitly linking against the Enzyme build folder. This doesn't cover CI macos yet. 3) It fixes the issue that setting ENZYME_RUNPASS was ignored by enzyme and in fact did not schedule enzyme's opt pass. 4) It also re-enables support for various other values for the autodiff flag, which were ignored since the refactor. 5) I merged some improvements to Enzyme core, which means we do not longer depend on LLVM being build with the Plugin Interface enabled. 6) Unrelated to other fixes, this changes `rustc_autodiff` to `EncodeCrossCrate::Yes`. It is not enough on it's own to enable usage of Enzyme in libraries, but it is for sure a piece of the fixes needed to get this to work. try-job: x86_64-gnu r? `@oli-obk` Tracking: - https://github.com/rust-lang/rust/issues/124509
Diffstat (limited to 'src')
| -rw-r--r-- | src/bootstrap/src/core/build_steps/compile.rs | 24 | ||||
| -rw-r--r-- | src/bootstrap/src/core/build_steps/llvm.rs | 7 | ||||
| -rw-r--r-- | src/doc/unstable-book/src/compiler-flags/autodiff.md | 9 | ||||
| m--------- | src/tools/enzyme | 0 |
4 files changed, 22 insertions, 18 deletions
diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs index aa08dd7e424..8e9b5856096 100644 --- a/src/bootstrap/src/core/build_steps/compile.rs +++ b/src/bootstrap/src/core/build_steps/compile.rs @@ -1174,9 +1174,15 @@ pub fn rustc_cargo( // We want to link against registerEnzyme and in the future we want to use additional // functionality from Enzyme core. For that we need to link against Enzyme. if builder.config.llvm_enzyme { - let llvm_config = builder.llvm_config(builder.config.build).unwrap(); - let llvm_version_major = llvm::get_llvm_version_major(builder, &llvm_config); - cargo.rustflag("-l").rustflag(&format!("Enzyme-{llvm_version_major}")); + let arch = builder.build.build; + let enzyme_dir = builder.build.out.join(arch).join("enzyme").join("lib"); + cargo.rustflag("-L").rustflag(enzyme_dir.to_str().expect("Invalid path")); + + if !builder.config.dry_run() { + let llvm_config = builder.llvm_config(builder.config.build).unwrap(); + let llvm_version_major = llvm::get_llvm_version_major(builder, &llvm_config); + cargo.rustflag("-l").rustflag(&format!("Enzyme-{llvm_version_major}")); + } } // Building with protected visibility reduces the number of dynamic relocations needed, giving @@ -2028,16 +2034,20 @@ impl Step for Assemble { let mut build_compiler = builder.compiler(target_compiler.stage - 1, builder.config.build); // Build enzyme - if builder.config.llvm_enzyme { + if builder.config.llvm_enzyme && !builder.config.dry_run() { debug!("`llvm_enzyme` requested"); 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 src_lib = enzyme_install.join("build/Enzyme/libEnzyme-19").with_extension(lib_ext); + let libenzyme = format!("libEnzyme-{llvm_version_major}"); + let src_lib = + enzyme_install.join("build/Enzyme").join(&libenzyme).with_extension(lib_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-19").with_extension(lib_ext); - let target_dst_lib = target_libdir.join("libEnzyme-19").with_extension(lib_ext); + let dst_lib = libdir.join(&libenzyme).with_extension(lib_ext); + let target_dst_lib = target_libdir.join(&libenzyme).with_extension(lib_ext); builder.copy_link(&src_lib, &dst_lib); builder.copy_link(&src_lib, &target_dst_lib); } diff --git a/src/bootstrap/src/core/build_steps/llvm.rs b/src/bootstrap/src/core/build_steps/llvm.rs index 3025f955660..40d701f22c1 100644 --- a/src/bootstrap/src/core/build_steps/llvm.rs +++ b/src/bootstrap/src/core/build_steps/llvm.rs @@ -996,13 +996,11 @@ impl Step for Enzyme { .config .update_submodule(Path::new("src").join("tools").join("enzyme").to_str().unwrap()); let mut cfg = cmake::Config::new(builder.src.join("src/tools/enzyme/enzyme/")); - // FIXME(ZuseZ4): Find a nicer way to use Enzyme Debug builds - //cfg.profile("Debug"); - //cfg.define("CMAKE_BUILD_TYPE", "Debug"); configure_cmake(builder, target, &mut cfg, true, LdFlags::default(), &[]); // Re-use the same flags as llvm to control the level of debug information - // generated for lld. + // generated by Enzyme. + // FIXME(ZuseZ4): Find a nicer way to use Enzyme Debug builds. let profile = match (builder.config.llvm_optimize, builder.config.llvm_release_debuginfo) { (false, _) => "Debug", (true, false) => "Release", @@ -1015,7 +1013,6 @@ impl Step for Enzyme { .env("LLVM_CONFIG_REAL", &llvm_config) .define("LLVM_ENABLE_ASSERTIONS", "ON") .define("ENZYME_EXTERNAL_SHARED_LIB", "ON") - .define("ENZYME_RUNPASS", "ON") .define("LLVM_DIR", builder.llvm_out(target)); cfg.build(); diff --git a/src/doc/unstable-book/src/compiler-flags/autodiff.md b/src/doc/unstable-book/src/compiler-flags/autodiff.md index 4e55be0ad95..95c188d1f3b 100644 --- a/src/doc/unstable-book/src/compiler-flags/autodiff.md +++ b/src/doc/unstable-book/src/compiler-flags/autodiff.md @@ -8,16 +8,13 @@ This feature allows you to differentiate functions using automatic differentiati Set the `-Zautodiff=<options>` compiler flag to adjust the behaviour of the autodiff feature. Multiple options can be separated with a comma. Valid options are: +`Enable` - Required flag to enable autodiff `PrintTA` - print Type Analysis Information `PrintAA` - print Activity Analysis Information `PrintPerf` - print Performance Warnings from Enzyme -`Print` - prints all intermediate transformations +`PrintSteps` - prints all intermediate transformations `PrintModBefore` - print the whole module, before running opts -`PrintModAfterOpts` - print the whole module just before we pass it to Enzyme -`PrintModAfterEnzyme` - print the module after Enzyme differentiated everything +`PrintModAfter` - print the module after Enzyme differentiated everything `LooseTypes` - Enzyme's loose type debug helper (can cause incorrect gradients) `Inline` - runs Enzyme specific Inlining -`NoModOptAfter` - do not optimize the module after Enzyme is done -`EnableFncOpt` - tell Enzyme to run LLVM Opts on each function it generated -`NoVecUnroll` - do not unroll vectorized loops `RuntimeActivity` - allow specifying activity at runtime diff --git a/src/tools/enzyme b/src/tools/enzyme -Subproject 7f3b207c4413c9d715fd54b36b8a8fd3179e0b6 +Subproject 5004a8f6f5d8468b64fae457afb7d96e1784c78 |
