Skip to content

Commit 6ccaafd

Browse files
authored
[DeviceMSAN] Add e2e tests for memcpy2d (#19335)
1 parent 02c90bb commit 6ccaafd

3 files changed

Lines changed: 81 additions & 8 deletions

File tree

sycl/test-e2e/MemorySanitizer/check_usm.cpp

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,16 @@
1313
#include <sycl/detail/core.hpp>
1414
#include <sycl/usm.hpp>
1515

16-
__attribute__((noinline)) long long foo(int data1, long long data2) {
16+
__attribute__((noinline)) int check(int data1, int data2) {
1717
return data1 + data2;
1818
}
1919

2020
void check_memset(sycl::queue &Q) {
2121
std::cout << "check_memset" << std::endl;
2222
auto *array = sycl::malloc_device<int>(2, Q);
2323
auto ev1 = Q.memset(array, 0, 2 * sizeof(int));
24-
auto ev2 = Q.single_task(ev1, [=]() { array[0] = foo(array[0], array[1]); });
24+
auto ev2 =
25+
Q.single_task(ev1, [=]() { array[0] = check(array[0], array[1]); });
2526
Q.wait();
2627
sycl::free(array, Q);
2728
std::cout << "PASS" << std::endl;
@@ -30,25 +31,41 @@ void check_memset(sycl::queue &Q) {
3031
// CHECK-NOT: use-of-uninitialized-value
3132
// CHECK: PASS
3233

34+
void check_fill(sycl::queue &Q) {
35+
std::cout << "check_fill" << std::endl;
36+
int *array = sycl::malloc_device<int>(2, Q);
37+
uint32_t pattern = 0;
38+
auto ev1 = Q.fill(array, pattern, 2);
39+
auto ev2 =
40+
Q.single_task(ev1, [=]() { array[0] = check(array[0], array[1]); });
41+
Q.wait();
42+
sycl::free(array, Q);
43+
std::cout << "PASS" << std::endl;
44+
}
45+
// CHECK-LABEL: check_fill
46+
// CHECK-NOT: use-of-uninitialized-value
47+
// CHECK: PASS
48+
3349
void check_memcpy(sycl::queue &Q) {
34-
std::cout << "check_memcpy2" << std::endl;
50+
std::cout << "check_memcpy" << std::endl;
3551
auto *source = sycl::malloc_device<int>(2, Q);
3652
auto *array = sycl::malloc_device<int>(2, Q);
37-
// FIXME: We don't support shadow propagation on host/shared usm
3853
auto ev1 = Q.memcpy(array, source, 2 * sizeof(int));
39-
auto ev2 = Q.single_task(ev1, [=]() { array[0] = foo(array[0], array[1]); });
54+
auto ev2 =
55+
Q.single_task(ev1, [=]() { array[0] = check(array[0], array[1]); });
4056
Q.wait();
4157
sycl::free(array, Q);
4258
sycl::free(source, Q);
4359
std::cout << "PASS" << std::endl;
4460
}
45-
// CHECK-LABEL: check_memcpy2
61+
// CHECK-LABEL: check_memcpy
4662
// CHECK: use-of-uninitialized-value
4763
// CHECK-NOT: PASS
4864

4965
int main() {
5066
sycl::queue Q;
5167
check_memset(Q);
68+
check_fill(Q);
5269
check_memcpy(Q);
5370
return 0;
5471
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// REQUIRES: linux, cpu || (gpu && level_zero)
2+
// RUN: %{build} %device_msan_flags -O0 -g -o %t2.out
3+
// RUN: %{run} not %t2.out 2>&1 | FileCheck %s
4+
// RUN: %{build} %device_msan_flags -O2 -g -o %t3.out
5+
// RUN: %{run} not %t3.out 2>&1 | FileCheck %s
6+
7+
// UNSUPPORTED: cpu
8+
// UNSUPPORTED-TRACKER: CMPLRLLVM-64618
9+
10+
// XFAIL: spirv-backend && gpu
11+
// XFAIL-TRACKER: CMPLRLLVM-64705
12+
13+
#include <sycl/detail/core.hpp>
14+
#include <sycl/ext/oneapi/memcpy2d.hpp>
15+
#include <sycl/usm.hpp>
16+
17+
constexpr size_t Pitch = 4;
18+
constexpr size_t Width = 2;
19+
constexpr size_t Height = 2;
20+
constexpr size_t Size = Pitch * Height;
21+
22+
__attribute__((noinline)) int check(int data1, int data2) {
23+
return data1 + data2;
24+
}
25+
26+
void check_memcpy2d(sycl::queue &Q) {
27+
std::cout << "check_memcpy2d" << std::endl;
28+
29+
auto *source = sycl::malloc_device<int>(Size, Q);
30+
Q.memset(source, 0, Size * sizeof(int)).wait();
31+
32+
auto *dest = sycl::malloc_device<int>(Size, Q);
33+
Q.ext_oneapi_memcpy2d(dest, Pitch * sizeof(int), source, Pitch * sizeof(int),
34+
Width * sizeof(int), Height)
35+
.wait();
36+
37+
Q.single_task<class Test1>([=]() {
38+
dest[0] = check(dest[0], dest[1]);
39+
dest[0] = check(dest[4], dest[5]);
40+
}).wait();
41+
// CHECK-NOT: check_usm2d.cpp:[[@LINE-3]]
42+
43+
Q.single_task<class Test2>([=]() {
44+
dest[0] = check(dest[2], dest[3]);
45+
}).wait();
46+
// CHECK: use-of-uninitialized-value
47+
// CHECK: check_usm2d.cpp:[[@LINE-3]]
48+
49+
sycl::free(dest, Q);
50+
sycl::free(source, Q);
51+
}
52+
53+
int main() {
54+
sycl::queue Q;
55+
check_memcpy2d(Q);
56+
return 0;
57+
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ ur_result_t urEnqueueUSMFill2DFallback(ur_queue_handle_t hQueue, void *pMem,
6161
ur_result_t Result = getContext()->urDdiTable.Enqueue.pfnUSMFill2D(
6262
hQueue, pMem, pitch, patternSize, pPattern, width, height,
6363
numEventsInWaitList, phEventWaitList, phEvent);
64-
if (Result == UR_RESULT_SUCCESS ||
65-
Result != UR_RESULT_ERROR_UNSUPPORTED_FEATURE) {
64+
if (Result != UR_RESULT_ERROR_UNSUPPORTED_FEATURE) {
6665
return Result;
6766
}
6867

0 commit comments

Comments
 (0)