File:  [cvs.NetBSD.org] / pkgsrc / math / openblas / Makefile.common
Revision 1.5: download - view: text, annotated - select for diffs
Tue Jun 15 04:41:52 2021 UTC (3 years, 7 months ago) by thor
Branches: MAIN
CVS tags: HEAD
mk/blas.bl3, Netlib and OpenBLAS packages, NumPy: C fixup and 64 bits

This delivers 64 bit index BLAS libraries alongside 32 bit ones. This is often
called ILP64 in the BLAS world, as opposed to LP64 where integers are 32 bit
due to the Fortran default integer type, not to be confused with the basic
system ABI used by C. For really large vectors on modern machines, you want
an 'ILP64' BLAS and layers on top of it.

In preparation of better support for vendor BLAS libraries, I had to realize
that you better use the C interfaces supplied by them, not the netlib one
strapped on. A simple reason of practicability: The vendor blas libraries,
just like openblas, like to ship all symbols in one library, so you get them
whether you want it or not. Also implementations may skip Fortran and implement
the underlying functionality directly in C anyway, so one might skip a
layer of indirection. Future will tell if other layers will follow. We still
have the framework of individual layers from Netlib to combine with certain
implementations that miss them (Accelerate framework comes to mind, which
needs further work).

The framework of netlib reference packages for the separate libraries
is instructive and helps keeping things small when you not need all of them.
The installation location of the headers is now in a subdirectory to be able
to have 32 and 64 bit variants independently. The 32 bit ones are linked to
${PREFIX}/include to keep the old picture. We could be brave and remove
those, but there is some value in a build just trying -lcblas and
inclusion of <cblas.h> to be happy.

There is one blas.buildlink3.mk that is supposed to be used only once and
so avoids a combination of conflicting libraries (as the 64 bit index symbols
have the same names as the 32 bit ones).

Basic usage for getting LAPACK+BLAS is still the same as before. You get
CBLAS and LAPACKE by setting BLAS_C_INTERFACE=yes in the package. The 64 bit
indices are selected via BLAS_INDEX64=yes.

Due to the special nature of the Accelerate framework, a package has to
explicitly indicate support for it and it will also not appear on the
list of implementations by default. The reason is that it does provide
mainly CBLAS and CLAPACK (another version of C interface to LAPACK, f2c-based)
and BLAS/LAPACK with f2c/g77 calling conventions. A default build with
gfortran would not like that

This commit also fixes up math/py-numpy and math/py-numpy16 to follow the
new scheme, as that are the only packages directly affected by the change
in CBLAS providership.

# $NetBSD: Makefile.common,v 1.5 2021/06/15 04:41:52 thor Exp $
#
# used by math/openblas_pthread/Makefile
# used by math/openblas_openmp/Makefile
# used by math/openblas/Makefile
# used by math/openblas64_pthread/Makefile
# used by math/openblas64_openmp/Makefile
# used by math/openblas64/Makefile
#
# This is the common Makefile for OpenBLAS builds. It depends on
# OPENBLAS_VARIANT = (openblas|openblas_pthread|openblas_openmp)
# being set.

DISTNAME=	OpenBLAS-${OPENBLAS_VERSION}
PKGNAME=	${OPENBLAS_VARIANT}-${OPENBLAS_VERSION}
DIST_SUBDIR=	openblas-${OPENBLAS_VERSION}
CATEGORIES=	math
MASTER_SITES=	${MASTER_SITE_GITHUB:=xianyi/} \
		http://www.netlib.org/lapack/timing/
DISTFILES=	${DISTNAME}.tar.gz ${LARGE_FILE} ${TIMING_FILE}
LARGE_FILE=	large.tgz
TIMING_FILE=	timing.tgz
GITHUB_PROJECT=	OpenBLAS
GITHUB_TAG=	v${OPENBLAS_VERSION}

DISTINFO_FILE=	${.CURDIR}/../../math/openblas/distinfo
PATCHDIR=	${.CURDIR}/../../math/openblas/patches

HOMEPAGE=	https://github.com/xianyi/OpenBLAS
COMMENT=	Optimized BLAS library based on GotoBLAS2 (variant ${OPENBLAS_VARIANT})
LICENSE=	modified-bsd

# Darwin has a .so/.dylib PLIST issue
# Untested on other platforms
ONLY_FOR_PLATFORM=	Linux-*-* NetBSD-*-*

USE_LANGUAGES=	c fortran
USE_TOOLS+=	gmake perl:build

NO_CONFIGURE=	yes

TEST_TARGET=	tests

# Also set compilers explicitly, overriding Makefile.rule
MAKE_FLAGS+=	CC=${CC:Q}
MAKE_FLAGS+=	CXX=${CXX:Q}
MAKE_FLAGS+=	FC=${FC:Q}

