Skip to content

Commit

Permalink
Trac #29398: Accept system (Open)BLAS
Browse files Browse the repository at this point in the history
As noted in #29397, Cygwin has openblas but does not provide
openblas.pc; instead blas.pc, cblas.pc, lapack.pc are provided (but
cblas.pc is broken).

From http://cygwin.1069669.n5.nabble.com/Updated-
openblas-0-3-3-1-td142613.html:

  2) No devel package is provided as liblapack-devel already provide the
needed headers and import. Openblas is fully compatible with Netlib
BLAS.

  3) libopenblas consist of a single file /usr/bin/cygblas-0.dll that
will precede in PATH the liblapack0 /usr/lib/lapack/cygblas-0.dll    and
used instead. Removing libopenblas will restore the    usage of Netlib
BLAS

Fedora has a similar omission - it does not install openblas.pc (while
its openblas has cblas and lapack capabilities) - see #29393 (Use system
openblas on Fedora)

URL: https://trac.sagemath.org/29398
Reported by: mkoeppe
Ticket author(s): Matthias Koeppe
Reviewer(s): Dima Pasechnik
  • Loading branch information
Release Manager committed Apr 8, 2020
2 parents 11a851d + 0cda07c commit 94b4e90
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 14 deletions.
2 changes: 1 addition & 1 deletion build/make/Makefile.in
Expand Up @@ -48,7 +48,7 @@ $(SAGE_PKGCONFIG)/gsl.pc:
@SAGE_GSL_PC_COMMAND@

# see build/pkgs/openblas/spkg-configure.m4
$(SAGE_PKGCONFIG)/blas.pc $(SAGE_PKGCONFIG)/cblas.pc $(SAGE_PKGCONFIG)/lapack.pc:
$(SAGE_PKGCONFIG)/openblas.pc $(SAGE_PKGCONFIG)/blas.pc $(SAGE_PKGCONFIG)/cblas.pc $(SAGE_PKGCONFIG)/lapack.pc:
-rm -f $@
@SAGE_OPENBLAS_PC_COMMAND@

Expand Down
101 changes: 88 additions & 13 deletions build/pkgs/openblas/spkg-configure.m4
@@ -1,9 +1,14 @@
SAGE_SPKG_CONFIGURE([openblas], [
dnl CHECK
SAGE_SPKG_DEPCHECK([gfortran], [
PKG_CHECK_MODULES([OPENBLAS], [openblas >= 0.2.20], [
SAVE_LIBS="$LIBS"
SAVE_LIBS="$LIBS"
SAVE_CFLAGS="$CFLAGS"
m4_pushdef([SAGE_OPENBLAS_MIN_VERSION_MAJOR], [0])
m4_pushdef([SAGE_OPENBLAS_MIN_VERSION_MINOR], [2])
m4_pushdef([SAGE_OPENBLAS_MIN_VERSION_MICRO], [20])
m4_pushdef([SAGE_OPENBLAS_MIN_VERSION], [SAGE_OPENBLAS_MIN_VERSION_MAJOR.SAGE_OPENBLAS_MIN_VERSION_MINOR.SAGE_OPENBLAS_MIN_VERSION_MICRO])
PKG_CHECK_MODULES([OPENBLAS], [openblas >= ]SAGE_OPENBLAS_MIN_VERSION, [
LIBS="$OPENBLAS_LIBS $LIBS"
SAVE_CFLAGS="$CFLAGS"
CFLAGS="$OPENBLAS_CFLAGS $CFLAGS"
PKG_CHECK_VAR([OPENBLASPCDIR], [openblas], [pcfiledir], [
sage_install_blas_pc=yes
Expand All @@ -30,24 +35,94 @@ SAGE_SPKG_CONFIGURE([openblas], [
AC_MSG_WARN([Unable to locate the directory of openblas.pc. This should not happen!])
sage_spkg_install_openblas=yes
])
LIBS="$SAVE_LIBS"
CFLAGS="$SAVE_CFLAGS"
], [sage_spkg_install_openblas=yes])
AS_IF([test x$sage_spkg_install_openblas != xyes], [
AC_SUBST([SAGE_SYSTEM_FACADE_PC_FILES])
AC_SUBST([SAGE_OPENBLAS_PC_COMMAND], ["\$(LN) -sf \"$OPENBLASPCDIR/openblas.pc\" \"\$(@)\""])
m4_foreach([blaslibnam], [blas, cblas, lapack], [
AS_IF([test x$sage_install_]blaslibnam[_pc = xyes], [
AS_VAR_APPEND([SAGE_SYSTEM_FACADE_PC_FILES], [" \$(SAGE_PKGCONFIG)/]blaslibnam[.pc"])
AS_IF([test x$sage_spkg_install_openblas != xyes], [
AC_SUBST([SAGE_SYSTEM_FACADE_PC_FILES])
AC_SUBST([SAGE_OPENBLAS_PC_COMMAND], ["\$(LN) -sf \"$OPENBLASPCDIR/openblas.pc\" \"\$(@)\""])
m4_foreach([blaslibnam], [blas, cblas, lapack], [
AS_IF([test x$sage_install_]blaslibnam[_pc = xyes], [
AS_VAR_APPEND([SAGE_SYSTEM_FACADE_PC_FILES], [" \$(SAGE_PKGCONFIG)/]blaslibnam[.pc"])
])
])
])
])
], [
dnl No openblas.pc
AS_CASE([$host],
[*-*-cygwin*], [dnl #29398: cygwin uses openblas only to provide a binary-compatible
dnl dll, /usr/bin/cygblas-0.dll, which shadows /usr/lib/lapack/cygblas-0.dll
dnl There is no .pc file, and openblas-specific functions such as
dnl openblas_get_config are not exported. We only accept the system BLAS
dnl if it is provided by OpenBLAS.
AC_MSG_CHECKING([whether cygblas-0.dll is openblas])
AS_IF([grep -q openblas_get_config $(which cygblas-0.dll)],
[AS_VAR_SET([HAVE_OPENBLAS], [yes])],
[AS_VAR_SET([HAVE_OPENBLAS], [no])])
AC_MSG_RESULT([$HAVE_OPENBLAS])
],
[dnl Recent OpenBLAS (>= 0.3.4, Dec 2018) provides the version number as
dnl part of openblas_get_config. We reject all older versions.
AC_SEARCH_LIBS([openblas_get_config], [openblas cblas blas], [
AS_IF([test x"$ac_cv_search_openblas_get_config" != x"none required"], [
AS_VAR_APPEND([OPENBLAS_LIBS], ["$ac_cv_search_openblas_get_config "])
])
AC_MSG_CHECKING([whether openblas_get_config indicates version >= ]SAGE_OPENBLAS_MIN_VERSION)
AC_LANG_PUSH([C])
AC_RUN_IFELSE([
AC_LANG_PROGRAM([[#include <stdio.h>
char *openblas_get_config(void);
int version[3]; ]],
[[version[0] = version[1] = version[2] = 0;
/*printf("%s", openblas_get_config());*/
if (sscanf(openblas_get_config(), "OpenBLAS %d.%d.%d",
version, version+1, version+2) < 1)
return 1;
if ( 10000 * version[0]
+ 100 * version[1]
+ version[2]
< 10000 * ]]SAGE_OPENBLAS_MIN_VERSION_MAJOR[[
+ 100 * ]]SAGE_OPENBLAS_MIN_VERSION_MINOR[[
+ ]]SAGE_OPENBLAS_MIN_VERSION_MICRO[[)
return 1;]])
], [AS_VAR_SET([HAVE_OPENBLAS], [yes])], [AS_VAR_SET([HAVE_OPENBLAS], [no])])
AC_LANG_POP([C])
AC_MSG_RESULT([$HAVE_OPENBLAS])
])
])
AC_SEARCH_LIBS([cblas_dgemm], [openblas cblas blas], [
AS_VAR_SET([HAVE_CBLAS_DGEMM], [yes])
AS_IF([test x"$ac_cv_search_cblas_dgemm" != x"none required"], [
AS_VAR_APPEND([OPENBLAS_LIBS], ["$ac_cv_search_cblas_dgemm "])
])
], [], [-lgfortran])
m4_foreach([dgeqrf_mangled], [dgeqrf, dgeqrf_, DGEQRF, DGEQRF_], [
AC_SEARCH_LIBS(dgeqrf_mangled, [openblas lapack], [
AS_VAR_SET([HAVE_DGEQRF], [yes])
AS_IF([test x"$ac_cv_search_]dgeqrf_mangled[" != x"none required"], [
AS_VAR_APPEND([OPENBLAS_LIBS], ["$ac_cv_search_]dgeqrf_mangled[ "])
])
], [], [-lgfortran])
])
AS_IF([test x"$HAVE_OPENBLAS" = xyes -a x"$HAVE_CBLAS_DGEMM" = xyes -a x"$HAVE_DGEQRF" = xyes], [
AC_SUBST([OPENBLAS_LIBS])
AC_SUBST([SAGE_SYSTEM_FACADE_PC_FILES])
AC_SUBST([SAGE_OPENBLAS_PC_COMMAND], [" (echo \"Name: openblas\"; echo \"Description: OpenBLAS\"; echo \"Version: 0.3\"; echo \"Libs: $OPENBLAS_LIBS\") > \"\$(@)\""])
m4_foreach([blaslibnam], [openblas, blas, cblas, lapack], [
AS_VAR_APPEND([SAGE_SYSTEM_FACADE_PC_FILES], [" \$(SAGE_PKGCONFIG)/]blaslibnam[.pc"])
])
], [
dnl No system BLAS found
sage_spkg_install_openblas=yes
])
])
LIBS="$SAVE_LIBS"
CFLAGS="$SAVE_CFLAGS"
])
], [
dnl REQUIRED-CHECK
AS_IF([test "x$with_blas" = xopenblas], [
sage_require_openblas=yes
sage_require_atlas=no])
], [
dnl PRE
AC_MSG_CHECKING([BLAS library])
AC_ARG_WITH([blas],
[AS_HELP_STRING([--with-blas=openblas],
Expand Down
1 change: 1 addition & 0 deletions build/pkgs/r/distros/cygwin.txt
@@ -1 +1,2 @@
R
libtirpc-devel # needed for building extensions

0 comments on commit 94b4e90

Please sign in to comment.