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

[docs] Refreshes development.md #3932

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
3df144f
docs(development.md): moves optional command addendums after LLVM det…
bjacobgordon Dec 19, 2024
9da0ec0
docs(development.md): tweaks headers to communicate mutual exclusivit…
bjacobgordon Dec 19, 2024
93abcad
docs(development.md): adds missing DLLVM_ENABLE_ASSERTIONS under "Sim…
bjacobgordon Dec 18, 2024
e04bdc0
docs(development.md): rearranges cmake configuration options
bjacobgordon Dec 19, 2024
5002543
docs(development.md): clarifies rationale for configuring "in-tree" b…
bjacobgordon Dec 19, 2024
f020a57
docs(development.md): moves "base options" to be first "in-tree" command
bjacobgordon Dec 19, 2024
a24d47b
docs(development.md): clarifies "configure" headers
bjacobgordon Dec 20, 2024
7fa51cc
docs(development.md): extracts common CMake options into first subheader
bjacobgordon Dec 20, 2024
993dc9f
docs(development.md): extracts common "in-tree" CMake options into fi…
bjacobgordon Dec 20, 2024
e769344
docs(development.md): extracts build optimization options into h5 header
bjacobgordon Dec 20, 2024
6fb7e5f
docs(development.md): simplifies section about CMake options for LLVM
bjacobgordon Dec 20, 2024
0e8584a
docs(development.md): moves notes to bottom of build optimization sec…
bjacobgordon Dec 20, 2024
cae34b5
docs(development.md): moves notes to bottom of CMake end-to-end tests…
bjacobgordon Dec 20, 2024
9b582d6
docs(development.md): updates DCMAKE_BUILD_TYPE to "RelWithDebInfo"
bjacobgordon Dec 18, 2024
a036e37
docs(development.md): converts headers under CMake to numbered list
bjacobgordon Dec 20, 2024
94cfac4
docs(development.md): combines common options with mandatory LLVM opt…
bjacobgordon Jan 28, 2025
c5996f4
docs(development.md): adds reminder to activate python environment be…
bjacobgordon Dec 20, 2024
7727257
docs(development.md): removes unused libtorch variables
bjacobgordon Dec 17, 2024
5ec3bf5
docs(development.md): enunciates CMake configuration is required befo…
bjacobgordon Dec 23, 2024
dc8dd0f
docs(development.md): converts details under "Initiate Build" section…
bjacobgordon Dec 23, 2024
647227b
docs(development.md): splits commands under "Initiate Build" into sep…
bjacobgordon Dec 23, 2024
7318410
docs(development.md): extracts comments from commands under "Initiate…
bjacobgordon Dec 23, 2024
d607f54
docs(development.md): moves vanilla build command to first bullet und…
bjacobgordon Dec 23, 2024
398db4f
docs(development.md): restructures the "Initiate Build" section
bjacobgordon Dec 23, 2024
84d17b6
docs(development.md): simplifies options for specifying linker
bjacobgordon Jan 21, 2025
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
176 changes: 82 additions & 94 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Contributor Author

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?

-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DPython3_FIND_VIRTUALENV=ONLY \
-DMLIR_ENABLE_BINDINGS_PYTHON=ON \
-DLLVM_TARGETS_TO_BUILD=host \
\
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
\

The additional line looks odd to me.

Copy link
Contributor Author

@bjacobgordon bjacobgordon Jan 30, 2025

Choose a reason for hiding this comment

The 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 \
\
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
\

`# For building LLVM "out-of-tree"` \
-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`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rephrase to, make enable building MLIR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 main.

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.
- [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
\
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
\
Copy link
Member

Choose a reason for hiding this comment

The 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

Expand Down
Loading