Skip to content

Conversation

@imciner2
Copy link
Contributor

@imciner2 imciner2 commented Nov 7, 2025

In the current integer detection logic, we first try the isamax() function if it exists, and if it doesn't (like if we only have a LAPACK library), we try dpotrf with an invalid input.

The problem is, dpotrf with an invalid input can trigger the xerbla() error reporting function, which in the reference BLAS/LAPACK will print an error to the screen and stop the program. (see JuliaLinearAlgebra/BLISBLAS.jl#24 for a case where we see this "in the wild").

Instead, lets use the ilaver() function in LAPACK as the first test to see what the integer size is. This test is similar to the others, where it takes a pointer to an integer that it then writes. We use this to see if it treats those pointers as 32-bits or 64-bits internally by making it -1 before the call (so all bits are 1), and then seeing if the upper 32-bits are written to in the call (e.g., if the value is still negative). If this test can't be done (e.g., there is no ilaver() function), or it fails for some reason, we fallback to the current tests in the same order as they are now.

cc @ViralBShah, @amontoison, @giordano, @staticfloat

I ran this on a bunch of BLAS/LAPACK libraries available on Fedora, and here are the results:

$ LD_PRELOAD=/opt/AMD/aocl/aocl-linux-aocc-5.1.0/aocc/lib/libaoclutils.so LD_LIBRARY_PATH=~/dev/numericalLA/libblastrampoline/src/build/ ./prefix/sdot_test 

Testing OpenBLAS:
Generating forwards to /usr/lib64/libopenblas64.so.0 (clear: 1, verbose: 1, suffix_hint: '')
 -> Autodetected symbol suffix ""
 Testing ilaver()
 -> Autodetected interface ILP64 (64-bit)
 -> Autodetected normal complex return style
 -> Autodetected gfortran calling convention
 -> CBLAS detected
Processed 5146 symbols; forwarded 5121 symbols with 64-bit interface and mangling to a suffix of ""
Generating forwards to /usr/lib64/libopenblas.so.0 (clear: 0, verbose: 1, suffix_hint: '')
 -> Autodetected symbol suffix ""
 Testing ilaver()
 -> Autodetected interface LP64 (32-bit)
 -> Autodetected normal complex return style
 -> Autodetected gfortran calling convention
Processed 5146 symbols; forwarded 5121 symbols with 32-bit interface and mangling to a suffix of ""
Library name: /usr/lib64/libopenblas64.so.0
Library name: /usr/lib64/libopenblas.so.0

Testing MKL:
Generating forwards to /opt/intel/oneapi/mkl/latest/lib/libmkl_rt.so (clear: 1, verbose: 1, suffix_hint: '')
 -> Autodetected symbol suffix ""
 Testing ilaver()
 -> Autodetected interface LP64 (32-bit)
 -> Autodetected argument-passing complex return style
 -> Autodetected gfortran calling convention
 - [2822] complex(cdotc_)
 - [2823] complex(cdotu_)
 - [4610] complex(zdotc_)
 - [4611] complex(zdotu_)
Processed 5146 symbols; forwarded 4914 symbols with 32-bit interface and mangling to a suffix of ""
Generating forwards to /opt/intel/oneapi/mkl/latest/lib/libmkl_rt.so (clear: 0, verbose: 1, suffix_hint: '64_')
 -> Autodetected symbol suffix "64_"
 Testing ilaver()
 -> Autodetected interface ILP64 (64-bit)
 -> Autodetected argument-passing complex return style
 -> Autodetected gfortran calling convention
 -> CBLAS detected
 - [2822] complex(cdotc_64_)
 - [2823] complex(cdotu_64_)
 - [4610] complex(zdotc_64_)
 - [4611] complex(zdotu_64_)
Processed 5146 symbols; forwarded 2304 symbols with 64-bit interface and mangling to a suffix of "64_"
Library name: /opt/intel/oneapi/mkl/latest/lib/libmkl_rt.so
Library name: /opt/intel/oneapi/mkl/latest/lib/libmkl_rt.so

Testing BLIS:
Generating forwards to /usr/lib64/libblis64.so.2 (clear: 1, verbose: 1, suffix_hint: '')
 -> Autodetected symbol suffix ""
 Testing isamax()
 -> Autodetected interface ILP64 (64-bit)
 -> Autodetected normal complex return style
 -> Autodetected gfortran calling convention
 -> CBLAS detected
Processed 5146 symbols; forwarded 318 symbols with 64-bit interface and mangling to a suffix of ""
Generating forwards to /usr/lib64/libblis.so.2 (clear: 0, verbose: 1, suffix_hint: '')
 -> Autodetected symbol suffix ""
 Testing isamax()
 -> Autodetected interface LP64 (32-bit)
 -> Autodetected normal complex return style
 -> Autodetected gfortran calling convention
Processed 5146 symbols; forwarded 318 symbols with 32-bit interface and mangling to a suffix of ""
Library name: /usr/lib64/libblis64.so.2
Library name: /usr/lib64/libblis.so.2

Testing AOCL:
Generating forwards to /opt/AMD/aocl/aocl-linux-aocc-5.1.0/aocc/lib_ILP64/libblis-mt.so (clear: 1, verbose: 1, suffix_hint: '')
 -> Autodetected symbol suffix ""
 Testing isamax()
 -> Autodetected interface ILP64 (64-bit)
 -> Autodetected argument-passing complex return style
 -> Autodetected gfortran calling convention
 -> CBLAS detected
 - [2822] complex(cdotc_64_)
 - [2823] complex(cdotu_64_)
 - [4610] complex(zdotc_64_)
 - [4611] complex(zdotu_64_)
Processed 5146 symbols; forwarded 335 symbols with 64-bit interface and mangling to a suffix of ""
Generating forwards to /opt/AMD/aocl/aocl-linux-aocc-5.1.0/aocc/lib_ILP64/libflame.so (clear: 0, verbose: 1, suffix_hint: '')
 -> Autodetected symbol suffix ""
 Testing ilaver()
 -> Autodetected interface ILP64 (64-bit)
 -> Autodetected argument-passing complex return style
 -> Autodetected gfortran calling convention
 -> CBLAS detected
 - [2822] complex(cdotc_64_)
 - [2823] complex(cdotu_64_)
 - [4610] complex(zdotc_64_)
 - [4611] complex(zdotu_64_)
Processed 5146 symbols; forwarded 4841 symbols with 64-bit interface and mangling to a suffix of ""
Generating forwards to /opt/AMD/aocl/aocl-linux-aocc-5.1.0/aocc/lib_LP64/libblis-mt.so (clear: 0, verbose: 1, suffix_hint: '')
 -> Autodetected symbol suffix ""
 Testing isamax()
 -> Autodetected interface LP64 (32-bit)
 -> Autodetected argument-passing complex return style
 -> Autodetected gfortran calling convention
 - [2822] complex(cdotc_)
 - [2823] complex(cdotu_)
 - [4610] complex(zdotc_)
 - [4611] complex(zdotu_)
Processed 5146 symbols; forwarded 335 symbols with 32-bit interface and mangling to a suffix of ""
Generating forwards to /opt/AMD/aocl/aocl-linux-aocc-5.1.0/aocc/lib_LP64/libflame.so (clear: 0, verbose: 1, suffix_hint: '')
 -> Autodetected symbol suffix ""
 Testing ilaver()
 -> Autodetected interface LP64 (32-bit)
 -> Autodetected argument-passing complex return style
 -> Autodetected gfortran calling convention
 - [2822] complex(cdotc_)
 - [2823] complex(cdotu_)
 - [4610] complex(zdotc_)
 - [4611] complex(zdotu_)
Processed 5146 symbols; forwarded 4841 symbols with 32-bit interface and mangling to a suffix of ""
Library name: /opt/AMD/aocl/aocl-linux-aocc-5.1.0/aocc/lib_ILP64/libblis-mt.so
Library name: /opt/AMD/aocl/aocl-linux-aocc-5.1.0/aocc/lib_ILP64/libflame.so
Library name: /opt/AMD/aocl/aocl-linux-aocc-5.1.0/aocc/lib_LP64/libblis-mt.so
Library name: /opt/AMD/aocl/aocl-linux-aocc-5.1.0/aocc/lib_LP64/libflame.so

Testing FlexiBLAS:
Generating forwards to /usr/lib64/libflexiblas64.so (clear: 1, verbose: 1, suffix_hint: '')
 -> Autodetected symbol suffix ""
 Testing ilaver()
 -> Autodetected interface ILP64 (64-bit)
 -> Autodetected normal complex return style
 -> Autodetected gfortran calling convention
 -> CBLAS detected
Processed 5146 symbols; forwarded 2300 symbols with 64-bit interface and mangling to a suffix of ""
Generating forwards to /usr/lib64/libflexiblas.so (clear: 0, verbose: 1, suffix_hint: '')
 -> Autodetected symbol suffix ""
 Testing ilaver()
 -> Autodetected interface LP64 (32-bit)
 -> Autodetected normal complex return style
 -> Autodetected gfortran calling convention
Processed 5146 symbols; forwarded 2300 symbols with 32-bit interface and mangling to a suffix of ""
Library name: /usr/lib64/libflexiblas64.so
Library name: /usr/lib64/libflexiblas.so

Testing Reference BLAS:
Generating forwards to /usr/lib64/libblas64.so (clear: 1, verbose: 1, suffix_hint: '')
 -> Autodetected symbol suffix ""
 Testing isamax()
 -> Autodetected interface ILP64 (64-bit)
 -> Autodetected normal complex return style
 -> Autodetected gfortran calling convention
 -> CBLAS not found/autodetection unavailable
Processed 5146 symbols; forwarded 151 symbols with 64-bit interface and mangling to a suffix of ""
Generating forwards to /usr/lib64/libblas.so (clear: 0, verbose: 1, suffix_hint: '')
 -> Autodetected symbol suffix ""
 Testing isamax()
 -> Autodetected interface LP64 (32-bit)
 -> Autodetected normal complex return style
 -> Autodetected gfortran calling convention
Processed 5146 symbols; forwarded 151 symbols with 32-bit interface and mangling to a suffix of ""
Library name: /usr/lib64/libblas64.so
Library name: /usr/lib64/libblas.so

Testing Reference LAPACK:
Generating forwards to /usr/lib64/liblapack64.so (clear: 1, verbose: 1, suffix_hint: '')
 -> Autodetected symbol suffix ""
 Testing ilaver()
 -> Autodetected interface ILP64 (64-bit)
 -> Autodetected normal complex return style
 -> Autodetected gfortran calling convention
 -> CBLAS not found/autodetection unavailable
Processed 5146 symbols; forwarded 2107 symbols with 64-bit interface and mangling to a suffix of ""
Generating forwards to /usr/lib64/liblapack.so (clear: 0, verbose: 1, suffix_hint: '')
 -> Autodetected symbol suffix ""
 Testing ilaver()
 -> Autodetected interface LP64 (32-bit)
 -> Autodetected normal complex return style
 -> Autodetected gfortran calling convention
Processed 5146 symbols; forwarded 2107 symbols with 32-bit interface and mangling to a suffix of ""
Library name: /usr/lib64/liblapack64.so
Library name: /usr/lib64/liblapack.so

The ilaver function does not give any error messages in the test, but
will still tell us how the library internally writes to integer pointers.
Copy link
Member

@staticfloat staticfloat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, I was using dpotrf because in my testing it didn't invoke xerbla(), it's too bad that one actually exists.

Is there a reason to keep the dpotrf version around then? If this works, it seems preferable in all cases.

@imciner2
Copy link
Contributor Author

imciner2 commented Nov 7, 2025

Is there a reason to keep the dpotrf version around then? If this works, it seems preferable in all cases.

Probably not, I left it in there mainly as a fallback in case this wasn't working. I think ilaver should be in basically every LAPACK library, so I think it is probably safe to rely on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants