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:
parent
f70af2cc57
commit
fedf8128ae
@ -70,6 +70,11 @@ class Openblas(CMakePackage, MakefilePackage):
|
|||||||
variant("ilp64", default=False, description="Force 64-bit Fortran native integers")
|
variant("ilp64", default=False, description="Force 64-bit Fortran native integers")
|
||||||
variant("pic", default=True, description="Build position independent code")
|
variant("pic", default=True, description="Build position independent code")
|
||||||
variant("shared", default=True, description="Build shared libraries")
|
variant("shared", default=True, description="Build shared libraries")
|
||||||
|
variant(
|
||||||
|
"dynamic_dispatch",
|
||||||
|
default=True,
|
||||||
|
description="Enable runtime cpu detection for best kernel selection",
|
||||||
|
)
|
||||||
variant(
|
variant(
|
||||||
"consistent_fpcsr",
|
"consistent_fpcsr",
|
||||||
default=False,
|
default=False,
|
||||||
@ -239,6 +244,12 @@ class Openblas(CMakePackage, MakefilePackage):
|
|||||||
when="%clang",
|
when="%clang",
|
||||||
msg="OpenBLAS @:0.2.19 does not support OpenMP with 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")
|
depends_on("perl", type="build")
|
||||||
|
|
||||||
@ -453,6 +464,9 @@ def make_defs(self):
|
|||||||
# Add target and architecture flags
|
# Add target and architecture flags
|
||||||
make_defs += self._microarch_target_args()
|
make_defs += self._microarch_target_args()
|
||||||
|
|
||||||
|
if self.spec.satisfies("+dynamic_dispatch"):
|
||||||
|
make_defs += ["DYNAMIC_ARCH=1"]
|
||||||
|
|
||||||
# Fortran-free compilation
|
# Fortran-free compilation
|
||||||
if "~fortran" in self.spec:
|
if "~fortran" in self.spec:
|
||||||
make_defs += ["NOFORTRAN=1"]
|
make_defs += ["NOFORTRAN=1"]
|
||||||
@ -562,6 +576,8 @@ def check_install(self):
|
|||||||
class CMakeBuilder(spack.build_systems.cmake.CMakeBuilder):
|
class CMakeBuilder(spack.build_systems.cmake.CMakeBuilder):
|
||||||
def cmake_args(self):
|
def cmake_args(self):
|
||||||
cmake_defs = [self.define("TARGET", "GENERIC")]
|
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"):
|
if self.spec.satisfies("platform=windows"):
|
||||||
cmake_defs += [
|
cmake_defs += [
|
||||||
self.define("DYNAMIC_ARCH", "OFF"),
|
self.define("DYNAMIC_ARCH", "OFF"),
|
||||||
|
Loading…
Reference in New Issue
Block a user