-
Notifications
You must be signed in to change notification settings - Fork 738
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DeviceSanitizer] Support detecting misaligned access error (#14148)
UR: oneapi-src/unified-runtime#1747 --------- Co-authored-by: Kenneth Benzie (Benie) <k.benzie@codeplay.com>
- Loading branch information
Showing
5 changed files
with
182 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
sycl/test-e2e/AddressSanitizer/misaligned/misalign-int.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// REQUIRES: linux, cpu | ||
// RUN: %{build} %device_asan_flags -O0 -g -o %t | ||
// RUN: env SYCL_PREFER_UR=1 %{run} not %t 2>&1 | FileCheck %s | ||
// RUN: %{build} %device_asan_flags -O1 -g -o %t | ||
// RUN: env SYCL_PREFER_UR=1 %{run} not %t 2>&1 | FileCheck %s | ||
// RUN: %{build} %device_asan_flags -O2 -g -o %t | ||
// RUN: env SYCL_PREFER_UR=1 %{run} not %t 2>&1 | FileCheck %s | ||
#include <sycl/detail/core.hpp> | ||
#include <sycl/usm.hpp> | ||
|
||
#include <random> | ||
|
||
int main() { | ||
std::random_device rd; | ||
std::mt19937 gen(rd()); | ||
std::uniform_int_distribution<> distrib(1, 3); | ||
|
||
sycl::queue Q; | ||
constexpr std::size_t N = 4; | ||
auto *array = sycl::malloc_host<int>(N, Q); | ||
auto offset = distrib(gen); | ||
std::cout << "offset: " << offset << std::endl; | ||
array = (int *)((char *)array + offset); | ||
|
||
Q.submit([&](sycl::handler &h) { | ||
h.parallel_for<class MyKernel>(sycl::nd_range<1>(N, 1), | ||
[=](sycl::nd_item<1> item) { ++array[0]; }); | ||
Q.wait(); | ||
}); | ||
// CHECK: ERROR: DeviceSanitizer: misaligned-access on Host USM | ||
// CHECK: READ of size 4 at kernel {{<.*MyKernel>}} LID(0, 0, 0) GID({{.*}}, 0, 0) | ||
// CHECK: #0 {{.*}} {{.*misalign-int.cpp}}:[[@LINE-5]] | ||
|
||
return 0; | ||
} |
35 changes: 35 additions & 0 deletions
35
sycl/test-e2e/AddressSanitizer/misaligned/misalign-long.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// REQUIRES: linux, cpu | ||
// RUN: %{build} %device_asan_flags -O0 -g -o %t | ||
// RUN: env SYCL_PREFER_UR=1 %{run} not %t 2>&1 | FileCheck %s | ||
// RUN: %{build} %device_asan_flags -O1 -g -o %t | ||
// RUN: env SYCL_PREFER_UR=1 %{run} not %t 2>&1 | FileCheck %s | ||
// RUN: %{build} %device_asan_flags -O2 -g -o %t | ||
// RUN: env SYCL_PREFER_UR=1 %{run} not %t 2>&1 | FileCheck %s | ||
#include <sycl/detail/core.hpp> | ||
#include <sycl/usm.hpp> | ||
|
||
#include <random> | ||
|
||
int main() { | ||
std::random_device rd; | ||
std::mt19937 gen(rd()); | ||
std::uniform_int_distribution<> distrib(1, 7); | ||
|
||
sycl::queue Q; | ||
constexpr std::size_t N = 4; | ||
auto *array = sycl::malloc_shared<long long>(N, Q); | ||
auto offset = distrib(gen); | ||
std::cout << "offset: " << offset << std::endl; | ||
array = (long long *)((char *)array + offset); | ||
|
||
Q.submit([&](sycl::handler &h) { | ||
h.parallel_for<class MyKernel>(sycl::nd_range<1>(N, 1), | ||
[=](sycl::nd_item<1> item) { ++array[0]; }); | ||
Q.wait(); | ||
}); | ||
// CHECK: ERROR: DeviceSanitizer: misaligned-access on Shared USM | ||
// CHECK: READ of size 8 at kernel {{<.*MyKernel>}} LID(0, 0, 0) GID({{.*}}, 0, 0) | ||
// CHECK: #0 {{.*}} {{.*misalign-long.cpp}}:[[@LINE-5]] | ||
|
||
return 0; | ||
} |
29 changes: 29 additions & 0 deletions
29
sycl/test-e2e/AddressSanitizer/misaligned/misalign-short.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// REQUIRES: linux, cpu | ||
// RUN: %{build} %device_asan_flags -O0 -g -o %t | ||
// RUN: env SYCL_PREFER_UR=1 %{run} not %t 2>&1 | FileCheck %s | ||
// RUN: %{build} %device_asan_flags -O1 -g -o %t | ||
// RUN: env SYCL_PREFER_UR=1 %{run} not %t 2>&1 | FileCheck %s | ||
// RUN: %{build} %device_asan_flags -O2 -g -o %t | ||
// RUN: env SYCL_PREFER_UR=1 %{run} not %t 2>&1 | FileCheck %s | ||
#include <sycl/detail/core.hpp> | ||
#include <sycl/usm.hpp> | ||
|
||
#include <random> | ||
|
||
int main() { | ||
sycl::queue Q; | ||
constexpr std::size_t N = 4; | ||
auto *array = sycl::malloc_device<short>(N, Q); | ||
array = (short *)((char *)array + 1); | ||
|
||
Q.submit([&](sycl::handler &h) { | ||
h.parallel_for<class MyKernel>(sycl::nd_range<1>(N, 1), | ||
[=](sycl::nd_item<1> item) { ++array[0]; }); | ||
Q.wait(); | ||
}); | ||
// CHECK: ERROR: DeviceSanitizer: misaligned-access on Device USM | ||
// CHECK: READ of size 2 at kernel {{<.*MyKernel>}} LID(0, 0, 0) GID({{.*}}, 0, 0) | ||
// CHECK: #0 {{.*}} {{.*misalign-short.cpp}}:[[@LINE-5]] | ||
|
||
return 0; | ||
} |