Commit 49c8cec
authored
[REVIEW] Improve 1-NN performance with split GEMM/reduction kernels on Blackwell (#1768)
cuVS currently implements 1-nearest neighbor using a fused-kernel approach, where the pairwise-distance GEMM and the subsequent reduction are combined into a single kernel. While this can be efficient, the fused implementation has limitations that prevent it from consistently achieving the best performance. Additionally, the separate-kernels implementation can be used for `half` and `int8` datatypes unlike the fused implementation which is restricted to `float` only.
This PR adds a separate-kernel path in which GEMM and reduction run as two distinct kernels. On Blackwell, the separate-kernel approach performs better for certain M, N, and K configurations (see results below).
In addition, this PR includes:
- A simple heuristic to choose between the fused and separate paths
- Unit tests covering both fused and separate execution paths
- A benchmark that compares fused vs. separate performance and also reports GEMM-only time for reference
**End-to-end benchmarks**
I ran the CUVS_IVF_PQ_ANN_BENCH on a dataset with 10 million vectors and with following build parameters
```
"build_param": {
"pq_dim": 128,
"pq_bits": 8,
"nlist": 10000,
"niter": 10,
"ratio": 100
},
```
Observed following performance improvements:
Fused:
<img width="467" height="154" alt="image" src="https://github.com/user-attachments/assets/45b7b6b6-85f9-4a01-a23b-77e1ea0efa71" />
Seperate:
<img width="402" height="135" alt="image" src="https://github.com/user-attachments/assets/498ec005-5333-4d25-aa35-f1553ffffe0f" />
**1-NN computing benchmark:**
Following table shows the performance of fused and separate computation of 1-NN for various sizes of M, N and K. The GEMM column shows the performance of pure GEMM for comparison. Higher is better here.
| M | N | K | Fused TFLOPS | Separate TFLOPS | GEMM TFLOPS |
|:-----:|:----:|:---:|:-----:|:--------:|:-----:|
| 16384 | 4096 | 128 | 28.28 | 37.14 | 44.53 |
| 16384 | 4096 | 64 | 22.04 | 25.86 | 33.66 |
| 8192 | 2048 | 128 | 26.43 | 35.33 | 40.96 |
| 8192 | 2048 | 64 | 18.57 | 24.77 | 30.54 |
Authors:
- Vinay Deshpande (https://github.com/vinaydes)
- Anupam (https://github.com/aamijar)
- Corey J. Nolet (https://github.com/cjnolet)
- Tamas Bela Feher (https://github.com/tfeher)
Approvers:
- Dante Gama Dessavre (https://github.com/dantegd)
- Tamas Bela Feher (https://github.com/tfeher)
URL: #17681 parent afb2b3f commit 49c8cec
7 files changed
Lines changed: 890 additions & 31 deletions
File tree
- cpp
- src
- cluster/detail
- distance
- tests
- neighbors
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
171 | 172 | | |
172 | 173 | | |
173 | 174 | | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
179 | 181 | | |
180 | 182 | | |
181 | 183 | | |
182 | 184 | | |
183 | 185 | | |
184 | 186 | | |
185 | | - | |
186 | 187 | | |
187 | 188 | | |
188 | | - | |
189 | | - | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
190 | 197 | | |
191 | 198 | | |
192 | 199 | | |
| |||
377 | 384 | | |
378 | 385 | | |
379 | 386 | | |
380 | | - | |
381 | | - | |
| 387 | + | |
| 388 | + | |
382 | 389 | | |
383 | 390 | | |
384 | 391 | | |
| |||
989 | 996 | | |
990 | 997 | | |
991 | 998 | | |
992 | | - | |
993 | | - | |
| 999 | + | |
| 1000 | + | |
994 | 1001 | | |
995 | 1002 | | |
996 | 1003 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
56 | 57 | | |
57 | 58 | | |
58 | 59 | | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
59 | 85 | | |
60 | 86 | | |
61 | 87 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
50 | 51 | | |
51 | 52 | | |
52 | 53 | | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
71 | 98 | | |
72 | 99 | | |
73 | 100 | | |
| |||
0 commit comments