Skip to contentSkip to conversation

package/openblas: allow disabling multithreading

PATCH New Thomas De Schampheleire 2 participants 3 messages Feb 12, 2021 – Feb 17, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 package/openblas: allow disabling multithreading

From: Thomas De Schampheleire <[email protected]>

Buildroot would automatically enable multithreading in OpenBLAS if the architecture supports it. However, one may want to avoid OpenBLAS creating threads itself and configure single-threaded operation. To accommodate this use case, add a config option for multithreading.

When multithreading is disabled but OpenBLAS functions are called in the same application by multiple threads, then locking is mandatory. The USE_LOCKING flag was added in version 0.3.7 with following release note:

a new option USE_LOCKING was added to ensure thread safety when OpenBLAS itself is built without multithreading but will be called from multiple threads.

However, if one knows that OpenBLAS will only be called from single-threaded applications, then passing USE_LOCKING is not necessary, so make it a config option too.

When multithreading is enabled, locking is implicitly enabled inside openblas, so only provide the locking option when multithreading is disabled.

---

This is a resend of v2, addressing comments of Thomas Petazzoni:
- let USE_LOCKING depend on !USE_THREAD
- don't pass USE_LOCKING=0 to avoid confusion

 package/openblas/Config.in   | 21 +++++++++++++++++++++
 package/openblas/openblas.mk |  9 ++++++++-
 2 files changed, 29 insertions(+), 1 deletion(-)
package/openblas/Config.in +21 -0
index 3f658c862a..0144e93a3f 100644
@@ -73,4 +73,25 @@ config BR2_PACKAGE_OPENBLAS_TARGET
 	string "OpenBLAS target CPU"
 	default BR2_PACKAGE_OPENBLAS_DEFAULT_TARGET
 
+config BR2_PACKAGE_OPENBLAS_USE_THREAD
+	bool "use multithreading"
+	default y
+	depends on BR2_TOOLCHAIN_HAS_THREADS
+	depends on !BR2_STATIC_LIBS
+	help
+	  Tell OpenBLAS to use multithreading, by passing USE_THREAD=1.
+
+config BR2_PACKAGE_OPENBLAS_USE_LOCKING
+	bool "use locking"
+	default y
+	depends on BR2_TOOLCHAIN_HAS_THREADS
+	depends on !BR2_PACKAGE_OPENBLAS_USE_THREAD
+	help
+	  Tell OpenBLAS to use locking, by passing USE_LOCKING=1.
+	  Locking is implicitly enabled when USE_THREAD=1.
+	  However, if USE_THREAD=0 (i.e. OpenBLAS itself will run in
+	  single-threaded mode) but an application makes OpenBLAS
+	  function calls from multiple threads, then locking is
+	  mandatory for correct operation.
+
 endif
package/openblas/openblas.mk +8 -1
index 9701df9148..21d05cf30d 100644
@@ -25,12 +25,19 @@ OPENBLAS_MAKE_OPTS += ONLY_CBLAS=1
 endif
 
 # Enable/Disable multi-threading (not for static-only since it uses dlfcn.h)
-ifeq ($(BR2_TOOLCHAIN_HAS_THREADS):$(BR2_STATIC_LIBS),y:)
+ifeq ($(BR2_PACKAGE_OPENBLAS_USE_THREAD),y)
 OPENBLAS_MAKE_OPTS += USE_THREAD=1
 else
 OPENBLAS_MAKE_OPTS += USE_THREAD=0
 endif
 
+ifeq ($(BR2_PACKAGE_OPENBLAS_USE_LOCKING),y)
+OPENBLAS_MAKE_OPTS += USE_LOCKING=1
+else
+# not passing USE_LOCKING=0 as this could be confusing: its effect is implicit
+# in case of USE_THREAD=1.
+endif
+
 # We don't know if OpenMP is available or not, so disable
 OPENBLAS_MAKE_OPTS += USE_OPENMP=0
 
Signature · 1 line
2.26.2
#1 lore raw

PATCH 2/2 package/openblas: fix detection of gfortran compiler

From: Thomas De Schampheleire <[email protected]>

The compiler detection since openblas 0.3.8 added support for gcc 10, but this broke detection of compilers created with crosstool-ng, or other toolchains that have a package version containing a version like x.y.z where at least one of x, y or z have more than one digit, for example "Crosstool-NG 1.24.0".

See the reported issue for more details [1].

Backport the upstream patch that fixes it.

[1] https://github.com/xianyi/OpenBLAS/issues/3099

---
 .../0001-fix-gfortran-detection.patch         | 30 +++++++++++++++++++
 1 file changed, 30 insertions(+)
 create mode 100644 package/openblas/0001-fix-gfortran-detection.patch
package/openblas/0001-fix-gfortran-detection.patch new file +30 -0
new file mode 100644
index 0000000000..1fecdac3e5
@@ -0,0 +1,30 @@
+From ece3ce581e3ec530eaccfe7f284c52e115ec7aa9 Mon Sep 17 00:00:00 2001
+From: Martin Kroeker <[email protected]>
+Date: Wed, 10 Feb 2021 14:22:59 +0100
+Subject: [PATCH] Strip parenthesized (pkgversion) data from GCC version string
+ to avoid misinterpretation
+
+See https://github.com/xianyi/OpenBLAS/issues/3099 for details.
+
+Upstream-status: backport
+
+[for import into Buildroot]
+Signed-off-by: Thomas De Schampheleire <[email protected]>
+
+
+---
+ f_check | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/f_check b/f_check
+index e9aca4ff9..ffe9c6b46 100644
+--- a/f_check
++++ b/f_check
+@@ -75,6 +75,7 @@ if ($compiler eq "") {
+ 
+ 	} elsif ($data =~ /GNU/ || $data =~ /GCC/ ) {
+ 
++            $data =~ s/\(+.*?\)+//g;
+ 	    $data =~ /(\d+)\.(\d+).(\d+)/;
+ 	    $major = $1;
+ 	    $minor = $2;
Signature · 1 line
2.26.2
#2 lore raw

PATCH 2/2 package/openblas: fix detection of gfortran compiler

Quoted 9 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Thomas" == Thomas De Schampheleire <[email protected]> writes:

From: Thomas De Schampheleire <[email protected]> The compiler detection since openblas 0.3.8 added support for gcc 10, but this broke detection of compilers created with crosstool-ng, or other toolchains that have a package version containing a version like x.y.z where at least one of x, y or z have more than one digit, for example "Crosstool-NG 1.24.0".

Quoted 7 lines

See the reported issue for more details [1].

Backport the upstream patch that fixes it.

[1] https://github.com/xianyi/OpenBLAS/issues/3099

Committed to 2020.11.x, thanks.

Signature · 1 line
Bye, Peter Korsgaard