Skip to content

Commit 9970bc0

Browse files
vmustyaigcbot
authored andcommitted
Support device assertion messages lowering in VC
When a workload emits assertion statement, the compiler should lower it into printf-like routine. NEO runtime provides a separate assert buffer address thru an implicit kernel argument.
1 parent c5e8352 commit 9970bc0

File tree

18 files changed

+270
-116
lines changed

18 files changed

+270
-116
lines changed

IGC/VectorCompiler/CMCL/lib/Headers/cm-cl/detail/builtins.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ __cm_cl_wrregion_float(vector_impl<T, dst_width> dst,
4747
vector_impl<T, src_width> src, int vstride, int width,
4848
int stride, vector_offset_type offset);
4949
// FIXME: For legacy issues 64-bit pointer is always returned.
50+
uint64_t __cm_cl_assert_buffer();
5051
uint64_t __cm_cl_printf_buffer();
5152

5253
int __cm_cl_printf_format_index(__constant const char *str);
@@ -228,8 +229,27 @@ void write_region(vector_impl<T, dst_width> &dst, vector_impl<T, src_width> src,
228229
}
229230
}
230231

232+
struct __assert_buffer_t {
233+
uint32_t size;
234+
uint32_t flags;
235+
uint32_t begin;
236+
};
237+
238+
inline __global uint32_t *assert_flags() {
239+
auto addr = static_cast<uintptr_t>(__cm_cl_assert_buffer());
240+
__global __assert_buffer_t *p =
241+
reinterpret_cast<__global __assert_buffer_t *>(addr);
242+
return &p->flags;
243+
}
244+
245+
inline __global void *assert_buffer() {
246+
auto addr = static_cast<uintptr_t>(__cm_cl_assert_buffer());
247+
__global __assert_buffer_t *p =
248+
reinterpret_cast<__global __assert_buffer_t *>(addr);
249+
return &p->begin;
250+
}
251+
231252
inline __global void *printf_buffer() {
232-
// FIXME: for legacy issues 64-bit pointer is always returned.
233253
auto ptr = static_cast<uintptr_t>(__cm_cl_printf_buffer());
234254
return reinterpret_cast<__global void *>(ptr);
235255
}

