Skip to content

Commit 1276ca3

Browse files
authored
[libspirv] Reuse clc function in generic math/common built-ins (#19231)
Delete unused .inc and .h files. Delete unused tables.cl.
1 parent acba675 commit 1276ca3

Some content is hidden

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

81 files changed

+267
-4606
lines changed

libclc/clc/include/clc/math/unary_builtin_scalarize.inc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,26 @@
1717
#define __CLC_BUILTIN_H __CLC_BUILTIN_F
1818
#endif
1919

20+
#if (!defined(__HALF_ONLY) && !defined(__DOUBLE_ONLY))
2021
_CLC_DEFINE_UNARY_BUILTIN_SCALARIZE(float, __CLC_FUNCTION, __CLC_BUILTIN_F, float)
22+
#endif
2123

22-
#ifndef __FLOAT_ONLY
23-
24+
#if (!defined(__HALF_ONLY) && !defined(__FLOAT_ONLY))
2425
#ifdef cl_khr_fp64
2526

2627
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
2728

2829
_CLC_DEFINE_UNARY_BUILTIN_SCALARIZE(double, __CLC_FUNCTION, __CLC_BUILTIN_D, double)
2930

3031
#endif
32+
#endif // (!defined(__HALF_ONLY) && !defined(__FLOAT_ONLY))
3133

34+
#if (!defined(__FLOAT_ONLY) && !defined(__DOUBLE_ONLY))
3235
#ifdef cl_khr_fp16
3336

3437
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
3538

3639
_CLC_DEFINE_UNARY_BUILTIN_SCALARIZE(half, __CLC_FUNCTION, __CLC_BUILTIN_H, half)
3740

3841
#endif
39-
40-
#endif // !__FLOAT_ONLY
42+
#endif // (!defined(__FLOAT_ONLY) && !defined(__DOUBLE_ONLY))

libclc/clc/lib/amdgcn/SOURCES

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
math/clc_exp.cl
12
math/clc_fmax.cl
23
math/clc_fmin.cl
34
math/clc_ldexp_override.cl
5+
math/clc_lgamma.cl
6+
math/clc_log.cl
7+
math/clc_sinpi.cl
8+
math/clc_sqrt.cl
9+
math/clc_sqrt_fp64.cl

libclc/libspirv/lib/amdgcn-amdhsa/math/exp.cl renamed to libclc/clc/lib/amdgcn/math/clc_exp.cl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include <clc/clcmacro.h>
10-
#include <libspirv/spirv.h>
9+
#include <clc/internal/clc.h>
10+
#include <clc/math/clc_exp.h>
1111

12-
#define __CLC_FUNCTION __spirv_ocl_exp
12+
#define __CLC_FUNCTION __clc_exp
1313
#define __CLC_BUILTIN __ocml_exp
1414

1515
float __ocml_exp_f32(float);

libclc/clc/lib/amdgcn/math/clc_fmax.cl

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,44 +6,25 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include <clc/clcmacro.h>
109
#include <clc/internal/clc.h>
11-
#include <clc/relational/clc_isnan.h>
10+
#include <clc/math/clc_fmax.h>
1211

13-
_CLC_DEF _CLC_OVERLOAD float __clc_fmax(float x, float y) {
14-
// fcanonicalize removes sNaNs and flushes denormals if not enabled. Otherwise
15-
// fmax instruction flushes the values for comparison, but outputs original
16-
// denormal
17-
x = __builtin_canonicalizef(x);
18-
y = __builtin_canonicalizef(y);
19-
return __builtin_fmaxf(x, y);
20-
}
21-
_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, float, __clc_fmax, float, float)
12+
#define __CLC_FUNCTION __clc_fmax
13+
#define __CLC_BUILTIN __ocml_fmax
2214

23-
#ifdef cl_khr_fp64
15+
float __ocml_fmax_f32(float, float);
16+
#define __CLC_BUILTIN_F __CLC_XCONCAT(__CLC_BUILTIN, _f32)
2417

