Commit f16a48d
Add AMD GPU support via ROCm/HIP (#94)
* [ROCm] Add AMD GPU support via ROCm/HIP
This adds an optional AMD GPU build to cuPDLPx through ROCm/HIP, alongside
the existing CUDA path. The CUDA build is unchanged when USE_HIP is off.
To review: start with internal/cuda_to_hip.h, which routes the CUDA runtime,
cuBLAS, cuSPARSE, and CUB symbols used by the solver to their hipRT, hipBLAS,
hipSPARSE, and hipCUB equivalents on a HIP build, and includes the standard
CUDA headers otherwise. The device sources keep their CUDA spelling and are
compiled as HIP. internal/cusparse_compat.h selects the standard hipsparseSpMV
path on ROCm, since hipSPARSE does not provide the cusparseSpMVOp variant.
CMakeLists.txt gains a USE_HIP option (off by default). When enabled the
project is configured with the HIP language, the .cu sources are compiled as
HIP, and the targets link hipBLAS, hipSPARSE, and hipCUB instead of the CUDA
libraries. GPU architectures are chosen with CMAKE_HIP_ARCHITECTURES,
defaulting to gfx90a. On Windows the CLI-only mps_parser.c is excluded from
the core library because it relies on strtok_r. The interface test gains a
case that runs the GPU solver path with presolve disabled, exercising the
hipBLAS and hipSPARSE execution path end to end.
Test Plan:
Built and ran on an AMD Instinct MI200 (gfx90a) with ROCm 7.2.1:
```
cmake -B build -DUSE_HIP=ON -DCMAKE_HIP_ARCHITECTURES=gfx90a -DCMAKE_PREFIX_PATH=/opt/rocm \
-DCUPDLPX_BUILD_CLI=ON -DCUPDLPX_BUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Release
cmake --build build -j$(nproc)
./build/tests/test_interface
```
The interface suite passes, including the GPU solver case (Status: OPTIMAL).
The same configuration builds cleanly for gfx1100 (RDNA3) and gfx1201
(RDNA4); the device code objects are identical across the documentation and
formatting commits that followed validation. The CUDA build path is
unaffected by these changes.
This work was authored with the assistance of Claude, an AI assistant by
Anthropic.
* [ROCm] Fix CUDA build: guard cub include for C translation units
The ROCm support commit routed all CUDA/HIP includes through
internal/cuda_to_hip.h and pulled it into utils.h and internal_types.h,
which are included by the C translation units (cli.c, cupdlpx.c,
mps_parser.c, presolve.c). On the CUDA path that header included
<cub/device/device_reduce.cuh> unconditionally; cub is C++ only, so the C
compiler failed with "unknown type name 'namespace'", breaking every
CUDA build job (all Linux and Windows toolchains, CUDA 12.4 through 13.1).
The HIP path was unaffected because its hipcub include was already guarded
with #ifdef __cplusplus.
The fix mirrors that guard on the CUDA branch: the cub header is only
included for C++ translation units (the .cu device sources that actually
use cub::DeviceReduce). The change is entirely within the #else CUDA
branch, so the HIP/ROCm device code is unchanged.
Authored with assistance from Claude.
Test Plan: reproduced and verified the CUDA path locally with the CUDA
12.8 toolkit (gcc 13, ninja), matching the upstream CI configure:
```
cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release \
-DCUPDLPX_BUILD_TESTS=OFF -DCMAKE_CUDA_ARCHITECTURES=80
cmake --build build --clean-first
```
Before: cc -std=gnu99 -c src/cupdlpx.c fails on cub/device/device_reduce.cuh.
After: clean build, links cupdlpx and libcupdlpx.so with 0 errors.
* [ROCm] Simplify HIP compat includes and strengthen interface test
Addresses review feedback on the ROCm support PR.
cuda_to_hip.h already includes the CUDA runtime/cuBLAS/cuSPARSE headers on
CUDA builds and their HIP equivalents on ROCm builds, so the per-file
`#if !defined(USE_HIP)` include blocks in utils.h and preconditioner.cu were
redundant. They are removed in favor of relying on cuda_to_hip.h alone.
The USE_HIP definition moves from directory-scoped add_compile_definitions to
target_compile_definitions on the cupdlpx_compile_flags interface target so it
travels reliably to every consumer, including the Python bindings.
test_interface Test 9 previously only checked for a non-NULL result, so it
could not catch a wrong answer. It now asserts TERMINATION_REASON_OPTIMAL and
the known optimum (objective 3.0 within 1e-4). The default 1e-4 relative
tolerance stops the solver around 3.0005, so the test tightens the convergence
tolerance to 1e-8, after which the objective reaches the true optimum.
On the device-link question: the HIP build does not use relocatable device
code (-fgpu-rdc is off), so each object is compiled whole-program and is
self-contained; no archive-boundary device link is needed for the static lib.
The CUDA path keeps CUDA_SEPARABLE_COMPILATION/CUDA_RESOLVE_DEVICE_SYMBOLS,
which it does require. The rationale is now recorded as comments in CMake.
Also drops the added per-file copyright/author lines from cuda_to_hip.h to
match the project's existing header convention.
This work was authored with the assistance of Claude, an AI assistant.
Test Plan:
Build and run the interface tests on gfx90a (MI250X, ROCm 7.2.1):
```
cmake -S . -B build -DUSE_HIP=ON -DCMAKE_HIP_ARCHITECTURES=gfx90a \
-DCUPDLPX_BUILD_CLI=ON -DCUPDLPX_BUILD_TESTS=ON -DCUPDLPX_BUILD_PYTHON=OFF \
-DCMAKE_BUILD_TYPE=Release
cmake --build build -j$(nproc)
HIP_VISIBLE_DEVICES=0 ./build/tests/test_interface # 9/9 pass, Test 9 obj=3.000000001
HIP_VISIBLE_DEVICES=0 ./build/cupdlpx 2club200v15p5scn.mps.gz . # OPTIMAL, obj -121.2216698
```
Build and exercise the ROCm Python extension with a HIP-aware C++ compiler:
```
cmake -S . -B pybuild -DUSE_HIP=ON -DCMAKE_HIP_ARCHITECTURES=gfx90a \
-DCMAKE_CXX_COMPILER=amdclang++ -DCUPDLPX_BUILD_PYTHON=ON -DCMAKE_BUILD_TYPE=Release
cmake --build pybuild -j$(nproc)
# import + solve -> Status OPTIMAL, ObjVal 3.0, X [1, 2]
```
* apply clang format
* CI: add build-hip
* [ROCm] Drop remaining duplicate CUDA header includes
* Fix missing #endif dropped during moat-port merge conflict resolution
The merge commit's manual resolution of internal/cusparse_compat.h
dropped the closing #endif // USE_HIP, leaving the outer
#if/#else unterminated and breaking the CUDA build.
---------
Co-authored-by: ZedongPeng <peng_zedong@126.com>1 parent 8599563 commit f16a48d
11 files changed
Lines changed: 427 additions & 55 deletions
File tree
- .github/workflows
- internal
- src
- test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
64 | 64 | | |
65 | 65 | | |
66 | 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
6 | 9 | | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
21 | 28 | | |
22 | | - | |
23 | 29 | | |
24 | | - | |
25 | | - | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
26 | 33 | | |
27 | 34 | | |
28 | 35 | | |
| |||
50 | 57 | | |
51 | 58 | | |
52 | 59 | | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
53 | 68 | | |
54 | 69 | | |
55 | 70 | | |
| |||
75 | 90 | | |
76 | 91 | | |
77 | 92 | | |
78 | | - | |
79 | | - | |
80 | | - | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
81 | 101 | | |
82 | 102 | | |
83 | 103 | | |
| |||
99 | 119 | | |
100 | 120 | | |
101 | 121 | | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
102 | 130 | | |
103 | 131 | | |
104 | 132 | | |
| |||
165 | 193 | | |
166 | 194 | | |
167 | 195 | | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
168 | 200 | | |
169 | 201 | | |
170 | 202 | | |
171 | 203 | | |
172 | 204 | | |
173 | 205 | | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
182 | 231 | | |
183 | 232 | | |
184 | 233 | | |
| |||
187 | 236 | | |
188 | 237 | | |
189 | 238 | | |
190 | | - | |
191 | | - | |
192 | 239 | | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
193 | 256 | | |
194 | 257 | | |
195 | 258 | | |
| |||
200 | 263 | | |
201 | 264 | | |
202 | 265 | | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
203 | 273 | | |
204 | 274 | | |
205 | | - | |
| 275 | + | |
| 276 | + | |
206 | 277 | | |
207 | 278 | | |
208 | 279 | | |
| |||
217 | 288 | | |
218 | 289 | | |
219 | 290 | | |
220 | | - | |
221 | 291 | | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
222 | 297 | | |
223 | 298 | | |
224 | 299 | | |
| |||
230 | 305 | | |
231 | 306 | | |
232 | 307 | | |
233 | | - | |
| 308 | + | |
234 | 309 | | |
235 | 310 | | |
236 | 311 | | |
237 | 312 | | |
238 | 313 | | |
239 | | - | |
240 | 314 | | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
241 | 320 | | |
242 | 321 | | |
243 | 322 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
30 | | - | |
| 29 | + | |
| 30 | + | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
| 36 | + | |
35 | 37 | | |
36 | 38 | | |
37 | 39 | | |
| |||
43 | 45 | | |
44 | 46 | | |
45 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
46 | 63 | | |
47 | 64 | | |
48 | 65 | | |
| |||
0 commit comments