Skip to content

Commit f6052be

Browse files
Naghasandavidtwco
andcommitted
[SYCL-PTX] Refactor of libclc sources in preparation of math builtins category implementation
The patch moves some include files from libs to include so they can be shared with libspirv side. Refactor the ptx-nvidiacl side as well and move the following builtins in their own file to avoid symbol redefinition: - acosh - asinh - atanh - cosh - erfc Signed-off-by: Victor Lomuller <[email protected]> Co-authored-by: David Wood <[email protected]>
1 parent d4e7929 commit f6052be

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+452
-349
lines changed

libclc/generic/include/clcmacro.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
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+
#ifndef __CLC_MACRO_H
10+
#define __CLC_MACRO_H
11+
112
#define _CLC_UNARY_VECTORIZE(DECLSPEC, RET_TYPE, FUNCTION, ARG1_TYPE) \
213
DECLSPEC RET_TYPE##2 FUNCTION(ARG1_TYPE##2 x) { \
314
return (RET_TYPE##2)(FUNCTION(x.x), FUNCTION(x.y)); \
@@ -177,3 +188,5 @@
177188
#define _CLC_DEFINE_UNARY_BUILTIN(RET_TYPE, FUNCTION, BUILTIN, ARG1_TYPE) \
178189
_CLC_DEF _CLC_OVERLOAD RET_TYPE FUNCTION(ARG1_TYPE x) { return BUILTIN(x); } \
179190
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, RET_TYPE, FUNCTION, ARG1_TYPE)
191+
192+
#endif // !__CLC_MACRO_H

libclc/ptx-nvidiacl/libspirv/math/binary_builtin.inc renamed to libclc/generic/include/math/binary_builtin.inc

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,23 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include "../../../generic/lib/clcmacro.h"
109
#include "utils.h"
10+
#include <clcmacro.h>
11+
12+
#ifndef __CLC_BUILTIN
13+
#define __CLC_BUILTIN __CLC_XCONCAT(__clc_, __CLC_FUNCTION)
14+
#endif
15+
16+
#ifndef __CLC_BUILTIN_D
17+
#define __CLC_BUILTIN_D __CLC_BUILTIN
18+
#endif
1119

1220
#ifndef __CLC_BUILTIN_F
13-
#define __CLC_BUILTIN_F __CLC_XCONCAT(__CLC_BUILTIN, f)
21+
#define __CLC_BUILTIN_F __CLC_BUILTIN
22+
#endif
23+
24+
#ifndef __CLC_BUILTIN_H
25+
#define __CLC_BUILTIN_H __CLC_BUILTIN_F
1426
#endif
1527

1628
_CLC_DEFINE_BINARY_BUILTIN(float, __CLC_FUNCTION, __CLC_BUILTIN_F, float, float)
@@ -21,7 +33,7 @@ _CLC_DEFINE_BINARY_BUILTIN(float, __CLC_FUNCTION, __CLC_BUILTIN_F, float, float)
2133

2234
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
2335

