Skip to content

[SYCL] Fix devicelib assert LIT test #1245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions sycl/test/devicelib/assert-windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
// explicitly. Since the test is going to crash, we'll have to follow a similar
// approach as on Linux - call the test in a subprocess.
//
// RUN: env SYCL_PI_TRACE=1 SYCL_DEVICELIB_INHIBIT_NATIVE=1 SYCL_DEVICE_TYPE=CPU CL_CONFIG_USE_VECTORIZER=False %t.out >%t.stdout.fallback 2>%t.stderr.fallback
// RUN: FileCheck %s --check-prefix=CHECK-MESSAGE --input-file %t.stdout.fallback
// RUN: env SYCL_PI_TRACE=1 SYCL_DEVICELIB_INHIBIT_NATIVE=1 CL_CONFIG_USE_VECTORIZER=False SYCL_DEVICE_TYPE=CPU %t.out >%t.stdout.pi.fallback
// RUN: env SHOULD_CRASH=1 SYCL_DEVICELIB_INHIBIT_NATIVE=1 CL_CONFIG_USE_VECTORIZER=False SYCL_DEVICE_TYPE=CPU %t.out >%t.stdout.msg.fallback
//
// RUN: FileCheck %s --check-prefix=CHECK-MESSAGE --input-file %t.stdout.msg.fallback
// CHECK-MESSAGE: {{.*}}assert-windows.cpp:{{[0-9]+}}: (null): global id: [{{[0-3]}},0,0], local id: [{{[0-3]}},0,0] Assertion `accessorC[wiID] == 0 && "Invalid value"` failed.
//
// RUN: FileCheck %s --input-file %t.stdout.fallback --check-prefix=CHECK-FALLBACK
// RUN: FileCheck %s --input-file %t.stdout.pi.fallback --check-prefix=CHECK-FALLBACK
// CHECK-FALLBACK: ---> piProgramLink

#include <CL/sycl.hpp>
Expand All @@ -45,6 +47,8 @@ void simple_vadd(const std::array<T, N> &VA, const std::array<T, N> &VB,
}
});

int shouldCrash = getenv("SHOULD_CRASH") ? 1 : 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these should be bool instead of int.