IGC/VectorCompiler/CMCL/lib/Support/TranslationDescription.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,16 @@
127127
]
128128
}
129129
},
130+
131+
"AssertBuffer": {
132+
"Name": "assert_buffer",
133+
"Operands": [],
134+
"TranslateInto": {
135+
"VC-Intrinsic": "assert_buffer",
136+
"ReturnType": {"GetBuiltinReturnType": []},
137+
"Operands": []
138+
}
139+
},
130140
"PrintfBuffer": {
131141
"Name": "printf_buffer",
132142
"Operands": [],

IGC/VectorCompiler/igcdeps/include/vc/igcdeps/cmc.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*========================== begin_copyright_notice ============================
22
3-
Copyright (C) 2019-2021 Intel Corporation
3+
Copyright (C) 2019-2023 Intel Corporation
44
55
SPDX-License-Identifier: MIT
66
@@ -100,6 +100,8 @@ class CMKernel {
100100
// Sampler
101101
void createSamplerAnnotation(unsigned argNo, unsigned BTI);
102102

103+
void createAssertBufferArgAnnotation(unsigned Index, unsigned BTI,
104+
unsigned Size, unsigned ArgOffset);
103105
void createPrintfBufferArgAnnotation(unsigned Index, unsigned BTI,
104106
unsigned Size, unsigned ArgOffset);
105107

IGC/VectorCompiler/igcdeps/src/cmc.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*========================== begin_copyright_notice ============================
22
3-
Copyright (C) 2019-2022 Intel Corporation
3+
Copyright (C) 2019-2023 Intel Corporation
44
55
SPDX-License-Identifier: MIT
66
@@ -456,6 +456,15 @@ void CMKernel::createSizeAnnotation(unsigned initPayloadPosition,
456456
iOpenCL::DATA_PARAMETER_DATA_SIZE * 3);
457457
}
458458

459+
void CMKernel::createAssertBufferArgAnnotation(unsigned Index, unsigned BTI,
460+
unsigned Size,
461+
unsigned ArgOffset) {
462+
// EnableZEBinary: ZEBinary related code
463+
zebin::ZEInfoBuilder::addPayloadArgumentImplicit(
464+
m_kernelInfo.m_zePayloadArgs,
465+
zebin::PreDefinedAttrGetter::ArgType::assert_buffer, ArgOffset, Size);
466+
}
467+
459468
void CMKernel::createPrintfBufferArgAnnotation(unsigned Index, unsigned BTI,
460469
unsigned Size,
461470
unsigned ArgOffset) {
@@ -690,6 +699,10 @@ static void setArgumentsInfo(const GenXOCLRuntimeInfo::KernelInfo &Info,
690699
Arg.getAccessKind());
691700
Kernel.m_kernelInfo.m_argIndexMap[Arg.getIndex()] = Arg.getBTI();
692701
break;
702+
case ArgKind::AssertBuffer:
703+
Kernel.createAssertBufferArgAnnotation(Arg.getIndex(), Arg.getBTI(),
704+
Arg.getSizeInBytes(), ArgOffset);
705+
break;
693706
case ArgKind::PrintBuffer:
694707
Kernel.createPrintfBufferArgAnnotation(Arg.getIndex(), Arg.getBTI(),
695708
Arg.getSizeInBytes(), ArgOffset);

IGC/VectorCompiler/include/vc/GenXCodeGen/GenXOCLRuntimeInfo.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*========================== begin_copyright_notice ============================
22
3-
Copyright (C) 2020-2022 Intel Corporation
3+
Copyright (C) 2020-2023 Intel Corporation
44
55
SPDX-License-Identifier: MIT
66
@@ -53,6 +53,7 @@ class GenXOCLRuntimeInfo : public ModulePass {
5353
Image2DArray,
5454
Image2DMediaBlock,
5555
Image3D,
56+
AssertBuffer,
5657
PrintBuffer,
5758
PrivateBase,
5859
ByValSVM,

IGC/VectorCompiler/include/vc/InternalIntrinsics/Intrinsic_definitions.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,16 @@
169169
### Print and assert intrinsics
170170
### ---------------------------
171171

172+
## ``llvm.vc.internal.assert.buffer`` : read stateless pointer to assert buffer
173+
## ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
174+
## ``llvm.vc.internal.assert.buffer`` : read implicit arg print assert ptr
175+
##
176+
## * return value: i64 address of assert buffer
177+
##
178+
"assert_buffer" : { "result" : "long",
179+
"arguments" : [],
180+
"attributes" : "ReadMem", },
181+
172182
## ``llvm.vc.internal.print.buffer`` : read stateless pointer to print buffer
173183
## ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
174184
## ``llvm.vc.internal.print.buffer`` : read implicit arg print buffer ptr

IGC/VectorCompiler/include/vc/Utils/GenX/ImplicitArgsBuffer.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*========================== begin_copyright_notice ============================
22
3-
Copyright (C) 2021 Intel Corporation
3+
Copyright (C) 2021-2023 Intel Corporation
44
55
SPDX-License-Identifier: MIT
66
@@ -69,6 +69,9 @@ enum Enum {
6969
GroupCountX,
7070
GroupCountY,
7171
GroupCountZ,
72+
Padding0,
73+
RtGlobalBufferPtr,
74+
AssertBufferPtr,
7275
Size
7376
};
7477
} // namespace Indices

IGC/VectorCompiler/include/vc/Utils/GenX/KernelInfo.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*========================== begin_copyright_notice ============================
22
3-
Copyright (C) 2017-2022 Intel Corporation
3+
Copyright (C) 2017-2023 Intel Corporation
44
55
SPDX-License-Identifier: MIT
66
@@ -294,7 +294,8 @@ class KernelMetadata {
294294
// payload in memory (for those platforms r0.0 is used to obtain the
295295
// pointer).
296296
IMP_IMPL_ARGS_BUFFER = 0xF << AKBitsForCategory,
297-
IMP_PSEUDO_INPUT = 0x10 << AKBitsForCategory
297+
IMP_PSEUDO_INPUT = 0x10 << AKBitsForCategory,
298+
IMP_OCL_ASSERT_BUFFER = 0x11 << AKBitsForCategory,
298299
};
299300

300301
enum { SKIP_OFFSET_VAL = -1 };
@@ -355,6 +356,10 @@ inline bool isPrintBufferKind(uint32_t ArgKind) {
355356
return isImplicitArgKind(ArgKind, KernelMetadata::IMP_OCL_PRINTF_BUFFER);
356357
}
357358

359+
inline bool isAssertBufferKind(uint32_t ArgKind) {
360+
return isImplicitArgKind(ArgKind, KernelMetadata::IMP_OCL_ASSERT_BUFFER);
361+
}
362+
358363
inline bool isPrivateBaseKind(uint32_t ArgKind) {
359364
return isImplicitArgKind(ArgKind, KernelMetadata::IMP_OCL_PRIVATE_BASE);
360365
}

IGC/VectorCompiler/lib/BiF/printf_not_cm_common.h

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*========================== begin_copyright_notice ============================
22
3-
Copyright (C) 2021 Intel Corporation
3+
Copyright (C) 2021-2023 Intel Corporation
44
55
SPDX-License-Identifier: MIT
66
@@ -60,17 +60,10 @@ inline int calcRequiredBufferSize(vector<int, ArgsInfoVector::Size> ArgsInfo) {
6060
static inline BufferElementTy
6161
getInitialBufferOffset(__global BufferElementTy *BufferPtr,
6262
BufferElementTy RequiredSize) {
63-
#if __clang_major__ > 9
64-
int ByteOffset =
65-
atomic::execute<atomic::operation::add, memory_order_relaxed,
66-
memory_scope_all_devices>(BufferPtr, RequiredSize);
67-
#else // __clang_major__ > 9
68-
// Helping clang-9 correctly deduce the argument type.
6963
int ByteOffset =
7064
atomic::execute<atomic::operation::add, memory_order_relaxed,
7165
memory_scope_all_devices, __global BufferElementTy>(
7266
BufferPtr, RequiredSize);
73-
#endif // __clang_major__ > 9
7467
return ByteOffset / sizeof(BufferElementTy);
7568
}
7669

@@ -111,21 +104,21 @@ generateTransferData(__global BufferElementTy *InitPtr,
111104

112105
// Printf initial routines. The function gets printf buffer and allocates
113106
// space in it. It needs some info about args to allocate enough space.
114-
template <int StringAnnotationSize>
107+
template <int StringAnnotationSize, bool IsAssert = false>
115108
vector<BufferElementTy, TransferDataSize>
116109
printf_init_impl(vector<int, ArgsInfoVector::Size> ArgsInfo) {
110+
using namespace cm::detail;
111+
117112
auto FmtStrSize = ArgsInfo[ArgsInfoVector::FormatStrSize];
118113
if (FmtStrSize > MaxFormatStrSize)
119114
return generateTransferData(/* BufferPtr */ nullptr, /* ReturnValue */ -1);
115+
120116
auto BufferSize = calcRequiredBufferSize<StringAnnotationSize>(ArgsInfo);
121-
#if __clang_major__ > 9
122-
auto *BufferPtr =
123-
static_cast<__global BufferElementTy *>(cm::detail::printf_buffer());
124-
#else // __clang_major__ > 9
125-
// clang-9 cannot handle this auto.
117+
118+
__global auto *BufferAddr = IsAssert ? assert_buffer() : printf_buffer();
126119
__global BufferElementTy *BufferPtr =
127-
static_cast<__global BufferElementTy *>(cm::detail::printf_buffer());
128-
#endif // __clang_major__ > 9
120+
static_cast<__global BufferElementTy *>(BufferAddr);
121+
129122
auto Offset = getInitialBufferOffset(BufferPtr, BufferSize);
130123
return generateTransferData(BufferPtr + Offset, /* ReturnValue */ 0);
131124
}

IGC/VectorCompiler/lib/BiF/printf_ocl_genx.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ printf_arg_str_impl(vector<BufferElementTy, TransferDataSize> TransferData,
5757
return TransferData;
5858
}
5959

60+
extern "C" cl_vector<BufferElementTy, TransferDataSize>
61+
__vc_assert_init(cl_vector<int, ArgsInfoVector::Size> ArgsInfo) {
62+
return printf_init_impl<StringAnnotationSize, true>(ArgsInfo).cl_vector();
63+
}
64+
6065
extern "C" cl_vector<BufferElementTy, TransferDataSize>
6166
__vc_printf_init(cl_vector<int, ArgsInfoVector::Size> ArgsInfo) {
6267
return printf_init_impl<StringAnnotationSize>(ArgsInfo).cl_vector();

IGC/VectorCompiler/lib/BiF/printf_ze_genx.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*========================== begin_copyright_notice ============================
22
3-
Copyright (C) 2021 Intel Corporation
3+
Copyright (C) 2021-2023 Intel Corporation
44
55
SPDX-License-Identifier: MIT
66
@@ -46,6 +46,11 @@ printf_arg_str_impl(vector<BufferElementTy, TransferDataSize> TransferData,
4646
castPointerToVector(String));
4747
}
4848

49+
extern "C" cl_vector<BufferElementTy, TransferDataSize>
50+
__vc_assert_init(cl_vector<int, ArgsInfoVector::Size> ArgsInfo) {
51+
return printf_init_impl<StringAnnotationSize, true>(ArgsInfo).cl_vector();
52+
}
53+
4954
extern "C" cl_vector<BufferElementTy, TransferDataSize>
5055
__vc_printf_init(cl_vector<int, ArgsInfoVector::Size> ArgsInfo) {
5156
return printf_init_impl<StringAnnotationSize>(ArgsInfo).cl_vector();

IGC/VectorCompiler/lib/GenXCodeGen/GenXOCLRuntimeInfo.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ KernelArgBuilder::getOCLArgKind(ArrayRef<StringRef> Tokens,
164164
return ArgKindType::LocalSize;
165165
if (vc::isGroupCountKind(RawKind))
166166
return ArgKindType::GroupCount;
167+
if (vc::isAssertBufferKind(RawKind))
168+
return ArgKindType::AssertBuffer;
167169
if (vc::isPrintBufferKind(RawKind))
168170
return ArgKindType::PrintBuffer;
169171
if (vc::isPrivateBaseKind(RawKind))

IGC/VectorCompiler/lib/GenXOpts/CMTrans/CMImpParam.cpp

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -274,27 +274,29 @@ struct CMImpParam : public ModulePass {
274274
uint32_t MapToKind(unsigned IID) {
275275
using namespace vc;
276276
switch (IID) {
277-
default:
278-
return KernelMetadata::AK_NORMAL;
279-
case vc::InternalIntrinsic::print_buffer:
280-
return KernelMetadata::AK_NORMAL | KernelMetadata::IMP_OCL_PRINTF_BUFFER;
281-
case GenXIntrinsic::genx_local_size:
282-
return KernelMetadata::AK_NORMAL | KernelMetadata::IMP_LOCAL_SIZE;
283-
case GenXIntrinsic::genx_local_id:
284-
case GenXIntrinsic::genx_local_id16:
285-
return KernelMetadata::AK_NORMAL | KernelMetadata::IMP_LOCAL_ID;
286-
case GenXIntrinsic::genx_group_count:
287-
return KernelMetadata::AK_NORMAL | KernelMetadata::IMP_GROUP_COUNT;
288-
case GenXIntrinsic::genx_get_scoreboard_deltas:
289-
return KernelMetadata::AK_NORMAL | KernelMetadata::IMP_SB_DELTAS;
290-
case GenXIntrinsic::genx_get_scoreboard_bti:
291-
return KernelMetadata::AK_SURFACE | KernelMetadata::IMP_SB_BTI;
292-
case GenXIntrinsic::genx_get_scoreboard_depcnt:
293-
return KernelMetadata::AK_SURFACE | KernelMetadata::IMP_SB_DEPCNT;
294-
case PseudoIntrinsic::PrivateBase:
295-
return KernelMetadata::AK_NORMAL | KernelMetadata::IMP_OCL_PRIVATE_BASE;
296-
case PseudoIntrinsic::ImplicitArgsBuffer:
297-
return KernelMetadata::AK_NORMAL | KernelMetadata::IMP_IMPL_ARGS_BUFFER;
277+
default:
278+
return KernelMetadata::AK_NORMAL;
279+
case InternalIntrinsic::assert_buffer:
280+
return KernelMetadata::AK_NORMAL | KernelMetadata::IMP_OCL_ASSERT_BUFFER;
281+
case vc::InternalIntrinsic::print_buffer:
282+
return KernelMetadata::AK_NORMAL | KernelMetadata::IMP_OCL_PRINTF_BUFFER;
283+
case GenXIntrinsic::genx_local_size:
284+
return KernelMetadata::AK_NORMAL | KernelMetadata::IMP_LOCAL_SIZE;
285+
case GenXIntrinsic::genx_local_id:
286+
case GenXIntrinsic::genx_local_id16:
287+
return KernelMetadata::AK_NORMAL | KernelMetadata::IMP_LOCAL_ID;
288+
case GenXIntrinsic::genx_group_count:
289+
return KernelMetadata::AK_NORMAL | KernelMetadata::IMP_GROUP_COUNT;
290+
case GenXIntrinsic::genx_get_scoreboard_deltas:
291+
return KernelMetadata::AK_NORMAL | KernelMetadata::IMP_SB_DELTAS;
292+
case GenXIntrinsic::genx_get_scoreboard_bti:
293+
return KernelMetadata::AK_SURFACE | KernelMetadata::IMP_SB_BTI;
294+
case GenXIntrinsic::genx_get_scoreboard_depcnt:
295+
return KernelMetadata::AK_SURFACE | KernelMetadata::IMP_SB_DEPCNT;
296+
case PseudoIntrinsic::PrivateBase:
297+
return KernelMetadata::AK_NORMAL | KernelMetadata::IMP_OCL_PRIVATE_BASE;
298+
case PseudoIntrinsic::ImplicitArgsBuffer:
299+
return KernelMetadata::AK_NORMAL | KernelMetadata::IMP_IMPL_ARGS_BUFFER;
298300
}
299301
return KernelMetadata::AK_NORMAL;
300302
}
@@ -339,6 +341,7 @@ struct CMImpParam : public ModulePass {
339341

340342
static Type *getIntrinRetType(LLVMContext &Context, unsigned IID) {
341343
switch (IID) {
344+
case vc::InternalIntrinsic::assert_buffer:
342345
case vc::InternalIntrinsic::print_buffer:
343346
case PseudoIntrinsic::PrivateBase:
344347
case PseudoIntrinsic::ImplicitArgsBuffer:
@@ -900,6 +903,7 @@ static bool isImplicitArgIntrinsic(const Function &F, bool IsCMRT) {
900903
case GenXIntrinsic::genx_local_id:
901904
case GenXIntrinsic::genx_local_id16:
902905
case GenXIntrinsic::genx_group_count:
906+
case vc::InternalIntrinsic::assert_buffer:
903907
case vc::InternalIntrinsic::print_buffer:
904908
return true;
905909
case GenXIntrinsic::genx_get_scoreboard_deltas:

IGC/VectorCompiler/lib/GenXOpts/CMTrans/GenXBTIAssignment.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*========================== begin_copyright_notice ============================
22
3-
Copyright (C) 2021 Intel Corporation
3+
Copyright (C) 2021-2023 Intel Corporation
44
55
SPDX-License-Identifier: MIT
66
@@ -188,6 +188,10 @@ int BTIAssignment::assignUAV(int SurfaceID, ZipTy &&Zippy) {
188188
Idx = StatelessBti;
189189
continue;
190190
}
191+
if (Kind & vc::KernelMetadata::IMP_OCL_ASSERT_BUFFER) {
192+
Idx = StatelessBti;
193+
continue;
194+
}
191195
}
192196
return SurfaceID;
193197
}

0 commit comments

Comments
 (0)