Enable ASAN in ROCm packages (#42704)
* Initial commit to enable ASAN * fix styling * fix styling * add asan option for hip-tensor and roctracer-dev
This commit is contained in:
parent
579bad05a8
commit
6d4dd33c46
14 changed files with 87 additions and 0 deletions
|
@ -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 @@ def hip_flags(amdgpu_target):
|
|||
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:
|
||||
|
|
|
@ -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 @@ def cmake_args(self):
|
|||
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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 @@ def determine_version(cls, lib):
|
|||
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"),
|
||||
|
|
|
@ -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)]
|
||||
|
|
|
@ -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")]
|
||||
|
||||
|
|
|
@ -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 @@ def cmake_args(self):
|
|||
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
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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 @@ def determine_version(cls, lib):
|
|||
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"),
|
||||
|
|
|
@ -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 @@ def determine_version(cls, lib):
|
|||
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"),
|
||||
|
|
|
@ -127,5 +127,7 @@ def cmake_args(self):
|
|||
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
|
||||
|
|
|
@ -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 @@ def setup_build_environment(self, env):
|
|||
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"):
|
||||
|
|
|
@ -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 @@ def cmake_args(self):
|
|||
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
|
||||
|
|
|
@ -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 @@ def patch(self):
|
|||
"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"),
|
||||
|
|
Loading…
Reference in a new issue