Skip to content
11 changes: 11 additions & 0 deletions libdevice/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ set(CMAKE_MODULE_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"
)

if(EXISTS ${FETCHCONTENT_BASE_DIR}/unified-runtime-src)
set(UR_SANITIZER_INCLUDE_DIR
${FETCHCONTENT_BASE_DIR}/unified-runtime-src/source/loader/layers/sanitizer)
elseif(EXISTS ${SYCL_UR_SOURCE_DIR})
set(UR_SANITIZER_INCLUDE_DIR
${SYCL_UR_SOURCE_DIR}/source/loader/layers/sanitizer)
else()
message(WARNING "Unified Runtime source directory is not provided, \
will not build libdevice sanitizer")
endif()

# Build libdevice for SYCL.
include(SYCLLibdevice)

Expand Down
14 changes: 8 additions & 6 deletions libdevice/cmake/modules/SYCLLibdevice.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,10 @@ set(cmath_obj_deps device_math.h device.h sycl-compiler)
set(imf_obj_deps device_imf.hpp imf_half.hpp imf_bf16.hpp imf_rounding_op.hpp imf_impl_utils.hpp device.h sycl-compiler)
set(itt_obj_deps device_itt.h spirv_vars.h device.h sycl-compiler)
set(bfloat16_obj_deps sycl-headers sycl-compiler)
if (NOT MSVC)
if (NOT MSVC AND UR_SANITIZER_INCLUDE_DIR)
set(sanitizer_obj_deps
device.h atomic.hpp spirv_vars.h
include/asan_libdevice.hpp
${UR_SANITIZER_INCLUDE_DIR}/asan_libdevice.hpp
include/sanitizer_utils.hpp
include/spir_global_var.hpp
sycl-compiler)
Expand Down Expand Up @@ -268,10 +268,12 @@ if(MSVC)
SRC msvc_math.cpp
DEPENDENCIES ${cmath_obj_deps})
else()
add_devicelibs(libsycl-sanitizer
SRC sanitizer_utils.cpp
DEPENDENCIES ${sanitizer_obj_deps}
EXTRA_OPTS -fno-sycl-instrument-device-code)
if(UR_SANITIZER_INCLUDE_DIR)
add_devicelibs(libsycl-sanitizer
SRC sanitizer_utils.cpp
DEPENDENCIES ${sanitizer_obj_deps}
EXTRA_OPTS -fno-sycl-instrument-device-code -I${UR_SANITIZER_INCLUDE_DIR})
endif()
endif()

add_devicelibs(libsycl-fallback-cassert
Expand Down
157 changes: 0 additions & 157 deletions libdevice/include/asan_libdevice.hpp

This file was deleted.

17 changes: 12 additions & 5 deletions libdevice/sanitizer_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
//
//===----------------------------------------------------------------------===//

#include "asan_libdevice.hpp"
#include "atomic.hpp"
#include "device.h"
#include "spirv_vars.h"

#include "include/asan_libdevice.hpp"
#include "include/sanitizer_utils.hpp"

using uptr = uintptr_t;
Expand Down Expand Up @@ -411,8 +411,11 @@ void __asan_internal_report_save(DeviceSanitizerErrorType error_type) {
auto &SanitizerReport = ((__SYCL_GLOBAL__ LaunchInfo *)__AsanLaunchInfo)
->SanitizerReport[WG_LID % ASAN_MAX_NUM_REPORTS];

if (atomicCompareAndSet(&SanitizerReport.Flag, Desired, Expected) ==
Expected) {
if (atomicCompareAndSet(
&(((__SYCL_GLOBAL__ LaunchInfo *)__AsanLaunchInfo)->ReportFlag), 1,
0) == 0 &&
atomicCompareAndSet(&SanitizerReport.Flag, Desired, Expected) ==
Expected) {
SanitizerReport.ErrorType = error_type;
SanitizerReport.IsRecover = false;

Expand Down Expand Up @@ -453,8 +456,12 @@ void __asan_internal_report_save(
auto &SanitizerReport = ((__SYCL_GLOBAL__ LaunchInfo *)__AsanLaunchInfo)
->SanitizerReport[WG_LID % ASAN_MAX_NUM_REPORTS];

if (atomicCompareAndSet(&SanitizerReport.Flag, Desired, Expected) ==
Expected) {
if ((is_recover ||
atomicCompareAndSet(
&(((__SYCL_GLOBAL__ LaunchInfo *)__AsanLaunchInfo)->ReportFlag), 1,
0) == 0) &&
atomicCompareAndSet(&SanitizerReport.Flag, Desired, Expected) ==
Expected) {

int FileLength = 0;
int FuncLength = 0;
Expand Down
8 changes: 2 additions & 6 deletions sycl/cmake/modules/FetchUnifiedRuntime.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,8 @@ if(SYCL_UR_USE_FETCH_CONTENT)
CACHE PATH "Path to external '${name}' adapter source dir" FORCE)
endfunction()

set(UNIFIED_RUNTIME_REPO "https://github.com/oneapi-src/unified-runtime.git")
# commit af7e275b509b41f54a66743ebf748dfb51668abf
# Author: Maosu Zhao <[email protected]>
# Date: Thu Oct 17 16:31:21 2024 +0800
# [DeviceSanitizer] Refactor the code to manage shadow memory (#2127)
set(UNIFIED_RUNTIME_TAG af7e275b509b41f54a66743ebf748dfb51668abf)
set(UNIFIED_RUNTIME_REPO "https://github.com/zhaomaosu/unified-runtime.git")
set(UNIFIED_RUNTIME_TAG devsan-add-report-flag)

set(UMF_BUILD_EXAMPLES OFF CACHE INTERNAL "EXAMPLES")
# Due to the use of dependentloadflag and no installer for UMF and hwloc we need
Expand Down
Loading