Subject: [alpine-devel] [PATCH 1/2] Add openblas 0.2.10: an easy-to-build BLAS implementation.

From: Isaac Dunham <[email-masked]>
Date: Thu, 28 Aug 2014 08:53:56 -0700

I've added a couple bugfixes cherry-picked from the development branch.
---
 testing/openblas/00-cpuid-arm.patch | 21 ++++++++++++++
 testing/openblas/01-sysconf.patch   | 51 +++++++++++++++++++++++++++++++++
 testing/openblas/APKBUILD           | 56 +++++++++++++++++++++++++++++++++++++
 3 files changed, 128 insertions(+)
 create mode 100644 testing/openblas/00-cpuid-arm.patch
 create mode 100644 testing/openblas/01-sysconf.patch
 create mode 100644 testing/openblas/APKBUILD

diff --git a/testing/openblas/00-cpuid-arm.patch b/testing/openblas/00-cpuid-arm.patch
new file mode 100644
index 0000000..cff164c
--- /dev/null
+++ b/testing/openblas/00-cpuid-arm.patch
@@ -0,0 +1,21 @@
+commit 1f2f00647d8b31f75165b552d120e00aa4683cbe
+Author: Isaiah Norton <[email-masked]>
+Date:   Thu Jul 31 04:59:30 2014 +0000
+
+    cpuid_arm: fix detection when cpuinfo uses "Processor"
+    
+    instead of "model name"
+
+diff --git a/cpuid_arm.c b/cpuid_arm.c
+index 809ef3d..b7181b2 100644
+--- a/cpuid_arm.c
++++ b/cpuid_arm.c
+@@ -90,7 +90,7 @@ int detect(void)
+ 	while (fgets(buffer, sizeof(buffer), infile))
+ 	{
+ 
+-		if (!strncmp("model name", buffer, 10))
++		if ((!strncmp("model name", buffer, 10)) || (!strncmp("Processor", buffer, 9)))
+ 		{
+ 			p = strchr(buffer, ':') + 2;
+ 			break;
diff --git a/testing/openblas/01-sysconf.patch b/testing/openblas/01-sysconf.patch
new file mode 100644
index 0000000..5af32ee
--- /dev/null
+++ b/testing/openblas/01-sysconf.patch
@@ -0,0 +1,51 @@
+commit 7f9226a11d6dcf27262d6cc42e51332e482b54ad
+Author: Isaac Dunham <[email-masked]>
+Date:   Sun Aug 3 15:06:30 2014 -0700
+
+    Fix link error on Linux/musl.
+    
+    get_nprocs() is a GNU convenience function equivalent to POSIX2008
+    sysconf(_SC_NPROCESSORS_ONLN); the latter should be available in unistd.h
+    on any current *nix. (OS X supports this call since 10.5, and FreeBSD
+    currently supports it. But this commit does not change FreeBSD or OS X
+    versions.)
+
+diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md
+index 58748ea..18a218c 100644
+--- a/CONTRIBUTORS.md
++++ b/CONTRIBUTORS.md
+@@ -114,5 +114,8 @@ In chronological order:
+ * carlkl <https://github.com/carlkl>
+   * [2013-12-13] Fixed LAPACKE building bug on Windows
+ 
++* Isaac Dunham <https://github.com/idunham>
++  * [2014-08-03] Fixed link error on Linux/musl
++
+ * [Your name or handle] <[email or website]>
+   * [Date] [Brief summary of your changes]
+diff --git a/driver/others/init.c b/driver/others/init.c
+index 30d35e0..85c7ca6 100644
+--- a/driver/others/init.c
++++ b/driver/others/init.c
+@@ -847,7 +847,7 @@ void gotoblas_set_affinity2(int threads) {};
+ 
+ void gotoblas_affinity_reschedule(void) {};
+ 
+-int get_num_procs(void) { return get_nprocs(); }
++int get_num_procs(void) { return sysconf(_SC_NPROCESSORS_ONLN); }
+ 
+ int get_num_nodes(void) { return 1; }
+ 
+diff --git a/driver/others/memory.c b/driver/others/memory.c
+index f44b37b..9fdb18f 100644
+--- a/driver/others/memory.c
++++ b/driver/others/memory.c
+@@ -162,7 +162,7 @@ int get_num_procs(void);
+ #else
+ int get_num_procs(void) {
+   static int nums = 0;
+-  if (!nums) nums = get_nprocs();
++  if (!nums) nums = sysconf(_SC_NPROCESSORS_ONLN);
+   return nums;
+ }
+ #endif
diff --git a/testing/openblas/APKBUILD b/testing/openblas/APKBUILD
new file mode 100644
index 0000000..1bcdda1
--- /dev/null
+++ b/testing/openblas/APKBUILD
@@ -0,0 +1,56 @@
+# Contributor: Isaac Dunham <[email-masked]>
+# Maintainer: Isaac Dunham <[email-masked]>
+pkgname=openblas
+pkgver=0.2.10
+pkgrel=0
+pkgdesc="A fast BSD-licensed BLAS based on gotoBLAS2, with LAPACK"
+url="http://www.openblas.net"
+arch="all"
+license="BSD"
+depends=""
+depends_dev="gfortran"
+makedepends="$depends_dev"
+install=""
+subpackages="$pkgname-dev $pkgname-doc"
+source="$pkgname-$pkgver.tar.gz::http://github.com/xianyi/OpenBLAS/archive/v$pkgver.tar.gz
+	00-cpuid-arm.patch
+	01-sysconf.patch"
+
+_builddir="$srcdir"/OpenBLAS-$pkgver
+prepare() {
+	local i
+	cd "$_builddir"
+	for i in $source; do
+		case $i in
+		*.patch) msg $i; patch -p1 -i "$srcdir"/$i || return 1;;
+		esac
+	done
+}
+
+build() {
+	cd "$_builddir"
+#USE_OPENMP=0: see GCC bug 60035
+#NO_AFFINITY: don't expect to work on musl, also breaks R
+	make USE_OPENMP=0 NO_LAPACK=0 NUM_THREADS=2 MAJOR_VERSION=3 \
+	NO_AFFINITY=1 TARGET=ATOM PREFIX=/usr || return 1
+}
+
+package() {
+	cd "$_builddir"
+	mkdir -pm 0755 "$pkgdir/usr/lib" "$pkgdir/usr/include" \
+	"$pkgdir/usr/share/doc/$pkgname" || return 1
+	make USE_OPENMP=0 NO_LAPACK=0 NUM_THREADS=2 MAJOR_VERSION=3 \
+	NO_AFFINITY=1 TARGET=ATOM PREFIX="$pkgdir/usr" install || return 1
+	for FILE in *.txt *.md LICENSE; do
+		install -m 0644 $FILE "$pkgdir/usr/share/doc/$pkgname" || return 1
+	done
+}
+md5sums="eb3ff035734ce5f4e1ff9d3e5c7ac734  openblas-0.2.10.tar.gz
+23129cfbe53ccd872d53de86a49befeb  00-cpuid-arm.patch
+c76c1e2aec82b0bbc4be7b597073626d  01-sysconf.patch"
+sha256sums="210ba4ba9f20275ebe9edb7cd555f1d8374a5797a3d2a8382e12e33ca3304b24  openblas-0.2.10.tar.gz
+dd4c217d02f983b8bba1735fe1efae0119470d19ef4cb50a7a19d8fc631109e9  00-cpuid-arm.patch
+c421313c6f199f043620910fb7baab022df4671cf4d96fb1e7ae3f20fc0309af  01-sysconf.patch"
+sha512sums="f672e4f95c3979ce695ed96e5c0ea8645057c4abb6e79092c87ff410d8cff8dbe751ee75d91f32770add96ad1ad3ae9278f254d93be2fc95e13110f00fa0ce85  openblas-0.2.10.tar.gz
+3a142905daa575e0367d7c80f99a19474f73663655d5eb5fbd5289fd3c21b23e5b06df4fb894af9b446782ed5c3e28dbdccea5dfadf1523f9c8dfd90fbe3c49c  00-cpuid-arm.patch
+d96d63b93925d7336bd435d072757bae4bf6e0a975a1a9d4c7b3df1cc608dc1e5dc12749945cac1fa74b69752ff498526ddb8218f7ba5ae7f23e7627c63b43da  01-sysconf.patch"
-- 
2.1.0

---
Unsubscribe:  [email-masked]
Help:         [email-masked]
---

---

From: Isaac Dunham <[email-masked]>
Date: Thu, 28 Aug 2014 08:53:57 -0700

Upgraded to 1.8.1 so I could build with OpenBLAS.
Fixed a typo while I was here.
---
 testing/py-numpy/APKBUILD |  17 +++--
 testing/py-numpy/site.cfg | 157 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 168 insertions(+), 6 deletions(-)
 create mode 100644 testing/py-numpy/site.cfg

diff --git a/testing/py-numpy/APKBUILD b/testing/py-numpy/APKBUILD
index a590ba1..db7f1f8 100644
--- a/testing/py-numpy/APKBUILD
+++ b/testing/py-numpy/APKBUILD
@@ -2,7 +2,7 @@
 # Maintainer: Francesco Colista <[email-masked]>
 pkgname=py-numpy
 _pkgname=numpy
-pkgver=1.7.1
+pkgver=1.8.1
 pkgrel=0
 pkgdesc="Scientific tools for Python"
 url="http://numpy.scipy.org/"
@@ -13,7 +13,8 @@ depends_dev="python-dev"
 makedepends="$depends_dev"
 install=""
 subpackages="$pkgname-dev $pkgname-doc"
-source="http://downloads.sourceforge.net/$_pkgname/$_pkgname-$pkgver.tar.gz"
+source="http://downloads.sourceforge.net/$_pkgname/$_pkgname-$pkgver.tar.gz
+	site.cfg"
 
 _builddir="$srcdir"/$_pkgname-$pkgver
 prepare() {
@@ -22,13 +23,14 @@ prepare() {
 	for i in $source; do
 		case $i in
 		*.patch) msg $i; patch -p1 -i "$srcdir"/$i || return 1;;
+		site.cfg) msg $i; cp "$srcdir"/$i ./ || return 1;;
 		esac
 	done
 }
 
 build() {
 	cd "$_builddir"
-	export Atles=None
+	export Atlas=None
 	LDFLAGS="$LDFLAGS -shared"
 	python setup.py build config_fc --fcompiler=gnu95  || return 1
 }
