Skip to content

Commit 450683b

Browse files
AllanZynewenju-hekbenzie
authored
[SYCL][DeviceSanitizer] Support GPU DG2 Device (#13450)
UR: oneapi-src/unified-runtime#1521 - Add MemToShadow_DG2 - Enable lit tests for GPU, decrease the global workgoup size in some tests due to the limit of GPU memory Although, the "_DG2" suffix might be misleading: DG2 present all 48bits virtual address devices, and PVC present all 58bits virtual address devices. --------- Co-authored-by: Wenju He <wenju.he@intel.com> Co-authored-by: Kenneth Benzie (Benie) <k.benzie@codeplay.com>
1 parent b50102b commit 450683b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+156
-81
lines changed

libdevice/sanitizer_utils.cpp

Lines changed: 103 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ static __SYCL_CONSTANT__ const char __generic_to[] =
8383
static __SYCL_CONSTANT__ const char __generic_to_fail[] =
8484
"[kernel] %p(4) - unknown address space\n";
8585

86+
static __SYCL_CONSTANT__ const char __mem_launch_info[] =
87+
"[kernel] launch_info: %p (local_shadow=%p~%p, numLocalArgs=%d, "
88+
"localArgs=%p)\n";
89+
8690
#define ASAN_REPORT_NONE 0
8791
#define ASAN_REPORT_START 1
8892
#define ASAN_REPORT_FINISH 2
@@ -111,56 +115,120 @@ __SYCL_PRIVATE__ void *ToPrivate(void *ptr) {
111115
return __spirv_GenericCastToPtrExplicit_ToPrivate(ptr, 7);
112116
}
113117

118+
inline bool ConvertGenericPointer(uptr &addr, uint32_t &as) {
119+
auto old = addr;
120+
if ((addr = (uptr)ToPrivate((void *)old))) {
121+
as = ADDRESS_SPACE_PRIVATE;
122+
} else if ((addr = (uptr)ToLocal((void *)old))) {
123+
as = ADDRESS_SPACE_LOCAL;
124+
} else if ((addr = (uptr)ToGlobal((void *)old))) {
125+
as = ADDRESS_SPACE_GLOBAL;
126+
} else {
127+
if (__AsanDebug)
128+
__spirv_ocl_printf(__generic_to_fail, old);
129+
return false;
130+
}
131+
if (__AsanDebug)
132+
__spirv_ocl_printf(__generic_to, old, addr, as);
133+
return true;
134+
}
135+
114136
inline uptr MemToShadow_CPU(uptr addr) {
115137
return __AsanShadowMemoryGlobalStart + (addr >> ASAN_SHADOW_SCALE);
116138
}
117139

118140
inline uptr MemToShadow_DG2(uptr addr, uint32_t as) {
119-
uptr shadow_ptr = 0;
120-
if (addr & (~0xffffffffffff)) {
121-
shadow_ptr = (((addr & 0xffffffffffff) >> ASAN_SHADOW_SCALE) +
122-
__AsanShadowMemoryGlobalStart) |
123-
(~0xffffffffffff);
124-
} else {
125-
shadow_ptr = (addr >> ASAN_SHADOW_SCALE) + __AsanShadowMemoryGlobalStart;
141+
if (as == ADDRESS_SPACE_GENERIC) {
142+
if (!ConvertGenericPointer(addr, as)) {
143+
return 0;
144+
}
126145
}
127146

128-
if (shadow_ptr > __AsanShadowMemoryGlobalEnd) {
129-
if (__asan_report_out_of_shadow_bounds()) {
130-
__spirv_ocl_printf(__global_shadow_out_of_bound, addr, shadow_ptr);
147+
if (as == ADDRESS_SPACE_GLOBAL) { // global
148+
if (addr & 0xFFFF000000000000ULL) { // Device USM
149+
return __AsanShadowMemoryGlobalStart + 0x80000000000ULL +
150+
((addr & 0x7FFFFFFFFFFFULL) >> ASAN_SHADOW_SCALE);
151+
} else { // Host/Shared USM
152+
return __AsanShadowMemoryGlobalStart + (addr >> ASAN_SHADOW_SCALE);
131153
}
132-
}
154+
} else if (as == ADDRESS_SPACE_LOCAL) { // local
155+
// The size of SLM is 64KB on DG2
156+
constexpr unsigned slm_size = 64 * 1024;
157+
const auto wg_lid =
158+
__spirv_BuiltInWorkgroupId.x * __spirv_BuiltInNumWorkgroups.y *
159+
__spirv_BuiltInNumWorkgroups.z +
160+
__spirv_BuiltInWorkgroupId.y * __spirv_BuiltInNumWorkgroups.z +
161+
__spirv_BuiltInWorkgroupId.z;
133162

134-
return shadow_ptr;
135-
}
163+
auto launch_info = (__SYCL_GLOBAL__ const LaunchInfo *)__AsanLaunchInfo;
164+
const auto shadow_offset = launch_info->LocalShadowOffset;
165+
const auto shadow_offset_end = launch_info->LocalShadowOffsetEnd;
136166

137-
static __SYCL_CONSTANT__ const char __mem_launch_info[] =
138-
"[kernel] launch_info: %p (local_shadow=%p~%p, numLocalArgs=%d, "
139-
"localArgs=%p)\n";
167+
if (shadow_offset == 0) {
168+
return 0;
169+
}
140170

141-
static __SYCL_CONSTANT__ const char __generic_to[] =
142-
"[kernel] %p(4) - %p(%d)\n";
171+
if (__AsanDebug)
172+
__spirv_ocl_printf(__mem_launch_info, launch_info,
173+
launch_info->LocalShadowOffset,
174+
launch_info->LocalShadowOffsetEnd,
175+
launch_info->NumLocalArgs, launch_info->LocalArgs);
143176

144-
static __SYCL_CONSTANT__ const char __generic_to_fail[] =
145-
"[kernel] %p(4) - unknown address space\n";
177+
auto shadow_ptr = shadow_offset +
178+
((wg_lid * slm_size) >> ASAN_SHADOW_SCALE) +
179+
((addr & (slm_size - 1)) >> ASAN_SHADOW_SCALE);
146180

147-
inline uptr MemToShadow_PVC(uptr addr, uint32_t as) {
181+
if (shadow_ptr > shadow_offset_end) {
182+
if (__asan_report_out_of_shadow_bounds()) {
183+
__spirv_ocl_printf(__local_shadow_out_of_bound, addr, shadow_ptr,
184+
wg_lid, (uptr)shadow_offset);
185+
}
186+
return 0;
187+
}
188+
return shadow_ptr;
189+
} else if (as == ADDRESS_SPACE_PRIVATE) { // private
190+
// work-group linear id
191+
const auto WG_LID =
192+
__spirv_BuiltInWorkgroupId.x * __spirv_BuiltInNumWorkgroups.y *
193+
__spirv_BuiltInNumWorkgroups.z +
194+
__spirv_BuiltInWorkgroupId.y * __spirv_BuiltInNumWorkgroups.z +
195+
__spirv_BuiltInWorkgroupId.z;
148196

149-
if (as == ADDRESS_SPACE_GENERIC) {
150-
auto old = addr;
151-
if ((addr = (uptr)ToPrivate((void *)old))) {
152-
as = ADDRESS_SPACE_PRIVATE;
153-
} else if ((addr = (uptr)ToLocal((void *)old))) {
154-
as = ADDRESS_SPACE_LOCAL;
155-
} else if ((addr = (uptr)ToGlobal((void *)old))) {
156-
as = ADDRESS_SPACE_GLOBAL;
157-
} else {
158-
if (__AsanDebug)
159-
__spirv_ocl_printf(__generic_to_fail, old);
197+
auto launch_info = (__SYCL_GLOBAL__ const LaunchInfo *)__AsanLaunchInfo;
198+
const auto shadow_offset = launch_info->PrivateShadowOffset;
199+
const auto shadow_offset_end = launch_info->LocalShadowOffsetEnd;
200+
201+
if (shadow_offset == 0) {
160202
return 0;
161203
}
204+
162205
if (__AsanDebug)
163-
__spirv_ocl_printf(__generic_to, old, addr, as);
206+
__spirv_ocl_printf(__mem_launch_info, launch_info,
207+
launch_info->PrivateShadowOffset, 0,
208+
launch_info->NumLocalArgs, launch_info->LocalArgs);
209+
210+
uptr shadow_ptr = shadow_offset +
211+
((WG_LID * ASAN_PRIVATE_SIZE) >> ASAN_SHADOW_SCALE) +
212+
((addr & (ASAN_PRIVATE_SIZE - 1)) >> ASAN_SHADOW_SCALE);
213+
214+
if (shadow_ptr > shadow_offset_end) {
215+
if (__asan_report_out_of_shadow_bounds()) {
216+
__spirv_ocl_printf(__private_shadow_out_of_bound, addr, shadow_ptr,
217+
WG_LID, (uptr)shadow_offset);
218+
}
219+
return 0;
220+
}
221+
return shadow_ptr;
222+
}
223+
224+
return 0;
225+
}
226+
227+
inline uptr MemToShadow_PVC(uptr addr, uint32_t as) {
228+
if (as == ADDRESS_SPACE_GENERIC) {
229+
if (!ConvertGenericPointer(addr, as)) {
230+
return 0;
231+
}
164232
}
165233

166234
if (as == ADDRESS_SPACE_GLOBAL) { // global
@@ -262,6 +330,8 @@ inline uptr MemToShadow(uptr addr, uint32_t as) {
262330
shadow_ptr = MemToShadow_CPU(addr);
263331
} else if (__DeviceType == DeviceType::GPU_PVC) {
264332
shadow_ptr = MemToShadow_PVC(addr, as);
333+
} else if (__DeviceType == DeviceType::GPU_DG2) {
334+
shadow_ptr = MemToShadow_DG2(addr, as);
265335
} else {
266336
if (__asan_report_unknown_device() && __AsanDebug) {
267337
__spirv_ocl_printf(__asan_print_unsupport_device_type, (int)__DeviceType);

sycl/plugins/unified_runtime/CMakeLists.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,13 @@ if(SYCL_PI_UR_USE_FETCH_CONTENT)
100100
endfunction()
101101

102102
set(UNIFIED_RUNTIME_REPO "https://github.com/oneapi-src/unified-runtime.git")
103-
# commit 9b209642d47a99fc445c3bdea3407a829f4623ae
104-
# Merge: fa6bf973 65b44315
103+
# commit e161516663bd5d14d15532dfaba626d5cdf32ed8
104+
# Merge: 47633088 febb18bb
105105
# Author: Kenneth Benzie (Benie) <k.benzie@codeplay.com>
106-
# Date: Tue Jul 23 19:22:06 2024 +0100
107-
# Merge pull request #1861 from aarongreig/aaron/addSetDataToMockHandle
108-
# Add getData/setData to mock dummy handle
109-
set(UNIFIED_RUNTIME_TAG 9b209642d47a99fc445c3bdea3407a829f4623ae)
106+
# Date: Wed Jul 24 13:54:43 2024 +0100
107+
# Merge pull request #1521 from AllanZyne/review/yang/dg2
108+
# [DeviceSanitizer] Support GPU DG2 & GEN Device
109+
set(UNIFIED_RUNTIME_TAG e161516663bd5d14d15532dfaba626d5cdf32ed8)
110110

111111
fetch_adapter_source(level_zero
112112
${UNIFIED_RUNTIME_REPO}

sycl/test-e2e/AddressSanitizer/bad-free/bad-free-host.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// REQUIRES: linux, cpu
1+
// REQUIRES: linux
22
// RUN: %{build} %device_asan_flags -O0 -g -o %t
33
// RUN: %force_device_asan_rt %{run} not %t 2>&1 | FileCheck %s
44
#include <sycl/usm.hpp>

sycl/test-e2e/AddressSanitizer/bad-free/bad-free-minus1.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// REQUIRES: linux, cpu
1+
// REQUIRES: linux
22
// RUN: %{build} %device_asan_flags -O0 -g -o %t
33
// RUN: %force_device_asan_rt %{run} not %t 2>&1 | FileCheck --check-prefixes CHECK,CHECK-DEVICE %s
44
// RUN: %{build} %device_asan_flags -DMALLOC_HOST -O0 -g -o %t

sycl/test-e2e/AddressSanitizer/bad-free/bad-free-plus1.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// REQUIRES: linux, cpu
1+
// REQUIRES: linux
22
// RUN: %{build} %device_asan_flags -O0 -g -o %t
33
// RUN: %force_device_asan_rt %{run} not %t 2>&1 | FileCheck --check-prefixes CHECK,CHECK-DEVICE %s
44
// RUN: %{build} %device_asan_flags -DMALLOC_HOST -O0 -g -o %t

sycl/test-e2e/AddressSanitizer/common/config-red-zone-size.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// REQUIRES: linux, cpu
1+
// REQUIRES: linux
22
// RUN: %{build} %device_asan_flags -DUNSAFE -O0 -g -o %t
33
// RUN: env SYCL_PREFER_UR=1 UR_LAYER_ASAN_OPTIONS=redzone:64 %{run} not %t 2>&1 | FileCheck %s
44
// RUN: %{build} %device_asan_flags -DSAFE -O0 -g -o %t

sycl/test-e2e/AddressSanitizer/common/demangle-kernel-name.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// REQUIRES: linux, cpu
1+
// REQUIRES: linux
22
// RUN: %{build} %device_asan_flags -O2 -g -o %t
33
// RUN: env SYCL_PREFER_UR=1 %{run} not %t &> %t.txt ; FileCheck --input-file %t.txt %s
44
#include <sycl/detail/core.hpp>

sycl/test-e2e/AddressSanitizer/common/kernel-debug.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// REQUIRES: linux, cpu
1+
// REQUIRES: linux
22
// RUN: %{build} %device_asan_flags -O2 -g -o %t
33
// RUN: env SYCL_PREFER_UR=1 UR_LAYER_ASAN_OPTIONS=debug:1 %{run} %t 2>&1 | FileCheck --check-prefixes CHECK-DEBUG %s
44
// RUN: env SYCL_PREFER_UR=1 UR_LAYER_ASAN_OPTIONS=debug:0 %{run} %t 2>&1 | FileCheck %s

sycl/test-e2e/AddressSanitizer/double-free/double-free.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// REQUIRES: linux, cpu
1+
// REQUIRES: linux
22
// RUN: %{build} %device_asan_flags -O0 -g -o %t
33
// RUN: %force_device_asan_rt UR_LAYER_ASAN_OPTIONS=quarantine_size_mb:1 %{run} not %t 2>&1 | FileCheck --check-prefixes CHECK,CHECK-DEVICE %s
44
// RUN: %{build} %device_asan_flags -DMALLOC_HOST -O0 -g -o %t

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@ config.substitutions.append(
77
config.substitutions.append(
88
("%force_device_asan_rt", "env SYCL_PREFER_UR=1 UR_ENABLE_LAYERS=UR_LAYER_ASAN")
99
)
10+
11+
config.unsupported_features += ['cuda', 'hip']
12+
13+
# FIXME: Skip gen devices, waiting for gfx driver uplifting
14+
config.unsupported_features += ['gpu-intel-gen9', 'gpu-intel-gen11', 'gpu-intel-gen12']

0 commit comments

Comments
 (0)