Skip to content

Commit 12cec43

Browse files
authored
[libclc] Implement clc_log/sinpi/sqrt with __nv_* functions (#150174)
This is to upstream implementations in https://github.com/intel/llvm/tree/sycl/libclc/clc/lib/ptx-nvidiacl/math
1 parent 1f86deb commit 12cec43

File tree

7 files changed

+180
-0
lines changed

7 files changed

+180
-0
lines changed

libclc/clc/include/clc/math/gentype.inc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
#define __CLC_U_GENTYPE __CLC_XCONCAT(uint, __CLC_VECSIZE)
8181

8282
#define __CLC_GENTYPE float
83+
#define __CLC_BIT_INT int
8384
#define __CLC_BIT_INTN int
8485
#define __CLC_SCALAR
8586
#define __CLC_VECSIZE
@@ -131,6 +132,7 @@
131132
#include __CLC_BODY
132133
#undef __CLC_VECSIZE
133134
#undef __CLC_GENTYPE
135+
#undef __CLC_BIT_INT
134136
#undef __CLC_BIT_INTN
135137

136138
#undef __CLC_VECSIZE_OR_1
@@ -159,6 +161,7 @@
159161
#define __CLC_VECSIZE
160162
#define __CLC_VECSIZE_OR_1 1
161163
#define __CLC_GENTYPE double
164+
#define __CLC_BIT_INT long
162165
#define __CLC_BIT_INTN long
163166
#include __CLC_BODY
164167
#undef __CLC_VECSIZE_OR_1
@@ -207,6 +210,7 @@
207210
#include __CLC_BODY
208211
#undef __CLC_VECSIZE
209212
#undef __CLC_GENTYPE
213+
#undef __CLC_BIT_INT
210214
#undef __CLC_BIT_INTN
211215

212216
#undef __CLC_VECSIZE_OR_1
@@ -235,6 +239,7 @@
235239
#define __CLC_VECSIZE
236240
#define __CLC_VECSIZE_OR_1 1
237241
#define __CLC_GENTYPE half
242+
#define __CLC_BIT_INT short
238243
#define __CLC_BIT_INTN short
239244
#include __CLC_BODY
240245
#undef __CLC_GENTYPE
@@ -283,6 +288,7 @@
283288
#include __CLC_BODY
284289
#undef __CLC_VECSIZE
285290
#undef __CLC_GENTYPE
291+
#undef __CLC_BIT_INT
286292
#undef __CLC_BIT_INTN
287293

288294
#undef __CLC_VECSIZE_OR_1

libclc/clc/lib/ptx-nvidiacl/SOURCES

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
math/clc_log.cl
2+
math/clc_rsqrt.cl
3+
math/clc_sinpi.cl
4+
math/clc_sqrt.cl
15
mem_fence/clc_mem_fence.cl
26
synchronization/clc_work_group_barrier.cl
37
workitem/clc_get_global_id.cl
@@ -7,3 +11,4 @@ workitem/clc_get_local_size.cl
711
workitem/clc_get_max_sub_group_size.cl
812
workitem/clc_get_num_groups.cl
913
workitem/clc_get_sub_group_local_id.cl
14+
relational/clc_isinf.cl
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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 <clc/math/clc_log.h>
10+
11+
float __nv_logf(float);
12+
double __nv_log(double);
13+
14+
_CLC_OVERLOAD _CLC_DEF float __clc_log(float x) { return __nv_logf(x); }
15+
16+
#ifdef cl_khr_fp64
17+
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
18+
19+
_CLC_OVERLOAD _CLC_DEF double __clc_log(double x) { return __nv_log(x); }
20+
21+
#endif
22+
23+
#ifdef cl_khr_fp16
24+
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
25+
26+
_CLC_OVERLOAD _CLC_DEF half __clc_log(half x) {
27+
return (half)__clc_log((float)x);
28+
}
29+
30+
#endif
31+
32+
#define FUNCTION __clc_log
33+
#define __CLC_BODY <clc/shared/unary_def_scalarize.inc>
34+
#include <clc/math/gentype.inc>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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 <clc/math/clc_rsqrt.h>
10+
11+
float __nv_rsqrtf(float);
12+
double __nv_rsqrt(double);
13+
14+
_CLC_OVERLOAD _CLC_DEF float __clc_rsqrt(float x) { return __nv_rsqrtf(x); }
15+
16+
#ifdef cl_khr_fp64
17+
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
18+
19+
_CLC_OVERLOAD _CLC_DEF double __clc_rsqrt(double x) { return __nv_rsqrt(x); }
20+
21+
#endif
22+
23+
#ifdef cl_khr_fp16
24+
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
25+
26+
_CLC_OVERLOAD _CLC_DEF half __clc_rsqrt(half x) {
27+
return (half)__clc_rsqrt((float)x);
28+
}
29+
30+
#endif
31+
32+
#define FUNCTION __clc_rsqrt
33+
#define __CLC_BODY <clc/shared/unary_def_scalarize.inc>
34+
#include <clc/math/gentype.inc>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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 <clc/math/clc_sinpi.h>
10+
11+
float __nv_sinpif(float);
12+
double __nv_sinpi(double);
13+
14+
_CLC_OVERLOAD _CLC_DEF float __clc_sinpi(float x) { return __nv_sinpif(x); }
15+
16+
#ifdef cl_khr_fp64
17+
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
18+
19+
_CLC_OVERLOAD _CLC_DEF double __clc_sinpi(double x) { return __nv_sinpi(x); }
20+
21+
#endif
22+
23+
#ifdef cl_khr_fp16
24+
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
25+
26+
_CLC_OVERLOAD _CLC_DEF half __clc_sinpi(half x) {
27+
return (half)__clc_sinpi((float)x);
28+
}
29+
30+
#endif
31+
32+
#define FUNCTION __clc_sinpi
33+
#define __CLC_BODY <clc/shared/unary_def_scalarize.inc>
34+
#include <clc/math/gentype.inc>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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 <clc/math/clc_sqrt.h>
10+
11+
float __nv_sqrtf(float);
12+
double __nv_sqrt(double);
13+
14+
_CLC_OVERLOAD _CLC_DEF float __clc_sqrt(float x) { return __nv_sqrtf(x); }
15+
16+
#ifdef cl_khr_fp64
17+
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
18+
19+
_CLC_OVERLOAD _CLC_DEF double __clc_sqrt(double x) { return __nv_sqrt(x); }
20+
21+
#endif
22+
23+
#ifdef cl_khr_fp16
24+
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
25+
26+
_CLC_OVERLOAD _CLC_DEF half __clc_sqrt(half x) {
27+
return (half)__clc_sqrt((float)x);
28+
}
29+
30+
#endif
31+
32+
#define FUNCTION __clc_sqrt
33+
#define __CLC_BODY <clc/shared/unary_def_scalarize.inc>
34+
#include <clc/math/gentype.inc>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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 <clc/relational/clc_isinf.h>
10+
11+
int __nv_isinff(float);
12+
int __nv_isinfd(double);
13+
14+
_CLC_OVERLOAD _CLC_DEF int __clc_isinf(float x) { return __nv_isinff(x); }
15+
16+
#ifdef cl_khr_fp64
17+
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
18+
19+
_CLC_OVERLOAD _CLC_DEF int __clc_isinf(double x) { return __nv_isinfd(x); }
20+
21+
#endif
22+
23+
#ifdef cl_khr_fp16
24+
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
25+
26+
_CLC_OVERLOAD _CLC_DEF int __clc_isinf(half x) { return __clc_isinf((float)x); }
27+
28+
#endif
29+
30+
#define FUNCTION __clc_isinf
31+
#define __CLC_BODY <clc/shared/unary_def_scalarize.inc>
32+
#define __CLC_RET_TYPE __CLC_BIT_INT
33+
#include <clc/math/gentype.inc>

0 commit comments

Comments
 (0)