|
| 1 | +# Installation |
| 2 | + |
| 3 | +In the near future, `std::autodiff` should become available in nightly builds for users. As a contribute however, you will still need to build rustc from source. Please be aware that the msvc target is not supported at the moment, all other tier 1 targets should work. Please open an issue if you encounter any problems on a supported tier 1 target, or if you succesfully build this project on a tier2/tier3 target. |
| 4 | + |
| 5 | +## Build instructions |
| 6 | + |
| 7 | +First you need to clone and configure the Rust repository: |
| 8 | +```bash |
| 9 | +git clone --depth=1 [email protected]:rust-lang/rust.git |
| 10 | +cd rust |
| 11 | +./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 |
| 12 | +``` |
| 13 | + |
| 14 | +Afterwards you can build rustc using: |
| 15 | +```bash |
| 16 | +./x.py build --stage 1 library |
| 17 | +``` |
| 18 | + |
| 19 | +Afterwards rustc toolchain link will allow you to use it through cargo: |
| 20 | +``` |
| 21 | +rustup toolchain link enzyme build/host/stage1 |
| 22 | +rustup toolchain install nightly # enables -Z unstable-options |
| 23 | +``` |
| 24 | + |
| 25 | +You can then run our test cases: |
| 26 | + |
| 27 | +```bash |
| 28 | +./x.py test --stage 1 library tests/ui/autodiff |
| 29 | +./x.py test --stage 1 library tests/codegen/autodiff |
| 30 | +./x.py test --stage 1 library tests/pretty/autodiff* |
| 31 | +``` |
| 32 | + |
| 33 | +Autodiff is still experimental, so if you want to use it in your own projects, you will need to add `lto="fat"` to your Cargo.toml |
| 34 | +and use `RUSTFLAGS="-Zautodiff=Enable" cargo +enzyme` instead of `cargo` or `cargo +nightly`. |
| 35 | + |
| 36 | +## Compiler Explorer and dist builds |
| 37 | + |
| 38 | +Our compiler explorer instance can be updated to a newer rustc in a similar way. First, prepare a docker instance. |
| 39 | +```bash |
| 40 | +docker run -it ubuntu:22.04 |
| 41 | +export CC=clang CXX=clang++ |
| 42 | +apt update |
| 43 | +apt install wget vim python3 git curl libssl-dev pkg-config lld ninja-build cmake clang build-essential |
| 44 | +``` |
| 45 | +Then build rustc in a slightly altered way: |
| 46 | +```bash |
| 47 | +git clone --depth=1 https://github.com/EnzymeAD/rust.git |
| 48 | +cd rust |
| 49 | +./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 |
| 50 | +./x dist |
| 51 | +``` |
| 52 | +We then copy the tarball to our host. The dockerid is the newest entry under `docker ps -a`. |
| 53 | +```bash |
| 54 | +docker cp <dockerid>:/rust/build/dist/rust-nightly-x86_64-unknown-linux-gnu.tar.gz rust-nightly-x86_64-unknown-linux-gnu.tar.gz |
| 55 | +``` |
| 56 | +Afterwards we can create a new (pre-release) tag on the EnzymeAD/rust repository and make a PR against the EnzymeAD/enzyme-explorer repository to update the tag. |
| 57 | +Remember to ping `tgymnich` on the PR to run his update script. |
| 58 | + |
| 59 | + |
| 60 | +## Build instruction for Enzyme itself |
| 61 | + |
| 62 | +Following the Rust build instruction above will build LLVMEnzyme, LLDEnzyme, and ClangEnzyme along with the Rust compiler. |
| 63 | +We recommend that approach, if you just want to use any of them and have no experience with cmake. |
| 64 | +However, if you prefer to just build Enzyme without Rust, then these instructions might help. |
| 65 | + |
| 66 | +```bash |
| 67 | +git clone --depth=1 [email protected]:llvm/llvm-project.git |
| 68 | +cd llvm-project |
| 69 | +mkdir build |
| 70 | +cd build |
| 71 | +cmake -G Ninja ../llvm -DLLVM_TARGETS_TO_BUILD="host" -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_ENABLE_PROJECTS="clang;lld" -DLLVM_ENABLE_RUNTIMES="openmp" -DLLVM_ENABLE_PLUGINS=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=. |
| 72 | +ninja |
| 73 | +ninja install |
| 74 | +``` |
| 75 | +This gives you a working LLVM build, now we can continue with building Enzyme. |
| 76 | +Leave the `llvm-project` folder, and execute the following commands: |
| 77 | +```bash |
| 78 | +git clone [email protected]:EnzymeAD/Enzyme.git |
| 79 | +cd Enzyme/enzyme |
| 80 | +mkdir build |
| 81 | +cd build |
| 82 | +cmake .. -G Ninja -DLLVM_DIR=<YourLocalPath>/llvm-project/build/lib/cmake/llvm/ -DLLVM_EXTERNAL_LIT=<YourLocalPath>/llvm-project/llvm/utils/lit/lit.py -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=YES -DBUILD_SHARED_LIBS=ON |
| 83 | +ninja |
| 84 | +``` |
| 85 | +This will build Enzyme, and you can find it in `Enzyme/enzyme/build/lib/<LLD/Clang/LLVM>Enzyme.so`. (Endings might differ based on your OS). |
| 86 | + |
0 commit comments