From fedf8128ae13abeaad933ef63f598db317c39d79 Mon Sep 17 00:00:00 2001 From: AMD Toolchain Support <73240730+amd-toolchain-support@users.noreply.github.com> Date: Fri, 22 Mar 2024 06:57:21 +0530 Subject: [PATCH] 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 --- .../repos/builtin/packages/openblas/package.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/var/spack/repos/builtin/packages/openblas/package.py b/var/spack/repos/builtin/packages/openblas/package.py index 5e1a6f2b8e4..269a2e9613a 100644 --- a/var/spack/repos/builtin/packages/openblas/package.py +++ b/var/spack/repos/builtin/packages/openblas/package.py @@ -70,6 +70,11 @@ class Openblas(CMakePackage, MakefilePackage): variant("ilp64", default=False, description="Force 64-bit Fortran native integers") 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, @@ -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 @@ def make_defs(self): # 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 @@ def check_install(self): 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"),