Skip to content
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

single patch containing all autodiff changes #161

Closed
wants to merge 1 commit into from
Closed
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
90 changes: 90 additions & 0 deletions .github/workflows/enzyme-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
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 Rust source
uses: actions/checkout@v4
with:
submodules: true # check out all submodules so the cache can work correctly
fetch-depth: 2
- uses: dtolnay/rust-toolchain@nightly
- name: Get LLVM commit hash
id: llvm-commit
run: echo "HEAD=$(git rev-parse HEAD:src/llvm-project)" >> $GITHUB_OUTPUT
- name: Cache LLVM
id: cache-llvm
uses: actions/cache@v4
with:
path: build/build/x86_64-unknown-linux-gnu/llvm
key: ${{ matrix.os }}-llvm-${{ steps.llvm-commit.outputs.HEAD }}
- name: Get Enzyme commit hash
id: enzyme-commit
run: echo "HEAD=$(git rev-parse HEAD:src/tools/enzyme)" >> $GITHUB_OUTPUT
- name: Cache Enzyme
id: cache-enzyme
uses: actions/cache@v4
with:
path: build/build/x86_64-unknown-linux-gnu/enzyme
key: ${{ matrix.os }}-enzyme-${{ steps.enzyme-commit.outputs.HEAD }}
- name: Cache bootstrap/stage0 artifacts for incremental builds
uses: actions/cache@v4
with:
path: |
build/build/bootstrap/
build/build/x86_64-unknown-linux-gnu/stage0-rustc/
build/build/x86_64-unknown-linux-gnu/stage0-std/
build/build/x86_64-unknown-linux-gnu/stage0-tools/
build/build/x86_64-unknown-linux-gnu/stage1-std/
# Approximate stable hash. It doesn't matter too much when this goes out of sync as it just caches
# some stage0/stage1 dependencies and stdlibs which *hopefully* are hash-keyed.
key: enzyme-rust-incremental-${{ runner.os }}-${{ hashFiles('src/**/Cargo.lock', 'Cargo.lock') }}
restore-keys: |
enzyme-rust-incremental-${{ runner.os }}
- name: Build
run: |
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add -
sudo apt-add-repository "deb http://apt.llvm.org/`lsb_release -c | cut -f2`/ llvm-toolchain-`lsb_release -c | cut -f2`-17 main" || true
sudo apt-get -y update
sudo apt-get install -y lld-17
mkdir lld-path-manipulation
ln -s "$(which lld-17)" lld-path-manipulation/lld
ln -s "$(which lld-17)" lld-path-manipulation/ld
ln -s "$(which lld-17)" lld-path-manipulation/ld.lld
ln -s "$(which lld-17)" lld-path-manipulation/lld-17
export PATH="$PWD/lld-path-manipulation:$PATH"
mkdir -p build
cd build
rm -f config.toml
../configure --enable-llvm-link-shared --enable-llvm-plugins --enable-llvm-enzyme --set=rust.use-lld=true --release-channel=nightly --enable-llvm-assertions --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 build/host/stage1
- name: checkout Enzyme/rustbook
uses: actions/checkout@v4
with:
repository: EnzymeAD/rustbook
ref: main
path: rustbook
- name: test Enzyme/rustbook
working-directory: rustbook
run: |
RUSTFLAGS='-Z unstable-options' cargo +enzyme test
ENZYME_LOOSE_TYPES=1 RUSTFLAGS='-Z unstable-options' cargo +enzyme test -p samples-loose-types
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,7 @@
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
shallow = true
2 changes: 2 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4261,6 +4261,7 @@ dependencies = [
name = "rustc_monomorphize"
version = "0.0.0"
dependencies = [
"rustc_ast",
"rustc_data_structures",
"rustc_errors",
"rustc_fluent_macro",
Expand All @@ -4269,6 +4270,7 @@ dependencies = [
"rustc_middle",
"rustc_session",
"rustc_span",
"rustc_symbol_mangling",
"rustc_target",
"serde",
"serde_json",
Expand Down
41 changes: 39 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,46 @@
# The Rust Programming Language
# The Rust Programming Language + AutoDiff

[![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:

```
./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
```

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

You can then run examples from our [docs](https://enzyme.mit.edu/index.fcgi/rust/usage/usage.html):

```bash
cd ..
git clone git@github.com:EnzymeAD/rustbook.git
cd rustbook/samples
cargo +enzyme test reverse
```
If you want to use Autodiff in your own projects, please always enable `lto="fat"` in your Cargo.toml
and use `cargo +enzyme` instead of `cargo` or `cargo +nightly`.

## Bug reporting
Bugs are pretty much expected at this point of the development process.
Any type of bug report is therefore highly appreciated. Documentation
on how to best debug this fork and how to report errors can be found
on our [website]: https://enzyme.mit.edu/index.fcgi/rust/Debugging.html



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

Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2574,6 +2574,12 @@ impl FnRetTy {
FnRetTy::Ty(ty) => ty.span,
}
}
pub fn has_ret(&self) -> bool {
match self {
FnRetTy::Default(_) => false,
FnRetTy::Ty(_) => true,
}
}
}

#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug)]
Expand Down
Loading
Loading