Skip to content

Commit 0bec16a

Browse files
committed
Cleanup Rust-Enzyme history
Co-authored-by: Lorenz Schmidt [email protected] Co-authored-by: William Moses [email protected]
1 parent bbcc169 commit 0bec16a

File tree

105 files changed

+3617
-41
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+3617
-41
lines changed

.github/workflows/enzyme-ci.yml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Rust CI
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
merge_group:
11+
12+
jobs:
13+
build:
14+
name: Rust Integration CI LLVM ${{ matrix.llvm }} ${{ matrix.build }} ${{ matrix.os }}
15+
runs-on: ${{ matrix.os }}
16+
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
os: [openstack22]
21+
22+
timeout-minutes: 600
23+
steps:
24+
- name: checkout the source code
25+
uses: actions/checkout@v3
26+
with:
27+
fetch-depth: 2
28+
- name: build
29+
run: |
30+
mkdir build
31+
cd build
32+
../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
33+
../x.py build --stage 1 library/std library/proc_macro library/test tools/rustdoc
34+
rustup toolchain link enzyme `pwd`/build/`rustup target list --installed`/stage1
35+
rustup toolchain install nightly # enables -Z unstable-options
36+
- name: test
37+
run: |
38+
cargo +enzyme test --examples

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,6 @@
4343
path = library/backtrace
4444
url = https://github.com/rust-lang/backtrace-rs.git
4545
shallow = true
46+
[submodule "src/tools/enzyme"]
47+
path = src/tools/enzyme
48+
url = https://github.com/EnzymeAD/Enzyme.git

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -4312,6 +4312,7 @@ dependencies = [
43124312
"rustc_middle",
43134313
"rustc_session",
43144314
"rustc_span",
4315+
"rustc_symbol_mangling",
43154316
"rustc_target",
43164317
"serde",
43174318
"serde_json",

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ exclude = [
6161
"src/tools/x",
6262
# stdarch has its own Cargo workspace
6363
"library/stdarch",
64+
"library/autodiff",
6465
]
6566

6667
[profile.release.package.compiler_builtins]

README.md

+61-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,68 @@
1-
# The Rust Programming Language
1+
# The Rust Programming Language +Enzyme
22

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

55
This is the main source code repository for [Rust]. It contains the compiler,
6-
standard library, and documentation.
6+
standard library, and documentation. It is modified to use Enzyme for AutoDiff.
7+
8+
Please configure this fork using the following command:
9+
10+
```
11+
mkdir build
12+
cd build
13+
../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
14+
```
15+
16+
Afterwards you can build rustc using:
17+
```
18+
../x.py build --stage 1 library/std library/proc_macro library/test tools/rustdoc
19+
```
20+
21+
Afterwards rustc toolchain link will allow you to use it through cargo:
22+
```
23+
rustup toolchain link enzyme `pwd`/build/`rustup target list --installed`/stage1
24+
rustup toolchain install nightly # enables -Z unstable-options
25+
```
26+
27+
You can then look at examples in the `library/autodiff/examples/*` folder and run them with
28+
29+
```bash
30+
# rosenbrock forward iteration
31+
cargo +enzyme run --example rosenbrock_fwd_iter --release
32+
33+
# or all of them
34+
cargo +enzyme test --examples
35+
```
36+
37+
## Enzyme Config
38+
To help with debugging, Enzyme can be configured using environment variables.
39+
```bash
40+
export ENZYME_PRINT_TA=1
41+
export ENZYME_PRINT_AA=1
42+
export ENZYME_PRINT=1
43+
export ENZYME_PRINT_MOD=1
44+
export ENZYME_PRINT_MOD_AFTER=1
45+
```
46+
The first three will print TypeAnalysis, ActivityAnalysis and the llvm-ir on a function basis, respectively.
47+
The last two variables will print the whole module directly before and after Enzyme differented the functions.
48+
49+
When experimenting with flags please make sure that EnzymeStrictAliasing=0
50+
is not changed, since it is required for Enzyme to handle enums correctly.
51+
52+
## Bug reporting
53+
Bugs are pretty much expected at this point of the development process.
54+
In order to help us please minimize the Rust code as far as possible.
55+
This tool might be a nicer helper: https://github.com/Nilstrieb/cargo-minimize
56+
If you have some knowledge of LLVM-IR we also greatly appreciate it if you could help
57+
us by compiling your minimized Rust code to LLVM-IR and reducing it further.
58+
59+
The only exception to this strategy is error based on "Can not deduce type of X",
60+
where reducing your example will make it harder for us to understand the origin of the bug.
61+
In this case please just try to inline all dependencies into a single crate or even file,
62+
without deleting used code.
63+
64+
65+
766

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

compiler/rustc_ast/src/mut_visit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ pub fn visit_bounds<T: MutVisitor>(bounds: &mut GenericBounds, vis: &mut T) {
381381
}
382382

383383
// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
384-
pub fn visit_fn_sig<T: MutVisitor>(FnSig { header, decl, span }: &mut FnSig, vis: &mut T) {
384+
pub fn visit_fn_sig<T: MutVisitor>(FnSig { header, decl, span, .. }: &mut FnSig, vis: &mut T) {
385385
vis.visit_fn_header(header);
386386
vis.visit_fn_decl(decl);
387387
vis.visit_span(span);

compiler/rustc_codegen_llvm/src/attributes.rs

+3
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ pub fn from_fn_attrs<'ll, 'tcx>(
285285
instance: ty::Instance<'tcx>,
286286
) {
287287
let codegen_fn_attrs = cx.tcx.codegen_fn_attrs(instance.def_id());
288+
let autodiff_attrs = cx.tcx.autodiff_attrs(instance.def_id());
288289

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

@@ -302,6 +303,8 @@ pub fn from_fn_attrs<'ll, 'tcx>(
302303
let inline =
303304
if codegen_fn_attrs.inline == InlineAttr::None && instance.def.requires_inline(cx.tcx) {
304305
InlineAttr::Hint
306+
} else if autodiff_attrs.is_active() {
307+
InlineAttr::Never
305308
} else {
306309
codegen_fn_attrs.inline
307310
};

compiler/rustc_codegen_llvm/src/back/lto.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ fn fat_lto(
273273
info!("pushing cached module {:?}", wp.cgu_name);
274274
(buffer, CString::new(wp.cgu_name).unwrap())
275275
}));
276+
276277
for module in modules {
277278
match module {
278279
FatLtoInput::InMemory(m) => in_memory.push(m),
@@ -734,7 +735,7 @@ pub unsafe fn optimize_thin_module(
734735
let llcx = llvm::LLVMRustContextCreate(cgcx.fewer_names);
735736
let llmod_raw = parse_module(llcx, module_name, thin_module.data(), &diag_handler)? as *const _;
736737
let mut module = ModuleCodegen {
737-
module_llvm: ModuleLlvm { llmod_raw, llcx, tm },
738+
module_llvm: ModuleLlvm { llmod_raw, llcx, tm, typetrees: Default::default() },
738739
name: thin_module.name().to_string(),
739740
kind: ModuleKind::Regular,
740741
};

0 commit comments

Comments
 (0)