summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAMD Toolchain Support <73240730+amd-toolchain-support@users.noreply.github.com>2024-03-22 06:57:21 +0530
committerGitHub <noreply@github.com>2024-03-22 02:27:21 +0100
commitfedf8128ae13abeaad933ef63f598db317c39d79 (patch)
treebcde747a33ca0545b571e55b8b274611a59fd3cd
parentf70af2cc57e73bdc85e76558a432cc5514ddda3d (diff)
downloadspack-fedf8128ae13abeaad933ef63f598db317c39d79.tar.gz
spack-fedf8128ae13abeaad933ef63f598db317c39d79.tar.bz2
spack-fedf8128ae13abeaad933ef63f598db317c39d79.tar.xz
spack-fedf8128ae13abeaad933ef63f598db317c39d79.zip
openblas: Add variant dynamic_dispatch: select best kernel at runtime (#42746)
Enable OpenBLAS's built-in CPU capability detection and kernel selection. This allows run-time selection of the "best" kernels for the running CPU, rather than what is specified at build time. For example, it allows OpenBLAS to use AVX512 kernels when running on ZEN4, and built targeting the "ZEN" architecture. Co-authored-by: Branden Moore <branden.moore@amd.com>
-rw-r--r--var/spack/repos/builtin/packages/openblas/package.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/var/spack/repos/builtin/packages/openblas/package.py b/var/spack/repos/builtin/packages/openblas/package.py
index 5e1a6f2b8e..269a2e9613 100644
--- a/var/spack/repos/builtin/packages/openblas/package.py
+++ b/var/spack/repos/builtin/packages/openblas/package.py
@@ -71,6 +71,11 @@ class Openblas(CMakePackage, MakefilePackage):
variant("pic", default=True, description="Build position independent code")
variant("shared", default=True, description="Build shared libraries")
variant(
+ "dynamic_dispatch",
+ default=True,
+ description="Enable runtime cpu detection for best kernel selection",
+ )
+ variant(
"consistent_fpcsr",
default=False,
description="Synchronize FP CSR between threads (x86/x86_64 only)",
@@ -239,6 +244,12 @@ class Openblas(CMakePackage, MakefilePackage):
when="%clang",
msg="OpenBLAS @:0.2.19 does not support OpenMP with clang!",
)
+ # See https://github.com/OpenMathLib/OpenBLAS/issues/2826#issuecomment-688399162
+ conflicts(
+ "+dynamic_dispatch",
+ when="platform=windows",
+ msg="Visual Studio does not support OpenBLAS dynamic dispatch features",
+ )
depends_on("perl", type="build")
@@ -453,6 +464,9 @@ class MakefileBuilder(spack.build_systems.makefile.MakefileBuilder):
# Add target and architecture flags
make_defs += self._microarch_target_args()
+ if self.spec.satisfies("+dynamic_dispatch"):
+ make_defs += ["DYNAMIC_ARCH=1"]
+
# Fortran-free compilation
if "~fortran" in self.spec:
make_defs += ["NOFORTRAN=1"]
@@ -562,6 +576,8 @@ class MakefileBuilder(spack.build_systems.makefile.MakefileBuilder):
class CMakeBuilder(spack.build_systems.cmake.CMakeBuilder):
def cmake_args(self):
cmake_defs = [self.define("TARGET", "GENERIC")]
+ if self.spec.satisfies("+dynamic_dispatch"):
+ cmake_defs += [self.define("DYNAMIC_ARCH", "ON")]
if self.spec.satisfies("platform=windows"):
cmake_defs += [
self.define("DYNAMIC_ARCH", "OFF"),