Skip to content

Commit cc078cf

Browse files
PawelJurekigcbot
authored andcommitted
__devicelib_assert_fail implementation
This is a DPCPP device library extension described in https://github.com/triSYCL/sycl/blob/sycl/unified/master/sycl/doc/design/Assert.md DPCPP assert(expr) macro ends up in call to __devicelib_assert_fail. Per design, the implementation needs to: 1. Write "1" to flag field in the assert buffer header. The buffer header is defined below. 2. Print the assert message to assert buffer. This is done in a similar fashion as "printf". __builtin_IB_printf_to_buffer builtin function is used for this purpose - it basically wraps the printf functionality to a buffer provided as an argument. 3. Trigger a software exception by setting appropriate Control Register bits. This is done by __builtin_IB_software_exception builtin. 4. We need to ensure that all stores in this function are uncached. This is handled by NontemporalLoadsAndStoresInAssert pass.
1 parent c3c66fe commit cc078cf

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

IGC/BiFModule/Implementation/IBiF_Impl.cl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,8 @@ SPDX-License-Identifier: MIT
110110
// Tile ID Extension Opcodes
111111
//*****************************************************************************/
112112
#include "tileid.cl"
113+
114+
//*****************************************************************************/
115+
// Assert implementation
116+
//*****************************************************************************/
117+
#include "assert.cl"
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*========================== begin_copyright_notice ============================
2+
3+
Copyright (C) 2023 Intel Corporation
4+
5+
SPDX-License-Identifier: MIT
6+
7+
============================= end_copyright_notice ===========================*/
8+
9+
// __devicelib_assert_fail implementation.
10+
// This is a DPCPP device library extension described in
11+
// https://github.com/triSYCL/sycl/blob/sycl/unified/master/sycl/doc/design/Assert.md
12+
// DPCPP assert(expr) macro ends up in call to __devicelib_assert_fail.
13+
// Per design, the implementation needs to:
14+
// 1. Write "1" to flag field in the assert buffer header. The buffer header is defined below.
15+
// 2. Print the assert message to assert buffer. This is done in a similar fashion as "printf".
16+
// __builtin_IB_printf_to_buffer builtin function is used for this purpose - it basically wraps
17+
// the printf functionality to a buffer provided as an argument.
18+
// 3. Trigger a software exception by setting appropriate Control Register bits.
19+
// This is done by __builtin_IB_software_exception builtin.
20+
// 4. We need to ensure that all stores in this function are uncached.
21+
// This is handled by NontemporalLoadsAndStoresInAssert pass.
22+
23+
#include "IBiF_Header.cl"
24+
25+
__global volatile uchar* __builtin_IB_get_assert_buffer();
26+
void __builtin_IB_software_exception();
27+
int __builtin_IB_printf_to_buffer(global char* buf, global char* currentOffset, int bufSize, ...);
28+
29+
typedef struct {
30+
int size;
31+
int flag;
32+
int begin;
33+
} AssertBufferHeader;
34+
35+
void __devicelib_assert_fail(char *expr, char *file, int line, char *func, long gid0, long gid1, long gid2, long lid0, long lid1, long lid2) {
36+
AssertBufferHeader* header = (AssertBufferHeader*) __builtin_IB_get_assert_buffer();
37+
header->flag = 1;
38+
global char* buf = (global char*) header;
39+
__builtin_IB_printf_to_buffer(buf, buf + 8, header->size, "%s:%d: %s: global id: [%lu,%lu,%lu], local id: [%lu,%lu,%lu] Assertion `%s` failed", file, line, func, gid0, gid1, gid2, lid0, lid1, lid2, expr);
40+
__builtin_IB_software_exception();
41+
}

0 commit comments

Comments
 (0)