18+
#ifdef cl_khr_fp64
2519
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
20+
double __ocml_fmax_f64(double, double);
21+
#define __CLC_BUILTIN_D __CLC_XCONCAT(__CLC_BUILTIN, _f64)
22+
#endif // cl_khr_fp64
2623

27-
_CLC_DEF _CLC_OVERLOAD double __clc_fmax(double x, double y) {
28-
x = __builtin_canonicalize(x);
29-
y = __builtin_canonicalize(y);
30-
return __builtin_fmax(x, y);
31-
}
32-
_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, __clc_fmax, double,
33-
double)
34-
35-
#endif
3624
#ifdef cl_khr_fp16
37-
3825
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
26+
half __ocml_fmax_f16(half, half);
27+
#define __CLC_BUILTIN_H __CLC_XCONCAT(__CLC_BUILTIN, _f16)
28+
#endif // cl_khr_fp16
3929

40-
_CLC_DEF _CLC_OVERLOAD half __clc_fmax(half x, half y) {
41-
if (__clc_isnan(x))
42-
return y;
43-
if (__clc_isnan(y))
44-
return x;
45-
return (y < x) ? x : y;
46-
}
47-
_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, half, __clc_fmax, half, half)
48-
49-
#endif
30+
#include <clc/math/binary_builtin.inc>

libclc/clc/lib/amdgcn/math/clc_fmin.cl

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,25 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include <clc/clcmacro.h>
109
#include <clc/internal/clc.h>
11-
#include <clc/relational/clc_isnan.h>
10+
#include <clc/math/clc_fmin.h>
1211

13-
_CLC_DEF _CLC_OVERLOAD float __clc_fmin(float x, float y) {
14-
// fcanonicalize removes sNaNs and flushes denormals if not enabled. Otherwise
15-
// fmin instruction flushes the values for comparison, but outputs original
16-
// denormal
17-
x = __builtin_canonicalizef(x);
18-
y = __builtin_canonicalizef(y);
19-
return __builtin_fminf(x, y);
20-
}
21-
_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, float, __clc_fmin, float, float)
12+
#define __CLC_FUNCTION __clc_fmin
13+
#define __CLC_BUILTIN __ocml_fmin
2214

23-
#ifdef cl_khr_fp64
15+
float __ocml_fmin_f32(float, float);
16+
#define __CLC_BUILTIN_F __CLC_XCONCAT(__CLC_BUILTIN, _f32)
2417

18+
#ifdef cl_khr_fp64
2519
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
26-
27-
_CLC_DEF _CLC_OVERLOAD double __clc_fmin(double x, double y) {
28-
x = __builtin_canonicalize(x);
29-
y = __builtin_canonicalize(y);
30-
return __builtin_fmin(x, y);
31-
}
32-
_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, __clc_fmin, double,
33-
double)
34-
35-
#endif
20+
double __ocml_fmin_f64(double, double);
21+
#define __CLC_BUILTIN_D __CLC_XCONCAT(__CLC_BUILTIN, _f64)
22+
#endif // cl_khr_fp64
3623

3724
#ifdef cl_khr_fp16
38-
3925
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
26+
half __ocml_fmin_f16(half, half);
27+
#define __CLC_BUILTIN_H __CLC_XCONCAT(__CLC_BUILTIN, _f16)
28+
#endif // cl_khr_fp16
4029

41-
_CLC_DEF _CLC_OVERLOAD half __clc_fmin(half x, half y) {
42-
if (__clc_isnan(x))
43-
return y;
44-
if (__clc_isnan(y))
45-
return x;
46-
return (y < x) ? y : x;
47-
}
48-
_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, half, __clc_fmin, half, half)
49-
50-
#endif
30+
#include <clc/math/binary_builtin.inc>

