Repository navigation
Description
While looking into a Gonum user issue (gonum/gonum#2008), I found that when calling dgesvd with memory allocated by our wrapper for the JOBU/JOBV N case results in a LAPACKE_xerbla, "Wrong parameter 12 in LAPACKE_dgesvd_work". This appears to be happening due to LAPACKE_dgesvd_work unconditionally checking leading dimensions of the output VT matrix even in the case that it will not be used.
The netlib LAPACK reference for DGESVD states
LDVT is INTEGER
The leading dimension of the array VT. LDVT >= 1; if
JOBVT = 'A', LDVT >= N; if JOBVT = 'S', LDVT >= min(M,N).
Indicating that it is unconstrained in the N case.
A Gonum-dependent replicator is available at gonum/gonum#2008, but also simplified here for convenience.
package main
import (
"math/rand"
"gonum.org/v1/gonum/blas/blas64"
"gonum.org/v1/gonum/lapack/lapack64"
"gonum.org/v1/gonum/mat"
netlib_blas "gonum.org/v1/netlib/blas/netlib"
netlib_lapack "gonum.org/v1/netlib/lapack/netlib"
)
func main() {
blas64.Use(netlib_blas.Implementation{})
lapack64.Use(netlib_lapack.Implementation{})
data := make([]float64, 10*10)
for i := range data {
data[i] = rand.Float64()
}
a := mat.NewDense(10, 10, data)
a.Mul(a.T(), a)
var svd mat.SVD
svd.Factorize(a, mat.SVDNone) // Does not fail with mat.SVDFull.
}
outputs
Wrong parameter 12 in LAPACKE_dgesvd_work
panic: lapack: insufficient declared workspace length
goroutine 1 [running]:
gonum.org/v1/netlib/lapack/netlib.Implementation.Dgesvd({}, 0x48?, 0xf2?, 0x10?, 0x49ac28?, {0xc0000ae380?, 0x10?, 0xa?}, 0xa?, {0xc000022140, ...}, ...)
…/pkg/mod/gonum.org/v1/[email protected]/lapack/netlib/lapack.go:2019 +0x44f
gonum.org/v1/gonum/lapack/lapack64.Gesvd(0x4e, 0x4e, {0xa, 0xa, {0xc0000ae380, 0x64, 0x64}, 0xa}, {0x0, 0x0, ...}, ...)
…/pkg/mod/gonum.org/v1/[email protected]/lapack/lapack64/lapack64.go:354 +0x1d0
gonum.org/v1/gonum/mat.(*SVD).Factorize(0xc000073e98, {0x5580a8, 0xc00003a100}, 0x0)
…/pkg/mod/gonum.org/v1/[email protected]/mat/svd.go:139 +0x8f4
main.main()
…/thinking/netlib/main.go:26 +0x1ee
exit status 2
The Go panic occurs because the first call to dgesvd to get the work size returns in error and so does not indicate the correct work length for the second call. The client code that is used here is unsurprising use of dgesvd.
For reference, the Gonum dimension checks are here.
Looking at the other checks in lapacke_dgesvd_work.c, I think that the lda check could be improved to if( lda < MAX(1, n) ) {, though this is not causing a problem here.
Activity
martin-frbg commentedon Jan 6, 2025
Looks like you're right and this needs to be brought to the attention of https://github.com/Reference-LAPACK/lapack too
kortschak commentedon Jan 6, 2025
Thanks @martin-frbg. Would you like me to do that?
martin-frbg commentedon Jan 6, 2025
As you prefer - I'm reminded that I wear a (very small and silly) LAPACK maintainer hat as well. My comment was mostly to clarify that what LAPACKE you see here is directly taken from Reference-LAPACK (as is well over 95 percent of the LAPACK)
kortschak commentedon Jan 6, 2025
OK. I'll leave it then. If you want to move this issue there, please do.