Skip to content

Commit a7e381f

Browse files
authored
[DevMSAN] Support device memory sanitizer for DG2 GPU device (#16619)
1 parent 7b9779e commit a7e381f

File tree

5 files changed

+30
-14
lines changed

5 files changed

+30
-14
lines changed

libdevice/include/sanitizer_defs.hpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,10 @@ enum ADDRESS_SPACE : uint32_t {
3434

3535
#if defined(__SPIR__) || defined(__SPIRV__)
3636

37-
#if defined(__SYCL_DEVICE_ONLY__)
38-
39-
#define __USE_SPIR_BUILTIN__ 1
40-
4137
#ifndef SYCL_EXTERNAL
4238
#define SYCL_EXTERNAL
4339
#endif // SYCL_EXTERNAL
4440

45-
#else // __SYCL_DEVICE_ONLY__
46-
47-
#define __USE_SPIR_BUILTIN__ 0
48-
49-
#endif // __SYCL_DEVICE_ONLY__
50-
51-
#if __USE_SPIR_BUILTIN__
5241
extern SYCL_EXTERNAL int
5342
__spirv_ocl_printf(const __SYCL_CONSTANT__ char *Format, ...);
5443

@@ -63,7 +52,6 @@ extern SYCL_EXTERNAL __attribute__((convergent)) void
6352
__spirv_ControlBarrier(uint32_t Execution, uint32_t Memory, uint32_t Semantics);
6453

6554
extern "C" SYCL_EXTERNAL void __devicelib_exit();
66-
#endif // __USE_SPIR_BUILTIN__
6755

6856
__SYCL_GLOBAL__ void *ToGlobal(void *ptr) {
6957
return __spirv_GenericCastToPtrExplicit_ToGlobal(ptr, 5);

libdevice/sanitizer/msan_rtl.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,27 @@ inline uptr __msan_get_shadow_cpu(uptr addr) {
136136
return addr ^ 0x500000000000ULL;
137137
}
138138

139+
inline uptr __msan_get_shadow_dg2(uptr addr, uint32_t as) {
140+
if (as == ADDRESS_SPACE_GENERIC) {
141+
ConvertGenericPointer(addr, as);
142+
}
143+
144+
if (as != ADDRESS_SPACE_GLOBAL || !(addr & 0xffff'0000'0000'0000ULL))
145+
return (uptr)((__SYCL_GLOBAL__ MsanLaunchInfo *)__MsanLaunchInfo.get())
146+
->CleanShadow;
147+
148+
// Device USM only
149+
auto shadow_begin = ((__SYCL_GLOBAL__ MsanLaunchInfo *)__MsanLaunchInfo.get())
150+
->GlobalShadowOffset;
151+
auto shadow_end = ((__SYCL_GLOBAL__ MsanLaunchInfo *)__MsanLaunchInfo.get())
152+
->GlobalShadowOffsetEnd;
153+
if (addr < shadow_begin) {
154+
return addr + (shadow_begin - 0xffff'8000'0000'0000ULL);
155+
} else {
156+
return addr - (0xffff'ffff'ffff'ffffULL - shadow_end);
157+
}
158+
}
159+
139160
inline uptr __msan_get_shadow_pvc(uptr addr, uint32_t as) {
140161
if (as == ADDRESS_SPACE_GENERIC) {
141162
ConvertGenericPointer(addr, as);
@@ -210,6 +231,8 @@ DEVICE_EXTERN_C_NOINLINE uptr __msan_get_shadow(uptr addr, uint32_t as) {
210231
shadow_ptr = __msan_get_shadow_cpu(addr);
211232
} else if (launch_info->DeviceTy == DeviceType::GPU_PVC) {
212233
shadow_ptr = __msan_get_shadow_pvc(addr, as);
234+
} else if (launch_info->DeviceTy == DeviceType::GPU_DG2) {
235+
shadow_ptr = __msan_get_shadow_dg2(addr, as);
213236
} else {
214237
MSAN_DEBUG(__spirv_ocl_printf(__msan_print_unsupport_device_type,
215238
launch_info->DeviceTy));

sycl/test-e2e/MemorySanitizer/lit.local.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# TRACKER: https://github.com/intel/llvm/issues/16184
22
has_arch_gpu_intel_pvc = any('arch-intel_gpu_pvc' in T for T in config.sycl_dev_features.values())
3-
if not has_arch_gpu_intel_pvc:
3+
has_arch_gpu_intel_dg2 = any('gpu-intel-dg2' in T for T in config.sycl_dev_features.values())
4+
if not has_arch_gpu_intel_pvc and not has_arch_gpu_intel_dg2:
45
config.unsupported_features += ['gpu']
56
else:
67
# TRACKER for PVC + igc-dev: https://github.com/intel/llvm/issues/16401

unified-runtime/source/loader/layers/sanitizer/msan/msan_shadow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ ur_result_t MsanShadowMemoryGPU::Setup() {
141141
// To reserve very large amount of GPU virtual memroy, the pStart param
142142
// should be beyond the SVM range, so that GFX driver will automatically
143143
// switch to reservation on the GPU heap.
144-
const void *StartAddress = (void *)(0x100'0000'0000'0000ULL);
144+
const void *StartAddress = (void *)GetStartAddress();
145145
// TODO: Protect Bad Zone
146146
auto Result = getContext()->urDdiTable.VirtualMem.pfnReserve(
147147
Context, StartAddress, ShadowSize, (void **)&ShadowBegin);

unified-runtime/source/loader/layers/sanitizer/msan/msan_shadow.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ struct MsanShadowMemoryGPU : public MsanShadowMemory {
103103

104104
virtual size_t GetShadowSize() = 0;
105105

106+
virtual uptr GetStartAddress() { return 0; }
107+
106108
private:
107109
ur_result_t EnqueueMapShadow(ur_queue_handle_t Queue, uptr Ptr, uptr Size,
108110
std::vector<ur_event_handle_t> &EventWaitList,
@@ -134,6 +136,8 @@ struct MsanShadowMemoryPVC final : public MsanShadowMemoryGPU {
134136
uptr MemToShadow(uptr Ptr) override;
135137

136138
size_t GetShadowSize() override { return 0x8000'0000'0000ULL; }
139+
140+
uptr GetStartAddress() override { return 0x100'0000'0000'0000ULL; }
137141
};
138142

139143
/// Shadow Memory layout of GPU DG2 device

0 commit comments

Comments
 (0)