Skip to content

Commit 101307f

Browse files
authored
[SYCL] Fix device assertion bug on windows (intel#15232)
This PR fixes a device assertion bug on Windows where the assertion message and information are not printed when an assertion is triggered. Also re-enabled some tests failing because of it. See intel#12797.
1 parent 56a6ae2 commit 101307f

12 files changed

+100
-20
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//== ----------------<assert.h> wrapper around STL--------------------------==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// Must not be guarded. C++ standard says the macro assert is redefined
10+
// according to the current state of NDEBUG each time that <cassert> is
11+
// included.
12+
13+
#if defined(__has_include_next)
14+
#include_next <assert.h>
15+
#else
16+
#include <../ucrt/assert.h>
17+
#endif
18+
19+
#ifdef __SYCL_DEVICE_ONLY__
20+
#include <CL/__spirv/spirv_vars.hpp>
21+
22+
// Device assertions on Windows do not work properly so we define these wrappers
23+
// around the STL assertion headers cassert and assert.h where we redefine
24+
// the assert macro to call __devicelib_assert_fail directly and bypass
25+
// _wassert.
26+
#if defined(_WIN32) && defined(assert)
27+
extern "C" __DPCPP_SYCL_EXTERNAL void
28+
__devicelib_assert_fail(const char *, const char *, int32_t, const char *,
29+
uint64_t, uint64_t, uint64_t, uint64_t, uint64_t,
30+
uint64_t);
31+
#undef assert
32+
#if defined(NDEBUG)
33+
#define assert(e) ((void)0)
34+
#else
35+
#define assert(e) \
36+
((e) ? void(0) \
37+
: __devicelib_assert_fail( \
38+
#e, __FILE__, __LINE__, nullptr, __spirv_GlobalInvocationId_x(), \
39+
__spirv_GlobalInvocationId_y(), __spirv_GlobalInvocationId_z(), \
40+
__spirv_LocalInvocationId_x(), __spirv_LocalInvocationId_y(), \
41+
__spirv_LocalInvocationId_z()))
42+
#endif
43+
#endif
44+
#endif
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//==---------------- <cassert> wrapper around STL --------------------------==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// Must not be guarded. C++ standard says the macro assert is redefined
10+
// according to the current state of NDEBUG each time that <cassert> is
11+
// included.
12+
13+
#if defined(__has_include_next)
14+
#include_next <cassert>
15+
#else
16+
#include <../include/cassert>
17+
#endif
18+
19+
#ifdef __SYCL_DEVICE_ONLY__
20+
#include <CL/__spirv/spirv_vars.hpp>
21+
22+
// Device assertions on Windows do not work properly so we define these wrappers
23+
// around the STL assertion headers cassert and assert.h where we redefine
24+
// the assert macro to call __devicelib_assert_fail directly and bypass
25+
// _wassert.
26+
#if defined(_WIN32) && defined(assert)
27+
extern "C" __DPCPP_SYCL_EXTERNAL void
28+
__devicelib_assert_fail(const char *, const char *, int32_t, const char *,
29+
uint64_t, uint64_t, uint64_t, uint64_t, uint64_t,
30+
uint64_t);
31+
#undef assert
32+
#if defined(NDEBUG)
33+
#define assert(e) ((void)0)
34+
#else
35+
#define assert(e) \
36+
((e) ? void(0) \
37+
: __devicelib_assert_fail( \
38+
#e, __FILE__, __LINE__, nullptr, __spirv_GlobalInvocationId_x(), \
39+
__spirv_GlobalInvocationId_y(), __spirv_GlobalInvocationId_z(), \
40+
__spirv_LocalInvocationId_x(), __spirv_LocalInvocationId_y(), \
41+
__spirv_LocalInvocationId_z()))
42+
#endif
43+
#endif
44+
#endif

sycl/test-e2e/Assert/assert_in_kernels_win.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
// https://github.com/intel/llvm/issues/12797
2-
// UNSUPPORTED: windows
31
// REQUIRES: windows
42
// RUN: %{build} -DSYCL_FALLBACK_ASSERT=1 -o %t.out
53
// Shouldn't fail on ACC as fallback assert isn't enqueued there
6-
// RUN: %{run} %t.out &> %t.txt ; FileCheck %s --input-file %t.txt %if acc %{ --check-prefix=CHECK-ACC %}
4+
// RUN: %{run} %t.out &> %t.txt ; FileCheck %s --input-file %t.txt %if fpga %{ --check-prefix=CHECK-ACC %}
75
//
86
// CHECK-NOT: One shouldn't see this message
97
// FIXME Windows version prints '(null)' instead of '<unknown func>' once in a

sycl/test-e2e/Assert/assert_in_multiple_tus_one_ndebug_win.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
// https://github.com/intel/llvm/issues/12797
2-
// UNSUPPORTED: windows
31
// REQUIRES: windows
42
// RUN: %clangxx -DSYCL_FALLBACK_ASSERT=1 -fsycl -fsycl-targets=%{sycl_triple} -DDEFINE_NDEBUG_INFILE2 -I %S/Inputs %S/assert_in_multiple_tus.cpp %S/Inputs/kernels_in_file2.cpp -o %t.out
53
// Shouldn't fail on ACC as fallback assert isn't enqueued there
6-
// RUN: %{run} %t.out &> %t.txt ; FileCheck %s --input-file %t.txt %if acc %{ --check-prefix=CHECK-ACC %}
4+
// RUN: %{run} %t.out &> %t.txt ; FileCheck %s --input-file %t.txt %if fpga %{ --check-prefix=CHECK-ACC %}
75
//
86
// CHECK-NOT: this message from calculus
97
// FIXME Windows version prints '(null)' instead of '<unknown func>' once in a

sycl/test-e2e/Assert/assert_in_multiple_tus_win.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
// https://github.com/intel/llvm/issues/12797
2-
// UNSUPPORTED: windows
31
// REQUIRES: windows
42
// RUN: %{build} -DSYCL_FALLBACK_ASSERT=1 -I %S/Inputs %S/Inputs/kernels_in_file2.cpp -o %t.out
53
// Shouldn't fail on ACC as fallback assert isn't enqueued there
6-
// RUN: %{run} %t.out &> %t.txt ; FileCheck %s --input-file %t.txt %if acc %{ --check-prefix=CHECK-ACC %}
4+
// RUN: %{run} %t.out &> %t.txt ; FileCheck %s --input-file %t.txt %if fpga %{ --check-prefix=CHECK-ACC %}
75
//
86
// FIXME Windows version prints '(null)' instead of '<unknown func>' once in a
97
// while for some insane reason.

sycl/test-e2e/Assert/assert_in_one_kernel_win.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
// https://github.com/intel/llvm/issues/12797
2-
// UNSUPPORTED: windows
31
// REQUIRES: windows
42
// RUN: %{build} -DSYCL_FALLBACK_ASSERT=1 -o %t.out
53
// Shouldn't fail on ACC as fallback assert isn't enqueued there
6-
// RUN: %{run} %t.out &> %t.txt ; FileCheck %s --input-file %t.txt %if acc %{ --check-prefix=CHECK-ACC %}
4+
// RUN: %{run} %t.out &> %t.txt ; FileCheck %s --input-file %t.txt %if fpga %{ --check-prefix=CHECK-ACC %}
75
//
86
// FIXME Windows version prints '(null)' instead of '<unknown func>' once in a
97
// while for some insane reason.

sycl/test-e2e/Assert/assert_in_simultaneous_kernels_win.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// https://github.com/intel/llvm/issues/12797
2-
// UNSUPPORTED: windows
31
// REQUIRES: windows
42
// RUN: %{build} -DSYCL_FALLBACK_ASSERT=1 -o %t.out %threads_lib
53
//
@@ -12,7 +10,7 @@
1210
// DEFINE: %{gpu_env} = env SYCL_PI_LEVEL_ZERO_TRACK_INDIRECT_ACCESS_MEMORY=1 SYCL_PI_SUPPRESS_ERROR_MESSAGE=1
1311

1412
// Shouldn't fail on ACC as fallback assert isn't enqueued there
15-
// RUN: %if gpu %{ %{gpu_env} %} %{run} %t.out &> %t.txt ; FileCheck %s --input-file %t.txt %if acc %{ --check-prefix=CHECK-ACC %}
13+
// RUN: %if gpu %{ %{gpu_env} %} %{run} %t.out &> %t.txt ; FileCheck %s --input-file %t.txt %if fpga %{ --check-prefix=CHECK-ACC %}
1614
//
1715
// FIXME Windows version prints '(null)' instead of '<unknown func>' once in a
1816
// while for some insane reason.

sycl/test-e2e/Assert/assert_in_simultaneously_multiple_tus.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
// FIXME: Remove XFAIL one intel/llvm#11364 is resolved
55
// XFAIL: (opencl && gpu)
66
//
7-
// https://github.com/intel/llvm/issues/12797
8-
// UNSUPPORTED: windows
97
//
108
// RUN: %{build} -DSYCL_FALLBACK_ASSERT=1 -I %S/Inputs %S/Inputs/kernels_in_file2.cpp -o %t.out %threads_lib
119
//

sycl/test-e2e/Assert/assert_in_simultaneously_multiple_tus_one_ndebug.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
// FIXME: Remove XFAIL one intel/llvm#11364 is resolved
66
// XFAIL: (opencl && gpu)
77
//
8-
// https://github.com/intel/llvm/issues/12797
9-
// UNSUPPORTED: windows
108
//
119
// RUN: %clangxx -DSYCL_FALLBACK_ASSERT=1 -fsycl -fsycl-targets=%{sycl_triple} -DDEFINE_NDEBUG_INFILE2 -I %S/Inputs %S/assert_in_simultaneously_multiple_tus.cpp %S/Inputs/kernels_in_file2.cpp -o %t.out %threads_lib
1210
// RUN: %if cpu %{ %{run} %t.out &> %t.cpu.txt ; FileCheck %s --input-file %t.cpu.txt %}

sycl/test/include_deps/sycl_accessor.hpp.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
// CHECK-NEXT: detail/boost/mp11/detail/mp_remove_if.hpp
5454
// CHECK-NEXT: detail/boost/mp11/detail/mp_map_find.hpp
5555
// CHECK-NEXT: detail/boost/mp11/detail/mp_with_index.hpp
56+
// CHECK-NEXT: stl_wrappers/cassert
57+
// CHECK-NEXT: stl_wrappers/assert.h
5658
// CHECK-NEXT: detail/boost/mp11/integer_sequence.hpp
5759
// CHECK-NEXT: buffer.hpp
5860
// CHECK-NEXT: backend_types.hpp

sycl/test/include_deps/sycl_buffer.hpp.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@
2222
// CHECK-NEXT: detail/string.hpp
2323
// CHECK-NEXT: ur_api.h
2424
// CHECK-NEXT: detail/common.hpp
25+
// CHECK-NEXT: stl_wrappers/cassert
26+
// CHECK-NEXT: stl_wrappers/assert.h
27+
// CHECK-NEXT: CL/__spirv/spirv_vars.hpp
2528
// CHECK-NEXT: detail/helpers.hpp
2629
// CHECK-NEXT: memory_enums.hpp
27-
// CHECK-NEXT: CL/__spirv/spirv_vars.hpp
2830
// CHECK-NEXT: detail/iostream_proxy.hpp
2931
// CHECK-NEXT: detail/is_device_copyable.hpp
3032
// CHECK-NEXT: detail/owner_less_base.hpp

sycl/test/include_deps/sycl_detail_core.hpp.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454
// CHECK-NEXT: detail/boost/mp11/detail/mp_remove_if.hpp
5555
// CHECK-NEXT: detail/boost/mp11/detail/mp_map_find.hpp
5656
// CHECK-NEXT: detail/boost/mp11/detail/mp_with_index.hpp
57+
// CHECK-NEXT: stl_wrappers/cassert
58+
// CHECK-NEXT: stl_wrappers/assert.h
5759
// CHECK-NEXT: detail/boost/mp11/integer_sequence.hpp
5860
// CHECK-NEXT: buffer.hpp
5961
// CHECK-NEXT: backend_types.hpp

0 commit comments

Comments
 (0)