Skip to content

Commit 1a83e6e

Browse files
authored
[DevTSAN] Treat each work item as a thread for GPU device (#18347)
* Update tests to make it more robust Signed-off-by: Zhao, Maosu <[email protected]>
1 parent b0b48a4 commit 1a83e6e

File tree

9 files changed

+74
-43
lines changed

9 files changed

+74
-43
lines changed

libdevice/sanitizer/tsan_rtl.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ inline void ConvertGenericPointer(uptr &addr, uint32_t &as) {
7676
}
7777

7878
inline Epoch IncrementEpoch(Sid sid) {
79-
return atomicAdd(&TsanLaunchInfo->Clock[sid].clk_[sid], 1);
79+
return TsanLaunchInfo->Clock[sid].clk_[sid]++;
8080
}
8181

8282
inline __SYCL_GLOBAL__ RawShadow *MemToShadow_CPU(uptr addr, uint32_t) {
@@ -145,12 +145,11 @@ inline Sid GetCurrentSid_CPU() {
145145
return wg_lid;
146146
}
147147

148-
// For GPU device, each sub group is a thread
148+
// For GPU device, each work item is a thread
149149
inline Sid GetCurrentSid_GPU() {
150150
// sub-group linear id
151-
const auto sg_lid =
152-
__spirv_BuiltInGlobalLinearId / __spirv_BuiltInSubgroupSize;
153-
return sg_lid;
151+
const auto lid = __spirv_BuiltInGlobalLinearId;
152+
return lid;
154153
}
155154

156155
inline Sid GetCurrentSid() {

sycl/test-e2e/ThreadSanitizer/check_access16.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ int main() {
1111
auto *array = sycl::malloc_device<sycl::int3>(1, Q);
1212

1313
Q.submit([&](sycl::handler &h) {
14-
h.parallel_for<class Test>(sycl::nd_range<1>(32, 8),
14+
h.parallel_for<class Test>(sycl::nd_range<1>(128, 8),
1515
[=](sycl::nd_item<1>) {
1616
sycl::int3 vec1 = {1, 1, 1};
1717
sycl::int3 vec2 = {2, 2, 2};

sycl/test-e2e/ThreadSanitizer/check_buffer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#include <sycl/detail/core.hpp>
99

10-
static const int N = 16;
10+
static const int N = 128;
1111

1212
int main() {
1313
sycl::queue q;

sycl/test-e2e/ThreadSanitizer/check_device_global.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ int main() {
1919
sycl::queue Q;
2020

2121
Q.submit([&](sycl::handler &h) {
22-
h.parallel_for<class Test>(sycl::nd_range<1>(32, 8),
22+
h.parallel_for<class Test>(sycl::nd_range<1>(128, 8),
2323
[=](sycl::nd_item<1>) { dev_global[0]++; });
2424
}).wait();
2525
// CHECK: WARNING: DeviceSanitizer: data race
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// REQUIRES: linux, cpu || (gpu && level_zero)
2+
// ALLOW_RETRIES: 10
3+
// RUN: %{build} %device_tsan_flags -O0 -g -o %t.out
4+
// RUN: %{run} %t.out 2>&1 | FileCheck %s
5+
#include "sycl/detail/core.hpp"
6+
#include "sycl/usm.hpp"
7+
8+
int main() {
9+
sycl::queue Q;
10+
auto *array = sycl::malloc_device<char>(1, Q);
11+
12+
Q.submit([&](sycl::handler &h) {
13+
h.parallel_for<class Test>(sycl::nd_range<1>(128, 8),
14+
[=](sycl::nd_item<1>) { array[0]++; });
15+
}).wait();
16+
// CHECK: WARNING: DeviceSanitizer: data race
17+
// CHECK-NEXT: When write of size 1 at 0x{{.*}} in kernel <{{.*}}Test>
18+
// CHECK-NEXT: #0 {{.*}}check_device_usm.cpp:[[@LINE-4]]
19+
20+
sycl::free(array, Q);
21+
return 0;
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// REQUIRES: linux, cpu || (gpu && level_zero)
2+
// ALLOW_RETRIES: 10
3+
// RUN: %{build} %device_tsan_flags -O0 -g -o %t.out
4+
// RUN: %{run} %t.out 2>&1 | FileCheck %s
5+
#include "sycl/detail/core.hpp"
6+
#include "sycl/usm.hpp"
7+
8+
int main() {
9+
sycl::queue Q;
10+
auto *array = sycl::malloc_host<char>(1, Q);
11+
12+
Q.submit([&](sycl::handler &h) {
13+
h.parallel_for<class Test>(sycl::nd_range<1>(128, 8),
14+
[=](sycl::nd_item<1>) { array[0]++; });
15+
}).wait();
16+
// CHECK: WARNING: DeviceSanitizer: data race
17+
// CHECK-NEXT: When write of size 1 at 0x{{.*}} in kernel <{{.*}}Test>
18+
// CHECK-NEXT: #0 {{.*}}check_host_usm.cpp:[[@LINE-4]]
19+
20+
sycl::free(array, Q);
21+
return 0;
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// REQUIRES: linux, cpu || (gpu && level_zero)
2+
// ALLOW_RETRIES: 10
3+
// RUN: %{build} %device_tsan_flags -O0 -g -o %t.out
4+
// RUN: %{run} %t.out 2>&1 | FileCheck %s
5+
#include "sycl/detail/core.hpp"
6+
#include "sycl/usm.hpp"
7+
8+
int main() {
9+
sycl::queue Q;
10+
auto *array = sycl::malloc_shared<char>(1, Q);
11+
12+
Q.submit([&](sycl::handler &h) {
13+
h.parallel_for<class Test>(sycl::nd_range<1>(128, 8),
14+
[=](sycl::nd_item<1>) { array[0]++; });
15+
}).wait();
16+
// CHECK: WARNING: DeviceSanitizer: data race
17+
// CHECK-NEXT: When write of size 1 at 0x{{.*}} in kernel <{{.*}}Test>
18+
// CHECK-NEXT: #0 {{.*}}check_shared_usm.cpp:[[@LINE-4]]
19+
20+
sycl::free(array, Q);
21+
return 0;
22+
}

sycl/test-e2e/ThreadSanitizer/check_unaligned_access.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ int main() {
1515
auto *array = sycl::malloc_device<S>(1, Q);
1616

1717
Q.submit([&](sycl::handler &h) {
18-
h.parallel_for<class Test>(sycl::nd_range<1>(32, 8),
18+
h.parallel_for<class Test>(sycl::nd_range<1>(128, 8),
1919
[=](sycl::nd_item<1>) { array[0].x++; });
2020
}).wait();
2121
// CHECK: WARNING: DeviceSanitizer: data race

sycl/test-e2e/ThreadSanitizer/check_usm.cpp

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)