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 33 commits into
base: main
Choose a base branch
from

Conversation

bjacobgordon
Copy link
Contributor

@bjacobgordon bjacobgordon commented Dec 23, 2024

First PR, super stoked! 🥳

Context

As part of Turbine Camp, I was referred to this doc to build Torch-MLIR on my Linux VM. It has a lot of potential, and I decided to nudge it in a productive direction a bunch of times as I read and used the doc.

Approach

I tried to make the commits here "atomic", i.e. each one is a singular unit of work such that the file "works better"/"makes more sense" post-commit than pre-commit.

The majority of the commits in this PR is the story of how I "refactored" the doc step by step to look the way it does. I wrote them with Future Us™ in mind! Each commit should have useful information of the changes made that IDEs like VSCode should be able to surface, so please don't squash haha.

Ready when you are, @marbre!

@bjacobgordon bjacobgordon marked this pull request as draft December 23, 2024 23:16
@bjacobgordon
Copy link
Contributor Author

@marbre The only thing I'm unsure about is removing the libtorch flags

@stellaraccident
Copy link
Collaborator

Thanks! Marius/Jacob, please review and land as you see fit. I'll have a closer look when I'm back and can contribute any adjustments then.

@bjacobgordon bjacobgordon force-pushed the docs-refreshes-development-md branch from bd16189 to 0927acd Compare January 2, 2025 14:48
@marbre marbre self-requested a review January 2, 2025 18:12
@bjacobgordon bjacobgordon marked this pull request as ready for review January 3, 2025 18:08
@bjacobgordon bjacobgordon changed the title Refreshes docs/development.md [docs] Refreshes development.md Jan 3, 2025
@bjacobgordon bjacobgordon force-pushed the docs-refreshes-development-md branch 4 times, most recently from 304b07f to a7275ff Compare January 13, 2025 15:21
@bjacobgordon bjacobgordon force-pushed the docs-refreshes-development-md branch 2 times, most recently from 05ea09d to 7f23d36 Compare January 20, 2025 14:47
Copy link
Member

@marbre marbre left a comment

Choose a reason for hiding this comment

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

Thanks for working through the documentation. I certainly understand that this needs improvement and should be restructured in some way. However, I am not sure if that is the structure we should aim for. Maybe we should split out some things, like the formatting, and land this separately. Next we could iterate on the docs, maybe in smaller chunks, before restructuring to much at once. Just thinking loud and other approaches have their benefits as well.

docs/development.md Outdated Show resolved Hide resolved
docs/development.md Outdated Show resolved Hide resolved
docs/development.md Outdated Show resolved Hide resolved
docs/development.md Outdated Show resolved Hide resolved
docs/development.md Outdated Show resolved Hide resolved
@bjacobgordon bjacobgordon force-pushed the docs-refreshes-development-md branch from 7f23d36 to d4b0153 Compare January 21, 2025 17:47
docs/development.md Outdated Show resolved Hide resolved
-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.

This "runs" and does not "appends" as there is no \ at the last line. I still find the append / run a little confusing. Maybe having multiple blocks that "just work" is easier, even if it adds redundancy. I could image that @zjgarvey or @ScottTodd might have an opinion on this.

Copy link
Member

Choose a reason for hiding this comment

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

A page like https://llvm.org/docs/CMake.html may be useful to study and replicate, for consistency within LLVM.

  • Start with the minimal command
  • Call out frequently used variables
  • List all other variables

In the IREE docs we have some recommended recipes at https://iree.dev/building-from-source/getting-started/. If the list of options gets longer and continues to branch based on usage style, I'd recommend looking at CMake presets or toolchain files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@marbre Yeah, one caveat is that it assumes you're going to use the code block copy button provided by GitHub! If you use that, it works great. You copy-paste, copy-paste, copy-paste all the parts you need and then run at the end.

@ScottTodd I definitely think some kind of preset would be super useful here! Will search on my end, but do you have any links handy?

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.

@ScottTodd Would this allow us to build a macro to specify stuff like

  • llvm in-tree: yes/no
  • frequent rebuilds: yes/no
  • enable tests: yes/no
    such that it'll just use the relevant options given the flags?

Copy link
Member

Choose a reason for hiding this comment

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

Sorta. Presets are a bit clunky when you get that far into the weeds though. They are good for high level switches that are mutually exclusive with one another.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@marbre 3 flags with 2 states each yields 8 separate combinations, meaning 8 separate (but closely related) code blocks. Because of this, I'm hesitant to go the "premade" route over the "composition" route. Maybe we could word it in a way that more effectively communicates how clusters of cmake options should be "tacked on"?

@ScottTodd Or maybe we just make a shell script for it until someone else has a chance to come along and make a decent preset for it?

Copy link
Member

Choose a reason for hiding this comment

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

That is just one reason why I think the previous structure wasn't too bad. A rather complete command + a simplified one. All other options described separately and if you need those, you'd need to adjust your configuration command. In contrast the patch forces users to always copy paste multiple blocks to get a working configuration.

docs/development.md Outdated Show resolved Hide resolved
-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.

A page like https://llvm.org/docs/CMake.html may be useful to study and replicate, for consistency within LLVM.

  • Start with the minimal command
  • Call out frequently used variables
  • List all other variables

