diff options
14 files changed, 87 insertions, 0 deletions
diff --git a/lib/spack/spack/build_systems/rocm.py b/lib/spack/spack/build_systems/rocm.py index a986c5e5b9..440cab7fde 100644 --- a/lib/spack/spack/build_systems/rocm.py +++ b/lib/spack/spack/build_systems/rocm.py @@ -75,6 +75,8 @@ # does not like its directory structure. # +import os + import spack.variant from spack.directives import conflicts, depends_on, variant from spack.package_base import PackageBase @@ -154,6 +156,32 @@ class ROCmPackage(PackageBase): archs = ",".join(amdgpu_target) return "--amdgpu-target={0}".format(archs) + # ASAN + @staticmethod + def asan_on(env, llvm_path): + env.set("CC", llvm_path + "/bin/clang") + env.set("CXX", llvm_path + "/bin/clang++") + env.set("ASAN_OPTIONS", "detect_leaks=0") + + for root, dirs, files in os.walk(llvm_path): + if "libclang_rt.asan-x86_64.so" in files: + asan_lib_path = root + env.prepend_path("LD_LIBRARY_PATH", asan_lib_path) + SET_DWARF_VERSION_4 = "" + try: + # This will throw an error if imported on a non-Linux platform. + import distro + + distname = distro.id() + except ImportError: + distname = "unknown" + if "rhel" in distname or "sles" in distname: + SET_DWARF_VERSION_4 = "-gdwarf-5" + + env.set("CFLAGS", "-fsanitize=address -shared-libasan -g " + SET_DWARF_VERSION_4) + env.set("CXXFLAGS", "-fsanitize=address -shared-libasan -g " + SET_DWARF_VERSION_4) + env.set("LDFLAGS", "-Wl,--enable-new-dtags -fuse-ld=lld -fsanitize=address -g -Wl,") + # HIP version vs Architecture # TODO: add a bunch of lines like: diff --git a/var/spack/repos/builtin/packages/comgr/package.py b/var/spack/repos/builtin/packages/comgr/package.py index 789dfc50b7..a8047e3568 100644 --- a/var/spack/repos/builtin/packages/comgr/package.py +++ b/var/spack/repos/builtin/packages/comgr/package.py @@ -42,6 +42,8 @@ class Comgr(CMakePackage): version("5.1.3", sha256="3078c10e9a852fe8357712a263ad775b15944e083f93a879935c877511066ac9") version("5.1.0", sha256="1cdcfe5acb768ef50fb0026d4ee7ba01e615251ad3c27bb2593cdcf8c070a894") + variant("asan", default=False, description="Build with address-sanitizer enabled or disabled") + # Disable the hip compile tests. Spack should not be using # /opt/rocm, and this breaks the build when /opt/rocm exists. patch("hip-tests.patch", when="@:4.2.0") @@ -90,6 +92,8 @@ class Comgr(CMakePackage): args = [self.define("BUILD_TESTING", self.run_tests)] if self.spec.satisfies("@5.4.3:"): args.append("-DCMAKE_INSTALL_LIBDIR=lib") + if self.spec.satisfies("@5.7:"): + args.append(self.define_from_variant("ADDRESS_SANITIZER", "asan")) return args @classmethod diff --git a/var/spack/repos/builtin/packages/hip-tensor/package.py b/var/spack/repos/builtin/packages/hip-tensor/package.py index bddebe34e1..a8d1a03f5e 100644 --- a/var/spack/repos/builtin/packages/hip-tensor/package.py +++ b/var/spack/repos/builtin/packages/hip-tensor/package.py @@ -22,9 +22,13 @@ class HipTensor(CMakePackage, ROCmPackage): version("5.7.1", sha256="96743d4e695fe865aef4097ae31d9b4e42a2d5a92135a005b0d187d9c0b17645") version("5.7.0", sha256="4b17f6d43b17fe2dc1d0c61e9663d4752006f7898cc94231206444a1663eb252") + variant("asan", default=False, description="Build with address-sanitizer enabled or disabled") + for ver in ["5.7.0", "5.7.1", "6.0.0", "6.0.2", "master"]: depends_on(f"composable-kernel@{ver}", when=f"@{ver}") depends_on(f"rocm-cmake@{ver}", when=f"@{ver}") def setup_build_environment(self, env): env.set("CXX", self.spec["hip"].hipcc) + if self.spec.satisfies("+asan"): + self.asan_on(env, self.spec["llvm-amdgpu"].prefix) diff --git a/var/spack/repos/builtin/packages/hipblas/package.py b/var/spack/repos/builtin/packages/hipblas/package.py index 7a58fc9d57..3115b52bb1 100644 --- a/var/spack/repos/builtin/packages/hipblas/package.py +++ b/var/spack/repos/builtin/packages/hipblas/package.py @@ -57,6 +57,7 @@ class Hipblas(CMakePackage, CudaPackage, ROCmPackage): sticky=True, ) variant("rocm", default=True, description="Enable ROCm support") + variant("asan", default=False, description="Build with address-sanitizer enabled or disabled") conflicts("+cuda +rocm", msg="CUDA and ROCm support are mutually exclusive") conflicts("~cuda ~rocm", msg="CUDA or ROCm support is required") @@ -114,6 +115,10 @@ class Hipblas(CMakePackage, CudaPackage, ROCmPackage): ver = None return ver + def setup_build_environment(self, env): + if self.spec.satisfies("+asan"): + self.asan_on(env, self.spec["llvm-amdgpu"].prefix) + def cmake_args(self): args = [ self.define("BUILD_CLIENTS_SAMPLES", "OFF"), diff --git a/var/spack/repos/builtin/packages/hipcub/package.py b/var/spack/repos/builtin/packages/hipcub/package.py index 870d9f299c..a8a43cc72e 100644 --- a/var/spack/repos/builtin/packages/hipcub/package.py +++ b/var/spack/repos/builtin/packages/hipcub/package.py @@ -50,6 +50,7 @@ class Hipcub(CMakePackage, CudaPackage, ROCmPackage): sticky=True, ) variant("rocm", default=True, description="Enable ROCm support") + variant("asan", default=False, description="Build with address-sanitizer enabled or disabled") conflicts("+cuda +rocm", msg="CUDA and ROCm support are mutually exclusive") conflicts("~cuda ~rocm", msg="CUDA or ROCm support is required") @@ -88,6 +89,8 @@ class Hipcub(CMakePackage, CudaPackage, ROCmPackage): def setup_build_environment(self, env): if self.spec.satisfies("+rocm"): env.set("CXX", self.spec["hip"].hipcc) + if self.spec.satisfies("+asan"): + self.asan_on(env, self.spec["llvm-amdgpu"].prefix) def cmake_args(self): args = [self.define("BUILD_TEST", self.run_tests)] diff --git a/var/spack/repos/builtin/packages/hipfft/package.py b/var/spack/repos/builtin/packages/hipfft/package.py index 695c2e21c7..818327b4fb 100644 --- a/var/spack/repos/builtin/packages/hipfft/package.py +++ b/var/spack/repos/builtin/packages/hipfft/package.py @@ -59,6 +59,7 @@ class Hipfft(CMakePackage, CudaPackage, ROCmPackage): variant("rocm", default=True, description="Enable ROCm support") conflicts("+cuda +rocm", msg="CUDA and ROCm support are mutually exclusive") conflicts("~cuda ~rocm", msg="CUDA or ROCm support is required") + variant("asan", default=False, description="Build with address-sanitizer enabled or disabled") depends_on("cmake@3.5:", type="build") @@ -91,6 +92,10 @@ class Hipfft(CMakePackage, CudaPackage, ROCmPackage): # https://github.com/ROCm/rocFFT/pull/85) patch("001-remove-submodule-and-sync-shared-files-from-rocFFT.patch", when="@6.0.0") + def setup_build_environment(self, env): + if self.spec.satisfies("+asan"): + self.asan_on(env, self.spec["llvm-amdgpu"].prefix) + def cmake_args(self): args = [self.define("BUILD_CLIENTS_SAMPLES", "OFF")] diff --git a/var/spack/repos/builtin/packages/hipify-clang/package.py b/var/spack/repos/builtin/packages/hipify-clang/package.py index 2414dbf31a..5b0839054a 100644 --- a/var/spack/repos/builtin/packages/hipify-clang/package.py +++ b/var/spack/repos/builtin/packages/hipify-clang/package.py @@ -39,6 +39,8 @@ class HipifyClang(CMakePackage): version("5.1.3", sha256="6354b08b8ab2f4c481398fb768652bae00bb78c4cec7a11d5f6c7e4cb831ddf1") version("5.1.0", sha256="ba792294cbdcc880e0f02e38ee352dff8d4a2c183430e13d1c5ed176bd46cfc5") + variant("asan", default=False, description="Build with address-sanitizer enabled or disabled") + # the patch was added to install the targets in the correct directory structure # this will fix the issue https://github.com/spack/spack/issues/30711 @@ -80,4 +82,6 @@ class HipifyClang(CMakePackage): args = [] if self.spec.satisfies("@5.5"): args.append(self.define("SWDEV_375013", "ON")) + if self.spec.satisfies("@5.7.0:"): + args.append(self.define_from_variant("ADDRESS_SANITIZER", "asan")) return args diff --git a/var/spack/repos/builtin/packages/hiprand/package.py b/var/spack/repos/builtin/packages/hiprand/package.py index 79022d5a5e..4152dddc0a 100644 --- a/var/spack/repos/builtin/packages/hiprand/package.py +++ b/var/spack/repos/builtin/packages/hiprand/package.py @@ -65,6 +65,7 @@ class Hiprand(CMakePackage, CudaPackage, ROCmPackage): values=("Release", "Debug", "RelWithDebInfo"), description="CMake build type", ) + variant("asan", default=False, description="Build with address-sanitizer enabled or disabled") depends_on("cmake@3.10.2:", type="build") @@ -106,6 +107,8 @@ class Hiprand(CMakePackage, CudaPackage, ROCmPackage): def setup_build_environment(self, env): env.set("CXX", self.spec["hip"].hipcc) + if self.spec.satisfies("+asan"): + self.asan_on(env, self.spec["llvm-amdgpu"].prefix) @classmethod def determine_version(cls, lib): diff --git a/var/spack/repos/builtin/packages/hipsolver/package.py b/var/spack/repos/builtin/packages/hipsolver/package.py index cefe8644b2..9d07038f0d 100644 --- a/var/spack/repos/builtin/packages/hipsolver/package.py +++ b/var/spack/repos/builtin/packages/hipsolver/package.py @@ -70,6 +70,7 @@ class Hipsolver(CMakePackage, CudaPackage, ROCmPackage): values=("Release", "Debug", "RelWithDebInfo"), description="CMake build type", ) + variant("asan", default=False, description="Build with address-sanitizer enabled or disabled") depends_on("cmake@3.5:", type="build") @@ -124,6 +125,10 @@ class Hipsolver(CMakePackage, CudaPackage, ROCmPackage): ver = None return ver + def setup_build_environment(self, env): + if self.spec.satisfies("+asan"): + self.asan_on(env, self.spec["llvm-amdgpu"].prefix) + def cmake_args(self): args = [ self.define("BUILD_CLIENTS_SAMPLES", "OFF"), diff --git a/var/spack/repos/builtin/packages/hipsparse/package.py b/var/spack/repos/builtin/packages/hipsparse/package.py index c3f06ba94c..4efec56801 100644 --- a/var/spack/repos/builtin/packages/hipsparse/package.py +++ b/var/spack/repos/builtin/packages/hipsparse/package.py @@ -54,6 +54,7 @@ class Hipsparse(CMakePackage, CudaPackage, ROCmPackage): sticky=True, ) variant("rocm", default=True, description="Enable ROCm support") + variant("asan", default=False, description="Build with address-sanitizer enabled or disabled") conflicts("+cuda +rocm", msg="CUDA and ROCm support are mutually exclusive") conflicts("~cuda ~rocm", msg="CUDA or ROCm support is required") @@ -100,6 +101,10 @@ class Hipsparse(CMakePackage, CudaPackage, ROCmPackage): ver = None return ver + def setup_build_environment(self, env): + if self.spec.satisfies("+asan"): + self.asan_on(env, self.spec["llvm-amdgpu"].prefix) + def cmake_args(self): args = [ self.define("CMAKE_CXX_STANDARD", "14"), diff --git a/var/spack/repos/builtin/packages/hsa-rocr-dev/package.py b/var/spack/repos/builtin/packages/hsa-rocr-dev/package.py index ea25289a91..44b37774ad 100644 --- a/var/spack/repos/builtin/packages/hsa-rocr-dev/package.py +++ b/var/spack/repos/builtin/packages/hsa-rocr-dev/package.py @@ -127,5 +127,7 @@ class HsaRocrDev(CMakePackage): args.append("-DCMAKE_INSTALL_LIBDIR=lib") if self.spec.satisfies("@6.0:"): args.append(self.define("ROCM_PATCH_VERSION", "60000")) + if self.spec.satisfies("@5.7.0:"): + args.append(self.define_from_variant("ADDRESS_SANITIZER", "asan")) return args diff --git a/var/spack/repos/builtin/packages/rocm-openmp-extras/package.py b/var/spack/repos/builtin/packages/rocm-openmp-extras/package.py index 597c0820a2..6638eabb24 100644 --- a/var/spack/repos/builtin/packages/rocm-openmp-extras/package.py +++ b/var/spack/repos/builtin/packages/rocm-openmp-extras/package.py @@ -173,6 +173,8 @@ class RocmOpenmpExtras(Package): version("5.1.3", sha256=versions_dict["5.1.3"]["aomp"], deprecated=True) version("5.1.0", sha256=versions_dict["5.1.0"]["aomp"], deprecated=True) + variant("asan", default=False, description="Build with address-sanitizer enabled or disabled") + depends_on("cmake@3:", type="build") depends_on("py-setuptools", type="build") depends_on("python@3:", type="build") @@ -270,6 +272,14 @@ class RocmOpenmpExtras(Package): llvm_prefix = self.spec["llvm-amdgpu"].prefix env.set("AOMP", "{0}".format(llvm_prefix)) env.set("FC", "{0}/bin/flang".format(openmp_extras_prefix)) + if self.spec.satisfies("+asan"): + env.set("SANITIZER", 1) + env.set("VERBOSE", 1) + env.set( + "LDSHARED", + self.spec["llvm-amdgpu"].prefix.bin.clang + + " -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro -g -fwrapv -O2", + ) gfx_list = "gfx700 gfx701 gfx801 gfx803 gfx900 gfx902 gfx906 gfx908" if self.spec.version >= Version("4.3.1"): diff --git a/var/spack/repos/builtin/packages/rocm-smi-lib/package.py b/var/spack/repos/builtin/packages/rocm-smi-lib/package.py index 7d50af78db..43b8a9bba5 100644 --- a/var/spack/repos/builtin/packages/rocm-smi-lib/package.py +++ b/var/spack/repos/builtin/packages/rocm-smi-lib/package.py @@ -44,6 +44,7 @@ class RocmSmiLib(CMakePackage): version("5.1.0", sha256="21b31b43015b77a9119cf4c1d4ff3864f9ef1f34e2a52a38f985a3f710dc5f87") variant("shared", default=True, description="Build shared or static library") + variant("asan", default=False, description="Build with address-sanitizer enabled or disabled") depends_on("cmake@3:", type="build") depends_on("python@3:", type=("build", "run")) @@ -58,6 +59,8 @@ class RocmSmiLib(CMakePackage): self.define("CMAKE_INSTALL_LIBDIR", "lib"), self.define("BUILD_TESTS", self.run_tests), ] + if self.spec.satisfies("@5.7.0:"): + args.append(self.define_from_variant("ADDRESS_SANITIZER", "asan")) return args @classmethod diff --git a/var/spack/repos/builtin/packages/roctracer-dev/package.py b/var/spack/repos/builtin/packages/roctracer-dev/package.py index f72e77e500..18e3da449b 100644 --- a/var/spack/repos/builtin/packages/roctracer-dev/package.py +++ b/var/spack/repos/builtin/packages/roctracer-dev/package.py @@ -41,6 +41,8 @@ class RoctracerDev(CMakePackage, ROCmPackage): version("5.1.3", sha256="45f19875c15eb609b993788b47fd9c773b4216074749d7744f3a671be17ef33c") version("5.1.0", sha256="58b535f5d6772258190e4adcc23f37c916f775057a91b960e1f2ee1f40ed5aac") + variant("asan", default=False, description="Build with address-sanitizer enabled or disabled") + depends_on("cmake@3:", type="build") depends_on("python@3:", type="build") depends_on("py-cppheaderparser", type="build") @@ -101,6 +103,10 @@ class RoctracerDev(CMakePackage, ROCmPackage): "hsaap.py", ) + def setup_build_environment(self, env): + if self.spec.satisfies("+asan"): + self.asan_on(env, self.spec["llvm-amdgpu"].prefix) + def cmake_args(self): args = [ self.define("HIP_VDI", "1"), |