Skip to content

Commit 8a28372

Browse files
Implement CUDA support and GPU operations for tensor processing (#8)
This PR adds a CUDA/GPU-oriented path to the `mlir/cuda-tile` Toy-based compiler flow, including a new `matmul` op, GPU outlining, and a pass to emit/embed CUDA Tile binaries, plus assorted scripts and sample MLIR/Toy programs to exercise the pipeline. **Changes:** - Add Toy dialect/compiler extensions: `matmul` op + lowering, GPU outlining (`toy.launch_gpu`/`toy.gpu_func`), and a CUDA Tile emission/embedding pass. - Add build/sync scripts, devcontainer configuration, and VS Code configs to stand up a CUDA/MLIR development environment. - Add sample `.toy`/`.mlir` programs and CUDA shim/kernel sources demonstrating GPU execution.
1 parent 3165b0c commit 8a28372

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+11515
-0
lines changed

mlir/cuda-tile/.clang-format

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
BasedOnStyle: LLVM
2+
LineEnding: LF
3+
IndentWidth: 2
4+
TabWidth: 2
5+
UseTab: Never
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
FROM alwaysproblem/fastdev-u2204:nv13.1.0
2+
3+
ARG UID=1000
4+
ARG GID=1000
5+
6+
RUN echo "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy main" > /etc/apt/sources.list.d/llvm.list \
7+
&& echo "deb-src http://apt.llvm.org/jammy/ llvm-toolchain-jammy main" >> /etc/apt/sources.list.d/llvm.list \
8+
&& echo "# 20" >> /etc/apt/sources.list.d/llvm.list \
9+
&& echo "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-20 main" >> /etc/apt/sources.list.d/llvm.list \
10+
&& echo "deb-src http://apt.llvm.org/jammy/ llvm-toolchain-jammy-20 main" >> /etc/apt/sources.list.d/llvm.list \
11+
&& echo "# 21" >> /etc/apt/sources.list.d/llvm.list \
12+
&& echo "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-21 main" >> /etc/apt/sources.list.d/llvm.list \
13+
&& echo "deb-src http://apt.llvm.org/jammy/ llvm-toolchain-jammy-21 main" >> /etc/apt/sources.list.d/llvm.list \
14+
&& wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc \
15+
&& apt update -y && \
16+
apt install -y \
17+
python3 python3-dev python3-setuptools python3-pip \
18+
libtinfo-dev zlib1g-dev \
19+
build-essential cmake ninja-build \
20+
clang-20 clang-tidy-20 clangd-20 cmake-format \
21+
clang-format-20 lldb-20 lld-20 libfmt-dev libspdlog-dev \
22+
&& apt clean -y && rm -rf /var/lib/apt/lists/* \
23+
&& update-alternatives --install /usr/bin/clang clang /usr/bin/clang-20 100 \
24+
&& update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-20 100 \
25+
&& update-alternatives --install /usr/bin/clangd clangd /usr/bin/clangd-20 100 \
26+
&& update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-20 100 \
27+
&& update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-20 100 \
28+
&& update-alternatives --install /usr/bin/lld lld /usr/bin/lld-20 100 \
29+
&& update-alternatives --install /usr/bin/lldb lldb /usr/bin/lldb-20 100
30+
31+
RUN apt update -y && apt install -yq software-properties-common \
32+
&& add-apt-repository -y ppa:ubuntu-toolchain-r/test \
33+
&& apt update -yq \
34+
&& apt install -yq gcc-13 g++-13 gdb \
35+
&& update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-13 100 \
36+
&& update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-13 100 \
37+
&& apt clean -y && rm -rf /var/lib/apt/lists/*
38+
39+
RUN git config --global --add safe.directory '*' && \
40+
/root/.local/bin/setup_new_user ${UID} ${GID} && \
41+
python3 -m pip install pre-commit compdb
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2+
// README at: https://github.com/devcontainers/templates/tree/main/src/anaconda
3+
{
4+
"remoteUser": "root",
5+
"name": "mlir-example",
6+
"workspaceMount": "source=${localWorkspaceFolder},target=${localWorkspaceFolder}/../../../MLcompiler-tutorial/mlir/${localWorkspaceFolderBasename},type=bind",
7+
"workspaceFolder": "/root/Desktop/dockerVolumn/MLcompiler-tutorial/mlir/${localWorkspaceFolderBasename}",
8+
"build": {
9+
"context": "${localWorkspaceFolder}/.devcontainer",
10+
"dockerfile": "Dockerfile",
11+
"options": [
12+
"--network=host"
13+
],
14+
"args": {
15+
"UID": "1000",
16+
"GID": "1000"
17+
}
18+
},
19+
// Features to add to the dev container. More info: https://containers.dev/features.
20+
// "features": {},
21+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
22+
// "forwardPorts": [],
23+
// Use 'postCreateCommand' to run commands after the container is created.
24+
// "postCreateCommand": "python --version",
25+
// Configure tool-specific properties.
26+
// "customizations": {},
27+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
28+
// "remoteUser": "root"
29+
"privileged": true,
30+
// "capAdd": ["SYS_PTRACE"],
31+
"mounts": [
32+
{
33+
"source": "${localWorkspaceFolder}/../../../",
34+
"target": "/root/Desktop/dockerVolumn",
35+
"type": "bind"
36+
}
37+
],
38+
"runArgs": [
39+
// "--cap-add=SYS_PTRACE",
40+
// "--security-opt",
41+
// "seccomp=unconfined",
42+
"--name",
43+
// "${localEnv:USER}-tvm",
44+
"yyx-cuda-tile",
45+
// "-v",
46+
// "/data/rech/yongxiy/Desktop/dockerVolumn:/root/Desktop/dockerVolumn"
47+
],
48+
"customizations": {
49+
"vscode": {
50+
"extensions": [
51+
"jeff-hykin.better-cpp-syntax",
52+
"aaron-bond.better-comments",
53+
"ms-vscode.cpptools-themes",
54+
"revng.llvm-ir",
55+
"jakob-erzar.llvm-tablegen",
56+
"MomenAbdelkarim-WyattCalandro-LuisPrieto.mlir",
57+
"ms-vscode.cpptools",
58+
"ms-vscode.cpptools-extension-pack",
59+
"twxs.cmake",
60+
"josetr.cmake-language-support-vscode",
61+
"ms-vscode.cmake-tools",
62+
"cheshirekow.cmake-format",
63+
"yzhang.markdown-all-in-one",
64+
"bierner.markdown-preview-github-styles",
65+
"bierner.markdown-mermaid",
66+
"DavidAnson.vscode-markdownlint",
67+
"llvm-vs-code-extensions.vscode-mlir",
68+
"llvm-vs-code-extensions.vscode-clangd",
69+
"llvm-vs-code-extensions.lldb-dap",
70+
"mutantdino.resourcemonitor",
71+
"hoovercj.vscode-power-mode",
72+
"GitHub.copilot-chat",
73+
"Codereviewforgithubcopilot.github-copilot-code-review"
74+
]
75+
}
76+
}
77+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This file copied into the container along with environment.yml* from the parent
2+
folder. This file is included to prevents the Dockerfile COPY instruction from
3+
failing if no environment.yml is found.

mlir/cuda-tile/.envsetup.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
source /root/miniconda3/etc/profile.d/conda.sh && conda activate mlir

mlir/cuda-tile/.gitignore

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
*.ptx
2+
*.cubin
3+
*.fatbin
4+
*.bc
5+
*.ll
6+
*.o
7+
*.s
8+
*.so
9+
*.dylib
10+
*.a
11+
*.dll
12+
*.obj
13+
*.exe
14+
*.log
15+
*.cache
16+
*.tmp
17+
*.bin
18+
*.out
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.3.0
4+
hooks:
5+
- id: check-yaml
6+
- id: trailing-whitespace
7+
- id: end-of-file-fixer
8+
9+
- repo: https://github.com/pre-commit/mirrors-clang-format
10+
rev: 'v14.0.6'
11+
hooks:
12+
- id: clang-format
13+
types_or: [c++, c]
14+
15+
- repo: https://github.com/cheshirekow/cmake-format-precommit
16+
rev: v0.6.10
17+
hooks:
18+
- id: cmake-format
19+
- id: cmake-lint

mlir/cuda-tile/CMakeLists.txt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
cmake_minimum_required(VERSION 3.10)
2+
3+
# note: fix ztd terminfo not found
4+
project(cuda-tile LANGUAGES C CXX)
5+
6+
# ############## For conda users.################################
7+
find_package(LLVM CONFIG REQUIRED)
8+
find_package(MLIR CONFIG REQUIRED)
9+
# set(MLIR_TABLEGEN_EXE /root/anaconda3/envs/mlir/bin/mlir-tblgen)
10+
# ##############################################################################
11+
12+
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
13+
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
14+
message(STATUS "Found MLIR ${MLIR_PACKAGE_VERSION}")
15+
message(STATUS "Using MLIRConfig.cmake in: ${MLIR_DIR}")
16+
message(STATUS "Found MLIRTableGen: ${MLIR_TABLEGEN_EXE}")
17+
message(STATUS "LLVM_INCLUDE_DIR include dir: ${LLVM_INCLUDE_DIR}")
18+
message(STATUS "MLIR_INCLUDE_DIR include dir: ${MLIR_INCLUDE_DIR}")
19+
20+
# This is for non-conda users.
21+
find_package(LLVM CONFIG PATHS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/lib/cmake/llvm)
22+
find_package(MLIR CONFIG PATHS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/lib/cmake/mlir)
23+
find_package(CUDAToolkit REQUIRED)
24+
# set(MLIR_TABLEGEN_EXE ${CMAKE_CURRENT_SOURCE_DIR}/third_party/bin/mlir-tblgen)
25+
message(STATUS "CUDA Toolkit found: ${CUDAToolkit_INCLUDE_DIRS}")
26+
message(STATUS "CUDA_TILE_SOURCE_DIR include dir: ${CUDA_TILE_SOURCE_DIR}")
27+
message(STATUS "CUDA_TILE_BINARY_DIR include dir: ${CUDA_TILE_BINARY_DIR}")
28+
29+
include_directories(${LLVM_INCLUDE_DIR})
30+
include_directories(${MLIR_INCLUDE_DIR})
31+
include_directories(${CUDAToolkit_INCLUDE_DIRS})
32+
include_directories(${CUDA_TILE_SOURCE_DIR}/include)
33+
include_directories(${CUDA_TILE_BINARY_DIR}/include)
34+
35+
include(LLVMDistributionSupport)
36+
include(TableGen)
37+
include(AddMLIR)
38+
include(AddLLVM)
39+
# include(HandleLLVMOptions)
40+
41+
# note: fix the llvm::cl undefined reference problem
42+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -fno-rtti")
43+
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
44+
45+
add_subdirectory(Toy)

0 commit comments

Comments
 (0)