Commit e844a68
committed
fix(cuda): set explicit cuBLAS/hipBLAS workspace to stop VRAM creep
Addresses upstream llama.cpp issue ggml-org#19979: on ROCm/HIP, VRAM creeps up
during long prompt processing when using non-f16 KV cache types (q4_0,
q5_1, q8_0, turbo2/3/4), eventually causing OOM. Does not occur with
f16/f16 KV cache.
Root cause: cublasCreate() is called but cublasSetWorkspace() is not,
so rocBLAS lazily allocates its own internal workspace on first GEMM
and grows it monotonically as it encounters new Tensile kernel shapes
across the varying batch sizes / KV cache lengths of prompt processing.
The growth is invisible to llama.cpp's memory accounting (hipMemGetInfo
snapshots it but the fit algorithm runs before the workspace exists).
Fix: after cublasCreate(), allocate a fixed 32 MiB buffer via cudaMalloc
and install it as the explicit workspace via cublasSetWorkspace (aliased
to hipblasSetWorkspace on HIP). rocBLAS then uses our workspace instead
of growing its own, and the workspace is freed deterministically in the
backend context destructor.
Added:
- GGML_CUDA_CUBLAS_WORKSPACE_SIZE constant (32 MiB) in common.cuh
- cublas_workspaces[] array in ggml_backend_cuda_context
- cublasSetWorkspace -> hipblasSetWorkspace alias in vendors/hip.h
- Workspace alloc + install in cublas_handle()
- Workspace free in ~ggml_backend_cuda_context() (after cublasDestroy)
Upstream reference:
ggml-org#19979
The 32 MiB size matches NVIDIA cuBLAS recommendations for typical
workloads. Bump if you see rocBLAS falling back to smaller kernels.
Affects all ROCm GPU archs, especially GFX11 (RDNA3/3.5) where Tensile
solution selection triggers more workspace growth.1 parent 57daafb commit e844a68
3 files changed
Lines changed: 37 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1354 | 1354 | | |
1355 | 1355 | | |
1356 | 1356 | | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + | |
| 1366 | + | |
| 1367 | + | |
| 1368 | + | |
1357 | 1369 | | |
1358 | 1370 | | |
1359 | 1371 | | |
1360 | 1372 | | |
1361 | 1373 | | |
1362 | 1374 | | |
1363 | 1375 | | |
| 1376 | + | |
1364 | 1377 | | |
1365 | 1378 | | |
1366 | 1379 | | |
| |||
1426 | 1439 | | |
1427 | 1440 | | |
1428 | 1441 | | |
| 1442 | + | |
| 1443 | + | |
| 1444 | + | |
| 1445 | + | |
| 1446 | + | |
| 1447 | + | |
| 1448 | + | |
| 1449 | + | |
| 1450 | + | |
| 1451 | + | |
1429 | 1452 | | |
1430 | 1453 | | |
1431 | 1454 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
577 | 577 | | |
578 | 578 | | |
579 | 579 | | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
580 | 588 | | |
581 | 589 | | |
582 | 590 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
65 | 71 | | |
66 | 72 | | |
67 | 73 | | |
| |||
0 commit comments