-
Notifications
You must be signed in to change notification settings - Fork 539
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
[docs] Refreshes development.md #3932
base: main
Are you sure you want to change the base?
Changes from all commits
3df144f
9da0ec0
93abcad
e04bdc0
5002543
f020a57
a24d47b
7fa51cc
993dc9f
e769344
6fb7e5f
0e8584a
cae34b5
9b582d6
a036e37
94cfac4
c5996f4
7727257
5ec3bf5
dc8dd0f
647227b
7318410
d607f54
398db4f
84d17b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -93,114 +93,102 @@ sudo apt install clang ccache lld | |||
1. Set up Developer PowerShell [for Visual Studio](https://learn.microsoft.com/en-us/visualstudio/ide/reference/command-prompt-powershell?view=vs-2022#start-in-visual-studio) | ||||
1. Ensure that the compiler and linker binaries are in the `PATH` variable. | ||||
|
||||
#### Configure for Building... | ||||
#### Configure for Building | ||||
|
||||
1. [Activate the Python environment](#set-up-the-python-environment) | ||||
1. Choose command with relevant LLVM options: | ||||
1. **If building "in-tree"**, run/append: | ||||
|
||||
```shell | ||||
cmake -GNinja -Bbuild \ | ||||
`# Enables "--debug" and "--debug-only" flags for the "torch-mlir-opt" tool` \ | ||||
-DCMAKE_BUILD_TYPE=RelWithDebInfo \ | ||||
-DLLVM_ENABLE_ASSERTIONS=ON \ | ||||
-DPython3_FIND_VIRTUALENV=ONLY \ | ||||
-DMLIR_ENABLE_BINDINGS_PYTHON=ON \ | ||||
-DLLVM_TARGETS_TO_BUILD=host \ | ||||
\ | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
The additional line looks odd to me. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree. Wanting to somehow communicate at-a-glance "this chunk of options is the key difference between the two otherwise-identical code blocks". What's another way we could do that? |
||||
`# For building LLVM "in-tree"` \ | ||||
externals/llvm-project/llvm \ | ||||
-DLLVM_ENABLE_PROJECTS=mlir \ | ||||
-DLLVM_EXTERNAL_PROJECTS="torch-mlir" \ | ||||
-DLLVM_EXTERNAL_TORCH_MLIR_SOURCE_DIR="$PWD" | ||||
``` | ||||
|
||||
- NOTE: uses external/llvm-project/llvm as the main build, so LLVM will be built in additional to torch-mlir and its sub-projects. | ||||
1. **If using "out-of-tree" build**, run/append: | ||||
|
||||
```shell | ||||
cmake -GNinja -Bbuild \ | ||||
`# Enables "--debug" and "--debug-only" flags for the "torch-mlir-opt" tool` \ | ||||
-DCMAKE_BUILD_TYPE=RelWithDebInfo \ | ||||
-DLLVM_ENABLE_ASSERTIONS=ON \ | ||||
-DPython3_FIND_VIRTUALENV=ONLY \ | ||||
-DMLIR_ENABLE_BINDINGS_PYTHON=ON \ | ||||
-DLLVM_TARGETS_TO_BUILD=host \ | ||||
\ | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
`# For building LLVM "out-of-tree"` \ | ||||
bjacobgordon marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
-DMLIR_DIR="$LLVM_INSTALL_DIR/lib/cmake/mlir/" \ | ||||
-DLLVM_DIR="$LLVM_INSTALL_DIR/lib/cmake/llvm/" | ||||
``` | ||||
|
||||
- Be sure to have built LLVM with `-DLLVM_ENABLE_PROJECTS=mlir`. | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would rephrase to, make enable building MLIR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Couldn't remember at first, but it looks like all I did was move it to a different spot haha. It's worded the same way it was on Could we save rephrasing this for a subsequent PR? |
||||
- Be aware that the installed version of LLVM needs in general to match the committed version in `externals/llvm-project`. Using a different version may or may not work. | ||||
bjacobgordon marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
- [About MLIR debugging](https://mlir.llvm.org/getting_started/Debugging/) | ||||
1. **If you anticipate needing to frequently rebuild LLVM**, append: | ||||
|
||||
Two setups are possible to build: in-tree and out-of-tree. The in-tree setup is the most straightforward, as it will build LLVM dependencies as well. | ||||
|
||||
##### ...with LLVM "in-tree" using... | ||||
|
||||
The following commands generate configuration files to build the project *in-tree*, that is, using llvm/llvm-project as the main build. This will build LLVM as well as torch-mlir and its subprojects. | ||||
|
||||
###### ...Base + Optimization Options | ||||
This will build `libtorch` / `PyTorch` wheels from source and requires [the enablement mentioned earlier](#optional-enable-quicker-builds). If you encounter issues when you run this, try the [simplified build command](#base-options) instead. | ||||
|
||||
```shell | ||||
cmake -GNinja -Bbuild \ | ||||
externals/llvm-project/llvm \ | ||||
-DCMAKE_BUILD_TYPE=Release \ | ||||
-DLLVM_ENABLE_ASSERTIONS=ON \ | ||||
-DPython3_FIND_VIRTUALENV=ONLY \ | ||||
-DLLVM_ENABLE_PROJECTS=mlir \ | ||||
-DLLVM_EXTERNAL_PROJECTS="torch-mlir" \ | ||||
-DLLVM_EXTERNAL_TORCH_MLIR_SOURCE_DIR="$PWD" \ | ||||
-DMLIR_ENABLE_BINDINGS_PYTHON=ON \ | ||||
-DLLVM_TARGETS_TO_BUILD=host \ | ||||
`# use clang`\ | ||||
-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ \ | ||||
`# use ccache to cache build results` \ | ||||
-DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ | ||||
`# use LLD to link in seconds, rather than minutes` \ | ||||
`# if using clang <= 13, replace --ld-path=ld.lld with -fuse-ld=lld` \ | ||||
-DCMAKE_EXE_LINKER_FLAGS_INIT="--ld-path=ld.lld" \ | ||||
-DCMAKE_MODULE_LINKER_FLAGS_INIT="--ld-path=ld.lld" \ | ||||
-DCMAKE_SHARED_LINKER_FLAGS_INIT="--ld-path=ld.lld" \ | ||||
`# Enabling libtorch binary cache instead of downloading the latest libtorch everytime.` \ | ||||
`# Testing against a mismatched version of libtorch may cause failures` \ | ||||
-DLIBTORCH_CACHE=ON \ | ||||
`# Enable an experimental path to build libtorch (and PyTorch wheels) from source,` \ | ||||
`# instead of downloading them` \ | ||||
-DLIBTORCH_SRC_BUILD=ON \ | ||||
`# Set the variant of libtorch to build / link against. (shared|static and optionally cxxabi11)` \ | ||||
-DLIBTORCH_VARIANT=shared | ||||
``` | ||||
|
||||
###### ...Base Options | ||||
|
||||
If you're running into issues with the above build command, consider using the following: | ||||
|
||||
```shell | ||||
cmake -GNinja -Bbuild \ | ||||
-DCMAKE_BUILD_TYPE=Release \ | ||||
-DPython3_FIND_VIRTUALENV=ONLY \ | ||||
-DLLVM_ENABLE_PROJECTS=mlir \ | ||||
-DLLVM_EXTERNAL_PROJECTS="torch-mlir" \ | ||||
-DLLVM_EXTERNAL_TORCH_MLIR_SOURCE_DIR="$PWD" \ | ||||
-DMLIR_ENABLE_BINDINGS_PYTHON=ON \ | ||||
-DLLVM_TARGETS_TO_BUILD=host \ | ||||
externals/llvm-project/llvm | ||||
``` | ||||
```shell | ||||
\ | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is what you had meant, right? All you need to get going is copying, pasting and running one of the "base" commands. Tacking this on before running is optional, right? |
||||
`# use clang`\ | ||||
-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ \ | ||||
`# use ccache to cache build results` \ | ||||
-DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ | ||||
`# use LLD to link in seconds, rather than minutes` \ | ||||
-DCMAKE_LINKER_TYPE=lld | ||||
``` | ||||
|
||||
##### Options to enable MLIR debugging | ||||
- This requires [the enablement mentioned earlier](#optional-enable-quicker-builds). | ||||
- If these options cause issues, just skip them for now. | ||||
1. **If you need to enable local end-to-end tests**, append: | ||||
|
||||
* Enabling `--debug` and `--debug-only` flags (see [MLIR docs](https://mlir.llvm.org/getting_started/Debugging/)) for the `torch-mlir-opt` tool | ||||
```shell | ||||
-DCMAKE_BUILD_TYPE=RelWithDebInfo \ # or =Debug | ||||
-DLLVM_ENABLE_ASSERTIONS=ON \ | ||||
``` | ||||
```shell | ||||
\ | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
-DTORCH_MLIR_ENABLE_PYTORCH_EXTENSIONS=ON \ | ||||
-DTORCH_MLIR_ENABLE_JIT_IR_IMPORTER=ON | ||||
``` | ||||
|
||||
##### Options to run end-to-end tests | ||||
- NOTE: The JIT IR importer depends on the native PyTorch extension features and defaults to `ON` if not changed. | ||||
1. Run assembled command (once you've appended the options pertaining to your workflow) | ||||
|
||||
Running the end-to-end execution tests locally requires enabling the native PyTorch extension features and the JIT IR importer, which depends on the | ||||
former and defaults to `ON` if not changed: | ||||
```shell | ||||
-DTORCH_MLIR_ENABLE_PYTORCH_EXTENSIONS=ON \ | ||||
-DTORCH_MLIR_ENABLE_JIT_IR_IMPORTER=ON \ | ||||
``` | ||||
#### Initiate Build | ||||
|
||||
##### ...with LLVM "out-of-tree" | ||||
1. [Configure the build](#configure-for-building) if you haven't already done so. | ||||
1. **If you want to...** | ||||
- **...build _everything_** (including LLVM if configured as "in-tree"), run: | ||||
|
||||
If you have built llvm-project separately in the directory `$LLVM_INSTALL_DIR`, you can also build the project *out-of-tree* using the following command as template: | ||||
```shell | ||||
cmake -GNinja -Bbuild \ | ||||
-DCMAKE_BUILD_TYPE=Release \ | ||||
-DPython3_FIND_VIRTUALENV=ONLY \ | ||||
-DMLIR_DIR="$LLVM_INSTALL_DIR/lib/cmake/mlir/" \ | ||||
-DLLVM_DIR="$LLVM_INSTALL_DIR/lib/cmake/llvm/" \ | ||||
-DMLIR_ENABLE_BINDINGS_PYTHON=ON \ | ||||
-DLLVM_TARGETS_TO_BUILD=host \ | ||||
. | ||||
``` | ||||
The same QoL CMake flags can be used to enable clang, ccache, and lld. Be sure to have built LLVM with `-DLLVM_ENABLE_PROJECTS=mlir`. | ||||
```shell | ||||
cmake --build build | ||||
``` | ||||
|
||||
Be aware that the installed version of LLVM needs in general to match the committed version in `externals/llvm-project`. Using a different version may or may not work. | ||||
- **...build _just_ torch-mlir** (not all of LLVM), run: | ||||
|
||||
#### Initiate Build | ||||
```shell | ||||
cmake --build build --target tools/torch-mlir/all | ||||
``` | ||||
|
||||
After either cmake run (in-tree/out-of-tree), use one of the following commands to build the project: | ||||
- **...run unit tests**, run: | ||||
|
||||
```shell | ||||
# Build just torch-mlir (not all of LLVM) | ||||
cmake --build build --target tools/torch-mlir/all | ||||
```shell | ||||
cmake --build build --target check-torch-mlir | ||||
``` | ||||
|
||||
# Run unit tests. | ||||
cmake --build build --target check-torch-mlir | ||||
- **...run Python regression tests**, run: | ||||
|
||||
# Run Python regression tests. | ||||
cmake --build build --target check-torch-mlir-python | ||||
```shell | ||||
cmake --build build --target check-torch-mlir-python | ||||
``` | ||||
|
||||
# Build everything (including LLVM if in-tree) | ||||
cmake --build build | ||||
``` | ||||
TIP: add multiple target options to stack build phases | ||||
|
||||
### Setup Python Environment to export the built Python packages | ||||
|
||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm guessing this is not what you had in mind haha. I'll need a little more direction here, which parts seem odd?