JuliaLinearAlgebra / libblastrampoline

Using PLT trampolines to provide a BLAS and LAPACK demuxing library.
MIT License
66 stars 17 forks source link

Autodetection of ILP64 can trigger Input Errors #101

Open BrandonGroth opened 1 year ago

BrandonGroth commented 1 year ago

In autodetection.c, LBT specifies a negative N value for input to "probe" the library whether it is using LP64 or ILP64 (autodetect_blas_interface calling isamax). However, our BLAS library by default treats negative N values as an input error and issues a STOP 1.

Other libraries like IMSL also treat negative N values as input errors and exit: https://help.imsl.com/fortran/6.0/stat/default.htm?turl=usererrors.htm

Is there any way to work around this issue?

staticfloat commented 1 year ago

If you have other ideas on how to more safely autodetect the library interface, I'm happy to try them out. In this case, this probing routine was chosen because it worked well with all libraries tested at the time (OpenBLAS, MKL, Accelerate and reference BLAS).

If your BLAS library is meant to be used by a variety of clients, I suggest not killing the process when the user does something wrong, but instead raising an error through whatever mechanism you like (in the case of LAPACK, there is an error return code for this purpose); it is quite disruptive to kill the process if someone calls with incorrect arguments.

It is possible we could add functionality to LBT to skip autodetection, but I am loathe to do that as the consequences for getting the interface wrong are severe; the program may segfault, or even worse, silently give wrong answers.