From 7dd09d9effd6a56d2c0c7abca38b21baa4d77fc8 Mon Sep 17 00:00:00 2001 From: jinge90 Date: Mon, 11 Nov 2024 14:52:02 +0800 Subject: [PATCH] [SYCL] Add asan AOT libdevice for different GPU/CPU (#15939) Device address sanitizer libraries can be optimized in AOT compilation mode, some redundant code checking which device current kernel is running on can be removed. This PR creates corresponding AOT address sanitizer device libraries for CPU, PVC, DG2 target and link them according to real AOT target. This PR also renames previous libsycl-sanitizer to libsycl-asan since current device sanitizer only supports address sanitizer and memory sanitizer will be added in the future. --------- Signed-off-by: jinge90 --- clang/lib/Driver/ToolChains/SYCL.cpp | 233 ++++++++++++------ ...bsycl-sanitizer.bc => libsycl-asan-cpu.bc} | 0 ...libsycl-sanitizer.o => libsycl-asan-cpu.o} | 0 .../Inputs/SYCL/lib/libsycl-asan-dg2.bc | 0 .../Driver/Inputs/SYCL/lib/libsycl-asan-dg2.o | 0 .../Inputs/SYCL/lib/libsycl-asan-pvc.bc | 0 .../Driver/Inputs/SYCL/lib/libsycl-asan-pvc.o | 0 .../Driver/Inputs/SYCL/lib/libsycl-asan.bc | 0 .../Driver/Inputs/SYCL/lib/libsycl-asan.o | 0 .../test/Driver/sycl-device-lib-old-model.cpp | 92 ++++++- clang/test/Driver/sycl-device-lib.cpp | 132 +++++++++- libdevice/cmake/modules/SYCLLibdevice.cmake | 74 +++++- libdevice/sanitizer_utils.cpp | 8 + sycl/test-e2e/Config/kernel_from_file.cpp | 6 +- 14 files changed, 460 insertions(+), 85 deletions(-) rename clang/test/Driver/Inputs/SYCL/lib/{libsycl-sanitizer.bc => libsycl-asan-cpu.bc} (100%) rename clang/test/Driver/Inputs/SYCL/lib/{libsycl-sanitizer.o => libsycl-asan-cpu.o} (100%) create mode 100644 clang/test/Driver/Inputs/SYCL/lib/libsycl-asan-dg2.bc create mode 100644 clang/test/Driver/Inputs/SYCL/lib/libsycl-asan-dg2.o create mode 100644 clang/test/Driver/Inputs/SYCL/lib/libsycl-asan-pvc.bc create mode 100644 clang/test/Driver/Inputs/SYCL/lib/libsycl-asan-pvc.o create mode 100644 clang/test/Driver/Inputs/SYCL/lib/libsycl-asan.bc create mode 100644 clang/test/Driver/Inputs/SYCL/lib/libsycl-asan.o diff --git a/clang/lib/Driver/ToolChains/SYCL.cpp b/clang/lib/Driver/ToolChains/SYCL.cpp index 6435618ae7f6a..7e8067f5ec2e4 100644 --- a/clang/lib/Driver/ToolChains/SYCL.cpp +++ b/clang/lib/Driver/ToolChains/SYCL.cpp @@ -345,6 +345,84 @@ static bool selectBfloatLibs(const llvm::Triple &Triple, const Compilation &C, return NeedLibs; } +struct OclocInfo { + const char *DeviceName; + const char *PackageName; + const char *Version; + SmallVector HexValues; +}; + +// The PVCDevices data structure is organized by device name, with the +// corresponding ocloc split release, version and possible Hex representations +// of various PVC devices. This information is gathered from the following: +// https://github.com/intel/compute-runtime/blob/master/shared/source/dll/devices/devices_base.inl +// https://github.com/intel/compute-runtime/blob/master/shared/source/dll/devices/devices_additional.inl +static OclocInfo PVCDevices[] = { + {"pvc-sdv", "gen12+", "12.60.1", {}}, + {"pvc", + "gen12+", + "12.60.7", + {0x0BD0, 0x0BD5, 0x0BD6, 0x0BD7, 0x0BD8, 0x0BD9, 0x0BDA, 0x0BDB}}}; + +static std::string getDeviceArg(const ArgStringList &CmdArgs) { + bool DeviceSeen = false; + std::string DeviceArg; + for (StringRef Arg : CmdArgs) { + // -device comes in as a single arg, split up all potential space + // separated values. + SmallVector SplitArgs; + Arg.split(SplitArgs, ' '); + for (StringRef SplitArg : SplitArgs) { + if (DeviceSeen) { + DeviceArg = SplitArg.str(); + break; + } + if (SplitArg == "-device") + DeviceSeen = true; + } + if (DeviceSeen) + break; + } + + return DeviceArg; +} + +static bool checkPVCDevice(std::string SingleArg, std::string &DevArg) { + // Handle shortened versions. + bool CheckShortVersion = true; + for (auto Char : SingleArg) { + if (!std::isdigit(Char) && Char != '.') { + CheckShortVersion = false; + break; + } + } + // Check for device, version or hex (literal values) + for (unsigned int I = 0; I < std::size(PVCDevices); I++) { + if (StringRef(SingleArg).equals_insensitive(PVCDevices[I].DeviceName) || + StringRef(SingleArg).equals_insensitive(PVCDevices[I].Version)) { + DevArg = SingleArg; + return true; + } + + for (int HexVal : PVCDevices[I].HexValues) { + int Value = 0; + if (!StringRef(SingleArg).getAsInteger(0, Value) && Value == HexVal) { + // TODO: Pass back the hex string to use for -device_options when + // IGC is updated to allow. Currently -device_options only accepts + // the device ID (i.e. pvc) or the version (12.60.7). + return true; + } + } + if (CheckShortVersion && + StringRef(PVCDevices[I].Version).starts_with(SingleArg)) { + DevArg = SingleArg; + return true; + } + } + + return false; +} + SmallVector SYCL::getDeviceLibraries(const Compilation &C, const llvm::Triple &TargetTriple, bool IsSpirvAOT) { @@ -360,6 +438,8 @@ SYCL::getDeviceLibraries(const Compilation &C, const llvm::Triple &TargetTriple, StringRef DeviceLibOption; }; + enum { JIT = 0, AOT_CPU, AOT_DG2, AOT_PVC }; + // Currently, all SYCL device libraries will be linked by default. llvm::StringMap DeviceLibLinkInfo = { {"libc", true}, {"libm-fp32", true}, {"libm-fp64", true}, @@ -460,8 +540,11 @@ SYCL::getDeviceLibraries(const Compilation &C, const llvm::Triple &TargetTriple, {"libsycl-itt-compiler-wrappers", "internal"}, {"libsycl-itt-stubs", "internal"}}; #if !defined(_WIN32) - const SYCLDeviceLibsList SYCLDeviceSanitizerLibs = { - {"libsycl-sanitizer", "internal"}}; + const SYCLDeviceLibsList SYCLDeviceAsanLibs = { + {"libsycl-asan", "internal"}, + {"libsycl-asan-cpu", "internal"}, + {"libsycl-asan-dg2", "internal"}, + {"libsycl-asan-pvc", "internal"}}; #endif const SYCLDeviceLibsList SYCLNativeCpuDeviceLibs = { @@ -493,6 +576,66 @@ SYCL::getDeviceLibraries(const Compilation &C, const llvm::Triple &TargetTriple, } }; + auto addSingleLibrary = [&](const DeviceLibOptInfo &Lib) { + if (!DeviceLibLinkInfo[Lib.DeviceLibOption]) + return; + SmallString<128> LibName(Lib.DeviceLibName); + llvm::sys::path::replace_extension(LibName, LibSuffix); + LibraryList.push_back(Args.MakeArgString(LibName)); + }; + + // This function is used to check whether there is only one GPU device + // (PVC or DG2) specified in AOT compilation mode. If yes, we can use + // corresponding libsycl-asan-* to improve device sanitizer performance, + // otherwise stick to fallback device sanitizer library used in JIT mode. + auto getSpecificGPUTarget = [](const ArgStringList &CmdArgs) -> size_t { + std::string DeviceArg = getDeviceArg(CmdArgs); + if ((DeviceArg.empty()) || (DeviceArg.find(",") != std::string::npos)) + return JIT; + + std::string Temp; + if (checkPVCDevice(DeviceArg, Temp)) + return AOT_PVC; + + if (DeviceArg == "dg2") + return AOT_DG2; + + return JIT; + }; + + auto getSingleBuildTarget = [&]() -> size_t { + if (!IsSpirvAOT) + return JIT; + + llvm::opt::Arg *SYCLTarget = Args.getLastArg(options::OPT_fsycl_targets_EQ); + if (!SYCLTarget || (SYCLTarget->getValues().size() != 1)) + return JIT; + + StringRef SYCLTargetStr = SYCLTarget->getValue(); + if (SYCLTargetStr.starts_with("spir64_x86_64")) + return AOT_CPU; + + if (SYCLTargetStr == "intel_gpu_pvc") + return AOT_PVC; + + if (SYCLTargetStr.starts_with("intel_gpu_dg2")) + return AOT_DG2; + + if (SYCLTargetStr.starts_with("spir64_gen")) { + ArgStringList TargArgs; + Args.AddAllArgValues(TargArgs, options::OPT_Xs, options::OPT_Xs_separate); + Args.AddAllArgValues(TargArgs, options::OPT_Xsycl_backend); + llvm::opt::Arg *A = nullptr; + if ((A = Args.getLastArg(options::OPT_Xsycl_backend_EQ)) && + StringRef(A->getValue()).starts_with("spir64_gen")) + TargArgs.push_back(A->getValue(1)); + + return getSpecificGPUTarget(TargArgs); + } + + return JIT; + }; + addLibraries(SYCLDeviceWrapperLibs); if (IsSpirvAOT) addLibraries(SYCLDeviceFallbackLibs); @@ -512,13 +655,14 @@ SYCL::getDeviceLibraries(const Compilation &C, const llvm::Triple &TargetTriple, addLibraries(SYCLDeviceAnnotationLibs); #if !defined(_WIN32) + size_t sanitizer_lib_idx = getSingleBuildTarget(); if (Arg *A = Args.getLastArg(options::OPT_fsanitize_EQ, options::OPT_fno_sanitize_EQ)) { if (A->getOption().matches(options::OPT_fsanitize_EQ) && A->getValues().size() == 1) { std::string SanitizeVal = A->getValue(); if (SanitizeVal == "address") - addLibraries(SYCLDeviceSanitizerLibs); + addSingleLibrary(SYCLDeviceAsanLibs[sanitizer_lib_idx]); } } else { // User can pass -fsanitize=address to device compiler via @@ -546,7 +690,7 @@ SYCL::getDeviceLibraries(const Compilation &C, const llvm::Triple &TargetTriple, } if (IsDeviceAsanEnabled) - addLibraries(SYCLDeviceSanitizerLibs); + addSingleLibrary(SYCLDeviceAsanLibs[sanitizer_lib_idx]); } #endif @@ -663,7 +807,10 @@ static llvm::SmallVector SYCLDeviceLibList{ #if defined(_WIN32) "msvc-math", #else - "sanitizer", + "asan", + "asan-pvc", + "asan-cpu", + "asan-dg2", #endif "imf", "imf-fp64", @@ -1131,87 +1278,23 @@ void SYCL::fpga::BackendCompiler::ConstructJob( C.addCommand(std::move(Cmd)); } -struct OclocInfo { - const char *DeviceName; - const char *PackageName; - const char *Version; - SmallVector HexValues; -}; - -// The PVCDevices data structure is organized by device name, with the -// corresponding ocloc split release, version and possible Hex representations -// of various PVC devices. This information is gathered from the following: -// https://github.com/intel/compute-runtime/blob/master/shared/source/dll/devices/devices_base.inl -// https://github.com/intel/compute-runtime/blob/master/shared/source/dll/devices/devices_additional.inl -static OclocInfo PVCDevices[] = { - {"pvc-sdv", "gen12+", "12.60.1", {}}, - {"pvc", - "gen12+", - "12.60.7", - {0x0BD0, 0x0BD5, 0x0BD6, 0x0BD7, 0x0BD8, 0x0BD9, 0x0BDA, 0x0BDB}}}; - // Determine if any of the given arguments contain any PVC based values for // the -device option. static bool hasPVCDevice(const ArgStringList &CmdArgs, std::string &DevArg) { - bool DeviceSeen = false; - StringRef DeviceArg; - for (StringRef Arg : CmdArgs) { - // -device comes in as a single arg, split up all potential space - // separated values. - SmallVector SplitArgs; - Arg.split(SplitArgs, ' '); - for (StringRef SplitArg : SplitArgs) { - if (DeviceSeen) { - DeviceArg = SplitArg; - break; - } - if (SplitArg == "-device") - DeviceSeen = true; - } - if (DeviceSeen) - break; - } - if (DeviceArg.empty()) + std::string Res = getDeviceArg(CmdArgs); + if (Res.empty()) return false; - // Go through all of the arguments to '-device' and determine if any of these // are pvc based. We only match literal values and will not find a match // when ranges or wildcards are used. // Here we parse the targets, tokenizing via ',' + StringRef DeviceArg(Res.c_str()); SmallVector SplitArgs; DeviceArg.split(SplitArgs, ","); for (const auto &SingleArg : SplitArgs) { - StringRef OclocTarget; - // Handle shortened versions. - bool CheckShortVersion = true; - for (auto Char : SingleArg.str()) { - if (!std::isdigit(Char) && Char != '.') { - CheckShortVersion = false; - break; - } - } - // Check for device, version or hex (literal values) - for (unsigned int I = 0; I < std::size(PVCDevices); I++) { - if (SingleArg.equals_insensitive(PVCDevices[I].DeviceName) || - SingleArg.equals_insensitive(PVCDevices[I].Version)) { - DevArg = SingleArg.str(); - return true; - } - for (int HexVal : PVCDevices[I].HexValues) { - int Value = 0; - if (!SingleArg.getAsInteger(0, Value) && Value == HexVal) { - // TODO: Pass back the hex string to use for -device_options when - // IGC is updated to allow. Currently -device_options only accepts - // the device ID (i.e. pvc) or the version (12.60.7). - return true; - } - } - if (CheckShortVersion && - StringRef(PVCDevices[I].Version).starts_with(SingleArg)) { - DevArg = SingleArg.str(); - return true; - } - } + bool IsPVC = checkPVCDevice(SingleArg.str(), DevArg); + if (IsPVC) + return true; } return false; } diff --git a/clang/test/Driver/Inputs/SYCL/lib/libsycl-sanitizer.bc b/clang/test/Driver/Inputs/SYCL/lib/libsycl-asan-cpu.bc similarity index 100% rename from clang/test/Driver/Inputs/SYCL/lib/libsycl-sanitizer.bc rename to clang/test/Driver/Inputs/SYCL/lib/libsycl-asan-cpu.bc diff --git a/clang/test/Driver/Inputs/SYCL/lib/libsycl-sanitizer.o b/clang/test/Driver/Inputs/SYCL/lib/libsycl-asan-cpu.o similarity index 100% rename from clang/test/Driver/Inputs/SYCL/lib/libsycl-sanitizer.o rename to clang/test/Driver/Inputs/SYCL/lib/libsycl-asan-cpu.o diff --git a/clang/test/Driver/Inputs/SYCL/lib/libsycl-asan-dg2.bc b/clang/test/Driver/Inputs/SYCL/lib/libsycl-asan-dg2.bc new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/clang/test/Driver/Inputs/SYCL/lib/libsycl-asan-dg2.o b/clang/test/Driver/Inputs/SYCL/lib/libsycl-asan-dg2.o new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/clang/test/Driver/Inputs/SYCL/lib/libsycl-asan-pvc.bc b/clang/test/Driver/Inputs/SYCL/lib/libsycl-asan-pvc.bc new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/clang/test/Driver/Inputs/SYCL/lib/libsycl-asan-pvc.o b/clang/test/Driver/Inputs/SYCL/lib/libsycl-asan-pvc.o new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/clang/test/Driver/Inputs/SYCL/lib/libsycl-asan.bc b/clang/test/Driver/Inputs/SYCL/lib/libsycl-asan.bc new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/clang/test/Driver/Inputs/SYCL/lib/libsycl-asan.o b/clang/test/Driver/Inputs/SYCL/lib/libsycl-asan.o new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/clang/test/Driver/sycl-device-lib-old-model.cpp b/clang/test/Driver/sycl-device-lib-old-model.cpp index cd3597ad20d74..ab8f900f6710d 100644 --- a/clang/test/Driver/sycl-device-lib-old-model.cpp +++ b/clang/test/Driver/sycl-device-lib-old-model.cpp @@ -196,7 +196,7 @@ // SYCL_LLVM_LINK_USER_ONLY_NEEDED: llvm-link{{.*}} "-only-needed" "{{.*}}" "-o" "{{.*}}.bc" "--suppress-warnings" /// ########################################################################### -/// test behavior of libsycl-sanitizer.o linking when -fsanitize=address is available +/// test behavior of libsycl-asan.bc linking when -fsanitize=address is available // RUN: %clangxx -fsycl --no-offload-new-driver %s --sysroot=%S/Inputs/SYCL -fsanitize=address -### 2>&1 \ // RUN: | FileCheck %s -check-prefix=SYCL_DEVICE_LIB_SANITIZER // RUN: %clangxx -fsycl --no-offload-new-driver %s --sysroot=%S/Inputs/SYCL -Xsycl-target-frontend -fsanitize=address -### 2>&1 \ @@ -226,8 +226,94 @@ // SYCL_DEVICE_LIB_SANITIZER-SAME: "{{.*}}libsycl-fallback-imf.bc" // SYCL_DEVICE_LIB_SANITIZER-SAME: "{{.*}}libsycl-fallback-imf-fp64.bc" // SYCL_DEVICE_LIB_SANITIZER-SAME: "{{.*}}libsycl-fallback-imf-bf16.bc" -// SYCL_DEVICE_LIB_SANITIZER-SAME: "{{.*}}libsycl-sanitizer.bc" +// SYCL_DEVICE_LIB_SANITIZER-SAME: "{{.*}}libsycl-asan.bc" // SYCL_DEVICE_ASAN_MACRO: "-cc1" // SYCL_DEVICE_ASAN_MACRO-SAME: "USE_SYCL_DEVICE_ASAN" // SYCL_DEVICE_ASAN_MACRO: llvm-link{{.*}} "-only-needed" -// SYCL_DEVICE_ASAN_MACRO-SAME: "{{.*}}libsycl-sanitizer.bc" +// SYCL_DEVICE_ASAN_MACRO-SAME: "{{.*}}libsycl-asan.bc" + +/// ########################################################################### +/// test behavior of linking libsycl-asan-pvc for PVC target AOT compilation when asan flag is applied. +// RUN: %clangxx -fsycl -fsycl-targets=intel_gpu_pvc --no-offload-new-driver %s --sysroot=%S/Inputs/SYCL \ +// RUN: -Xarch_device -fsanitize=address -### 2>&1 | FileCheck %s -check-prefix=SYCL_DEVICE_LIB_ASAN_PVC +// RUN: %clangxx -fsycl -fsycl-targets=spir64_gen -Xsycl-target-backend "-device pvc" --no-offload-new-driver %s \ +// RUN: --sysroot=%S/Inputs/SYCL -Xarch_device -fsanitize=address -### 2>&1 | FileCheck %s -check-prefix=SYCL_DEVICE_LIB_ASAN_PVC +// RUN: %clangxx -fsycl -fsycl-targets=spir64_gen -Xsycl-target-backend=spir64_gen "-device pvc" --no-offload-new-driver %s \ +// RUN: --sysroot=%S/Inputs/SYCL -Xarch_device -fsanitize=address -### 2>&1 | FileCheck %s -check-prefix=SYCL_DEVICE_LIB_ASAN_PVC +// RUN: %clangxx -fsycl -fsycl-targets=spir64_gen -Xsycl-target-backend "-device 12.60.7" --no-offload-new-driver %s \ +// RUN: --sysroot=%S/Inputs/SYCL -Xarch_device -fsanitize=address -### 2>&1 | FileCheck %s -check-prefix=SYCL_DEVICE_LIB_ASAN_PVC +// RUN: %clangxx -fsycl -fsycl-targets=spir64_gen -Xs "-device 12.60.7" --no-offload-new-driver %s --sysroot=%S/Inputs/SYCL \ +// RUN: -Xarch_device -fsanitize=address -### 2>&1 | FileCheck %s -check-prefix=SYCL_DEVICE_LIB_ASAN_PVC +// SYCL_DEVICE_LIB_ASAN_PVC: llvm-link{{.*}} "{{.*}}libsycl-crt.bc" +// SYCL_DEVICE_LIB_ASAN_PVC-SAME: "{{.*}}libsycl-complex.bc" +// SYCL_DEVICE_LIB_ASAN_PVC-SAME: "{{.*}}libsycl-complex-fp64.bc" +// SYCL_DEVICE_LIB_ASAN_PVC-SAME: "{{.*}}libsycl-cmath.bc" +// SYCL_DEVICE_LIB_ASAN_PVC-SAME: "{{.*}}libsycl-cmath-fp64.bc" +// SYCL_DEVICE_LIB_ASAN_PVC-SAME: "{{.*}}libsycl-imf.bc" +// SYCL_DEVICE_LIB_ASAN_PVC-SAME: "{{.*}}libsycl-imf-fp64.bc" +// SYCL_DEVICE_LIB_ASAN_PVC-SAME: "{{.*}}libsycl-imf-bf16.bc" +// SYCL_DEVICE_LIB_ASAN_PVC-SAME: "{{.*}}libsycl-fallback-cassert.bc" +// SYCL_DEVICE_LIB_ASAN_PVC-SAME: "{{.*}}libsycl-fallback-cstring.bc" +// SYCL_DEVICE_LIB_ASAN_PVC-SAME: "{{.*}}libsycl-fallback-complex.bc" +// SYCL_DEVICE_LIB_ASAN_PVC-SAME: "{{.*}}libsycl-fallback-complex-fp64.bc" +// SYCL_DEVICE_LIB_ASAN_PVC-SAME: "{{.*}}libsycl-fallback-cmath.bc" +// SYCL_DEVICE_LIB_ASAN_PVC-SAME: "{{.*}}libsycl-fallback-cmath-fp64.bc" +// SYCL_DEVICE_LIB_ASAN_PVC-SAME: "{{.*}}libsycl-fallback-imf.bc" +// SYCL_DEVICE_LIB_ASAN_PVC-SAME: "{{.*}}libsycl-fallback-imf-fp64.bc" +// SYCL_DEVICE_LIB_ASAN_PVC-SAME: "{{.*}}libsycl-fallback-imf-bf16.bc" +// SYCL_DEVICE_LIB_ASAN_PVC-SAME: "{{.*}}libsycl-asan-pvc.bc" + +/// ########################################################################### +/// test behavior of linking libsycl-asan-cpu for CPU target AOT compilation when asan flag is applied. +// RUN: %clangxx -fsycl -fsycl-targets=spir64_x86_64 --no-offload-new-driver %s --sysroot=%S/Inputs/SYCL \ +// RUN: -Xarch_device -fsanitize=address -### 2>&1 | FileCheck %s -check-prefix=SYCL_DEVICE_LIB_ASAN_CPU +// SYCL_DEVICE_LIB_ASAN_CPU: llvm-link{{.*}} "{{.*}}libsycl-crt.bc" +// SYCL_DEVICE_LIB_ASAN_CPU-SAME: "{{.*}}libsycl-complex.bc" +// SYCL_DEVICE_LIB_ASAN_CPU-SAME: "{{.*}}libsycl-complex-fp64.bc" +// SYCL_DEVICE_LIB_ASAN_CPU-SAME: "{{.*}}libsycl-cmath.bc" +// SYCL_DEVICE_LIB_ASAN_CPU-SAME: "{{.*}}libsycl-cmath-fp64.bc" +// SYCL_DEVICE_LIB_ASAN_CPU-SAME: "{{.*}}libsycl-imf.bc" +// SYCL_DEVICE_LIB_ASAN_CPU-SAME: "{{.*}}libsycl-imf-fp64.bc" +// SYCL_DEVICE_LIB_ASAN_CPU-SAME: "{{.*}}libsycl-imf-bf16.bc" +// SYCL_DEVICE_LIB_ASAN_CPU-SAME: "{{.*}}libsycl-fallback-cassert.bc" +// SYCL_DEVICE_LIB_ASAN_CPU-SAME: "{{.*}}libsycl-fallback-cstring.bc" +// SYCL_DEVICE_LIB_ASAN_CPU-SAME: "{{.*}}libsycl-fallback-complex.bc" +// SYCL_DEVICE_LIB_ASAN_CPU-SAME: "{{.*}}libsycl-fallback-complex-fp64.bc" +// SYCL_DEVICE_LIB_ASAN_CPU-SAME: "{{.*}}libsycl-fallback-cmath.bc" +// SYCL_DEVICE_LIB_ASAN_CPU-SAME: "{{.*}}libsycl-fallback-cmath-fp64.bc" +// SYCL_DEVICE_LIB_ASAN_CPU-SAME: "{{.*}}libsycl-fallback-imf.bc" +// SYCL_DEVICE_LIB_ASAN_CPU-SAME: "{{.*}}libsycl-fallback-imf-fp64.bc" +// SYCL_DEVICE_LIB_ASAN_CPU-SAME: "{{.*}}libsycl-fallback-imf-bf16.bc" +// SYCL_DEVICE_LIB_ASAN_CPU-SAME: "{{.*}}libsycl-asan-cpu.bc" + +/// ########################################################################### +/// test behavior of linking libsycl-asan-dg2 for DG2 target AOT compilation when asan flag is applied. +// RUN: %clangxx -fsycl -fsycl-targets=intel_gpu_dg2_g10 --no-offload-new-driver %s --sysroot=%S/Inputs/SYCL \ +// RUN: -Xarch_device -fsanitize=address -### 2>&1 | FileCheck %s -check-prefix=SYCL_DEVICE_LIB_ASAN_DG2 +// RUN: %clangxx -fsycl -fsycl-targets=spir64_gen -Xsycl-target-backend "-device dg2" --no-offload-new-driver %s \ +// RUN: --sysroot=%S/Inputs/SYCL -Xarch_device -fsanitize=address -### 2>&1 \ +// RUN: | FileCheck %s -check-prefix=SYCL_DEVICE_LIB_ASAN_DG2 +// RUN: %clangxx -fsycl -fsycl-targets=spir64_gen -Xsycl-target-backend=spir64_gen "-device dg2" --no-offload-new-driver %s \ +// RUN: --sysroot=%S/Inputs/SYCL -Xarch_device -fsanitize=address -### 2>&1 \ +// RUN: | FileCheck %s -check-prefix=SYCL_DEVICE_LIB_ASAN_DG2 +// RUN: %clangxx -fsycl -fsycl-targets=spir64_gen -Xs "-device dg2" --no-offload-new-driver %s \ +// RUN: --sysroot=%S/Inputs/SYCL -Xarch_device -fsanitize=address -### 2>&1 \ +// RUN: | FileCheck %s -check-prefix=SYCL_DEVICE_LIB_ASAN_DG2 +// SYCL_DEVICE_LIB_ASAN_DG2: llvm-link{{.*}} "{{.*}}libsycl-crt.bc" +// SYCL_DEVICE_LIB_ASAN_DG2-SAME: "{{.*}}libsycl-complex.bc" +// SYCL_DEVICE_LIB_ASAN_DG2-SAME: "{{.*}}libsycl-complex-fp64.bc" +// SYCL_DEVICE_LIB_ASAN_DG2-SAME: "{{.*}}libsycl-cmath.bc" +// SYCL_DEVICE_LIB_ASAN_DG2-SAME: "{{.*}}libsycl-cmath-fp64.bc" +// SYCL_DEVICE_LIB_ASAN_DG2-SAME: "{{.*}}libsycl-imf.bc" +// SYCL_DEVICE_LIB_ASAN_DG2-SAME: "{{.*}}libsycl-imf-fp64.bc" +// SYCL_DEVICE_LIB_ASAN_DG2-SAME: "{{.*}}libsycl-imf-bf16.bc" +// SYCL_DEVICE_LIB_ASAN_DG2-SAME: "{{.*}}libsycl-fallback-cassert.bc" +// SYCL_DEVICE_LIB_ASAN_DG2-SAME: "{{.*}}libsycl-fallback-cstring.bc" +// SYCL_DEVICE_LIB_ASAN_DG2-SAME: "{{.*}}libsycl-fallback-complex.bc" +// SYCL_DEVICE_LIB_ASAN_DG2-SAME: "{{.*}}libsycl-fallback-complex-fp64.bc" +// SYCL_DEVICE_LIB_ASAN_DG2-SAME: "{{.*}}libsycl-fallback-cmath.bc" +// SYCL_DEVICE_LIB_ASAN_DG2-SAME: "{{.*}}libsycl-fallback-cmath-fp64.bc" +// SYCL_DEVICE_LIB_ASAN_DG2-SAME: "{{.*}}libsycl-fallback-imf.bc" +// SYCL_DEVICE_LIB_ASAN_DG2-SAME: "{{.*}}libsycl-fallback-imf-fp64.bc" +// SYCL_DEVICE_LIB_ASAN_DG2-SAME: "{{.*}}libsycl-fallback-imf-bf16.bc" +// SYCL_DEVICE_LIB_ASAN_DG2-SAME: "{{.*}}libsycl-asan-dg2.bc" diff --git a/clang/test/Driver/sycl-device-lib.cpp b/clang/test/Driver/sycl-device-lib.cpp index 197f7fc5e46d9..e84eaadc5405a 100644 --- a/clang/test/Driver/sycl-device-lib.cpp +++ b/clang/test/Driver/sycl-device-lib.cpp @@ -153,7 +153,7 @@ // SYCL_NO_DEVICE_LIB_INVALID_VALUE: error: unsupported argument '[[Val]]' to option '-fno-sycl-device-lib=' /// ########################################################################### -/// test behavior of libsycl-sanitizer.o linking when -fsanitize=address is available +/// test behavior of libsycl-asan.o linking when -fsanitize=address is available // RUN: %clangxx -fsycl --offload-new-driver %s --sysroot=%S/Inputs/SYCL -fsanitize=address -### 2>&1 \ // RUN: | FileCheck %s -check-prefix=SYCL_DEVICE_LIB_SANITIZER // RUN: %clangxx -fsycl --offload-new-driver %s --sysroot=%S/Inputs/SYCL -Xsycl-target-frontend -fsanitize=address -### 2>&1 \ @@ -184,7 +184,133 @@ // SYCL_DEVICE_LIB_SANITIZER-SAME: {{.*}}libsycl-fallback-imf.new.o // SYCL_DEVICE_LIB_SANITIZER-SAME: {{.*}}libsycl-fallback-imf-fp64.new.o // SYCL_DEVICE_LIB_SANITIZER-SAME: {{.*}}libsycl-fallback-imf-bf16.new.o -// SYCL_DEVICE_LIB_SANITIZER-SAME: {{.*}}libsycl-sanitizer.new.o +// SYCL_DEVICE_LIB_SANITIZER-SAME: {{.*}}libsycl-asan.new.o // SYCL_DEVICE_ASAN_MACRO: "-cc1" // SYCL_DEVICE_ASAN_MACRO-SAME: "USE_SYCL_DEVICE_ASAN" -// SYCL_DEVICE_ASAN_MACRO: libsycl-sanitizer.new.o +// SYCL_DEVICE_ASAN_MACRO: libsycl-asan.new.o + + +/// ########################################################################### +/// test behavior of linking libsycl-asan-pvc for PVC target AOT compilation when asan flag is applied. +// RUN: %clangxx -fsycl -fsycl-targets=intel_gpu_pvc --offload-new-driver %s --sysroot=%S/Inputs/SYCL \ +// RUN: -Xarch_device -fsanitize=address -### 2>&1 | FileCheck %s -check-prefix=SYCL_DEVICE_LIB_ASAN_PVC +// RUN: %clangxx -fsycl -fsycl-targets=spir64_gen --offload-new-driver %s --sysroot=%S/Inputs/SYCL \ +// RUN: -Xarch_device -fsanitize=address -Xsycl-target-backend "-device pvc" -### 2>&1 \ +// RUN: | FileCheck %s -check-prefix=SYCL_DEVICE_LIB_ASAN_PVC +// RUN: %clangxx -fsycl -fsycl-targets=spir64_gen --offload-new-driver %s --sysroot=%S/Inputs/SYCL \ +// RUN: -Xarch_device -fsanitize=address -Xsycl-target-backend=spir64_gen "-device pvc" -### 2>&1 \ +// RUN: | FileCheck %s -check-prefix=SYCL_DEVICE_LIB_ASAN_PVC +// RUN: %clangxx -fsycl -fsycl-targets=spir64_gen --offload-new-driver %s --sysroot=%S/Inputs/SYCL \ +// RUN: -Xarch_device -fsanitize=address -Xsycl-target-backend "-device 12.60.7" -### 2>&1 \ +// RUN: | FileCheck %s -check-prefix=SYCL_DEVICE_LIB_ASAN_PVC +// RUN: %clangxx -fsycl -fsycl-targets=spir64_gen --offload-new-driver %s --sysroot=%S/Inputs/SYCL \ +// RUN: -Xarch_device -fsanitize=address -Xs "-device pvc" -### 2>&1 \ +// RUN: | FileCheck %s -check-prefix=SYCL_DEVICE_LIB_ASAN_PVC +// RUN: %clangxx -fsycl -fsycl-targets=spir64_gen --offload-new-driver %s --sysroot=%S/Inputs/SYCL \ +// RUN: -Xarch_device -fsanitize=address -Xs "-device 12.60.7" -### 2>&1 \ +// RUN: | FileCheck %s -check-prefix=SYCL_DEVICE_LIB_ASAN_PVC +// SYCL_DEVICE_LIB_ASAN_PVC: clang-linker-wrapper{{.*}} "-sycl-device-libraries +// SYCL_DEVICE_LIB_ASAN_PVC: {{.*}}libsycl-crt.new.o +// SYCL_DEVICE_LIB_ASAN_PVC-SAME: {{.*}}libsycl-complex. +// SYCL_DEVICE_LIB_ASAN_PVC-SAME: {{.*}}libsycl-complex-fp64. +// SYCL_DEVICE_LIB_ASAN_PVC-SAME: {{.*}}libsycl-cmath.new.o +// SYCL_DEVICE_LIB_ASAN_PVC-SAME: {{.*}}libsycl-cmath-fp64.new.o +// SYCL_DEVICE_LIB_ASAN_PVC-SAME: {{.*}}libsycl-imf.new.o +// SYCL_DEVICE_LIB_ASAN_PVC-SAME: {{.*}}libsycl-imf-fp64.new.o +// SYCL_DEVICE_LIB_ASAN_PVC-SAME: {{.*}}libsycl-imf-bf16.new.o +// SYCL_DEVICE_LIB_ASAN_PVC-SAME: {{.*}}libsycl-fallback-cassert.new.o +// SYCL_DEVICE_LIB_ASAN_PVC-SAME: {{.*}}libsycl-fallback-cstring.new.o +// SYCL_DEVICE_LIB_ASAN_PVC-SAME: {{.*}}libsycl-fallback-complex.new.o +// SYCL_DEVICE_LIB_ASAN_PVC-SAME: {{.*}}libsycl-fallback-complex-fp64.new.o +// SYCL_DEVICE_LIB_ASAN_PVC-SAME: {{.*}}libsycl-fallback-cmath.new.o +// SYCL_DEVICE_LIB_ASAN_PVC-SAME: {{.*}}libsycl-fallback-cmath-fp64.new.o +// SYCL_DEVICE_LIB_ASAN_PVC-SAME: {{.*}}libsycl-fallback-imf.new.o +// SYCL_DEVICE_LIB_ASAN_PVC-SAME: {{.*}}libsycl-fallback-imf-fp64.new.o +// SYCL_DEVICE_LIB_ASAN_PVC-SAME: {{.*}}libsycl-fallback-imf-bf16.new.o +// SYCL_DEVICE_LIB_ASAN_PVC-SAME: {{.*}}libsycl-asan-pvc.new.o + +/// ########################################################################### +/// test behavior of linking libsycl-asan-cpu for CPU target AOT compilation when asan flag is applied. +// RUN: %clangxx -fsycl -fsycl-targets=spir64_x86_64 --offload-new-driver %s --sysroot=%S/Inputs/SYCL \ +// RUN: -Xarch_device -fsanitize=address -### 2>&1 | FileCheck %s -check-prefix=SYCL_DEVICE_LIB_ASAN_CPU +// SYCL_DEVICE_LIB_ASAN_CPU: clang-linker-wrapper{{.*}} "-sycl-device-libraries +// SYCL_DEVICE_LIB_ASAN_CPU: {{.*}}libsycl-crt.new.o +// SYCL_DEVICE_LIB_ASAN_CPU-SAME: {{.*}}libsycl-complex. +// SYCL_DEVICE_LIB_ASAN_CPU-SAME: {{.*}}libsycl-complex-fp64. +// SYCL_DEVICE_LIB_ASAN_CPU-SAME: {{.*}}libsycl-cmath.new.o +// SYCL_DEVICE_LIB_ASAN_CPU-SAME: {{.*}}libsycl-cmath-fp64.new.o +// SYCL_DEVICE_LIB_ASAN_CPU-SAME: {{.*}}libsycl-imf.new.o +// SYCL_DEVICE_LIB_ASAN_CPU-SAME: {{.*}}libsycl-imf-fp64.new.o +// SYCL_DEVICE_LIB_ASAN_CPU-SAME: {{.*}}libsycl-imf-bf16.new.o +// SYCL_DEVICE_LIB_ASAN_CPU-SAME: {{.*}}libsycl-fallback-cassert.new.o +// SYCL_DEVICE_LIB_ASAN_CPU-SAME: {{.*}}libsycl-fallback-cstring.new.o +// SYCL_DEVICE_LIB_ASAN_CPU-SAME: {{.*}}libsycl-fallback-complex.new.o +// SYCL_DEVICE_LIB_ASAN_CPU-SAME: {{.*}}libsycl-fallback-complex-fp64.new.o +// SYCL_DEVICE_LIB_ASAN_CPU-SAME: {{.*}}libsycl-fallback-cmath.new.o +// SYCL_DEVICE_LIB_ASAN_CPU-SAME: {{.*}}libsycl-fallback-cmath-fp64.new.o +// SYCL_DEVICE_LIB_ASAN_CPU-SAME: {{.*}}libsycl-fallback-imf.new.o +// SYCL_DEVICE_LIB_ASAN_CPU-SAME: {{.*}}libsycl-fallback-imf-fp64.new.o +// SYCL_DEVICE_LIB_ASAN_CPU-SAME: {{.*}}libsycl-fallback-imf-bf16.new.o +// SYCL_DEVICE_LIB_ASAN_CPU-SAME: {{.*}}libsycl-asan-cpu.new.o + +/// ########################################################################### +/// test behavior of linking libsycl-asan-dg2 for DG2 target AOT compilation when asan flag is applied. +// RUN: %clangxx -fsycl -fsycl-targets=intel_gpu_dg2_g10 --offload-new-driver %s --sysroot=%S/Inputs/SYCL \ +// RUN: -Xarch_device -fsanitize=address -### 2>&1 | FileCheck %s -check-prefix=SYCL_DEVICE_LIB_ASAN_DG2 +// RUN: %clangxx -fsycl -fsycl-targets=spir64_gen --offload-new-driver %s --sysroot=%S/Inputs/SYCL \ +// RUN: -Xarch_device -fsanitize=address -Xsycl-target-backend "-device dg2" -### 2>&1 \ +// RUN: | FileCheck %s -check-prefix=SYCL_DEVICE_LIB_ASAN_DG2 +// RUN: %clangxx -fsycl -fsycl-targets=spir64_gen --offload-new-driver %s --sysroot=%S/Inputs/SYCL \ +// RUN: -Xarch_device -fsanitize=address -Xsycl-target-backend=spir64_gen "-device dg2" -### 2>&1 \ +// RUN: | FileCheck %s -check-prefix=SYCL_DEVICE_LIB_ASAN_DG2 +// RUN: %clangxx -fsycl -fsycl-targets=spir64_gen --offload-new-driver %s --sysroot=%S/Inputs/SYCL \ +// RUN: -Xarch_device -fsanitize=address -Xs "-device dg2" -### 2>&1 \ +// RUN: | FileCheck %s -check-prefix=SYCL_DEVICE_LIB_ASAN_DG2 +// SYCL_DEVICE_LIB_ASAN_DG2: clang-linker-wrapper{{.*}} "-sycl-device-libraries +// SYCL_DEVICE_LIB_ASAN_DG2: {{.*}}libsycl-crt.new.o +// SYCL_DEVICE_LIB_ASAN_DG2-SAME: {{.*}}libsycl-complex. +// SYCL_DEVICE_LIB_ASAN_DG2-SAME: {{.*}}libsycl-complex-fp64. +// SYCL_DEVICE_LIB_ASAN_DG2-SAME: {{.*}}libsycl-cmath.new.o +// SYCL_DEVICE_LIB_ASAN_DG2-SAME: {{.*}}libsycl-cmath-fp64.new.o +// SYCL_DEVICE_LIB_ASAN_DG2-SAME: {{.*}}libsycl-imf.new.o +// SYCL_DEVICE_LIB_ASAN_DG2-SAME: {{.*}}libsycl-imf-fp64.new.o +// SYCL_DEVICE_LIB_ASAN_DG2-SAME: {{.*}}libsycl-imf-bf16.new.o +// SYCL_DEVICE_LIB_ASAN_DG2-SAME: {{.*}}libsycl-fallback-cassert.new.o +// SYCL_DEVICE_LIB_ASAN_DG2-SAME: {{.*}}libsycl-fallback-cstring.new.o +// SYCL_DEVICE_LIB_ASAN_DG2-SAME: {{.*}}libsycl-fallback-complex.new.o +// SYCL_DEVICE_LIB_ASAN_DG2-SAME: {{.*}}libsycl-fallback-complex-fp64.new.o +// SYCL_DEVICE_LIB_ASAN_DG2-SAME: {{.*}}libsycl-fallback-cmath.new.o +// SYCL_DEVICE_LIB_ASAN_DG2-SAME: {{.*}}libsycl-fallback-cmath-fp64.new.o +// SYCL_DEVICE_LIB_ASAN_DG2-SAME: {{.*}}libsycl-fallback-imf.new.o +// SYCL_DEVICE_LIB_ASAN_DG2-SAME: {{.*}}libsycl-fallback-imf-fp64.new.o +// SYCL_DEVICE_LIB_ASAN_DG2-SAME: {{.*}}libsycl-fallback-imf-bf16.new.o +// SYCL_DEVICE_LIB_ASAN_DG2-SAME: {{.*}}libsycl-asan-dg2.new.o + +/// ########################################################################### +/// test behavior of linking libsycl-asan for multiple targets AOT compilation +/// when asan flag is applied. +// RUN: %clangxx -fsycl -fsycl-targets=spir64_gen --offload-new-driver %s --sysroot=%S/Inputs/SYCL \ +// RUN: -Xarch_device -fsanitize=address -Xsycl-target-backend "-device pvc,dg2" -### 2>&1 \ +// RUN: | FileCheck %s -check-prefix=SYCL_DEVICE_LIB_ASAN_MUL +// RUN: %clangxx -fsycl -fsycl-targets=spir64_gen --offload-new-driver %s --sysroot=%S/Inputs/SYCL \ +// RUN: -Xarch_device -fsanitize=address -Xsycl-target-backend=spir64_gen "-device pvc,dg2" -### 2>&1 \ +// RUN: | FileCheck %s -check-prefix=SYCL_DEVICE_LIB_ASAN_MUL +// SYCL_DEVICE_LIB_ASAN_MUL: clang-linker-wrapper{{.*}} "-sycl-device-libraries +// SYCL_DEVICE_LIB_ASAN_MUL: {{.*}}libsycl-crt.new.o +// SYCL_DEVICE_LIB_ASAN_MUL-SAME: {{.*}}libsycl-complex. +// SYCL_DEVICE_LIB_ASAN_MUL-SAME: {{.*}}libsycl-complex-fp64. +// SYCL_DEVICE_LIB_ASAN_MUL-SAME: {{.*}}libsycl-cmath.new.o +// SYCL_DEVICE_LIB_ASAN_MUL-SAME: {{.*}}libsycl-cmath-fp64.new.o +// SYCL_DEVICE_LIB_ASAN_MUL-SAME: {{.*}}libsycl-imf.new.o +// SYCL_DEVICE_LIB_ASAN_MUL-SAME: {{.*}}libsycl-imf-fp64.new.o +// SYCL_DEVICE_LIB_ASAN_MUL-SAME: {{.*}}libsycl-imf-bf16.new.o +// SYCL_DEVICE_LIB_ASAN_MUL-SAME: {{.*}}libsycl-fallback-cassert.new.o +// SYCL_DEVICE_LIB_ASAN_MUL-SAME: {{.*}}libsycl-fallback-cstring.new.o +// SYCL_DEVICE_LIB_ASAN_MUL-SAME: {{.*}}libsycl-fallback-complex.new.o +// SYCL_DEVICE_LIB_ASAN_MUL-SAME: {{.*}}libsycl-fallback-complex-fp64.new.o +// SYCL_DEVICE_LIB_ASAN_MUL-SAME: {{.*}}libsycl-fallback-cmath.new.o +// SYCL_DEVICE_LIB_ASAN_MUL-SAME: {{.*}}libsycl-fallback-cmath-fp64.new.o +// SYCL_DEVICE_LIB_ASAN_MUL-SAME: {{.*}}libsycl-fallback-imf.new.o +// SYCL_DEVICE_LIB_ASAN_MUL-SAME: {{.*}}libsycl-fallback-imf-fp64.new.o +// SYCL_DEVICE_LIB_ASAN_MUL-SAME: {{.*}}libsycl-fallback-imf-bf16.new.o +// SYCL_DEVICE_LIB_ASAN_MUL-SAME: {{.*}}libsycl-asan.new.o diff --git a/libdevice/cmake/modules/SYCLLibdevice.cmake b/libdevice/cmake/modules/SYCLLibdevice.cmake index 043ffc49e2fac..02da6b7283209 100644 --- a/libdevice/cmake/modules/SYCLLibdevice.cmake +++ b/libdevice/cmake/modules/SYCLLibdevice.cmake @@ -35,6 +35,18 @@ string(CONCAT sycl_targets_opt "spir64-unknown-unknown," "spirv64-unknown-unknown") +string(CONCAT sycl_pvc_target_opt + "-fsycl-targets=" + "intel_gpu_pvc") + +string(CONCAT sycl_cpu_target_opt + "-fsycl-targets=" + "spir64_x86_64-unknown-unknown") + +string(CONCAT sycl_dg2_target_opt + "-fsycl-targets=" + "spir64_gen-unknown-unknown") + set(compile_opts # suppress an error about SYCL_EXTERNAL being used for # a function with a raw pointer parameter. @@ -223,6 +235,55 @@ if (NOT MSVC AND UR_SANITIZER_INCLUDE_DIR) include/sanitizer_utils.hpp include/spir_global_var.hpp sycl-compiler) + + set(sanitizer_generic_compile_opts ${compile_opts} + -fno-sycl-instrument-device-code + -I${UR_SANITIZER_INCLUDE_DIR}) + + set(asan_pvc_compile_opts_obj -fsycl -c + ${sanitizer_generic_compile_opts} + ${sycl_pvc_target_opt} + -D__LIBDEVICE_PVC__) + + set(asan_cpu_compile_opts_obj -fsycl -c + ${sanitizer_generic_compile_opts} + ${sycl_cpu_target_opt} + -D__LIBDEVICE_CPU__) + + set(asan_dg2_compile_opts_obj -fsycl -c + ${sanitizer_generic_compile_opts} + ${sycl_dg2_target_opt} + -D__LIBDEVICE_DG2__) + + set(asan_pvc_compile_opts_bc ${bc_device_compile_opts} + ${sanitizer_generic_compile_opts} + -D__LIBDEVICE_PVC__) + + set(asan_cpu_compile_opts_bc ${bc_device_compile_opts} + ${sanitizer_generic_compile_opts} + -D__LIBDEVICE_CPU__) + + set(asan_dg2_compile_opts_bc ${bc_device_compile_opts} + ${sanitizer_generic_compile_opts} + -D__LIBDEVICE_DG2__) + + set(asan_pvc_compile_opts_obj-new-offload -fsycl -c --offload-new-driver + -foffload-lto=thin + ${sanitizer_generic_compile_opts} + ${sycl_pvc_target_opt} + -D__LIBDEVICE_PVC__) + + set(asan_cpu_compile_opts_obj-new-offload -fsycl -c --offload-new-driver + -foffload-lto=thin + ${sanitizer_generic_compile_opts} + ${sycl_cpu_target_opt} + -D__LIBDEVICE_CPU__) + + set(asan_dg2_compile_opts_obj-new-offload -fsycl -c --offload-new-driver + -foffload-lto=thin + ${sanitizer_generic_compile_opts} + ${sycl_dg2_target_opt} + -D__LIBDEVICE_DG2__) endif() if("native_cpu" IN_LIST SYCL_ENABLE_BACKENDS) @@ -285,10 +346,21 @@ if(MSVC) DEPENDENCIES ${cmath_obj_deps}) else() if(UR_SANITIZER_INCLUDE_DIR) - add_devicelibs(libsycl-sanitizer + add_devicelibs(libsycl-asan SRC sanitizer_utils.cpp DEPENDENCIES ${sanitizer_obj_deps} EXTRA_OPTS -fno-sycl-instrument-device-code -I${UR_SANITIZER_INCLUDE_DIR}) + set(asan_filetypes obj obj-new-offload bc) + set(asan_devicetypes pvc cpu dg2) + foreach(asan_ft IN LISTS asan_filetypes) + foreach(asan_device IN LISTS asan_devicetypes) + compile_lib_ext(libsycl-asan-${asan_device} + SRC sanitizer_utils.cpp + FILETYPE ${asan_ft} + DEPENDENCIES ${sanitizer_obj_deps} + OPTS ${asan_${asan_device}_compile_opts_${asan_ft}}) + endforeach() + endforeach() endif() endif() diff --git a/libdevice/sanitizer_utils.cpp b/libdevice/sanitizer_utils.cpp index 097cd97a4f706..e71bdeea8b501 100644 --- a/libdevice/sanitizer_utils.cpp +++ b/libdevice/sanitizer_utils.cpp @@ -301,6 +301,13 @@ inline uptr MemToShadow_PVC(uptr addr, uint32_t as) { inline uptr MemToShadow(uptr addr, uint32_t as) { uptr shadow_ptr = 0; +#if defined(__LIBDEVICE_PVC__) + shadow_ptr = MemToShadow_PVC(addr, as); +#elif defined(__LIBDEVICE_CPU__) + shadow_ptr = MemToShadow_CPU(addr); +#elif defined(__LIBDEVICE_DG2__) + shadow_ptr = MemToShadow_DG2(addr, as); +#else auto launch_info = (__SYCL_GLOBAL__ const LaunchInfo *)__AsanLaunchInfo; if (launch_info->DeviceTy == DeviceType::CPU) { shadow_ptr = MemToShadow_CPU(addr); @@ -314,6 +321,7 @@ inline uptr MemToShadow(uptr addr, uint32_t as) { __asan_report_unknown_device(); return 0; } +#endif ASAN_DEBUG( if (shadow_ptr) { diff --git a/sycl/test-e2e/Config/kernel_from_file.cpp b/sycl/test-e2e/Config/kernel_from_file.cpp index 8450d6eae2573..9cd3bdf1c12f3 100644 --- a/sycl/test-e2e/Config/kernel_from_file.cpp +++ b/sycl/test-e2e/Config/kernel_from_file.cpp @@ -7,11 +7,11 @@ // As we are doing a separate device compilation here, we need to explicitly // add the device lib instrumentation (itt_compiler_wrapper) // RUN: %clangxx -Wno-error=ignored-attributes -DSYCL_DISABLE_FALLBACK_ASSERT %cxx_std_optionc++17 -fsycl-device-only -fno-sycl-dead-args-optimization -Xclang -fsycl-int-header=%t.h %s -o %t.bc -Xclang -verify-ignore-unexpected=note,warning -Wno-sycl-strict -// >> ---- unbundle compiler wrapper and sanitizer device objects +// >> ---- unbundle compiler wrapper and asan device objects // RUN: clang-offload-bundler -type=o -targets=sycl-spir64-unknown-unknown -input=%sycl_static_libs_dir/libsycl-itt-compiler-wrappers%obj_ext -output=%t_compiler_wrappers.bc -unbundle -// RUN: %if linux %{ clang-offload-bundler -type=o -targets=sycl-spir64-unknown-unknown -input=%sycl_static_libs_dir/libsycl-sanitizer%obj_ext -output=%t_sanitizer.bc -unbundle %} +// RUN: %if linux %{ clang-offload-bundler -type=o -targets=sycl-spir64-unknown-unknown -input=%sycl_static_libs_dir/libsycl-asan%obj_ext -output=%t_asan.bc -unbundle %} // >> ---- link device code -// RUN: %if linux %{ llvm-link -o=%t_app.bc %t.bc %t_compiler_wrappers.bc %t_sanitizer.bc %} %else %{ llvm-link -o=%t_app.bc %t.bc %t_compiler_wrappers.bc %} +// RUN: %if linux %{ llvm-link -o=%t_app.bc %t.bc %t_compiler_wrappers.bc %t_asan.bc %} %else %{ llvm-link -o=%t_app.bc %t.bc %t_compiler_wrappers.bc %} // >> ---- translate to SPIR-V // RUN: llvm-spirv -o %t.spv %t_app.bc // RUN: %clangxx -Wno-error=ignored-attributes -DSYCL_DISABLE_FALLBACK_ASSERT %cxx_std_optionc++17 %include_option %t.h %s -o %t.out %sycl_options -fno-sycl-dead-args-optimization -Xclang -verify-ignore-unexpected=note,warning