libclc/libspirv/lib/amdgcn-amdhsa/math/lgamma.cl renamed to libclc/clc/lib/amdgcn/math/clc_lgamma.cl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include <clc/clcmacro.h>
10-
#include <libspirv/spirv.h>
9+
#include <clc/internal/clc.h>
10+
#include <clc/math/clc_lgamma.h>
1111

12-
#define __CLC_FUNCTION __spirv_ocl_lgamma
12+
#define __CLC_FUNCTION __clc_lgamma
1313
#define __CLC_BUILTIN __ocml_lgamma
1414

1515
float __ocml_lgamma_f32(float);

libclc/libspirv/lib/amdgcn-amdhsa/math/log.cl renamed to libclc/clc/lib/amdgcn/math/clc_log.cl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include <clc/clcmacro.h>
10-
#include <libspirv/spirv.h>
9+
#include <clc/internal/clc.h>
10+
#include <clc/math/clc_log.h>
1111

12-
#define __CLC_FUNCTION __spirv_ocl_log
12+
#define __CLC_FUNCTION __clc_log
1313
#define __CLC_BUILTIN __ocml_log
1414

1515
float __ocml_log_f32(float);

libclc/libspirv/lib/amdgcn-amdhsa/math/sinpi.cl renamed to libclc/clc/lib/amdgcn/math/clc_sinpi.cl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include <clc/clcmacro.h>
10-
#include <libspirv/spirv.h>
9+
#include <clc/internal/clc.h>
10+
#include <clc/math/clc_sinpi.h>
1111

12-
#define __CLC_FUNCTION __spirv_ocl_sinpi
12+
#define __CLC_FUNCTION __clc_sinpi
1313
#define __CLC_BUILTIN __ocml_sinpi
1414

1515
float __ocml_sinpi_f32(float);

libclc/libspirv/lib/amdgcn-amdhsa/math/sqrt.cl renamed to libclc/clc/lib/amdgcn/math/clc_sqrt.cl

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,26 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include <clc/clcmacro.h>
10-
#include <libspirv/spirv.h>
9+
#include <clc/internal/clc.h>
10+
#include <clc/math/clc_sqrt.h>
1111

12-
#define __CLC_FUNCTION __spirv_ocl_sqrt
12+
#define __CLC_FUNCTION __clc_sqrt
1313
#define __CLC_BUILTIN __ocml_sqrt
1414

1515
float __ocml_sqrt_f32(float);
1616
#define __CLC_BUILTIN_F __CLC_XCONCAT(__CLC_BUILTIN, _f32)
1717

18-
#ifdef cl_khr_fp64
19-
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
20-
double __ocml_sqrt_f64(double);
21-
#define __CLC_BUILTIN_D __CLC_XCONCAT(__CLC_BUILTIN, _f64)
22-
#endif // cl_khr_fp64
18+
#define __FLOAT_ONLY
19+
#include <clc/math/unary_builtin_scalarize.inc>
20+
21+
#undef __FLOAT_ONLY
22+
#undef __CLC_BUILTIN_H
2323

2424
#ifdef cl_khr_fp16
2525
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
2626
half __ocml_sqrt_f16(half);
2727
#define __CLC_BUILTIN_H __CLC_XCONCAT(__CLC_BUILTIN, _f16)
2828
#endif // cl_khr_fp16
2929

30+
#define __HALF_ONLY
3031
#include <clc/math/unary_builtin_scalarize.inc>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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/internal/clc.h>
10+
#include <clc/math/clc_sqrt.h>
11+
12+
#define __CLC_FUNCTION __clc_sqrt
13+
#define __CLC_BUILTIN __ocml_sqrt
14+
15+
#ifdef cl_khr_fp64
16+
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
17+
double __ocml_sqrt_f64(double);
18+
#define __CLC_BUILTIN_D __CLC_XCONCAT(__CLC_BUILTIN, _f64)
19+
#endif // cl_khr_fp64
20+
21+
#define __DOUBLE_ONLY
22+
#include <clc/math/unary_builtin_scalarize.inc>

