From patchwork Tue Jan 5 15:03:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas De Schampheleire X-Patchwork-Id: 1422514 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=aISMff8P; 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 4D9G3b0c2vz9sWM for ; Wed, 6 Jan 2021 02:03:54 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id DCDB485FEF; Tue, 5 Jan 2021 15:03:51 +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 MAKt8Sg7X02w; Tue, 5 Jan 2021 15:03:49 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by fraxinus.osuosl.org (Postfix) with ESMTP id 2E70785F95; Tue, 5 Jan 2021 15:03:49 +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 A88E11BF2C7 for ; Tue, 5 Jan 2021 15:03:47 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 8040E20367 for ; Tue, 5 Jan 2021 15:03:47 +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 sDyl9SQshber for ; Tue, 5 Jan 2021 15:03:45 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) by silver.osuosl.org (Postfix) with ESMTPS id 1A5A820112 for ; Tue, 5 Jan 2021 15:03:45 +0000 (UTC) Received: by mail-pj1-f44.google.com with SMTP id iq13so1838876pjb.3 for ; Tue, 05 Jan 2021 07:03:45 -0800 (PST) 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=MMw8tSw9DUnuth1Gw/XsQYI8jCEB2fRayFNS43Ynk/I=; b=aISMff8PVxbQDr0L/Av4ZO2Q5I03v0VVULgX4tJDu8EkflCQdZ5WNOh2wruYj+poDq a1FbXTbGqcfrxo4qejKBOvHqxOo5EGyUryy++Ay8INDAUAOy5blH+u0MrNRaMKGXGSJb KOZ7V1XDKFAPwUQTg+GC9slnw9YRJbj5+myTJps9Em1ZBnjfQaZbVFVDBLKRKatrCemY UVVjLyXGpY+BMyq6ST8jmBSMt79LuPsZMxM4hyzn2PVDfW3xaOVjLt7EP+FiExabBvng TqFDJpwXm2TAXcFj46pluj3nW258E6axgf1+SmDKJKR54Gf9Bi1eLIKuiWm2CFtfwMnb 6/8A== 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=MMw8tSw9DUnuth1Gw/XsQYI8jCEB2fRayFNS43Ynk/I=; b=sn6xvxswC+qIUVq8Uwac8FaFrdbeLEw5IfPBIWYjuGgDB3JRZYjC++3k4dEdMfDvAp GJOFg2F+Sc7JzJ5tJ4TSwWRxec/l+flyn+G/lASIUjeEAluytVJ4O7bCxgkFh/Ygianx 5I+XuAEyAIRz5Tt6jSgOx2UedERmRnVoEZrEXhmKnj0XVGsV7QMoEj69CurjdllltTIG NuG0njbwnWlvNtQUFOxooLy8U9fKcvi5lnyXtbnQt0go17riFTn6FUJnDkGUYlidoasl HWlfHiz1w81fnAJK7iSZl7PRDCmx80f9leO5SBlwqOpc66TLRDtyYmAi6TdFN1lgbi7O e9xw== X-Gm-Message-State: AOAM530a587+LnJsOml9/s9Gy4Vj+SWuAe32/0HGau94L4t/PVtRZeYJ 2qRIozRDMJhfN/0CHbsmYRK4viK9RgpM9A== X-Google-Smtp-Source: ABdhPJyCU3sVmqCgGMcQhEcf4lUda9ho6TEBQXArk/GqrTVS12YWMnvv7qKC3W7AVK0BIUnoMBhvfg== X-Received: by 2002:a17:902:b616:b029:da:fcfd:7568 with SMTP id b22-20020a170902b616b02900dafcfd7568mr19830pls.35.1609859023298; Tue, 05 Jan 2021 07:03:43 -0800 (PST) Received: from localhost (ptr-5gw9tx0z7f066xyxzn.18120a2.ip6.access.telenet.be. [2a02:1810:510:3800:124:6af2:167b:d993]) by smtp.gmail.com with ESMTPSA id b125sm45274609pfg.165.2021.01.05.07.03.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Jan 2021 07:03:42 -0800 (PST) From: Thomas De Schampheleire To: buildroot@buildroot.org Date: Tue, 5 Jan 2021 16:03:28 +0100 Message-Id: <20210105150330.29315-1-patrickdepinguin@gmail.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Subject: [Buildroot] [PATCHv2] 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 , Thomas Petazzoni 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. When multithreading is enabled, locking is implicitly enabled inside openblas, so only provide the locking option when multithreading is disabled. Signed-off-by: Thomas De Schampheleire --- v2: - 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(-) diff --git a/package/openblas/Config.in b/package/openblas/Config.in index 3f658c862a..0144e93a3f 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 + 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 diff --git a/package/openblas/openblas.mk b/package/openblas/openblas.mk index 9701df9148..21d05cf30d 100644 --- a/package/openblas/openblas.mk +++ b/package/openblas/openblas.mk @@ -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