cl::sycl::range<1> numOfItems{N};
cl::sycl::buffer<T, 1> bufferA(VA.data(), numOfItems);
cl::sycl::buffer<T, 1> bufferB(VB.data(), numOfItems);
Expand All @@ -57,7 +61,9 @@ void simple_vadd(const std::array<T, N> &VA, const std::array<T, N> &VB,

cgh.parallel_for<class SimpleVaddT>(numOfItems, [=](cl::sycl::id<1> wiID) {
accessorC[wiID] = accessorA[wiID] + accessorB[wiID];
assert(accessorC[wiID] == 0 && "Invalid value");
if (shouldCrash) {
assert(accessorC[wiID] == 0 && "Invalid value");
}
});
});
deviceQueue.wait_and_throw();
Expand Down
35 changes: 28 additions & 7 deletions sycl/test/devicelib/assert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@
// the message can still be buffered by stdio. We turn the bufferization
// off explicitly.
//
// 4. We want to check both compilation flow in (1) and the message in (3),
// but these messages can interleave and fail to match. To avoid this,
// first run with SYCL_PI_TRACE and collect a trace, and then with
// SHOULD_CRASH (without SYCL_PI_TRACE) to collect an error message.
//
// SYCL_DEVICELIB_INHIBIT_NATIVE=1 environment variable is used to force a mode
// in SYCL Runtime, so it doesn't look into a device extensions list and always
// link the fallback library.
Expand All @@ -70,12 +75,14 @@
//
// Overall this sounds stable enough. What could possibly go wrong?
//
// RUN: env SYCL_PI_TRACE=1 CL_CONFIG_USE_VECTORIZER=False SYCL_DEVICE_TYPE=CPU EXPECTED_SIGNAL=SIGABRT SKIP_IF_NO_EXT=1 %t.out 2>%t.stderr.native >%t.stdout.native
// RUN: env SYCL_PI_TRACE=1 SHOULD_CRASH=1 CL_CONFIG_USE_VECTORIZER=False SYCL_DEVICE_TYPE=CPU EXPECTED_SIGNAL=SIGABRT SKIP_IF_NO_EXT=1 %t.out 2>%t.stderr.native >%t.stdout.native
// RUN: FileCheck %s --input-file %t.stdout.native --check-prefixes=CHECK-NATIVE || FileCheck %s --input-file %t.stderr.native --check-prefix CHECK-NOTSUPPORTED
// RUN: FileCheck %s --input-file %t.stderr.native --check-prefixes=CHECK-MESSAGE || FileCheck %s --input-file %t.stderr.native --check-prefix CHECK-NOTSUPPORTED
//
// RUN: env SYCL_PI_TRACE=1 SYCL_DEVICELIB_INHIBIT_NATIVE=cl_intel_devicelib_assert CL_CONFIG_USE_VECTORIZER=False SYCL_DEVICE_TYPE=CPU EXPECTED_SIGNAL=SIGSEGV %t.out 2>%t.stderr.fallback >%t.stdout.fallback
// RUN: FileCheck %s --input-file %t.stdout.fallback --check-prefixes=CHECK-FALLBACK,CHECK-MESSAGE
// RUN: env SYCL_PI_TRACE=1 SYCL_DEVICELIB_INHIBIT_NATIVE=cl_intel_devicelib_assert CL_CONFIG_USE_VECTORIZER=False SYCL_DEVICE_TYPE=CPU EXPECTED_SIGNAL=SIGSEGV %t.out >%t.stdout.pi.fallback
// RUN: env SHOULD_CRASH=1 SYCL_DEVICELIB_INHIBIT_NATIVE=cl_intel_devicelib_assert CL_CONFIG_USE_VECTORIZER=False SYCL_DEVICE_TYPE=CPU EXPECTED_SIGNAL=SIGSEGV %t.out >%t.stdout.msg.fallback
// RUN: FileCheck %s --input-file %t.stdout.pi.fallback --check-prefixes=CHECK-FALLBACK
// RUN: FileCheck %s --input-file %t.stdout.msg.fallback --check-prefixes=CHECK-MESSAGE
//
// CHECK-NATIVE: ---> piProgramBuild
// CHECK-FALLBACK: ---> piProgramLink
Expand Down Expand Up @@ -134,6 +141,8 @@ void simple_vadd(const std::array<T, N> &VA, const std::array<T, N> &VB,
exit(EXIT_SKIP_TEST);
}

int shouldCrash = getenv("SHOULD_CRASH") ? 1 : 0;

cl::sycl::range<1> numOfItems{N};
cl::sycl::buffer<T, 1> bufferA(VA.data(), numOfItems);
cl::sycl::buffer<T, 1> bufferB(VB.data(), numOfItems);
Expand All @@ -146,7 +155,9 @@ void simple_vadd(const std::array<T, N> &VA, const std::array<T, N> &VB,

cgh.parallel_for<class SimpleVaddT>(numOfItems, [=](cl::sycl::id<1> wiID) {
accessorC[wiID] = accessorA[wiID] + accessorB[wiID];
assert(accessorC[wiID] == 0 && "Invalid value");
if (shouldCrash) {
assert(accessorC[wiID] == 0 && "Invalid value");
}
});
});
deviceQueue.wait_and_throw();
Expand All @@ -160,9 +171,19 @@ int main() {
if (WIFEXITED(status) && WEXITSTATUS(status) == EXIT_SKIP_TEST) {
return 0;
}
if (!WIFSIGNALED(status)) {
fprintf(stderr, "error: process did not terminate by a signal\n");
return 1;
if (getenv("SHOULD_CRASH")) {
if (!WIFSIGNALED(status)) {
fprintf(stderr, "error: process did not terminate by a signal\n");
return 1;
}
} else {
if (WIFSIGNALED(status)) {
fprintf(stderr, "error: process should not terminate\n");
return 1;
}
// We should not check anything if the child finished successful and this
// was expected.
return 0;
}
int sig = WTERMSIG(status);
int expected = 0;
Expand Down