Skip to content

Commit 826f966

Browse files
yinfan98xwu-intel
authored andcommitted
[Misc] use parallel build for cmake in sgl-kernel (sgl-project#5919)
1 parent 3c4c690 commit 826f966

File tree

2 files changed

+43
-35
lines changed

2 files changed

+43
-35
lines changed

sgl-kernel/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ install: submodule ## Install package in development mode
2626
@pip install -e . --no-build-isolation
2727

2828
build: install-deps submodule ## Build and install wheel package
29-
@rm -rf dist/* || true && export MAX_JOBS=$(nproc) && uv build --wheel -Cbuild-dir=build . --verbose --color=always --no-build-isolation && pip3 install dist/*whl --force-reinstall --no-deps
29+
@rm -rf dist/* || true && export MAX_JOBS=$(nproc) && CMAKE_BUILD_PARALLEL_LEVEL=$(nproc) uv build --wheel -Cbuild-dir=build . --verbose --color=always --no-build-isolation && pip3 install dist/*whl --force-reinstall --no-deps
3030

3131
clean: ## Remove build artifacts
3232
@rm -rf build dist *.egg-info

sgl-kernel/README.md

Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,46 @@ For CUDA 12.1 or CUDA 12.4:
1717
```bash
1818
pip3 install sgl-kernel
1919
```
20+
## Build from source
21+
22+
Development build:
23+
24+
```bash
25+
make build
26+
```
27+
28+
Note:
29+
30+
The `sgl-kernel` is rapidly evolving. If you experience a compilation failure, try using `make rebuild`.
31+
32+
### Build with [ccache](https://github.com/ccache/ccache)
33+
```bash
34+
# or `yum install -y ccache`.
35+
apt-get install -y ccache
36+
# Building with ccache is enabled when ccache is installed and CCACHE_DIR is set.
37+
export CCACHE_DIR=/path/to/your/ccache/dir
38+
export CCACHE_BACKEND=""
39+
export CCACHE_KEEP_LOCAL_STORAGE="TRUE"
40+
unset CCACHE_READONLY
41+
python -m uv build --wheel -Cbuild-dir=build --color=always .
42+
```
43+
44+
### Configuring CMake Build Options
45+
Cmake options can be configuring by adding `-Ccmake.define.<option>=<value>` to the `uv build` flags.
46+
For example, to enable building FP4 kernels, use:
47+
```bash
48+
python -m uv build --wheel -Cbuild-dir=build -Ccmake.define.SGL_KERNEL_ENABLE_FP4=1 --color=always .
49+
```
50+
See CMakeLists.txt for more options.
51+
52+
### Parallel Build
53+
54+
We highly recommend you build sgl-kernel with Ninja. Ninja can automatically build sgl-kernel in parallel.
55+
And if you build the sgl-kernel with cmake, you need to add `CMAKE_BUILD_PARALLEL_LEVEL` for parallel build like:
56+
57+
```bash
58+
CMAKE_BUILD_PARALLEL_LEVEL=$(nproc) python -m uv build --wheel -Cbuild-dir=build --color=always .
59+
```
2060

2161
# Developer Guide
2262

@@ -132,40 +172,6 @@ To use this with your library functions, simply wrap them with make_pytorch_shim
132172
m.impl("fwd", torch::kCUDA, make_pytorch_shim(&mha_fwd));
133173
```
134174

135-
### Build & Install
136-
137-
Development build:
138-
139-
```bash
140-
make build
141-
```
142-
143-
Note:
144-
145-
The `sgl-kernel` is rapidly evolving. If you experience a compilation failure, try using `make rebuild`.
146-
147-
#### Build with [ccache](https://github.com/ccache/ccache)
148-
```bash
149-
# or `yum install -y ccache`.
150-
apt-get install -y ccache
151-
# Building with ccache is enabled when ccache is installed and CCACHE_DIR is set.
152-
export CCACHE_DIR=/path/to/your/ccache/dir
153-
export CCACHE_BACKEND=""
154-
export CCACHE_KEEP_LOCAL_STORAGE="TRUE"
155-
unset CCACHE_READONLY
156-
python -m uv build --wheel -Cbuild-dir=build --color=always .
157-
```
158-
159-
> When encountering this error while compiling using ccache: `ImportError: /usr/local/lib/python3.10/dist-packages/sgl_kernel/common_ops.abi3.so: undefined symbol: _ZN3c108ListType3getERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEENS_4Type24SingletonOrSharedTypePtrIS9_EE`, please modify the last command as follows to resolve it: `python3 -m uv build --wheel -Cbuild-dir=build . --color=always --no-build-isolation` .
160-
161-
##### Configuring CMake Build Options
162-
Cmake options can be configuring by adding `-Ccmake.define.<option>=<value>` to the `uv build` flags.
163-
For example, to enable building FP4 kernels, use:
164-
```bash
165-
python -m uv build --wheel -Cbuild-dir=build -Ccmake.define.SGL_KERNEL_ENABLE_FP4=1 --color=always .
166-
```
167-
See CMakeLists.txt for more options.
168-
169175
### Testing & Benchmarking
170176

171177
1. Add pytest tests in [tests/](https://github.com/sgl-project/sglang/tree/main/sgl-kernel/tests), if you need to skip some test, please use `@pytest.mark.skipif`
@@ -179,7 +185,9 @@ See CMakeLists.txt for more options.
179185
2. Add benchmarks using [triton benchmark](https://triton-lang.org/main/python-api/generated/triton.testing.Benchmark.html) in [benchmark/](https://github.com/sgl-project/sglang/tree/main/sgl-kernel/benchmark)
180186
3. Run test suite
181187

188+
### FAQ
182189

190+
- When encountering this error while compiling using ccache: `ImportError: /usr/local/lib/python3.10/dist-packages/sgl_kernel/common_ops.abi3.so: undefined symbol: _ZN3c108ListType3getERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEENS_4Type24SingletonOrSharedTypePtrIS9_EE`, please modify the last command as follows to resolve it: `python3 -m uv build --wheel -Cbuild-dir=build . --color=always --no-build-isolation` .
183191

184192
### Release new version
185193

0 commit comments

Comments
 (0)