@@ -41,6 +43,9 @@ package() {
 	install -m644 LICENSE.txt "$pkgdir"/usr/share/licenses/custom/$pkgname/LICENSE
 }
 
-md5sums="0ab72b3b83528a7ae79c6df9042d61c6  numpy-1.7.1.tar.gz"
-sha256sums="5525019a3085c3d860e6cfe4c0a30fb65d567626aafc50cf1252a641a418084a  numpy-1.7.1.tar.gz"
-sha512sums="d58177f3971b6d07baf6f81a2088ba371c7e43ea64ee7ada261da97c6d725b4bd4927122ac373c55383254e4e31691939276dab08a79a238bfa55172a3eff684  numpy-1.7.1.tar.gz"
+md5sums="be95babe263bfa3428363d6db5b64678  numpy-1.8.1.tar.gz
+6f15bb8fe3d12faa8983a9e18bbea2a9  site.cfg"
+sha256sums="3d722fc3ac922a34c50183683e828052cd9bb7e9134a95098441297d7ea1c7a9  numpy-1.8.1.tar.gz
+8aa71c1aec2a9fdf6ab6167c92e86bdaf27f9a263b6b9849097ec7dcdf6d91a3  site.cfg"
+sha512sums="39ef9e13f8681a2c2ba3d74ab96fd28c5669e653308fd1549f262921814fa7c276ce6d9fb65ef135006584c608bdf3db198d43f66c9286fc7b3c79803dbc1f57  numpy-1.8.1.tar.gz
+21ca8db304cbbf5949f07702f2a42bb5e5a0d641921e36649555a41b0e48f04e96f53760417823177ac27f6de24b2191e6e1d5f0eb393beafa29f7484e23284f  site.cfg"
diff --git a/testing/py-numpy/site.cfg b/testing/py-numpy/site.cfg
new file mode 100644
index 0000000..effb46f
--- /dev/null
+++ b/testing/py-numpy/site.cfg
@@ -0,0 +1,157 @@
+# This file provides configuration information about non-Python dependencies for
+# numpy.distutils-using packages. Create a file like this called "site.cfg" next
+# to your package's setup.py file and fill in the appropriate sections. Not all
+# packages will use all sections so you should leave out sections that your
+# package does not use.
+
+# To assist automatic installation like easy_install, the user's home directory
+# will also be checked for the file ~/.numpy-site.cfg .
+
+# The format of the file is that of the standard library's ConfigParser module.
+#
+#   http://www.python.org/doc/current/lib/module-ConfigParser.html
+#
+# Each section defines settings that apply to one particular dependency. Some of
+# the settings are general and apply to nearly any section and are defined here.
+# Settings specific to a particular section will be defined near their section.
+#
+#   libraries
+#       Comma-separated list of library names to add to compile the extension
+#       with. Note that these should be just the names, not the filenames. For
+#       example, the file "libfoo.so" would become simply "foo".
+#           libraries = lapack,f77blas,cblas,atlas
+#
+#   library_dirs
+#       List of directories to add to the library search path when compiling
+#       extensions with this dependency. Use the character given by os.pathsep
+#       to separate the items in the list. Note that this character is known to
+#       vary on some unix-like systems; if a colon does not work, try a comma.
+#       This also applies to include_dirs and src_dirs (see below).
+#       On UN*X-type systems (OS X, most BSD and Linux systems):
+#           library_dirs = /usr/lib:/usr/local/lib
+#       On Windows:
+#           library_dirs = c:\mingw\lib,c:\atlas\lib
+#       On some BSD and Linux systems:
+#           library_dirs = /usr/lib,/usr/local/lib
+#
+#   include_dirs
+#       List of directories to add to the header file earch path.
+#           include_dirs = /usr/include:/usr/local/include
+#
+#   src_dirs 
+#       List of directories that contain extracted source code for the
+#       dependency. For some dependencies, numpy.distutils will be able to build
+#       them from source if binaries cannot be found. The FORTRAN BLAS and
+#       LAPACK libraries are one example. However, most dependencies are more
+#       complicated and require actual installation that you need to do
+#       yourself.
+#           src_dirs = /home/rkern/src/BLAS_SRC:/home/rkern/src/LAPACK_SRC
+#
+#   search_static_first
+#       Boolean (one of (0, false, no, off) for False or (1, true, yes, on) for
+#       True) to tell numpy.distutils to prefer static libraries (.a) over
+#       shared libraries (.so). It is turned off by default.
+#           search_static_first = false
+
+# Defaults
+# ========
+# The settings given here will apply to all other sections if not overridden.
+# This is a good place to add general library and include directories like
+# /usr/local/{lib,include}
+#
+#[DEFAULT]
+#library_dirs = /usr/local/lib
+#include_dirs = /usr/local/include
+
+# Atlas
+# -----
+# Atlas is an open source optimized implementation of the BLAS and Lapack
+# routines. Numpy will try to build against Atlas by default when available in
+# the system library dirs. To build numpy against a custom installation of
+# Atlas you can add an explicit section such as the following. Here we assume
+# that Atlas was configured with ``prefix=/opt/atlas``.
+#
+# [atlas]
+# library_dirs = /opt/atlas/lib
+# include_dirs = /opt/atlas/include
+
+# OpenBLAS
+# --------
+# OpenBLAS is another open source optimized implementation of BLAS and Lapack
+# and can be seen as an alternative to Atlas. To build numpy against OpenBLAS
+# instead of Atlas, use this section instead of the above, adjusting as needed
+# for your configuration (in the following example we installed OpenBLAS with
+# ``make install PREFIX=/opt/OpenBLAS``.
+#
+# **Warning**: OpenBLAS, by default, is built in multithreaded mode. Due to the
+# way Python's multiprocessing is implemented, a multithreaded OpenBLAS can
+# cause programs using both to hang as soon as a worker process is forked on
+# POSIX systems (Linux, Mac).
+# This is fixed in Openblas 0.2.9 for the pthread build, the OpenMP build using
+# GNU openmp is as of gcc-4.9 not fixed yet.
+# Python 3.4 will introduce a new feature in multiprocessing, called the
+# "forkserver", which solves this problem. For older versions, make sure
+# OpenBLAS is built using pthreads or use Python threads instead of
+# multiprocessing.
+# (This problem does not exist with multithreaded ATLAS.)
+#
+# http://docs.python.org/3.4/library/multiprocessing.html#contexts-and-start-methods
+# https://github.com/xianyi/OpenBLAS/issues/294
+#
+[openblas]
+libraries = openblas
+library_dirs = /usr/lib
+include_dirs = /usr/include
+
+# MKL
+#----
+# MKL is Intel's very optimized yet proprietary implementation of BLAS and
+# Lapack.
+# For recent (9.0.21, for example) mkl, you need to change the names of the
+# lapack library. Assuming you installed the mkl in /opt, for a 32 bits cpu:
+# [mkl]
+# library_dirs = /opt/intel/mkl/9.1.023/lib/32/
+# lapack_libs = mkl_lapack
+#
+# For 10.*, on 32 bits machines:
+# [mkl]
+# library_dirs = /opt/intel/mkl/10.0.1.014/lib/32/
+# lapack_libs = mkl_lapack
+# mkl_libs = mkl, guide
+
+# UMFPACK
+# -------
+# The UMFPACK library is used in scikits.umfpack to factor large sparse matrices. 
+# It, in turn, depends on the AMD library for reordering the matrices for
+# better performance.  Note that the AMD library has nothing to do with AMD
+# (Advanced Micro Devices), the CPU company.
+#
+# UMFPACK is not needed for numpy or scipy.
+#
+#   http://www.cise.ufl.edu/research/sparse/umfpack/
+#   http://www.cise.ufl.edu/research/sparse/amd/
+#   http://scikits.appspot.com/umfpack
+#
+#[amd]
+#amd_libs = amd
+#
+#[umfpack]
+#umfpack_libs = umfpack
+
+# FFT libraries
+# -------------
+# There are two FFT libraries that we can configure here: FFTW (2 and 3) and djbfft.
+# Note that these libraries are not needed for numpy or scipy.
+#
+#   http://fftw.org/
+#   http://cr.yp.to/djbfft.html
+#
+# Given only this section, numpy.distutils will try to figure out which version
+# of FFTW you are using.
+#[fftw]
+#libraries = fftw3
+#
+# For djbfft, numpy.distutils will look for either djbfft.a or libdjbfft.a . 
+#[djbfft]
+#include_dirs = /usr/local/djbfft/include
+#library_dirs = /usr/local/djbfft/lib
-- 
2.1.0

---