[BUG] cuvs-java device matrices are capped at a quarter of GPU memory
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Ambito
- backend, performance
Direzione di ricerca
Start with the cuvsRMMAlloc and cuvsRMMFree C API functions, which the issue says switched from the current device memory resource to the RAFT workspace resource in #2035. Run the Python ctypes script in the report on a GPU to reproduce the 6,224,112-row cap. Done means CuVSMatrix.deviceBuilder can hold an 8M x 1,024 float32 matrix while scratch buffers such as filter bitsets keep using the workspace pool.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the bug
Since #2035, cuvsRMMAlloc allocates from the RAFT workspace resource instead of the current device memory resource. cuvs-java allocates device matrices (CuVSMatrix.deviceBuilder) through cuvsRMMAlloc, so a device matrix can't be larger than the workspace limit, which defaults to a quarter of total device memory. On a 96 GB GPU that is 6,224,112 rows of 1,024 float32. cuvsResourcesSetWorkspacePool, which is documented as configuring an uncapped pool, keeps the same limit.
I hit this building Vamana graphs through cuvs-java. An 8M × 1,024 dataset couldn't be copied to the GPU, so my code built from host memory instead, and the build ran over 2 hours where 4M took about 5 minutes from a device copy.
Steps/Code to reproduce bug
The script below calls the C API through ctypes on one otherwise idle GPU.
import ctypes
import cupy
lib = ctypes.CDLL("libcuvs_c.so")
lib.cuvsResourcesCreate.argtypes = [ctypes.POINTER(ctypes.c_size_t)]
lib.cuvsRMMAlloc.argtypes = [ctypes.c_size_t, ctypes.POINTER(ctypes.c_void_p), ctypes.c_size_t]
lib.cuvsRMMFree.argtypes = [ctypes.c_size_t, ctypes.c_void_p, ctypes.c_size_t]
lib.cuvsResourcesSetWorkspacePool.argtypes = [ctypes.c_size_t, ctypes.c_size_t]
lib.cuvsGetLastErrorText.restype = ctypes.c_char_p
CUVS_SUCCESS = 1
free, total = cupy.cuda.runtime.memGetInfo()
row = 1024 * 4 # one 1,024-dimensional float32 vector
quarter_rows = total // 4 // row
print(f"total device memory {total} bytes, a quarter holds {quarter_rows} rows")
def alloc(rows, pool=None):
res = ctypes.c_size_t()
assert lib.cuvsResourcesCreate(ctypes.byref(res)) == CUVS_SUCCESS
if pool is not None:
assert lib.cuvsResourcesSetWorkspacePool(res, pool) == CUVS_SUCCESS
ptr = ctypes.c_void_p()
ok = lib.cuvsRMMAlloc(res, ctypes.byref(ptr), rows * row) == CUVS_SUCCESS
print(f"{rows} rows{' after SetWorkspacePool' if pool else ''}:",
"OK" if ok else lib.cuvsGetLastErrorText().decode().rsplit(": ", 1)[-1])
if ok:
lib.cuvsRMMFree(res, ptr, rows * row)
alloc(quarter_rows)
alloc(quarter_rows + 1)
alloc(8_000_000)
alloc(8_000_000, pool=1 << 30)
x = cupy.empty((8_000_000, 1024), dtype=cupy.float32)
print("8000000 rows with CuPy: OK")
Output
total device memory 101975851008 bytes, a quarter holds 6224112 rows
6224112 rows: OK
6224113 rows: Exceeded memory limit 25493962752; Allocated bytes 0; Requested bytes 25493966848
8000000 rows: Exceeded memory limit 25493962752; Allocated bytes 0; Requested bytes 32768000000
8000000 rows after SetWorkspacePool: Exceeded memory limit 25493962752; Allocated bytes 0; Requested bytes 32768000000
8000000 rows with CuPy: OK
In cuvs-java, CuVSMatrix.deviceBuilder(resources, 8_000_000, 1024, CuVSMatrix.DataType.FLOAT).build() fails the same way.
Expected behavior
A device matrix that holds a dataset should be limited by device memory, as it was before #2035. RAFT's comment on default_allocation_limit describes the workspace limit as "merely an order for algorithm internals to plan the batching accordingly", so long-lived allocations like datasets shouldn't go through it.
Environment details (please complete the following information):
- Environment location: Bare-metal
- Method of cuVS install: conda, libcuvs 26.12.00a12 from rapidsai-nightly (commit c740818b), with cuvs-java 26.12.0 built from source.
cuvsRMMAllocis unchanged on main as of 32776b9. - GPU: NVIDIA RTX PRO 6000 Blackwell Server Edition (96 GB), driver 595.71.05
Additional context
#2035 changed cuvsRMMAlloc and cuvsRMMFree from rmm::mr::get_current_device_resource_ref() to raft::resource::get_workspace_resource_ref(). cuvs-java uses cuvsRMMAlloc both for short-lived buffers, such as filter bitsets, and for long-lived device matrices. The workspace pool suits the first and caps the second.
A possible fix is to keep the workspace pool for scratch buffers and give device matrices their own allocation and free path through the current device memory resource. Unpooled cudaMalloc and cudaFree synchronize the device, so the cuvs-java docs should also recommend enableRMMPooledMemory or enableRMMAsyncMemory for multithreaded applications. I'm happy to open a PR with this.
#682 reports the same workspace limit inside balanced k-means.
- Lingua principale
- Cuda
- Stelle
- 902
- Fork
- 267
- Merge medio
- 2g 21h
- PR unite (30g)
- 57
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di NVIDIA/cuvs
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
I maintainer di solito rispondono entro 1 giorno
-
[BUG] CAGRA multi-CTA and multi-kernel search over-allocate the hashmap they useForse già presa @mc8max l’ha presa 12 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
NVIDIA/cuvs#2856 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
[BUG] cuVS Bench Faiss CAGRA b_ratio reads the wrong JSON keyForse già presa @arcusbuilds l’ha presa 55 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
I maintainer di solito rispondono entro 1 giorno
-
doc
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Upgrade faiss to v1.16.0Forse già presa @aamijar l’ha presa 8 giorni fa. Apertafaiss improvement
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 86/100
I maintainer di solito rispondono entro 1 giorno
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
I maintainer di solito rispondono entro 1 giorno
-
aws-documentation-mcp-server: empty spanning headers shift table column labelsForse già presa @pradeep-ramola l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 2 giorni
-
bug untriaged
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
opensearch-project/sql#5990 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
GustavoBaranda/chatflow-agent#238 ·
I maintainer di solito rispondono entro 1 giorno