Installation.md 8.8 KB
Newer Older
1
2
3
4
5
6
# Installation Guide

## Installing with pip

**Prerequisites for installation via wheel or PyPI:**

7
- **glibc**: 2.28 (Ubuntu 20.04 or later)
8
- **Python Version**: >= 3.8
9
- **CUDA Version**: 12.0 <= CUDA < 13
10

11
The easiest way to install tilelang is directly from PyPI using pip. To install the latest version, run the following command in your terminal:
12
13
14
15
16

```bash
pip install tilelang
```

17
Alternatively, you may choose to install tilelang using prebuilt packages available on the Release Page:
18
19
20
21
22

```bash
pip install tilelang-0.0.0.dev0+ubuntu.20.4.cu120-py3-none-any.whl
```

23
To install the latest version of tilelang from the GitHub repository, you can run the following command:
24
25
26
27
28

```bash
pip install git+https://github.com/tile-ai/tilelang.git
```

29
After installing tilelang, you can verify the installation by running:
30
31
32
33
34
35
36
37
38
39

```bash
python -c "import tilelang; print(tilelang.__version__)"
```

## Building from Source

**Prerequisites for building from source:**

- **Operating System**: Linux
40
- **Python Version**: >= 3.8
41
42
- **CUDA Version**: >= 10.0

