Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 5 additions & 36 deletions source/loader/layers/sanitizer/asan_interceptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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 =
Expand Down
17 changes: 9 additions & 8 deletions source/loader/layers/sanitizer/asan_libdevice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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];
};
Expand Down Expand Up @@ -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";

Expand Down
3 changes: 1 addition & 2 deletions source/loader/layers/sanitizer/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#pragma once

#include "asan_libdevice.hpp"
#include "ur/ur.hpp"
#include "ur_ddi.h"

Expand Down Expand Up @@ -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:
Expand Down
Loading