# You may override the autodetected thread count limit.
# Default is detected from build host, which may differ from run host.
BUILD_DEFS+=	OPENBLAS_THREAD_LIMIT

.include "../../mk/bsd.prefs.mk"

# Using conservative default of 32 threads as that matches the
# limit for related stack arrays in OpenBLAS. Might raise it
# in future, anyway. There some memory usage/efficiency tradeoff
# when this number is excessively high.
OPENBLAS_THREAD_LIMIT?=	32
.if !empty(OPENBLAS_THREAD_LIMIT)
MAKE_FLAGS+=		NUM_THREADS=${OPENBLAS_THREAD_LIMIT:Q}
.endif
BENCHMARK_MAXTHREADS?=	8

.if ${MACHINE_ARCH:M*64} == ""
MAKE_FLAGS+=		BINARY32=1
.  if !empty(OPENBLAS_VARIANT:M*64*)
PKG_FAIL_REASON+=	"${OPENBLAS_VARIANT} incompatible with non-64-bit platform"
.  endif
.else
MAKE_FLAGS+=		BINARY64=1
.endif

# Build with the C APIs, as do other optimized libraries.
#MAKE_FLAGS+=		NO_CBLAS=0 NO_LAPACKE=0

# Separate headers and cmake stuff.
MAKE_FLAGS+=	OPENBLAS_INCLUDE_DIR=${PREFIX}/include/${OPENBLAS_VARIANT}
MAKE_FLAGS+=	OPENBLAS_CMAKE_DIR=${PREFIX}/lib/cmake/${OPENBLAS_VARIANT}

# TODO: Set INTERFACE64=1 with additional OPENBLAS_VARIANTs.
# Need to settle on a convention for SYMBOLSUFFIX first, see
# https://github.com/xianyi/OpenBLAS/issues/646 .
MAKE_FLAGS+=	FIXED_LIBNAME=1
.if ${OPENBLAS_VARIANT} == openblas || ${OPENBLAS_VARIANT} == openblas64
MAKE_FLAGS+=	USE_OPENMP=0 USE_THREAD=0 USE_LOCKING=1
BENCHMARK_ENV=	USE_SIMPLE_THREADED_LEVEL3=1
.elif !empty(OPENBLAS_VARIANT:Mopenblas*_pthread)
MAKE_FLAGS+=	LIBNAMESUFFIX=pthread
MAKE_FLAGS+=	USE_OPENMP=0 USE_THREAD=1
BENCHMARK_ENV=	OPENBLAS_NUM_THREADS=${BENCHMARK_MAXTHREADS}
.elif !empty(OPENBLAS_VARIANT:Mopenblas*_openmp)
MAKE_FLAGS+=	LIBNAMESUFFIX=openmp
MAKE_FLAGS+=	USE_OPENMP=1 NO_AFFINITY=1
BENCHMARK_ENV=	OMP_NUM_THREADS=${BENCHMARK_MAXTHREADS}
.endif

.if !empty(OPENBLAS_VARIANT:M*64*)
MAKE_FLAGS+=	INTERFACE64=1 LIBSONAMEBASE=openblas64
.endif

SUBST_CLASSES+=		threads
SUBST_STAGE.threads=	pre-build
SUBST_SED.threads+=	-e "s+OPENBLAS_NUM_THREADS+OMP_NUM_THREADS+g"
SUBST_FILES.threads+=	test/Makefile
SUBST_FILES.threads+=	ctest/Makefile

PLIST_SRC=	${.CURDIR}/../../math/openblas/PLIST
PLIST_SUBST+=	OPENBLAS_VARIANT=${OPENBLAS_VARIANT}

post-extract:
	rm ${WRKSRC}/relapack/src/lapack_wrappers.c.orig
	(cd ${DISTDIR}/${DIST_SUBDIR} && \
		${CP} ${LARGE_FILE} ${TIMING_FILE} ${WRKSRC})

# This builds some benchmark programs you can call from ${WRKSRC} afterwards.
.PHONY: benchmark
benchmark: build
	(cd ${WRKSRC} && ${SETENV} ${MAKE_ENV} ${BENCHMARK_ENV} \
		${MAKE_PROGRAM} ${MAKE_FLAGS} hpl)
	(cd ${WRKSRC}/benchmark && ${SETENV} ${MAKE_ENV} \
		${BENCHMARK_ENV} ${MAKE_PROGRAM} ${MAKE_FLAGS})

.include "../../math/openblas/version.mk"

.include "options.mk"

CVSweb <webmaster@jp.NetBSD.org>