Skip to content

Commit

Permalink
Cleanup Rust-Enzyme history
Browse files Browse the repository at this point in the history
Co-authored-by: Lorenz Schmidt git@lorenzschmidt.com
Co-authored-by: William Moses gh@wsmoses.com
  • Loading branch information
ZuseZ4 committed Oct 30, 2023
1 parent bbcc169 commit 3e4e28a
Show file tree
Hide file tree
Showing 105 changed files with 3,600 additions and 42 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/enzyme-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Rust CI

on:
push:
branches:
- master
pull_request:
branches:
- master
merge_group:

jobs:
build:
name: Rust Integration CI LLVM ${{ matrix.llvm }} ${{ matrix.build }} ${{ matrix.os }}
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
os: [openstack22]

timeout-minutes: 600
steps:
- name: checkout the source code
uses: actions/checkout@v3
with:
fetch-depth: 2
- name: build
run: |
mkdir build
cd build
../configure --enable-llvm-link-shared --enable-llvm-plugins --enable-llvm-enzyme --release-channel=nightly --enable-llvm-assertions --enable-clang --enable-lld --enable-option-checking --enable-ninja --disable-docs
../x.py build --stage 1 library/std library/proc_macro library/test tools/rustdoc
rustup toolchain link enzyme `pwd`/build/`rustup target list --installed`/stage1
rustup toolchain install nightly # enables -Z unstable-options
- name: test
run: |
cargo +enzyme test --examples
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@
path = library/backtrace
url = https://github.com/rust-lang/backtrace-rs.git
shallow = true
[submodule "src/tools/enzyme"]
path = src/tools/enzyme
url = https://github.com/EnzymeAD/Enzyme.git
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4312,6 +4312,7 @@ dependencies = [
"rustc_middle",
"rustc_session",
"rustc_span",
"rustc_symbol_mangling",
"rustc_target",
"serde",
"serde_json",
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ exclude = [
"src/tools/x",
# stdarch has its own Cargo workspace
"library/stdarch",
"library/autodiff",
]

[profile.release.package.compiler_builtins]
Expand Down
63 changes: 61 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,68 @@
# The Rust Programming Language
# The Rust Programming Language +Enzyme

[![Rust Community](https://img.shields.io/badge/Rust_Community%20-Join_us-brightgreen?style=plastic&logo=rust)](https://www.rust-lang.org/community)

This is the main source code repository for [Rust]. It contains the compiler,
standard library, and documentation.
standard library, and documentation. It is modified to use Enzyme for AutoDiff.

Please configure this fork using the following command:

```
mkdir build
cd build
../configure --enable-llvm-link-shared --enable-llvm-plugins --enable-llvm-enzyme --release-channel=nightly --enable-llvm-assertions --enable-clang --enable-lld --enable-option-checking --enable-ninja --disable-docs
```

Afterwards you can build rustc using:
```
../x.py build --stage 1 library/std library/proc_macro library/test tools/rustdoc
```

Afterwards rustc toolchain link will allow you to use it through cargo:
```
rustup toolchain link enzyme `pwd`/build/`rustup target list --installed`/stage1
rustup toolchain install nightly # enables -Z unstable-options
```

You can then look at examples in the `library/autodiff/examples/*` folder and run them with

```bash
# rosenbrock forward iteration
cargo +enzyme run --example rosenbrock_fwd_iter --release

# or all of them
cargo +enzyme test --examples
```

## Enzyme Config
To help with debugging, Enzyme can be configured using environment variables.
```bash
export ENZYME_PRINT_TA=1
export ENZYME_PRINT_AA=1
export ENZYME_PRINT=1
export ENZYME_PRINT_MOD=1
export ENZYME_PRINT_MOD_AFTER=1
```
The first three will print TypeAnalysis, ActivityAnalysis and the llvm-ir on a function basis, respectively.
The last two variables will print the whole module directly before and after Enzyme differented the functions.

When experimenting with flags please make sure that EnzymeStrictAliasing=0
is not changed, since it is required for Enzyme to handle enums correctly.

## Bug reporting
Bugs are pretty much expected at this point of the development process.
In order to help us please minimize the Rust code as far as possible.
This tool might be a nicer helper: https://github.com/Nilstrieb/cargo-minimize
If you have some knowledge of LLVM-IR we also greatly appreciate it if you could help
us by compiling your minimized Rust code to LLVM-IR and reducing it further.

The only exception to this strategy is error based on "Can not deduce type of X",
where reducing your example will make it harder for us to understand the origin of the bug.
In this case please just try to inline all dependencies into a single crate or even file,
without deleting used code.




[Rust]: https://www.rust-lang.org/

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast/src/mut_visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ pub fn visit_bounds<T: MutVisitor>(bounds: &mut GenericBounds, vis: &mut T) {
}

// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
pub fn visit_fn_sig<T: MutVisitor>(FnSig { header, decl, span }: &mut FnSig, vis: &mut T) {
pub fn visit_fn_sig<T: MutVisitor>(FnSig { header, decl, span, .. }: &mut FnSig, vis: &mut T) {
vis.visit_fn_header(header);
vis.visit_fn_decl(decl);
vis.visit_span(span);
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_codegen_llvm/src/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ pub fn from_fn_attrs<'ll, 'tcx>(
instance: ty::Instance<'tcx>,
) {
let codegen_fn_attrs = cx.tcx.codegen_fn_attrs(instance.def_id());
let autodiff_attrs = cx.tcx.autodiff_attrs(instance.def_id());

let mut to_add = SmallVec::<[_; 16]>::new();

Expand All @@ -302,6 +303,8 @@ pub fn from_fn_attrs<'ll, 'tcx>(
let inline =
if codegen_fn_attrs.inline == InlineAttr::None && instance.def.requires_inline(cx.tcx) {
InlineAttr::Hint
} else if autodiff_attrs.is_active() {
InlineAttr::Never
} else {
codegen_fn_attrs.inline
};
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_codegen_llvm/src/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ fn fat_lto(
info!("pushing cached module {:?}", wp.cgu_name);
(buffer, CString::new(wp.cgu_name).unwrap())
}));

for module in modules {
match module {
FatLtoInput::InMemory(m) => in_memory.push(m),
Expand Down Expand Up @@ -734,7 +735,7 @@ pub unsafe fn optimize_thin_module(
let llcx = llvm::LLVMRustContextCreate(cgcx.fewer_names);
let llmod_raw = parse_module(llcx, module_name, thin_module.data(), &diag_handler)? as *const _;
let mut module = ModuleCodegen {
module_llvm: ModuleLlvm { llmod_raw, llcx, tm },
module_llvm: ModuleLlvm { llmod_raw, llcx, tm, typetrees: Default::default() },
name: thin_module.name().to_string(),
kind: ModuleKind::Regular,
};
Expand Down
Loading

0 comments on commit 3e4e28a

Please sign in to comment.