Commit 3934632
Unify CUDA and HIP kernel sources via compat.cuh portability layer (#1877)
* first commit
* update
* Activate unified CUDA/HIP kernel files from csrc/examples/
Move the unified portability-header-based files from csrc/examples/
into csrc/, replacing the duplicated CUDA and HIP kernel files.
- Add compat.cuh and compat_device.cuh (portability headers)
- Replace common.cuh, kernels.cu, ops.cu, ops.cuh, pythonInterface.cpp,
CMakeLists.txt with unified versions
- Update kernels.cuh: rename kQuantizeBlockwise32 -> kQuantizeBlockwiseSmall
- Delete HIP-only files: common_hip.cuh, kernels.hip, kernels_hip.cuh,
ops.hip, ops_hip.cuh
- Delete csrc/examples/ (files are now in their final locations)
Net: 10 source files -> 7, ~3300 fewer lines of duplicated code.
Same .cu files compiled by both nvcc (CUDA) and hipcc (HIP).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Fix HIP build errors in unified kernel files
- Add hip/hip_bfloat16.h include to compat.cuh (bnb_bfloat16 type alias
requires hip_bfloat16 to be defined)
- Add __syncwarp() no-op macro for HIP (AMD warps are always in lockstep)
- Add hipblas version check (#if hipblasVersionMajor >= 3) for GemmEx calls
(ROCm 6.1 ships hipblas v2 which uses HIPBLAS_R_* not HIPBLAS_COMPUTE_*)
- Fix include in ops.cuh: common.h -> common.cuh (BNB_WARP_SIZE visibility)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Restore common.h include in ops.cuh for DataType_t enum
common.h defines General8bit, FP4, NF4 enum values used in template
instantiations. It was previously the only include; now include both
common.h (for DataType_t) and common.cuh (for BNB_WARP_SIZE).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Guard blocksize=64 quantize instantiations for warp size compatibility
On AMD CDNA GPUs (warp size 64), blocksize=64 would mean only 1 thread
per warp in the quantize kernels, which is incompatible. Wrap these
instantiations with #if BNB_WARP_SIZE == 32 so they only compile on
NVIDIA.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Guard all blocksize=64 quantize instantiations for warp size compat
The previous commit missed the float/NF4 and all bnb_bfloat16
blocksize=64 instantiations. These use BLOCK_LOAD_WARP_TRANSPOSE
with 32 threads (64/2), which requires block_dim >= warp_size.
On CDNA (warp=64), 32 threads is insufficient.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Use conditional load/store algo for warp size compatibility
BLOCK_LOAD_WARP_TRANSPOSE requires threads >= warp_size. On CDNA
(warp=64), kQuantizeBlockwise with BLOCK_SIZE=64 has only 32
threads. Fall back to BLOCK_LOAD_DIRECT / BLOCK_STORE_DIRECT
when threads < BNB_WARP_SIZE. This avoids rocprim compilation
errors while keeping WARP_TRANSPOSE for larger block sizes.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Fix BNB_WARP_SIZE detection for HIP host compilation pass
__GFX9__ is only defined during the device compilation pass, not
during host compilation. This caused BNB_WARP_SIZE to be 32 on
the host pass even for gfx942 (CDNA, warp=64), making the
conditional WARP_TRANSPOSE vs DIRECT selection wrong.
Use __AMDGCN_WAVEFRONT_SIZE instead, which the HIP compiler
defines correctly in both host and device passes.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Remove blocksize=64 instantiation guards
Now that kQuantizeBlockwise falls back to BLOCK_LOAD_DIRECT when
threads < warp_size, the blocksize=64 instantiations compile
correctly on both CUDA and HIP. The guards were causing linker
errors because ops.cu still references these symbols for the
General8bit dispatch path.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Apply clang-format formatting fixes
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* merge unified-hip-validation & code cleaning
---------
Co-authored-by: Tim Dettmers <tim.dettmers@gmail.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>1 parent 96b37ec commit 3934632
File tree
14 files changed
+644
-3023
lines changed- csrc
14 files changed
+644
-3023
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | | - | |
58 | | - | |
| 57 | + | |
59 | 58 | | |
60 | 59 | | |
61 | 60 | | |
| |||
225 | 224 | | |
226 | 225 | | |
227 | 226 | | |
228 | | - | |
| 227 | + | |
229 | 228 | | |
230 | 229 | | |
231 | 230 | | |
| |||
244 | 243 | | |
245 | 244 | | |
246 | 245 | | |
247 | | - | |
| 246 | + | |
248 | 247 | | |
249 | 248 | | |
250 | 249 | | |
| |||
389 | 388 | | |
390 | 389 | | |
391 | 390 | | |
392 | | - | |
| 391 | + | |
393 | 392 | | |
394 | 393 | | |
395 | 394 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
1 | 3 | | |
2 | 4 | | |
3 | | - | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
4 | 30 | | |
5 | 31 | | |
6 | 32 | | |
| |||
14 | 40 | | |
15 | 41 | | |
16 | 42 | | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
17 | 51 | | |
18 | 52 | | |
19 | | - | |
20 | 53 | | |
| 54 | + | |
21 | 55 | | |
22 | | - | |
| 56 | + | |
23 | 57 | | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
29 | 64 | | |
30 | 65 | | |
31 | 66 | | |
32 | 67 | | |
33 | 68 | | |
34 | 69 | | |
35 | 70 | | |
| 71 | + | |
36 | 72 | | |
37 | | - | |
| 73 | + | |
38 | 74 | | |
39 | 75 | | |
40 | | - | |
41 | | - | |
| 76 | + | |
| 77 | + | |
42 | 78 | | |
43 | 79 | | |
44 | 80 | | |
| |||
This file was deleted.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 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 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 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 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
0 commit comments