Skip to content

Commit 4b0b0a9

Browse files
committed
[SYCL-PTX] Add fmod builtin
Signed-off-by: Victor Lomuller <[email protected]>
1 parent e02e118 commit 4b0b0a9

File tree

7 files changed

+93
-4
lines changed

7 files changed

+93
-4
lines changed

libclc/generic/libspirv/SOURCES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ math/floor.cl
5555
math/fma.cl
5656
math/fmax.cl
5757
math/fmin.cl
58+
math/fmod.cl
5859
math/fract.cl
5960
math/ldexp.cl
6061
math/log.cl
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <utils.h>
2+
3+
// TODO: Enable half precision when the sw routine is implemented
4+
#if __CLC_FPSIZE > 16
5+
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __CLC_FUNC(__CLC_GENTYPE x,
6+
__CLC_GENTYPE y) {
7+
return __CLC_SW_FUNC(x, y);
8+
}
9+
#endif

libclc/generic/libspirv/math/fmod.cl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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 <spirv/spirv.h>
10+
11+
#include <math/clc_fmod.h>
12+
13+
#define __CLC_FUNC __spirv_ocl_fmod
14+
#define __CLC_SW_FUNC __clc_fmod
15+
#define __CLC_BODY <clc_sw_binary.inc>
16+
#include <clc/math/gentype.inc>
17+
#undef __CLC_SW_FUNC

libclc/ptx-nvidiacl/include/libdevice.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,39 @@
99
#ifndef PTX_NVIDIACL_LIBDEVICE_H
1010
#define PTX_NVIDIACL_LIBDEVICE_H
1111

12-
#define __LIBDEVICE_UNARY_BUILTIN_F(BUILTIN) float __nv_ ## BUILTIN ## f(float);
12+
#define __LIBDEVICE_UNARY_BUILTIN_F(BUILTIN) float __nv_##BUILTIN##f(float);
13+
#define __LIBDEVICE_BINARY_BUILTIN_F(BUILTIN) \
14+
float __nv_##BUILTIN##f(float, float);
1315

1416
#ifdef cl_khr_fp64
1517

1618
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
1719

18-
#define __LIBDEVICE_UNARY_BUILTIN_D(BUILTIN) double __nv_ ## BUILTIN(double);
20+
#define __LIBDEVICE_UNARY_BUILTIN_D(BUILTIN) double __nv_##BUILTIN(double);
21+
#define __LIBDEVICE_BINARY_BUILTIN_D(BUILTIN) \
22+
double __nv_##BUILTIN(double, double);
1923

2024
#else
2125

2226
#define __LIBDEVICE_UNARY_BUILTIN_D(BUILTIN)
2327

2428
#endif
2529

26-
#define __LIBDEVICE_UNARY_BUILTIN(BUILTIN) \
27-
__LIBDEVICE_UNARY_BUILTIN_F(BUILTIN) \
30+
#define __LIBDEVICE_UNARY_BUILTIN(BUILTIN) \
31+
__LIBDEVICE_UNARY_BUILTIN_F(BUILTIN) \
2832
__LIBDEVICE_UNARY_BUILTIN_D(BUILTIN)
2933

34+
#define __LIBDEVICE_BINARY_BUILTIN(BUILTIN) \
35+
__LIBDEVICE_BINARY_BUILTIN_F(BUILTIN) \
36+
__LIBDEVICE_BINARY_BUILTIN_D(BUILTIN)
37+
3038
__LIBDEVICE_UNARY_BUILTIN(exp)
3139
__LIBDEVICE_UNARY_BUILTIN(exp2)
3240
__LIBDEVICE_UNARY_BUILTIN(exp10)
3341
__LIBDEVICE_UNARY_BUILTIN(expm1)
3442
__LIBDEVICE_UNARY_BUILTIN_F(fast_exp)
3543
__LIBDEVICE_UNARY_BUILTIN_F(fast_exp10)
3644

45+
__LIBDEVICE_BINARY_BUILTIN(fmod)
3746

3847
#endif

libclc/ptx-nvidiacl/libspirv/SOURCES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ math/exp.cl
1212
math/exp10.cl
1313
math/exp2.cl
1414
math/expm1.cl
15+
math/fmod.cl
1516
math/native_exp.cl
1617
math/native_exp10.cl
1718
math/native_exp2.cl
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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 "utils.h"
11+
12+
#ifndef __CLC_BUILTIN_F
13+
#define __CLC_BUILTIN_F __CLC_XCONCAT(__CLC_BUILTIN, f)
14+
#endif
15+
16+
_CLC_DEFINE_BINARY_BUILTIN(float, __CLC_FUNCTION, __CLC_BUILTIN_F, float, float)
17+
18+
#ifndef __FLOAT_ONLY
19+
20+
#ifdef cl_khr_fp64
21+
22+
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
23+
24+
_CLC_DEFINE_BINARY_BUILTIN(double, __CLC_FUNCTION, __CLC_BUILTIN, double,
25+
double)
26+
27+
#endif
28+
29+
#ifdef cl_khr_fp16
30+
31+
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
32+
33+
_CLC_DEFINE_BINARY_BUILTIN(half, __CLC_FUNCTION, __CLC_BUILTIN, half, half)
34+
35+
#endif
36+
37+
#endif
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_fmod
14+
#define __CLC_BUILTIN __nv_fmod
15+
#include "binary_builtin.inc"

0 commit comments

Comments
 (0)