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>
This commit is contained in:
AMD Toolchain Support 2024-03-22 06:57:21 +05:30 committed by GitHub
parent f70af2cc57
commit fedf8128ae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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"),