Skip to content

Commit

Permalink
Add Devcontainer files and Docs (onnx#2048)
Browse files Browse the repository at this point in the history
Signed-off-by: Maximilian Bartel <[email protected]>
Co-authored-by: gongsu832 <[email protected]>
  • Loading branch information
maxbartel and gongsu832 authored Mar 21, 2023
1 parent 4c0d2da commit 7d805b1
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,4 @@ dmypy.json

# Visual Studio Code Files
.vscode
.devcontainer
13 changes: 13 additions & 0 deletions docs/Docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,16 @@ git push --set-upstream origin main

A Docker container can be used to investigate a bug, or to develop a new feature. Some like to create a new images for each new version of ONNX-MLIR; others prefer to create one image and use git to update the main branch and use git to switch between multiple branches. Both are valid approaches.

## Using a devcontainer
Another way of building onnx-mlir for development in VSCode is using a devcontainer. This way you only mount your source folder, meaning that changes you do are saved on your local machine. For this setup to work you need a `Dockerfile` and a `devcontainer.json` file. Both are provided in `docs/devcontainer-example`.

The [`Dockerfile`](devcontainer-example/Dockerfile.llvm-project) is a simple Dockerfile based on the precompiled LLVM/MLIR image that is shared. It installs additional software that is useful for developing and also sets `LLVM_PROJECT_ROOT` to easily refer to the LLVM path.


The [`devcontainer.json`](devcontainer-example/devcontainer.json) preinstalls extensions and defines settings for the VS Code server running inside the container. This way you don't have to setup VS Code everytime you enter the container. In `postAttachCommand` ONNX is installed.

To use this setup you first clone onnx-mlir and all submodules (for example with` git clone --recursive https://github.com/onnx/onnx-mlir.git`). You then create a new folder named `.devcontainer` in the source root. After that you copy the two files in `docs/devcontainer-example` into that folder. Now simply press `CTRL+SHIFT+P` and execute `Dev Containers: Reopen in Container`. VS Code will now create the docker image and mount the source folder.

You can now configure onnx-mlir as described in [BuildOnLinuxOSX](BuildOnLinuxOSX.md). `MLIR_DIR` is already set for you, so you can skip that step.

**Note:** To run this on M1/2 Macs something like Rosetta is needed. This is related to https://github.com/docker/roadmap/issues/384
14 changes: 14 additions & 0 deletions docs/devcontainer-example/Dockerfile.llvm-project
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ARG BASE_IMAGE="onnxmlirczar/onnx-mlir-llvm-static:amd64"
FROM ${BASE_IMAGE}

RUN apt-get update

# 2) Install optional packages, comment/uncomment/add as you see fit.
RUN apt-get install -y vim bash valgrind clang-format lsb-release \
wget software-properties-common ssh-client gdb
RUN python3 -m pip install -U pip && pip install commitizen

# For development
ENV LLVM_PROJECT_ROOT=/workdir/llvm-project
ENV MLIR_DIR=/workdir/llvm-project/build/lib/cmake/mlir
ENV eval "$(ssh-agent)"
74 changes: 74 additions & 0 deletions docs/devcontainer-example/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"build": { "dockerfile": "Dockerfile.llvm-project" },
"customizations": {
"vscode": {
"settings": {
"terminal.integrated.defaultProfile.linux": "bash",
"cmake.mergedCompileCommands": "${workspaceFolder}/compile_commands.json",
"cmakeExplorer.suiteDelimiter": ".",
"cmakeExplorer.debugConfig": "(gdb) Launch",
"editor.formatOnSave": true,
"[cpp]": {
"editor.defaultFormatter": "xaver.clang-format",
"editor.tabSize": 2
},
"clangd.path": "/usr/bin/clangd-15",
"clangd.arguments": [
"--background-index",
"-header-insertion=never",
"-j=4"
],
"cmake.buildDirectory": "${workspaceFolder}/build",
"cmake.generator": "Ninja",
"cmake.defaultVariants": {
"buildType": {
"default": "reldeb",
"description": "The build type.",
"choices": {
"debug": {
"short": "Debug",
"long": "Disable optimizations - include debug information.",
"buildType": "Debug"
},
"release": {
"short": "Release",
"long": "Optimize for speed - exclude debug information.",
"buildType": "Release"
},
"minsize": {
"short": "MinSizeRel",
"long": "Optimize for smallest binary size - exclude debug information.",
"buildType": "MinSizeRel"
},
"reldeb": {
"short": "RelWithDebInfo",
"long": "Optimize for speed - include debug information.",
"buildType": "RelWithDebInfo"
}
}
}
}
},
"extensions": [
"llvm-vs-code-extensions.vscode-clangd",
"vadimcn.vscode-lldb",
"ms-vscode.cmake-tools",
"fredericbonnet.cmake-test-adapter",
"twxs.cmake",
"xaver.clang-format",
"notskm.clang-tidy",
"ms-python.python",
"ms-python.vscode-pylance",
"eamodio.gitlens",
"llvm-vs-code-extensions.vscode-mlir",
"cschlosser.doxdocgen",
"chneau.resource-monitor",
"spmeesseman.vscode-taskexplorer",
"edonet.vscode-command-runner"
]
}
},
"workspaceFolder": "${localWorkspaceFolder}",
"workspaceMount": "source=${localWorkspaceFolder},target=${localWorkspaceFolder},type=bind,consistency=cached",
"postAttachCommand": "ONNX_ROOT=third_party/onnx && cd ${ONNX_ROOT} && python3 -m pip install . && cd ../.."
}

0 comments on commit 7d805b1

Please sign in to comment.