deeplearning4j/deeplearning4j · error · BlasException
cusolverDnSgeqrf_bufferSize failed
Error message
cusolverDnSgeqrf_bufferSize failed
What it means
sgeqrf first calls cusolverDnSgeqrf_bufferSize to query the workspace size needed for the float QR factorization. When the returned status is not CUSOLVER_STATUS_SUCCESS, JcublasLapack throws this BlasException. It means the cuSOLVER query itself failed before any factorization ran - typically bad dimensions (M<=0/N<=0), a null/invalid device pointer, or an uninitialized/failed cuSOLVER handle/stream.
Solutions
- Validate input: ensure the INDArray is non-empty and rows/columns are > 0 before calling sgeqrf.
- Check GPU health and memory (nvidia-smi); an OOM or driver failure corrupts subsequent calls - restart the JVM/app.
- Verify nd4j-cuda backend version matches the installed CUDA toolkit (e.g. nd4j-cuda-11.6 with CUDA 11.6).
- Confirm cusolverDnSetStream succeeded just before the call (see 'solverSetStream failed' for the setup path).
- Fall back to CPU backend for this computation to isolate whether the failure is CUDA-specific.
Example fix
// before
INDArray a = Nd4j.create(new float[0]); // empty
INDArrayInfo info = Nd4j.getBlasWrapper().lapack().geqrf(a, tau);
// after
if (a.isEmpty() || a.rows() < 1 || a.columns() < 1) {
throw new IllegalArgumentException("geqrf requires a non-empty matrix, got " + a.shape());
}
INDArrayInfo info = Nd4j.getBlasWrapper().lapack().geqrf(a, tau); Defensive patterns
Strategy: validation
Validate before calling
// Java/ND4j
if (a == null || a.isEmpty() || a.rows() < 1 || a.columns() < 1) {
throw new IllegalArgumentException("sgeqrf requires a non-empty matrix, got shape " + (a == null ? "null" : java.util.Arrays.toString(a.shape())));
} Try / catch
// Java
try {
lapack.geqrf(a, tau);
} catch (BlasException e) {
// fall back to CPU backend or abort with a clear message
throw new IllegalStateException("QR failed on GPU: " + e.getMessage(), e);
} Prevention
- Validate matrix shape and dtype before every Lapack call
- Keep nd4j-cuda backend version aligned with the CUDA toolkit
- Monitor GPU memory before large factorizations
- Test linear algebra paths with the CPU backend in CI to separate logic bugs from GPU issues
When it happens
Trigger: Calling Nd4j's sgeqrf on a CUDA backend when the input INDArray is empty, has non-positive rows/columns, is not in a layout cuSOLVER accepts, or when the preceding cusolverDnSetStream/handle setup failed; also when the NativeBlas binding could not map the device pointer (uninitialized buffer).
Common situations: Passing zero-length or broadcast/empty arrays to QR decomposition on GPUs; using an NDArray with an unsupported stride/offset; mixing CUDA backend jars with mismatched cuSOLVER versions (CUDA toolkit upgrade without updating nd4j-cuda-*-platform); GPU out of memory corrupting pointer allocation.
Related errors
- cusolverDnDgeqrf_bufferSize failed
- cusolverDnDgeqrf failed
- cusolverDnDgeqrf failed with info
- cusolverDnDorgqr failed
- cusolverDnSgeqrf failed
AI-assisted analysis of deeplearning4j/deeplearning4j@4c22ac5fe4 (2026-09-07).
Data as JSON: /api/errors/4734150188a622c1.
Report an issue: GitHub.
Appendix: source
Thrown at nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/blas/JcublasLapack.java:246
if (result != 0)
throw new IllegalStateException("solverSetStream failed");
// transfer the INDArray into GPU memory
CublasPointer xAPointer = new CublasPointer(a, ctx);
CublasPointer xTauPointer = new CublasPointer(tau, ctx);
// this output - indicates how much memory we'll need for the real operation
val worksizeBuffer = (BaseCudaDataBuffer) Nd4j.getDataBufferFactory().createInt(1);
worksizeBuffer.lazyAllocateHostPointer();
int stat = cusolverDnSgeqrf_bufferSize(solverDn, M, N,
(FloatPointer) xAPointer.getDevicePointer(), M,
(IntPointer) worksizeBuffer.addressPointer() // we intentionally use host pointer here
);
if (stat != CUSOLVER_STATUS_SUCCESS) {
throw new BlasException("cusolverDnSgeqrf_bufferSize failed", stat);
}
int worksize = worksizeBuffer.getInt(0);
// Now allocate memory for the workspace, the permutation matrix and a return code
Pointer workspace = new Workspace(worksize * Nd4j.sizeOfDataType());
// Do the actual QR decomp
stat = cusolverDnSgeqrf(solverDn, M, N,
(FloatPointer) xAPointer.getDevicePointer(), M,
(FloatPointer) xTauPointer.getDevicePointer(),
new CudaPointer(workspace).asFloatPointer(),
worksize,
new CudaPointer(allocator.getPointer(INFO, ctx)).asIntPointer()
);
if (stat != CUSOLVER_STATUS_SUCCESS) {
throw new BlasException("cusolverDnSgeqrf failed", stat);
}
allocator.registerAction(ctx, a);View on GitHub (pinned to 4c22ac5fe4)