Skip to content

Commit d8fd116

Browse files
kychendevigcbot
authored andcommitted
Add VC BiF support for rnde.
Add roundne function to CMCL math library and builtin translation support for SPIR-V.
1 parent fadd220 commit d8fd116

File tree

4 files changed

+35
-3
lines changed

4 files changed

+35
-3
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ template <typename T> T __cm_cl_abs_float(T src);
8585
template <typename T> T __cm_cl_ceil(T src);
8686
template <typename T> T __cm_cl_floor(T src);
8787
template <typename T> T __cm_cl_trunc(T src);
88+
template <typename T> T __cm_cl_roundne(T src);
8889

8990
template <typename T> T __cm_cl_minnum(T src0, T src1);
9091
template <typename T> T __cm_cl_maxnum(T src0, T src1);
@@ -336,6 +337,12 @@ template <typename T> T trunc(T src) {
336337
return __cm_cl_trunc(src);
337338
}
338339

340+
template <typename T> T roundne(T src) {
341+
static_assert(cl::is_floating_point<T>::value,
342+
"Roundne function expects floating poing type.");
343+
return __cm_cl_roundne(src);
344+
}
345+
339346
template <typename T> T min_float(T src0, T src1) {
340347
static_assert(cl::is_floating_point<T>::value,
341348
"illegal type provided in min_float");

IGC/VectorCompiler/CMCL/lib/Headers/cm-cl/math.h

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-2022 Intel Corporation
44
55
SPDX-License-Identifier: MIT
66
@@ -234,6 +234,11 @@ vector<T, width> truncate(vector<T, width> src) {
234234
return detail::trunc(src.cl_vector());
235235
}
236236

237+
template <typename T> T roundne(T src) { return detail::roundne(src); }
238+
template <typename T, int width> vector<T, width> roundne(vector<T, width> src) {
239+
return detail::roundne(src.cl_vector());
240+
}
241+
237242
/*================== Square root ===========================*/
238243

239244
template <typename T> T square_root(T src) {

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"copyright": [
33
"============================ begin_copyright_notice ============================",
44
"",
5-
"Copyright (C) 2021 Intel Corporation",
5+
"Copyright (C) 2021-2022 Intel Corporation",
66
"",
77
"SPDX-License-Identifier: MIT",
88
"",
@@ -412,6 +412,19 @@
412412
]
413413
}
414414
},
415+
"Roundne": {
416+
"Name": "roundne",
417+
"Operands": [
418+
{"Name": "Source", "Kind": "Input"}
419+
],
420+
"TranslateInto": {
421+
"VC-Intrinsic": "genx_rnde",
422+
"ReturnType": {"GetBuiltinReturnType": []},
423+
"Operands": [
424+
{"GetBuiltinOperand": ["Source"]}
425+
]
426+
}
427+
},
415428
"Sqrt": {
416429
"Name": "sqrt",
417430
"Operands": [

IGC/VectorCompiler/lib/BiF/spirv_math_builtins_genx.cpp

Lines changed: 8 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-2022 Intel Corporation
44
55
SPDX-License-Identifier: MIT
66
@@ -376,6 +376,7 @@ SPIRV_MATH_BUILTIN_DECL_1ARG_SCALAR_CUSTOM(popcount, ulong,
376376
SPIRV_MATH_BUILTIN_DECL_1ARG_SCALAR_CUSTOM(ceil, float, cm::math::ceil)
377377
SPIRV_MATH_BUILTIN_DECL_1ARG_SCALAR_CUSTOM(floor, float, cm::math::floor)
378378
SPIRV_MATH_BUILTIN_DECL_1ARG_SCALAR_CUSTOM(trunc, float, cm::math::truncate)
379+
SPIRV_MATH_BUILTIN_DECL_1ARG_SCALAR_CUSTOM(roundne, float, cm::math::roundne)
379380

380381
SPIRV_MATH_BUILTIN_DECL_1ARG_SCALAR_CUSTOM(s_abs, char, cm::math::absolute)
381382
SPIRV_MATH_BUILTIN_DECL_1ARG_SCALAR_CUSTOM(s_abs, short, cm::math::absolute)
@@ -677,6 +678,12 @@ SPIRV_MATH_BUILTIN_DECL_1ARG_VECTOR_CUSTOM(trunc, float, 4, cm::math::truncate)
677678
SPIRV_MATH_BUILTIN_DECL_1ARG_VECTOR_CUSTOM(trunc, float, 8, cm::math::truncate)
678679
SPIRV_MATH_BUILTIN_DECL_1ARG_VECTOR_CUSTOM(trunc, float, 16, cm::math::truncate)
679680

681+
SPIRV_MATH_BUILTIN_DECL_1ARG_VECTOR_CUSTOM(roundne, float, 2, cm::math::roundne)
682+
SPIRV_MATH_BUILTIN_DECL_1ARG_VECTOR_CUSTOM(roundne, float, 3, cm::math::roundne)
683+
SPIRV_MATH_BUILTIN_DECL_1ARG_VECTOR_CUSTOM(roundne, float, 4, cm::math::roundne)
684+
SPIRV_MATH_BUILTIN_DECL_1ARG_VECTOR_CUSTOM(roundne, float, 8, cm::math::roundne)
685+
SPIRV_MATH_BUILTIN_DECL_1ARG_VECTOR_CUSTOM(roundne, float, 16, cm::math::roundne)
686+
680687
#define SPIRV_MATH_BUILTIN_DECL_2ARG_VECTOR_CUSTOM(FUNC_NAME, ELEMENT_TYPE, N, \
681688
CUSTOM_NAME) \
682689
CM_NODEBUG CM_INLINE cl_vector<ELEMENT_TYPE, N> __spirv_ocl_##FUNC_NAME( \

0 commit comments

Comments
 (0)