diff --git a/source/loader/layers/sanitizer/asan_interceptor.cpp b/source/loader/layers/sanitizer/asan_interceptor.cpp index ba1e9e2088..4a315588fd 100644 --- a/source/loader/layers/sanitizer/asan_interceptor.cpp +++ b/source/loader/layers/sanitizer/asan_interceptor.cpp @@ -414,42 +414,6 @@ ur_result_t SanitizerInterceptor::registerProgram(ur_context_handle_t Context, for (auto Device : Devices) { ManagedQueue Queue(Context, Device); - auto DeviceInfo = getDeviceInfo(Device); - - // Write global variable to program - auto EnqueueWriteGlobal = [&Queue, &Program]( - const char *Name, const void *Value, - size_t Size, bool ReportWarning = true) { - auto Result = - getContext()->urDdiTable.Enqueue.pfnDeviceGlobalVariableWrite( - Queue, Program, Name, false, Size, 0, Value, 0, nullptr, - nullptr); - if (ReportWarning && Result != UR_RESULT_SUCCESS) { - getContext()->logger.warning( - "Failed to write device global \"{}\": {}", Name, Result); - return false; - } - return true; - }; - - // Write debug - // We use "uint64_t" here because EnqueueWriteGlobal will fail when it's "uint32_t" - // Because EnqueueWriteGlobal is a async write, so - // we need to extend its lifetime - static uint64_t Debug = getOptions().Debug ? 1 : 0; - EnqueueWriteGlobal(kSPIR_AsanDebug, &Debug, sizeof(Debug), false); - - // Write shadow memory offset for global memory - EnqueueWriteGlobal(kSPIR_AsanShadowMemoryGlobalStart, - &DeviceInfo->Shadow->ShadowBegin, - sizeof(DeviceInfo->Shadow->ShadowBegin)); - EnqueueWriteGlobal(kSPIR_AsanShadowMemoryGlobalEnd, - &DeviceInfo->Shadow->ShadowEnd, - sizeof(DeviceInfo->Shadow->ShadowEnd)); - - // Write device type - EnqueueWriteGlobal(kSPIR_DeviceType, &DeviceInfo->Type, - sizeof(DeviceInfo->Type)); uint64_t NumOfDeviceGlobal; auto Result = @@ -687,6 +651,11 @@ ur_result_t SanitizerInterceptor::prepareLaunch( } } + LaunchInfo.Data->GlobalShadowOffset = DeviceInfo->Shadow->ShadowBegin; + LaunchInfo.Data->GlobalShadowOffsetEnd = DeviceInfo->Shadow->ShadowEnd; + LaunchInfo.Data->DeviceTy = DeviceInfo->Type; + LaunchInfo.Data->Debug = getOptions().Debug ? 1 : 0; + if (LaunchInfo.LocalWorkSize.empty()) { LaunchInfo.LocalWorkSize.resize(LaunchInfo.WorkDim); auto URes = diff --git a/source/loader/layers/sanitizer/asan_libdevice.hpp b/source/loader/layers/sanitizer/asan_libdevice.hpp index 8f3a7907c3..8eba929f34 100644 --- a/source/loader/layers/sanitizer/asan_libdevice.hpp +++ b/source/loader/layers/sanitizer/asan_libdevice.hpp @@ -16,6 +16,8 @@ namespace ur_sanitizer_layer { +enum class DeviceType : uint32_t { UNKNOWN = 0, CPU, GPU_PVC, GPU_DG2 }; + enum class DeviceSanitizerErrorType : int32_t { UNKNOWN, OUT_OF_BOUNDS, @@ -70,14 +72,20 @@ struct LocalArgsInfo { constexpr std::size_t ASAN_MAX_NUM_REPORTS = 10; struct LaunchInfo { + uintptr_t GlobalShadowOffset = 0; + uintptr_t GlobalShadowOffsetEnd = 0; + uintptr_t PrivateShadowOffset = 0; uintptr_t PrivateShadowOffsetEnd = 0; uintptr_t LocalShadowOffset = 0; uintptr_t LocalShadowOffsetEnd = 0; - uint32_t NumLocalArgs = 0; LocalArgsInfo *LocalArgs = nullptr; // Ordered by ArgIndex + uint32_t NumLocalArgs = 0; + + DeviceType DeviceTy = DeviceType::UNKNOWN; + uint32_t Debug = 0; DeviceSanitizerReport SanitizerReport[ASAN_MAX_NUM_REPORTS]; }; @@ -110,13 +118,6 @@ const int kPrivateLeftRedzoneMagic = (char)0xf1; const int kPrivateMidRedzoneMagic = (char)0xf2; const int kPrivateRightRedzoneMagic = (char)0xf3; -constexpr auto kSPIR_AsanShadowMemoryGlobalStart = - "__AsanShadowMemoryGlobalStart"; -constexpr auto kSPIR_AsanShadowMemoryGlobalEnd = "__AsanShadowMemoryGlobalEnd"; - -constexpr auto kSPIR_DeviceType = "__DeviceType"; -constexpr auto kSPIR_AsanDebug = "__AsanDebug"; - constexpr auto kSPIR_AsanDeviceGlobalCount = "__AsanDeviceGlobalCount"; constexpr auto kSPIR_AsanDeviceGlobalMetadata = "__AsanDeviceGlobalMetadata"; diff --git a/source/loader/layers/sanitizer/common.hpp b/source/loader/layers/sanitizer/common.hpp index 90402b9429..ea5e33ed4b 100644 --- a/source/loader/layers/sanitizer/common.hpp +++ b/source/loader/layers/sanitizer/common.hpp @@ -12,6 +12,7 @@ #pragma once +#include "asan_libdevice.hpp" #include "ur/ur.hpp" #include "ur_ddi.h" @@ -137,8 +138,6 @@ struct SourceInfo { int column = 0; }; -enum class DeviceType : uint64_t { UNKNOWN = 0, CPU, GPU_PVC, GPU_DG2 }; - inline const char *ToString(DeviceType Type) { switch (Type) { case DeviceType::UNKNOWN: