From patchwork Tue Aug 4 13:37:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas De Schampheleire X-Patchwork-Id: 1340868 Return-Path: X-Original-To: incoming-buildroot@patchwork.ozlabs.org Delivered-To: patchwork-incoming-buildroot@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=busybox.net (client-ip=140.211.166.137; helo=fraxinus.osuosl.org; envelope-from=buildroot-bounces@busybox.net; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=KLc3XcfW; dkim-atps=neutral Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BLbNL5gPdz9sRR for ; Tue, 4 Aug 2020 23:35:14 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 74D7A84D11; Tue, 4 Aug 2020 13:35:11 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id U--DPrLd_P4m; Tue, 4 Aug 2020 13:35:10 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by fraxinus.osuosl.org (Postfix) with ESMTP id A434684E23; Tue, 4 Aug 2020 13:35:10 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by ash.osuosl.org (Postfix) with ESMTP id A00B11BF5DF for ; Tue, 4 Aug 2020 13:35:08 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 99DD0203C4 for ; Tue, 4 Aug 2020 13:35:08 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id H0t8wQQ--n4d for ; Tue, 4 Aug 2020 13:35:07 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-ej1-f67.google.com (mail-ej1-f67.google.com [209.85.218.67]) by silver.osuosl.org (Postfix) with ESMTPS id 0CF462010F for ; Tue, 4 Aug 2020 13:35:07 +0000 (UTC) Received: by mail-ej1-f67.google.com with SMTP id a26so16644076ejc.2 for ; Tue, 04 Aug 2020 06:35:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=gVyAHCzFhU0je3hwwEhISG7ccIxeQBmk3VHhOLqJiiA=; b=KLc3XcfWKFwQ0w2cBUbwFtj2Hh0WmY9/hOqSbHBdpbdCgiJiOEoe4iEZaZwfGdsXfT bnMEqs1TZipbL/TEkSyMn2tMBZzJtHldHMBIUXcnBy9iSBwUnrFnj3MBbjhA8CTYAs6O Sm+Qf4+MU7bdAQm1UXMxRZWNNABOCJraHHCUPRKH6hgudEhA+XSAcmdFVnlBvkcrIEus cY+m+kAHoK6yyB47+lzk+grf0b2eJzP5UVUcy5GvgAzoGqWa5d2H1MxhG9qlTqFG6eGs k+eZfMKnK8in7kjxiQmY8od2ZsKRis8ebDdI640u70i0BR6wzYp5RTrZ7zOgg8F75WGI Ffxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=gVyAHCzFhU0je3hwwEhISG7ccIxeQBmk3VHhOLqJiiA=; b=L8qQE4woSt4bIQ9von5Yrq+qzhv5ESz/EUs3Og3B3AypCL6wAkJfoyMtIWkwE1etow owrztsuOgtqsoSj2O1LDuO30WrqOid+KaPpcT7wNp7PuVQqEUsCQxiAnjYNO9b1BQC6Z IYk2XfEpsJAF5qkftcFp77/lxf3Ytm0HJUUdcp+btaHC65i8qn4uQE1+zj1c6/vpOz02 E9EpDrZTf32X8R7fzS9V+Sva4mi9y1j4v2tv1Qd7fWzzSci+Zcw7UkGrrfLgAD1fe4Pv wlA4I8AhrHXWNCOsTLnnttVXMhBZYFae5lWoLt8cPVUQP4yZa/9/Hdz7RaPue71P7DUM gQpg== X-Gm-Message-State: AOAM530PCc5ZpCpcUG8s0K09Hs9ecnrUMay6657uOv+2efBkksePkCRN ixBNHtCvXVSz7w6t48AdxspMwWG5KFk= X-Google-Smtp-Source: ABdhPJzxFahoA65Rac+J9Q/SXLPDMcQnS1KxzX0MiovrDQKDdrF1ui/r4ODJEe58VOua6VxxbOivVA== X-Received: by 2002:a17:906:fa0c:: with SMTP id lo12mr2382612ejb.390.1596548104914; Tue, 04 Aug 2020 06:35:04 -0700 (PDT) Received: from localhost ([131.228.32.166]) by smtp.gmail.com with ESMTPSA id v7sm20549217edd.48.2020.08.04.06.35.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Aug 2020 06:35:04 -0700 (PDT) From: Thomas De Schampheleire To: buildroot@buildroot.org Date: Tue, 4 Aug 2020 15:37:16 +0200 Message-Id: <20200804133716.22902-1-patrickdepinguin@gmail.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Subject: [Buildroot] [PATCH] package/openblas: allow disabling multithreading X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas De Schampheleire Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" From: Thomas De Schampheleire 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. Signed-off-by: Thomas De Schampheleire --- package/openblas/Config.in | 21 +++++++++++++++++++++ package/openblas/openblas.mk | 8 +++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/package/openblas/Config.in b/package/openblas/Config.in index 3f658c862a..e09f3d0c5a 100644 --- a/package/openblas/Config.in +++ b/package/openblas/Config.in @@ -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 + help + Tell OpenBLAS to use locking, by passing USE_LOCKING=1. + Locking is implicitly enabled when USE_THREAD=1, in which case + disabling this option will not have an effect. + 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 diff --git a/package/openblas/openblas.mk b/package/openblas/openblas.mk index 9701df9148..0fd761c89c 100644 --- a/package/openblas/openblas.mk +++ b/package/openblas/openblas.mk @@ -25,12 +25,18 @@ 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 +OPENBLAS_MAKE_OPTS += USE_LOCKING=0 +endif + # We don't know if OpenMP is available or not, so disable OPENBLAS_MAKE_OPTS += USE_OPENMP=0