43
If you prefer Docker, please skip to the [Install Using Docker](#install-using-docker) section. This section focuses on building from source on a native Linux environment.
44

45
First, install the OS-level prerequisites on Ubuntu/Debian-based systems using the following commands:
46
47

```bash
48
49
apt-get update
apt-get install -y python3 python3-dev python3-setuptools gcc zlib1g-dev build-essential cmake libedit-dev
50
51
```

52
53
54
Then, clone the tilelang repository and install it using pip. The `-v` flag enables verbose output during the build process.

> **Note**: Use the `--recursive` flag to include necessary submodules. Tilelang currently depends on a customized version of TVM, which is included as a submodule. If you prefer [Building with Existing TVM Installation](#using-existing-tvm), you can skip cloning the TVM submodule (but still need other dependencies).
55
56
57

```bash
git clone --recursive https://github.com/tile-ai/tilelang.git
58
cd tilelang
59
pip install . -v
60
61
```

62
If you want to install tilelang in development mode, you can use the `-e` flag so that any changes to the Python files will be reflected immediately without reinstallation.
63
64

```bash
65
pip install -e . -v
66
67
```

68
69
70
71
> **Note**: changes to C++ files require rebuilding the tilelang C++ library. See [Faster Rebuild for Developers](#faster-rebuild-for-developers) below. A default `build` directory will be created if you use `pip install`, so you can also directly run `make` in the `build` directory to rebuild it as [Working from Source via PYTHONPATH](#working-from-source-via-pythonpath) suggested below.

(working-from-source-via-pythonpath)=

72
### Working from Source via `PYTHONPATH` (Recommended for Developers)
73

74
If you prefer to work directly from the source tree via `PYTHONPATH` instead of using pip, make sure the native extension (`libtilelang.so`) is built first:
75
76
77
78
79
80
81

```bash
mkdir -p build
cd build
cmake .. -DUSE_CUDA=ON
make -j
```
82
83
84
85
86
87
88
89

We also recommend using `ninja` to speed up compilation:

```bash
cmake .. -DUSE_CUDA=ON -G Ninja
ninja
```

90
91
92
93
94
95
96
97
98
99
100
101
Then add the repository root to `PYTHONPATH` before importing `tilelang`, for example:

```bash
export PYTHONPATH=/path/to/tilelang:$PYTHONPATH
python -c "import tilelang; print(tilelang.__version__)"
```

Some useful CMake options you can toggle while configuring:
- `-DUSE_CUDA=ON|OFF` builds against NVIDIA CUDA (default ON when CUDA headers are found).
- `-DUSE_ROCM=ON` selects ROCm support when building on AMD GPUs.
- `-DNO_VERSION_LABEL=ON` disables the backend/git suffix in `tilelang.__version__`.

102
(using-existing-tvm)=
103

104
### Building with Customized TVM Path
105

106
If you already have a TVM codebase, use the `TVM_ROOT` environment variable to specify the location of your existing TVM repository when building tilelang:
107

108
109
110
111
```bash
TVM_ROOT=<your-tvm-repo> pip install . -v
```

112
113
> **Note**: This will still rebuild the TVM-related libraries (stored in `TL_LIBS`). And this method often leads to some path issues. Check `env.py` to see some environment variables which are not set properly.

114
(install-using-docker)=
115

116
117
118
## Install Using Docker

For users who prefer a containerized environment with all dependencies pre-configured, tilelang provides Docker images for different CUDA versions. This method is particularly useful for ensuring consistent environments across different systems.
119
120
121

**Prerequisites:**
- Docker installed on your system
122
- NVIDIA Docker runtime or GPU is not necessary for building tilelang, you can build on a host without GPU and use that built image on other machine.
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164

1. **Clone the Repository**:

```bash
git clone --recursive https://github.com/tile-ai/tilelang
cd tilelang
```

2. **Build Docker Image**:

Navigate to the docker directory and build the image for your desired CUDA version:

```bash
cd docker
docker build -f Dockerfile.cu120 -t tilelang-cu120 .
```

Available Dockerfiles:
- `Dockerfile.cu120` - For CUDA 12.0
- Other CUDA versions may be available in the docker directory

3. **Run Docker Container**:

Start the container with GPU access and volume mounting:

```bash
docker run -itd \
  --shm-size 32g \
  --gpus all \
  -v /home/tilelang:/home/tilelang \
  --name tilelang_b200 \
  tilelang-cu120 \
  /bin/zsh
```

**Command Parameters Explanation:**
- `--shm-size 32g`: Increases shared memory size for better performance
- `--gpus all`: Enables access to all available GPUs
- `-v /home/tilelang:/home/tilelang`: Mounts host directory to container (adjust path as needed)
- `--name tilelang_b200`: Assigns a name to the container for easy management
- `/bin/zsh`: Uses zsh as the default shell

165
4. **Access the Container and Verify Installation**:
166
167
168

```bash
docker exec -it tilelang_b200 /bin/zsh
169
# Inside the container:
170
171
172
python -c "import tilelang; print(tilelang.__version__)"
```

173
## Install with Nightly Version
174

175
For users who want access to the latest features and improvements before official releases, we provide nightly builds of tilelang.
176
177

```bash
178
179
pip install tilelang -f https://tile-ai.github.io/whl/nightly/cu121/
# or pip install tilelang --find-links https://tile-ai.github.io/whl/nightly/cu121/
180
181
```

182
> **Note:** Nightly builds contain the most recent code changes but may be less stable than official releases. They're ideal for testing new features or if you need a specific bugfix that hasn't been released yet.
183

184
## Install Configs
185

186
187
### Build-time environment variables
`USE_CUDA`: If to enable CUDA support, default: `ON` on Linux, set to `OFF` to build a CPU version. By default, we'll use `/usr/local/cuda` for building tilelang. Set `CUDAToolkit_ROOT` to use different cuda toolkit.
188

189
`USE_ROCM`: If to enable ROCm support, default: `OFF`. If your ROCm SDK does not located in `/opt/rocm`, set `USE_ROCM=<rocm_sdk>` to enable build ROCm against custom sdk path.
190

191
`USE_METAL`: If to enable Metal support, default: `ON` on Darwin.
192

193
194
195
196
197
198
199
200
201
`TVM_ROOT`: TVM source root to use.

`NO_VERSION_LABEL` and `NO_TOOLCHAIN_VERSION`:
When building tilelang, we'll try to embed SDK and version information into package version as below,
where local version label could look like `<sdk>.git<git_hash>`. Set `NO_VERSION_LABEL=ON` to disable this behavior.
```
$ python -mbuild -w
...
Successfully built tilelang-0.1.6.post1+cu116.git0d4a74be-cp38-abi3-linux_x86_64.whl
202
203
```

204
205
206
where `<sdk>={cuda,rocm,metal}`. Specifically, when `<sdk>=cuda` and `CUDA_VERSION` is provided via env,
`<sdk>=cu<cuda_major><cuda_minor>`, similar with this part in pytorch.
Set `NO_TOOLCHAIN_VERSION=ON` to disable this.
207

208
### Run-time environment variables
209

210
Please refer to the `env.py` file for a full list of supported run-time environment variables.
211
212

## Other Tips
213

214
### IDE Configs
215

216
Building tilelang locally will automatically generate a `compile_commands.json` file in `build` dir.
217
218
VSCode with clangd and [clangd extension](https://marketplace.visualstudio.com/items?itemName=llvm-vs-code-extensions.vscode-clangd) should be able to index that without extra configuration.

219
### Compile Cache
220

221
The default path of the compile cache is `~/.tilelang/cache`. `ccache` will be automatically used if found.
222

223
### Repairing Wheels
224
225

If you plan to use your wheel in other environment,
226
it's recommended to use auditwheel (on Linux) or delocate (on Darwin)
227
to repair them.
228

229
230
231
(faster-rebuild-for-developers)=

### Faster Rebuild for Developers
232
233
234
235
236
237
238
239

`pip install` introduces extra [un]packaging and takes ~30 sec to complete,
even if no source change.

Developers who needs to recompile frequently could use:

```bash
pip install -r requirements-dev.txt
240
241

# For first time compilation
242
243
pip install -e . -v --no-build-isolation

244
245
246
247
248
249
250
# Or manually compile with cmake/ninja. Remember to set PYTHONPATH properly.
mkdir build
cd build
cmake .. -G Ninja
ninja

# Rebuild when you change the cpp code
251
252
253
254
255
256
257
258
259
260
cd build; ninja
```

When running in editable/developer mode,
you'll see logs like below:

```console
$ python -c 'import tilelang'
2025-10-14 11:11:29  [TileLang:tilelang.env:WARNING]: Loading tilelang libs from dev root: /Users/yyc/repo/tilelang/build
```