spatial sparse convolution
Project description
SpConv: Spatially Sparse Convolution Library
*: sm_89 and sm_90 is added in CUDA 11.8. If you use RTX 4090 or H100, you should use this version.
spconv
is a project that provide heavily-optimized sparse convolution implementation with tensor core support. check benchmark to see how fast spconv 2.x runs.
Spconv 1.x code. We won't provide any support for spconv 1.x since it's deprecated. use spconv 2.x if possible.
Check spconv 2.x algorithm introduction to understand sparse convolution algorithm in spconv 2.x!
WARNING
Use spconv >= cu114 if possible. cuda 11.4 can compile greatly faster kernel in some situation.
Update Spconv: you MUST UNINSTALL all spconv/cumm/spconv-cuxxx/cumm-cuxxx first, use pip list | grep spconv
and pip list | grep cumm
to check all installed package. then use pip to install new spconv.
NEWS
- spconv 2.2: ampere feature support (by EvernightAurora), pure c++ code generation, nvrtc, drop python 3.6
Spconv 2.2 vs Spconv 2.1
- faster fp16 conv kernels (~5-30%) in ampere GPUs (tested in RTX 3090)
- greatly faster int8 conv kernels (~1.2x-2.7x) in ampere GPUs (tested in RTX 3090)
- drop python 3.6 support
- nvrtc support: kernel in old GPUs will be compiled in runtime.
- libspconv: pure c++ build of all spconv ops. see example
- tf32 kernels, faster fp32 training, disabled by default. set
import spconv as spconv_core; spconv_core.constants.SPCONV_ALLOW_TF32 = True
to enable them. - all weights are KRSC layout, some old model can't be loaded anymore.
Spconv 2.1 vs Spconv 1.x
- spconv now can be installed by pip. see install section in readme for more details. Users don't need to build manually anymore!
- Microsoft Windows support (only windows 10 has been tested).
- fp32 (not tf32) training/inference speed is increased (+50~80%)
- fp16 training/inference speed is greatly increased when your layer support tensor core (channel size must be multiple of 8).
- int8 op is ready, but we still need some time to figure out how to run int8 in pytorch.
- doesn't depend on pytorch binary, but you may need at least pytorch >= 1.5.0 to run spconv 2.x.
- since spconv 2.x doesn't depend on pytorch binary (never in future), it's impossible to support torch.jit/libtorch inference.
Usage
Firstly you need to use import spconv.pytorch as spconv
in spconv 2.x.
Then see this.
Don't forget to check performance guide.
Common Solution for Some Bugs
see common problems.
Install
You need to install python >= 3.7 first to use spconv 2.x.
You need to install CUDA toolkit first before using prebuilt binaries or build from source.
You need at least CUDA 11.0 to build and run spconv 2.x. We won't offer any support for CUDA < 11.0.
Prebuilt
We offer python 3.7-3.11 and cuda 10.2/11.3/11.4/11.7/12.0 prebuilt binaries for linux (manylinux).
We offer python 3.7-3.11 and cuda 10.2/11.4/11.7/12.0 prebuilt binaries for windows 10/11.
For Linux users, you need to install pip >= 20.3 first to install prebuilt.
WARNING: spconv-cu117 may require CUDA Driver >= 515.
pip install spconv
for CPU only (Linux Only). you should only use this for debug usage, the performance isn't optimized due to manylinux limit (no omp support).
pip install spconv-cu102
for CUDA 10.2
pip install spconv-cu113
for CUDA 11.3 (Linux Only)
pip install spconv-cu114
for CUDA 11.4
pip install spconv-cu117
for CUDA 11.7
pip install spconv-cu120
for CUDA 12.0
NOTE It's safe to have different minor cuda version between system and conda (pytorch) in CUDA >= 11.0 because of CUDA Minor Version Compatibility. For example, you can use spconv-cu114 with anaconda version of pytorch cuda 11.1 in a OS with CUDA 11.2 installed.
NOTE In Linux, you can install spconv-cuxxx without install CUDA to system! only suitable NVIDIA driver is required. for CUDA 11, we need driver >= 450.82. You may need newer driver if you use newer CUDA. for cuda 11.8, you need to have driver >= 520 installed.
Prebuilt GPU Support Matrix
See this page to check supported GPU names by arch.
If you use a GPU architecture that isn't compiled in prebuilt, spconv will use NVRTC to compile a slightly slower kernel.
CUDA version | GPU Arch List |
---|---|
11.1~11.7 | 52,60,61,70,75,80,86 |
11.8+ | 60,70,75,80,86,89,90 |
Build from source for development (JIT, recommend)
The c++ code will be built automatically when you change c++ code in project.
For NVIDIA Embedded Platforms, you need to specify cuda arch before build: export CUMM_CUDA_ARCH_LIST="7.2"
for xavier, export CUMM_CUDA_ARCH_LIST="6.2"
for TX2, export CUMM_CUDA_ARCH_LIST="8.7"
for orin.
You need to remove cumm
in requires
section in pyproject.toml after install editable cumm
and before install spconv due to pyproject limit (can't find editable installed cumm
).
You need to ensure pip list | grep spconv
and pip list | grep cumm
show nothing before install editable spconv/cumm.
Linux
- uninstall spconv and cumm installed by pip
- install build-essential, install CUDA
git clone https://github.com/FindDefinition/cumm
,cd ./cumm
,pip install -e .
git clone https://github.com/traveller59/spconv
,cd ./spconv
,pip install -e .
- in python,
import spconv
and wait for build finish.
Windows
- uninstall spconv and cumm installed by pip
- install visual studio 2019 or newer. make sure C++ development component is installed. install CUDA
- set powershell script execution policy
- start a new powershell, run
tools/msvc_setup.ps1
git clone https://github.com/FindDefinition/cumm
,cd ./cumm
,pip install -e .
git clone https://github.com/traveller59/spconv
,cd ./spconv
,pip install -e .
- in python,
import spconv
and wait for build finish.
Build wheel from source (not recommend, this is done in CI.)
You need to rebuild cumm
first if you are build along a CUDA version that not provided in prebuilts.
Linux
- install build-essential, install CUDA
- run
export SPCONV_DISABLE_JIT="1"
- run
pip install pccm cumm wheel
- run
python setup.py bdist_wheel
+pip install dists/xxx.whl
Windows
- install visual studio 2019 or newer. make sure C++ development component is installed. install CUDA
- set powershell script execution policy
- start a new powershell, run
tools/msvc_setup.ps1
- run
$Env:SPCONV_DISABLE_JIT = "1"
- run
pip install pccm cumm wheel
- run
python setup.py bdist_wheel
+pip install dists/xxx.whl
Citation
If you find this project useful in your research, please consider cite:
@misc{spconv2022,
title={Spconv: Spatially Sparse Convolution Library},
author={Spconv Contributors},
howpublished = {\url{https://github.com/traveller59/spconv}},
year={2022}
}
Contributers
- EvernightAurora: add ampere feature.
Note
The work is done when the author is an employee at Tusimple.
LICENSE
Apache 2.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Hashes for spconv_cu102-2.2.5-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cdfc35e603a98e3845afdaabcc70a90b2a9b1b1c3f7d66d2d79bac95e9513e66 |
|
MD5 | bb6c4956243ed8a9655aeb465c4f9370 |
|
BLAKE2b-256 | 3478330b24f0b78766be0dc2a6c87fe25ccf5762e1bcf862f7b07f4b92dbff30 |
Hashes for spconv_cu102-2.2.5-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a3e2fc1a9dff61f0e196463fdf08ab634abf5b5bbc75f4f61b0d23cf40dc415e |
|
MD5 | 1df226edc0801f818163397c113cf1b9 |
|
BLAKE2b-256 | 225f03a4b9b5ae73d98c91542f54953499867696b5af5a9a1a2d7a9f99b1bcc0 |
Hashes for spconv_cu102-2.2.5-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e02359c120c714c62bb45f2d1ddebf0e504b9e63a66586a1da36b51fecc1acc0 |
|
MD5 | 04d27178e5a173500add8b7f512382e7 |
|
BLAKE2b-256 | 3df1d2ef85c73e15c11d9e9a4679042a52823b43fb0501c98c5319a730679162 |
Hashes for spconv_cu102-2.2.5-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc140285f4fd1e98eafdcf78bcb5e82d053f2df4add345b0a14ec4791b74d76a |
|
MD5 | 65f549fe6ccaaf26d5f7d250cdf9c072 |
|
BLAKE2b-256 | 1c4d9c526ad99bf1a4a368c6c5865874d7b5f7be5b9e2b63b977026169876c95 |
Hashes for spconv_cu102-2.2.5-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | be2e13bbe2a182893b3e35dd8416520ebeb24224d754468a0906ea8d65742442 |
|
MD5 | 8291e20ca33f220a51a8d877db160ee0 |
|
BLAKE2b-256 | 2c2c56c6737cee9c5e7bd3936d4b5e5bbcf83a2383fd534f11702032272b52c0 |