comparison m4/octave_blas.m4 @ 31134:4dc326899f65

build: simplify BLAS library detection in configure (bug #62715) * configure.ac: Replace calls to OCTAVE_BLAS_F77_FUNC with OCTAVE_BLAS. * m4/octave_blas_f77_func.m4: Removed obsolete macro file. * m4/octave_blas.m4: New file with OCTAVE_BLAS macro to detect BLAS library and find size of integers in library. * m4/module.mk: Add octave_blas.m4 to build system.
author Rik <rik@octave.org>
date Fri, 08 Jul 2022 21:38:05 -0700
parents
children 1d61c36bb34a
comparison
equal deleted inserted replaced
31133:f8d3c0f035d0 31134:4dc326899f65
1 dnl
2 dnl Check for BLAS libary and if valid determine integer size in library
3 dnl
4 AC_DEFUN([OCTAVE_BLAS], [
5 AC_PREREQ(2.50)
6 dnl Call reference macro to find BLAS library
7 AX_BLAS
8
9 if test "$cross_compiling" = yes ; then
10 dnl Assume generic 4-byte BLAS library exists when cross compiling
11 ax_blas_ok=yes
12 ax_cv_blas_integer_size=4
13 AC_MSG_CHECKING([BLAS can be called from Fortran])
14 AC_MSG_RESULT([yes assumed for cross compilation])
15 elif test x"$ax_blas_ok" = xyes; then
16 save_octave_blas_f77_func_LIBS="$LIBS"
17 LIBS="$BLAS_LIBS $LIBS"
18 AC_LANG_PUSH(Fortran 77)
19 ## Check BLAS library integer size.
20 ## If it does not appear to be 8 bytes, we assume it is 4 bytes.
21 ## FIXME: this may fail with options like -ftrapping-math.
22 AC_CACHE_CHECK([BLAS library integer size],
23 [ax_cv_blas_integer_size],
24 [AC_RUN_IFELSE([AC_LANG_PROGRAM(,[[
25 integer*8 two, n
26 integer*4 n2(2)
27 double precision d, a(1), b(1), ddot
28 equivalence (n, n2)
29
30 a(1) = 1.0
31 b(1) = 1.0
32
33 c Generate 2**32 + 1 in an 8-byte integer. Whether we have a big
34 c endian or little endian system, both 4-byte words of this value
35 c should be 1.
36
37 two = 2
38 n = (two ** 32) + 1
39
40 c Check that our expectation about the type conversions are correct.
41
42 if (n2(1) .ne. 1 .or. n2(2) .ne. 1) then
43 print *, 'invalid assumption about integer type conversion'
44 stop 2
45 endif
46
47 * print *, n, n2(1), n2(2)
48 * print *, a(1), b(1)
49
50 c DDOT will either see 1 or a large value for N. Since INCX and INCY
51 c are both 0, we will never increment the index, so A and B only need to
52 c have a single element. If N is interpreted as 1 (BLAS compiled with
53 c 4-byte integers) then the result will be 1. If N is interpreted as a
54 c large value (BLAS compiled with 8-byte integers) then the result will
55 c be the summation a(1)*b(1) 2^32+1 times. This will also take some
56 c time to compute, but at least for now it is the unusual case so we are
57 c much more likely to exit quickly after detecting that the BLAS library
58 c was compiled with 4-byte integers.
59
60 d = ddot (n, a, 0, b, 0)
61
62 * print *, a(1), b(1), d
63
64 c Success (0 exit status) means we detected BLAS compiled with
65 c 8-byte integers.
66
67 if (d .eq. 1.0) then
68 stop 1
69 endif
70
71 ]])],
72 ax_cv_blas_integer_size=8,
73 ax_cv_blas_integer_size=4)
74 ])
75
76 AC_LANG_POP(Fortran 77)
77 LIBS="$save_octave_blas_f77_func_LIBS"
78 fi
79
80 ])