README.md 6.59 KB
Newer Older
yan.yan's avatar
yan.yan committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<!--
 Copyright 2021 Yan Yan
 
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at
 
     http://www.apache.org/licenses/LICENSE-2.0
 
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-->

yan.yan's avatar
v2.1  
yan.yan committed
17
# SpConv: Spatially Sparse Convolution Library
traveller59's avatar
traveller59 committed
18

tusimple's avatar
tusimple committed
19
20
[![Build Status](https://github.com/traveller59/spconv/workflows/build/badge.svg)](https://github.com/traveller59/spconv/actions?query=workflow%3Abuild)

yan.yan's avatar
v2.1  
yan.yan committed
21
```spconv``` is a project that provide heavily-optimized sparse convolution implementation with tensor core support.
22

yan.yan's avatar
v2.1  
yan.yan committed
23
[Spconv 1.x code](https://github.com/traveller59/spconv/tree/v1.2.1). We won't provide any support for spconv 1.x since it's deprecated. use spconv 2.x if possible. <!--remove this message in spconv 2.2-->
FindDefinition's avatar
FindDefinition committed
24

yan.yan's avatar
v2.1  
yan.yan committed
25
## Breaking changes in Spconv 2.x
FindDefinition's avatar
FindDefinition committed
26

yan.yan's avatar
v2.1  
yan.yan committed
27
Spconv 1.x users **NEED READ [THIS](docs/SPCONV_2_BREAKING_CHANGEs.md)** before using spconv 2.x.
FindDefinition's avatar
FindDefinition committed
28

yan.yan's avatar
v2.1  
yan.yan committed
29
## Spconv 2.1 vs Spconv 1.x
traveller59's avatar
traveller59 committed
30

yan.yan's avatar
v2.1  
yan.yan committed
31
32
33
34
35
* spconv now can be installed by **pip**. see install section in readme for more details.
* 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.
yan.yan's avatar
yan.yan committed
36
37
* doesn't depend on pytorch binary. 
* since spconv 2.x doesn't depend on pytorch binary (never in future), it's impossible to support torch.jit/libtorch inference.
traveller59's avatar
traveller59 committed
38

yan.yan's avatar
v2.1  
yan.yan committed
39
Spconv 2.1 vs 1.x speed:
40
41
42
43
44
45

|                | 1080Ti Spconv 1.x F32 | 1080Ti Spconv 2.0 F32 | 3080M* Spconv 2.1 F16  |
| -------------- |:---------------------:| ---------------------:| ----------:|
| 27x128x128 Fwd | 11ms                  | 5.4ms                 | 1.4ms      |

\* 3080M (Laptop) ~= 3070 Desktop
yan.yan's avatar
yan.yan committed
46

yan.yan's avatar
v2.1  
yan.yan committed
47
48
49
50
51
52
53
54
55
56
57
58
59

<!--
TODO Spconv vs [MinkowskiEngine](https://github.com/NVIDIA/MinkowskiEngine) vs [torchsparse](https://github.com/mit-han-lab/torchsparse)
-->


## Roadmap for Spconv 2.2-2.3: 
* TensorFormat32 support for faster fp32 training when you use NVIDIA Geforce RTX 30x0/Tesla A100/Quadro RTX Ax000 (2.2)
* change implicit gemm weight layout from KRSC to RSKC to make sure we can use native algorithm with implicit gemm weight. (2.2)
* documents (2.2)
* Ampere feature support (2.3)
* pytorch int8 inference, and QAT support (2.3)

yan.yan's avatar
yan.yan committed
60
61
62
63
## Usage

Firstly you need to use ```import spconv.pytorch as spconv``` in spconv 2.x.

yan.yan's avatar
v2.1  
yan.yan committed
64
Then see [this](docs/USAGE.md).
yan.yan's avatar
yan.yan committed
65

yan.yan's avatar
v2.1  
yan.yan committed
66
Don't forget to check [performance guide](docs/PERFORMANCE_GUIDE.md).
traveller59's avatar
traveller59 committed
67

yan.yan's avatar
yan.yan committed
68
## Install
traveller59's avatar
traveller59 committed
69

yan.yan's avatar
yan.yan committed
70
You need to install python >= 3.7 first to use spconv 2.x.
traveller59's avatar
traveller59 committed
71

yan.yan's avatar
yan.yan committed
72
You need to install CUDA toolkit first before using prebuilt binaries or build from source.
traveller59's avatar
traveller59 committed
73

yan.yan's avatar
yan.yan committed
74
You need at least CUDA 10.2 to build and run spconv 2.x. We won't offer any support for CUDA < 10.2.
traveller59's avatar
traveller59 committed
75

yan.yan's avatar
yan.yan committed
76
### Prebuilt
traveller59's avatar
traveller59 committed
77

yan.yan's avatar
v2.1  
yan.yan committed
78
We offer python 3.7-3.10 and cuda 10.2/11.1/11.3/11.4 prebuilt binaries for linux (manylinux) and windows 10/11.
traveller59's avatar
traveller59 committed
79

yan.yan's avatar
v2.1  
yan.yan committed
80
We will provide prebuilts for CUDA versions supported by latest pytorch release. For example, pytorch 1.10 provide cuda 10.2 and 11.3 prebuilts, so we provide them too.
traveller59's avatar
traveller59 committed
81

yan.yan's avatar
yan.yan committed
82
For Linux users, you need to install pip >= 20.3 first to install prebuilt.
traveller59's avatar
traveller59 committed
83

yan.yan's avatar
v2.1  
yan.yan committed
84
85
86
87
88
89
CUDA 11.1 will be removed in spconv 2.2 because pytorch 1.10 don't provide prebuilts for it.

```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

yan.yan's avatar
yan.yan committed
90
```pip install spconv-cu111``` for CUDA 11.1
traveller59's avatar
traveller59 committed
91

yan.yan's avatar
v2.1  
yan.yan committed
92
93
```pip install spconv-cu113``` for CUDA 11.3

yan.yan's avatar
yan.yan committed
94
```pip install spconv-cu114``` for CUDA 11.4
traveller59's avatar
traveller59 committed
95

yan.yan's avatar
v2.1  
yan.yan committed
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
**NOTE** It's safe to have different **minor** cuda version between system and conda (pytorch) **in Linux**. for example, you can use spconv-cu114 with anaconda version of pytorch cuda 11.1 in a OS with CUDA 11.2 installed.


### 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.

#### Linux
0. uninstall spconv and cumm installed by pip
1. install build-essential, install CUDA
2. ```git clone https://github.com/FindDefinition/cumm```, ```cd ./cumm```, ```pip install -e .```
3. ```git clone https://github.com/traveller59/spconv```, ```cd ./spconv```, ```pip install -e .```
4. in python, ```import spconv``` and wait for build finish.

#### Windows
0. uninstall spconv and cumm installed by pip
1. install visual studio 2019 or newer. make sure C++ development component is installed. install CUDA
2. set [powershell script execution policy](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7.1)
3. start a new powershell, run ```tools/msvc_setup.ps1```
4. ```git clone https://github.com/FindDefinition/cumm```, ```cd ./cumm```, ```pip install -e .```
5. ```git clone https://github.com/traveller59/spconv```, ```cd ./spconv```, ```pip install -e .```
6. in python, ```import spconv``` and wait for build finish.
yan.yan's avatar
yan.yan committed
120

yan.yan's avatar
v2.1  
yan.yan committed
121
### Build wheel from source (not recommend, this is done in CI.)
traveller59's avatar
traveller59 committed
122

yan.yan's avatar
yan.yan committed
123
You need to rebuild ```cumm``` first if you are build along a CUDA version that not provided in prebuilts.
traveller59's avatar
traveller59 committed
124

yan.yan's avatar
yan.yan committed
125
#### Linux
traveller59's avatar
traveller59 committed
126

yan.yan's avatar
yan.yan committed
127
128
1. install build-essential, install CUDA
2. run ```export SPCONV_DISABLE_JIT="1"```
yan.yan's avatar
v2.1  
yan.yan committed
129
130
3. run ```pip install pccm cumm wheel```
4. run ```python setup.py bdist_wheel```+```pip install dists/xxx.whl```
traveller59's avatar
traveller59 committed
131

yan.yan's avatar
v2.1  
yan.yan committed
132
#### Windows
traveller59's avatar
traveller59 committed
133

yan.yan's avatar
v2.1  
yan.yan committed
134
1. install visual studio 2019 or newer. make sure C++ development component is installed. install CUDA
yan.yan's avatar
yan.yan committed
135
136
137
2. set [powershell script execution policy](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7.1)
3. start a new powershell, run ```tools/msvc_setup.ps1```
4. run ```$Env:SPCONV_DISABLE_JIT = "1"```
yan.yan's avatar
v2.1  
yan.yan committed
138
139
5. run ```pip install pccm cumm wheel```
6. run ```python setup.py bdist_wheel```+```pip install dists/xxx.whl```
traveller59's avatar
traveller59 committed
140

yan.yan's avatar
yan.yan committed
141
142
143
144
145
146
147
## TODO in Spconv 2.x
- [ ] Ampere (A100 / RTX 3000 series) feature support (work in progress)
- [ ] torch QAT support (work in progress)
- [ ] TensorRT (torch.fx based)
- [ ] Build C++ only package
- [ ] JIT compilation for CUDA kernels
- [ ] Document (low priority)
yan.yan's avatar
yan.yan committed
148

yan.yan's avatar
yan.yan committed
149
## Note
traveller59's avatar
traveller59 committed
150

yan.yan's avatar
yan.yan committed
151
The work is done when the author is an employee at Tusimple.
traveller59's avatar
traveller59 committed
152

yan.yan's avatar
yan.yan committed
153
## LICENSE
traveller59's avatar
traveller59 committed
154

FindDefinition's avatar
FindDefinition committed
155
Apache 2.0