24-
_CLC_DEFINE_BINARY_BUILTIN(double, __CLC_FUNCTION, __CLC_BUILTIN, double,
36+
_CLC_DEFINE_BINARY_BUILTIN(double, __CLC_FUNCTION, __CLC_BUILTIN_D, double,
2537
double)
2638

2739
#endif
@@ -30,12 +42,8 @@ _CLC_DEFINE_BINARY_BUILTIN(double, __CLC_FUNCTION, __CLC_BUILTIN, double,
3042

3143
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
3244

33-
_CLC_DEFINE_BINARY_BUILTIN(half, __CLC_FUNCTION, __CLC_BUILTIN, half, half)
45+
_CLC_DEFINE_BINARY_BUILTIN(half, __CLC_FUNCTION, __CLC_BUILTIN_H, half, half)
3446

3547
#endif
3648

3749
#endif
38-
39-
#undef __CLC_BUILTIN
40-
#undef __CLC_BUILTIN_F
41-
#undef __CLC_FUNCTION

libclc/generic/include/math/math.h

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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+
#ifndef __CLC_MATH_H_
10+
#define __CLC_MATH_H_
11+
12+
#include "as_type.h"
13+
#include "config.h"
14+
#include "func.h"
15+
16+
#define SNAN 0x001
17+
#define QNAN 0x002
18+
#define NINF 0x004
19+
#define NNOR 0x008
20+
#define NSUB 0x010
21+
#define NZER 0x020
22+
#define PZER 0x040
23+
#define PSUB 0x080
24+
#define PNOR 0x100
25+
#define PINF 0x200
26+
27+
#if (defined __AMDGCN__ || defined __R600__) && !defined __HAS_FMAF__
28+
#define HAVE_HW_FMA32() (0)
29+
#else
30+
#define HAVE_HW_FMA32() (1)
31+
#endif
32+
33+
#define HAVE_BITALIGN() (0)
34+
#define HAVE_FAST_FMA32() (0)
35+
36+
#define MATH_DIVIDE(X, Y) ((X) / (Y))
37+
#define MATH_RECIP(X) (1.0f / (X))
38+
#define MATH_SQRT(X) __spirv_ocl_sqrt(X)
39+
40+
#define SIGNBIT_SP32 0x80000000
41+
#define EXSIGNBIT_SP32 0x7fffffff
42+
#define EXPBITS_SP32 0x7f800000
43+
#define MANTBITS_SP32 0x007fffff
44+
#define ONEEXPBITS_SP32 0x3f800000
45+
#define TWOEXPBITS_SP32 0x40000000
46+
#define HALFEXPBITS_SP32 0x3f000000
47+
#define IMPBIT_SP32 0x00800000
48+
#define QNANBITPATT_SP32 0x7fc00000
49+
#define INDEFBITPATT_SP32 0xffc00000
50+
#define PINFBITPATT_SP32 0x7f800000
51+
#define NINFBITPATT_SP32 0xff800000
52+
#define EXPBIAS_SP32 127
53+
#define EXPSHIFTBITS_SP32 23
54+
#define BIASEDEMIN_SP32 1
55+
#define EMIN_SP32 -126
56+
#define BIASEDEMAX_SP32 254
57+
#define EMAX_SP32 127
58+
#define LAMBDA_SP32 1.0e30
59+
#define MANTLENGTH_SP32 24
60+
#define BASEDIGITS_SP32 7
61+
62+
_CLC_OVERLOAD _CLC_INLINE float __clc_flush_denormal_if_not_supported(float x) {
63+
int ix = as_int(x);
64+
if (!__clc_fp32_subnormals_supported() && ((ix & EXPBITS_SP32) == 0) &&
65+
((ix & MANTBITS_SP32) != 0)) {
66+
ix &= SIGNBIT_SP32;
67+
x = as_float(ix);
68+
}
69+
return x;
70+
}
71+
72+
#ifdef cl_khr_fp64
73+
74+
#define SIGNBIT_DP64 0x8000000000000000L
75+
#define EXSIGNBIT_DP64 0x7fffffffffffffffL
76+
#define EXPBITS_DP64 0x7ff0000000000000L
77+
#define MANTBITS_DP64 0x000fffffffffffffL
78+
#define ONEEXPBITS_DP64 0x3ff0000000000000L
79+
#define TWOEXPBITS_DP64 0x4000000000000000L
80+
#define HALFEXPBITS_DP64 0x3fe0000000000000L
81+
#define IMPBIT_DP64 0x0010000000000000L
82+
#define QNANBITPATT_DP64 0x7ff8000000000000L
83+
#define INDEFBITPATT_DP64 0xfff8000000000000L
84+
#define PINFBITPATT_DP64 0x7ff0000000000000L
85+
#define NINFBITPATT_DP64 0xfff0000000000000L
86+
#define EXPBIAS_DP64 1023
87+
#define EXPSHIFTBITS_DP64 52
88+
#define BIASEDEMIN_DP64 1
89+
#define EMIN_DP64 -1022
90+
#define BIASEDEMAX_DP64 2046 /* 0x7fe */
91+
#define EMAX_DP64 1023 /* 0x3ff */
92+
#define LAMBDA_DP64 1.0e300
93+
#define MANTLENGTH_DP64 53
94+
#define BASEDIGITS_DP64 15
95+
96+
#endif // cl_khr_fp64
97+
98+
#define ALIGNED(x) __attribute__((aligned(x)))
99+
#endif // __CLC_MATH_H_

libclc/ptx-nvidiacl/libspirv/math/unary_builtin.inc renamed to libclc/generic/include/math/unary_builtin.inc

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,23 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include "../../../generic/lib/clcmacro.h"
109
#include "utils.h"
10+
#include <clcmacro.h>
11+
12+
#ifndef __CLC_BUILTIN
13+
#define __CLC_BUILTIN __CLC_XCONCAT(__clc_, __CLC_FUNCTION)
14+
#endif
15+
16+
#ifndef __CLC_BUILTIN_D
17+
#define __CLC_BUILTIN_D __CLC_BUILTIN
18+
#endif
1119

1220
#ifndef __CLC_BUILTIN_F
13-
#define __CLC_BUILTIN_F __CLC_XCONCAT(__CLC_BUILTIN, f)
21+
#define __CLC_BUILTIN_F __CLC_BUILTIN
22+
#endif
23+
24+
#ifndef __CLC_BUILTIN_H
25+
#define __CLC_BUILTIN_H __CLC_BUILTIN_F
1426
#endif
1527

1628
_CLC_DEFINE_UNARY_BUILTIN(float, __CLC_FUNCTION, __CLC_BUILTIN_F, float)
@@ -21,20 +33,16 @@ _CLC_DEFINE_UNARY_BUILTIN(float, __CLC_FUNCTION, __CLC_BUILTIN_F, float)
2133

2234
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
2335

24-
_CLC_DEFINE_UNARY_BUILTIN(double, __CLC_FUNCTION, __CLC_BUILTIN, double)
36+
_CLC_DEFINE_UNARY_BUILTIN(double, __CLC_FUNCTION, __CLC_BUILTIN_D, double)
2537

2638
#endif
2739

2840
#ifdef cl_khr_fp16
2941

3042
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
3143

32-
_CLC_DEFINE_UNARY_BUILTIN(half, __CLC_FUNCTION, __CLC_BUILTIN, half)
33-
34-
#endif
44+
_CLC_DEFINE_UNARY_BUILTIN(half, __CLC_FUNCTION, __CLC_BUILTIN_H, half)
3545

3646
#endif
3747

38-
#undef __CLC_BUILTIN
39-
#undef __CLC_BUILTIN_F
40-
#undef __CLC_FUNCTION
48+
#endif // !__FLOAT_ONLY

libclc/generic/lib/clcmacro.h

Lines changed: 0 additions & 163 deletions
This file was deleted.

libclc/generic/lib/clcmacro.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../include/clcmacro.h

libclc/generic/lib/common/degrees.cl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include <clc/clc.h>
2424
#include <spirv/spirv.h>
2525

26-
#include "../clcmacro.h"
26+
#include <clcmacro.h>
2727

2828
_CLC_OVERLOAD _CLC_DEF float degrees(float radians) {
2929
return __spirv_ocl_degrees(radians);

0 commit comments

Comments
 (0)