In the IREE docs we have some recommended recipes at https://iree.dev/building-from-source/getting-started/. If the list of options gets longer and continues to branch based on usage style, I'd recommend looking at CMake presets or toolchain files.

Comment on lines +192 to +171
1. **If you want to...**
- **...build _just_ torch-mlir (not all of LLVM)**, append:

```shell
--target tools/torch-mlir/all
```
Copy link
Member

Choose a reason for hiding this comment

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

Echoing some of the other comments about individual code blocks and appending, here I would spell out of the full command for easier copy/paste

Suggested change
1. **If you want to...**
- **...build _just_ torch-mlir (not all of LLVM)**, append:
```shell
--target tools/torch-mlir/all
```
1. **If you want to...**
- **...build _just_ torch-mlir (not all of LLVM)**:
```shell
cmake --build build --target tools/torch-mlir/all
```

same with the other examples

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 had tried that initially, but it didn't really convey that you could add all three targets, one on top of the other.

If I wanna run unit tests and regression tests, I can copy-paste to get:
cmake --build build --target check-torch-mlir --target check-torch-mlir-python

From there, I can recall from command line history as much as I need!

But having them in separate blocks required me to click-drag-copy-paste.

What cmake wizardry do you recommend?

Copy link
Member

Choose a reason for hiding this comment

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

What cmake wizardry do you recommend?

For any high productivity setup (and not just validating that some set of options works or casually testing a project), I configure Visual Studio Code. My examples here are for IREE, but they should also apply for other projects like torch-mlir.

  • JSON workspace/settings files let you track all of your options, toggling lines commented out as you want to flip between sets

    // iree.code-workspace
    {
        "folders": [
    	    {
    		    "path": ".."
    	    }
        ],
        "settings": {
    	    "cmake.automaticReconfigure": false,
    	    "cmake.buildDirectory": "${workspaceFolder}/../iree-build",
    	    "cmake.configureArgs": [
    		    "-DIREE_BUILD_PYTHON_BINDINGS=OFF",
    		    // "-DIREE_BUILD_PYTHON_BINDINGS=ON",
    		    "-DPython3_EXECUTABLE=${workspaceFolder}/.venv/bin/python",
    		    //
    		    "-DIREE_HAL_DRIVER_CUDA=ON",
    		    "-DIREE_HAL_DRIVER_HIP=ON",
    		    "-DIREE_HAL_DRIVER_LOCAL_SYNC=ON",
    		    "-DIREE_HAL_DRIVER_LOCAL_TASK=ON",
    		    "-DIREE_HAL_DRIVER_METAL=OFF",
    		    "-DIREE_HAL_DRIVER_NULL=ON",
    		    "-DIREE_HAL_DRIVER_VULKAN=ON",
    		    //
    		    "-DIREE_TARGET_BACKEND_VMVX=ON",
    		    "-DIREE_TARGET_BACKEND_LLVM_CPU=ON",
    		    "-DIREE_TARGET_BACKEND_LLVM_CPU_WASM=ON",
    		    "-DIREE_TARGET_BACKEND_METAL_SPIRV=ON",
    		    "-DIREE_TARGET_BACKEND_VULKAN_SPIRV=ON",
    		    "-DIREE_TARGET_BACKEND_ROCM=ON",
    		    "-DIREE_TARGET_BACKEND_CUDA=ON",
    		    //
    		    "-DIREE_HIP_TEST_TARGET_CHIP=gfx1100",
    		    //
    		    // ccache: https://ccache.dev/
    		    "-DCMAKE_C_COMPILER_LAUNCHER=ccache",
    		    "-DCMAKE_CXX_COMPILER_LAUNCHER=ccache",
    		    //
    		    "-DIREE_ENABLE_LLD=ON",
    	    ],
    	    "cmakeExplorer.buildDir": "${workspaceFolder}/../iree-build",
    	    "cmakeExplorer.suiteDelimiter": "/",
    	    "cmakeExplorer.extraCtestRunArgs": "--verbose",
        }
    }
  • GUI lets you select which target, including meta targets like all, to build
    image

  • Test explorer lets you choose which tests to run, including all tests under a given package/namespace
    image

Copy link
Contributor Author

@bjacobgordon bjacobgordon Jan 22, 2025

Choose a reason for hiding this comment

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

@ScottTodd That looks great!

The development.md doc doesn't really specify anything for IDE config, probably because it's a "nice to have". Is that the direction we wanna go? Or are we just wanting to get new contributors going with the "need to have" items?

docs/development.md Outdated Show resolved Hide resolved
- emphasizes the common options between "in-tree extended", "in-of-tree base", and "out-of-tree"
- tweaks existing headers to communicate command construction rather than immediate execution
- adds new header to indicate when the command should actually be executed
- the use-case for this doc leans more toward "development" rather than "release"
- leverages numbering and indentation to reduce cognitive load
CMake issued a warning upon fresh build:
"""
Manually-specified variables were not used by the project:
   LIBTORCH_CACHE
   LIBTORCH_SRC_BUILD
   LIBTORCH_VARIANT
"""
…arate code blocks

- makes them individually copyable from GitHub
… Build"

- makes it so that the GitHub copy button only grabs the code snippet itself
- less repetitive
- emphasizes that the targets can be chained
@bjacobgordon bjacobgordon force-pushed the docs-refreshes-development-md branch from d4b0153 to 1c5d64e Compare January 21, 2025 23:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants