[CUDA] Cholesky via cuSOLVER - #4262
Closed
HaoXuAI wants to merge 1 commit into
Closed
Conversation
Backs Cholesky::eval_gpu with potrf and potrfBatched, and adds the shared cusolver_utils handle and error plumbing for the remaining linalg ops.
Member
|
Thanks for the PR! There is actually already a almost identical PR #4208 so I'm closing this as a duplicate. |
Contributor
Author
|
thanks, when I started the PR was not there |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Choleskyis aNO_GPUstub on CUDA, somx.linalg.choleskyrequires a CPUstream. This backs it with cuSOLVER
potrf/potrfBatched, and adds thecusolver_utilshandle and error plumbing thatgetrf,geqrf,gesvdandsyevdcan reuse.linalg::choleskyno longer forces a CPU stream when CUDA is available.Metal behaviour is unchanged:
cu::is_available()is false there, so theexisting error is still raised.
Testing
Verified on an L40S (sm_89) with CUDA 12.6, against the CPU/LAPACK path:
test_linalg.pypasses 19 tests / 266 subtests, including underDEVICE=gpu.The new test covers batched, non-contiguous and empty inputs, and asserts the
unrequested triangle is exactly zero.
Benchmarks
benchmarks/python/cholesky_bench.py, fp32,MLX_ENABLE_TF32=0, vstorch.linalg.choleskyon the same GPU (MLX ms / PyTorch ms):upperupperTwo thirds of the single-matrix gap is
potrfitself — even in its faster fillmode 4096² takes 3.82 ms against PyTorch's 2.40 ms. The rest is that
upper=Falsemaps toCUBLAS_FILL_MODE_UPPER, consistently slower thanFILL_MODE_LOWER. Computing the fast mode and transposing is equivalent andmeasures +13% at n=4096 but -8% at n=512, so I left it out.
Note
check_cpu_stream_unless_cudais new cross-cutting surface that each furtherlinalg op would touch. Happy to reshape it — a per-primitive capability query
may be preferable to a CUDA-specific branch.