libclc/clc/lib/ptx-nvidiacl/SOURCES

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
math/clc_log.cl
2+
math/clc_sinpi.cl
3+
math/clc_sqrt.cl

libclc/libspirv/lib/ptx-nvidiacl/math/log.cl renamed to libclc/clc/lib/ptx-nvidiacl/math/clc_log.cl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include <libspirv/spirv.h>
9+
#include <clc/internal/clc.h>
10+
#include <clc/math/clc_log.h>
1011

11-
#include <libspirv/ptx-nvidiacl/libdevice.h>
12-
#include <clc/clcmacro.h>
12+
float __nv_logf(float);
13+
double __nv_log(double);
1314

14-
#define __CLC_FUNCTION __spirv_ocl_log
15+
#define __CLC_FUNCTION __clc_log
1516
#define __CLC_BUILTIN __nv_log
1617
#define __CLC_BUILTIN_F __CLC_XCONCAT(__CLC_BUILTIN, f)
1718
#include <clc/math/unary_builtin_scalarize.inc>

libclc/libspirv/lib/ptx-nvidiacl/math/sinpi.cl renamed to libclc/clc/lib/ptx-nvidiacl/math/clc_sinpi.cl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include <libspirv/spirv.h>
9+
#include <clc/internal/clc.h>
10+
#include <clc/math/clc_sinpi.h>
1011

11-
#include <libspirv/ptx-nvidiacl/libdevice.h>
12-
#include <clc/clcmacro.h>
12+
float __nv_sinpif(float);
13+
double __nv_sinpi(double);
1314

14-
#define __CLC_FUNCTION __spirv_ocl_sinpi
15+
#define __CLC_FUNCTION __clc_sinpi
1516
#define __CLC_BUILTIN __nv_sinpi
1617
#define __CLC_BUILTIN_F __CLC_XCONCAT(__CLC_BUILTIN, f)
1718
#include <clc/math/unary_builtin_scalarize.inc>

libclc/libspirv/lib/ptx-nvidiacl/math/sqrt.cl renamed to libclc/clc/lib/ptx-nvidiacl/math/clc_sqrt.cl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include <libspirv/spirv.h>
9+
#include <clc/internal/clc.h>
10+
#include <clc/math/clc_sqrt.h>
1011

11-
#include <libspirv/ptx-nvidiacl/libdevice.h>
12+
float __nv_sqrtf(float);
13+
double __nv_sqrt(double);
1214

13-
#define __CLC_FUNCTION __spirv_ocl_sqrt
15+
#define __CLC_FUNCTION __clc_sqrt
1416
#define __CLC_BUILTIN __nv_sqrt
1517
#define __CLC_BUILTIN_F __CLC_XCONCAT(__CLC_BUILTIN, f)
1618
#include <clc/math/unary_builtin_scalarize.inc>

libclc/libspirv/lib/amdgcn-amdhsa/SOURCES

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,15 @@ math/cosh.cl
3333
math/cospi.cl
3434
math/erf.cl
3535
math/erfc.cl
36-
math/exp.cl
3736
math/exp10.cl
3837
math/exp2.cl
3938
math/expm1.cl
4039
math/fdim.cl
41-
math/fmax.cl
42-
math/fmin.cl
4340
math/fmod.cl
4441
math/frexp.cl
4542
math/hypot.cl
4643
math/ilogb.cl
4744
math/ldexp.cl
48-
math/lgamma.cl
49-
math/log.cl
5045
math/log2.cl
5146
math/log10.cl
5247
math/log1p.cl
@@ -60,8 +55,6 @@ math/rsqrt.cl
6055
math/sin.cl
6156
math/sincos.cl
6257
math/sinh.cl
63-
math/sinpi.cl
64-
math/sqrt.cl
6558
math/tan.cl
6659
math/tanh.cl
6760
workitem/get_global_size.cl

libclc/libspirv/lib/amdgcn-amdhsa/math/fmax.cl

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

0 commit comments

Comments
 (0)