Skip to content

Commit 9370549

Browse files
authored
[SYCL][CUDA] libdevice: add builtins (#1827)
Add some scalar math builtins to ptx/libdevice: - acos - asin - atan - cbrt - ceil - cos - erf - fabs - floor - fmax - fmin - lgamma - sqrt sycl/test/built-ins/scalar_math.cpp test is split in two parts: scalar_math.cpp -> supported by cuda (no xfail) scalar_math_2.cpp -> unsupported ## Missing float builtins: atan2 copysign fdim fma for these it fails with Unresolved extern function '_Z15__spirv_ocl_fmafff' ## Integer Builtins -> need to make something similar too binary_builtin.inc for uint, int, long, ulong ## Geometry Functions -> these aren't within _nv*. Maybe there is a way to reuse generic functions for these? Signed-off-by: hiaselhans <[email protected]>
1 parent f024b4b commit 9370549

File tree

19 files changed

+499
-226
lines changed

19 files changed

+499
-226
lines changed

libclc/ptx-nvidiacl/include/libdevice.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,32 @@
3535
__LIBDEVICE_BINARY_BUILTIN_F(BUILTIN) \
3636
__LIBDEVICE_BINARY_BUILTIN_D(BUILTIN)
3737

38+
__LIBDEVICE_UNARY_BUILTIN(acos)
39+
__LIBDEVICE_UNARY_BUILTIN(acosh)
40+
__LIBDEVICE_UNARY_BUILTIN(asin)
41+
__LIBDEVICE_UNARY_BUILTIN(asinh)
42+
__LIBDEVICE_UNARY_BUILTIN(atan)
43+
__LIBDEVICE_UNARY_BUILTIN(atanh)
44+
__LIBDEVICE_UNARY_BUILTIN(cbrt)
45+
__LIBDEVICE_UNARY_BUILTIN(ceil)
46+
__LIBDEVICE_UNARY_BUILTIN(cos)
47+
__LIBDEVICE_UNARY_BUILTIN(cosh)
48+
__LIBDEVICE_UNARY_BUILTIN(cospi)
49+
__LIBDEVICE_UNARY_BUILTIN(erf)
50+
__LIBDEVICE_UNARY_BUILTIN(erfc)
3851
__LIBDEVICE_UNARY_BUILTIN(exp)
3952
__LIBDEVICE_UNARY_BUILTIN(exp2)
4053
__LIBDEVICE_UNARY_BUILTIN(exp10)
4154
__LIBDEVICE_UNARY_BUILTIN(expm1)
55+
__LIBDEVICE_UNARY_BUILTIN(fabs)
56+
__LIBDEVICE_UNARY_BUILTIN(floor)
4257
__LIBDEVICE_UNARY_BUILTIN_F(fast_exp)
4358
__LIBDEVICE_UNARY_BUILTIN_F(fast_exp10)
59+
__LIBDEVICE_UNARY_BUILTIN(lgamma)
60+
__LIBDEVICE_UNARY_BUILTIN(sqrt)
4461

62+
__LIBDEVICE_BINARY_BUILTIN(fmax)
63+
__LIBDEVICE_BINARY_BUILTIN(fmin)
4564
__LIBDEVICE_BINARY_BUILTIN(fmod)
4665

4766
#endif

libclc/ptx-nvidiacl/libspirv/SOURCES

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,24 @@ workitem/get_group_id.cl
88
workitem/get_local_id.cl
99
workitem/get_local_size.cl
1010
workitem/get_num_groups.cl
11+
math/acos.cl
12+
math/asin.cl
13+
math/atan.cl
14+
math/cbrt.cl
15+
math/ceil.cl
16+
math/cos.cl
17+
math/erf.cl
1118
math/exp.cl
1219
math/exp10.cl
1320
math/exp2.cl
1421
math/expm1.cl
22+
math/fabs.cl
23+
math/floor.cl
24+
math/fmax.cl
25+
math/fmin.cl
1526
math/fmod.cl
27+
math/lgamma.cl
1628
math/native_exp.cl
1729
math/native_exp10.cl
1830
math/native_exp2.cl
31+
math/sqrt.cl
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===----------------------------------------------------------------------===//
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+
#include "../../../generic/lib/clcmacro.h"
10+
#include "../../include/libdevice.h"
11+
#include <spirv/spirv.h>
12+
13+
#define __CLC_FUNCTION __spirv_ocl_acos
14+
#define __CLC_BUILTIN __nv_acos
15+
#include "unary_builtin.inc"
16+
17+
#define __CLC_FUNCTION __spirv_ocl_acosh
18+
#define __CLC_BUILTIN __nv_acosh
19+
#include "unary_builtin.inc"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===----------------------------------------------------------------------===//
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+
#include "../../../generic/lib/clcmacro.h"
10+
#include "../../include/libdevice.h"
11+
#include <spirv/spirv.h>
12+
13+
#define __CLC_FUNCTION __spirv_ocl_asin
14+
#define __CLC_BUILTIN __nv_asin
15+
#include "unary_builtin.inc"
16+
17+
#define __CLC_FUNCTION __spirv_ocl_asinh
18+
#define __CLC_BUILTIN __nv_asinh
19+
#include "unary_builtin.inc"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===----------------------------------------------------------------------===//
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+
#include "../../../generic/lib/clcmacro.h"
10+
#include "../../include/libdevice.h"
11+
#include <spirv/spirv.h>
12+
13+
#define __CLC_FUNCTION __spirv_ocl_atan
14+
#define __CLC_BUILTIN __nv_atan
15+
#include "unary_builtin.inc"
16+
17+
#define __CLC_FUNCTION __spirv_ocl_atanh
18+
#define __CLC_BUILTIN __nv_atanh
19+
#include "unary_builtin.inc"

libclc/ptx-nvidiacl/libspirv/math/binary_builtin.inc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,7 @@ _CLC_DEFINE_BINARY_BUILTIN(half, __CLC_FUNCTION, __CLC_BUILTIN, half, half)
3535
#endif
3636

3737
#endif
38+
39+
#undef __CLC_BUILTIN
40+
#undef __CLC_BUILTIN_F
41+
#undef __CLC_FUNCTION
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//===----------------------------------------------------------------------===//
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+
#include "../../../generic/lib/clcmacro.h"
10+
#include "../../include/libdevice.h"
11+
#include <spirv/spirv.h>
12+
13+
#define __CLC_FUNCTION __spirv_ocl_cbrt
14+
#define __CLC_BUILTIN __nv_cbrt
15+
#include "unary_builtin.inc"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//===----------------------------------------------------------------------===//
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+
#include "../../../generic/lib/clcmacro.h"
10+
#include "../../include/libdevice.h"
11+
#include <spirv/spirv.h>
12+
13+
#define __CLC_FUNCTION __spirv_ocl_ceil
14+
#define __CLC_BUILTIN __nv_ceil
15+
#include "unary_builtin.inc"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===----------------------------------------------------------------------===//
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+
#include "../../../generic/lib/clcmacro.h"
10+
#include "../../include/libdevice.h"
11+
#include <spirv/spirv.h>
12+
13+
#define __CLC_FUNCTION __spirv_ocl_cos
14+
#define __CLC_BUILTIN __nv_cos
15+
#include "unary_builtin.inc"
16+
17+
#define __CLC_FUNCTION __spirv_ocl_cosh
18+
#define __CLC_BUILTIN __nv_cosh
19+
#include "unary_builtin.inc"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===----------------------------------------------------------------------===//
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+
#include "../../../generic/lib/clcmacro.h"
10+
#include "../../include/libdevice.h"
11+
#include <spirv/spirv.h>
12+
13+
#define __CLC_FUNCTION __spirv_ocl_erf
14+
#define __CLC_BUILTIN __nv_erf
15+
#include "unary_builtin.inc"
16+
17+
#define __CLC_FUNCTION __spirv_ocl_erfc
18+
#define __CLC_BUILTIN __nv_erfc
19+
#include "unary_builtin.inc"

0 commit comments

Comments
 (0)