Skip to content

Commit

Permalink
[libc][libm][GPU] Populating 'libmgpu.a' for math on the GPU
Browse files Browse the repository at this point in the history
This commit populates `libmgpu.a` with wrappers for the following built-ins
- modf, modff
- nearbyint, nearbyintf
- remainder, remainderf
- remquo, remquof
- rint, rintf
- scalbn, scalbnf
- sqrt, sqrtf
- tan, tanf
- tanh, tanhf
- trunc, truncf
and wrappers the following vendor implementations
- nextafter, nextafterf
- sincos, sincosf
- sinh, sinhf
- sinf
- tan, tanf
- tanh, tanhf

Reviewed By: jhuber6

Differential Revision: https://reviews.llvm.org/D153395
  • Loading branch information
AntonRydahl committed Aug 1, 2023
1 parent 5754f5a commit 53f5bfd
Show file tree
Hide file tree
Showing 43 changed files with 1,027 additions and 10 deletions.
25 changes: 24 additions & 1 deletion libc/config/gpu/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,32 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.pow
libc.src.math.powf
libc.src.math.sin
libc.src.math.modf
libc.src.math.modff
libc.src.math.nearbyint
libc.src.math.nearbyintf
libc.src.math.nextafter
libc.src.math.nextafterf
libc.src.math.remainder
libc.src.math.remainderf
libc.src.math.remquo
libc.src.math.remquof
libc.src.math.rint
libc.src.math.rintf
libc.src.math.round
libc.src.math.roundf
libc.src.math.roundl
libc.src.math.scalbn
libc.src.math.scalbnf
libc.src.math.sinh
libc.src.math.sinhf
libc.src.math.sqrt
libc.src.math.sqrtf
libc.src.math.tan
libc.src.math.tanf
libc.src.math.tanh
libc.src.math.tanhf
libc.src.math.trunc
libc.src.math.truncf
)

set(TARGET_LLVMLIBC_ENTRYPOINTS
Expand Down
4 changes: 4 additions & 0 deletions libc/src/math/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ add_math_entrypoint_object(sincosf)

add_math_entrypoint_object(sin)
add_math_entrypoint_object(sinf)

add_math_entrypoint_object(sinh)
add_math_entrypoint_object(sinhf)

add_math_entrypoint_object(sqrt)
Expand All @@ -206,6 +208,8 @@ add_math_entrypoint_object(sqrtl)

add_math_entrypoint_object(tan)
add_math_entrypoint_object(tanf)

add_math_entrypoint_object(tanh)
add_math_entrypoint_object(tanhf)

add_math_entrypoint_object(trunc)
Expand Down
220 changes: 220 additions & 0 deletions libc/src/math/gpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,106 @@ add_math_entrypoint_gpu_object(
-O2
)

add_math_entrypoint_gpu_object(
modf
SRCS
modf.cpp
HDRS
../modf.h
COMPILE_OPTIONS
-O2
)

add_math_entrypoint_gpu_object(
modff
SRCS
modff.cpp
HDRS
../modff.h
COMPILE_OPTIONS
-O2
)

add_math_entrypoint_gpu_object(
nearbyint
SRCS
nearbyint.cpp
HDRS
../nearbyint.h
COMPILE_OPTIONS
-O2
)

add_math_entrypoint_gpu_object(
nearbyintf
SRCS
nearbyintf.cpp
HDRS
../nearbyintf.h
COMPILE_OPTIONS
-O2
)

add_math_entrypoint_gpu_object(
remainder
SRCS
remainder.cpp
HDRS
../remainder.h
COMPILE_OPTIONS
-O2
)

add_math_entrypoint_gpu_object(
remainderf
SRCS
remainderf.cpp
HDRS
../remainderf.h
COMPILE_OPTIONS
-O2
)

add_math_entrypoint_gpu_object(
remquo
SRCS
remquo.cpp
HDRS
../remquo.h
COMPILE_OPTIONS
-O2
)

add_math_entrypoint_gpu_object(
remquof
SRCS
remquof.cpp
HDRS
../remquof.h
COMPILE_OPTIONS
-O2
)

add_math_entrypoint_gpu_object(
rint
SRCS
rint.cpp
HDRS
../rint.h
COMPILE_OPTIONS
-O2
)

add_math_entrypoint_gpu_object(
rintf
SRCS
rintf.cpp
HDRS
../rintf.h
COMPILE_OPTIONS
-O2
)

add_math_entrypoint_gpu_object(
round
SRCS
Expand All @@ -212,3 +312,123 @@ add_math_entrypoint_gpu_object(
COMPILE_OPTIONS
-O2
)

add_math_entrypoint_gpu_object(
scalbn
SRCS
scalbn.cpp
HDRS
../scalbn.h
COMPILE_OPTIONS
-O2
)

add_math_entrypoint_gpu_object(
scalbnf
SRCS
scalbnf.cpp
HDRS
../scalbnf.h
COMPILE_OPTIONS
-O2
)

add_math_entrypoint_gpu_object(
sinh
SRCS
sinh.cpp
HDRS
../sinh.h
COMPILE_OPTIONS
-O2
)

add_math_entrypoint_gpu_object(
sinhf
SRCS
sinhf.cpp
HDRS
../sinhf.h
COMPILE_OPTIONS
-O2
)

add_math_entrypoint_gpu_object(
sqrt
SRCS
sqrt.cpp
HDRS
../sqrt.h
COMPILE_OPTIONS
-O2
)

add_math_entrypoint_gpu_object(
sqrtf
SRCS
sqrtf.cpp
HDRS
../sqrtf.h
COMPILE_OPTIONS
-O2
)

add_math_entrypoint_gpu_object(
tan
SRCS
tan.cpp
HDRS
../tan.h
COMPILE_OPTIONS
-O2
)

add_math_entrypoint_gpu_object(
tanf
SRCS
tanf.cpp
HDRS
../tanf.h
COMPILE_OPTIONS
-O2
)

add_math_entrypoint_gpu_object(
tanh
SRCS
tanh.cpp
HDRS
../tanh.h
COMPILE_OPTIONS
-O2
)

add_math_entrypoint_gpu_object(
tanhf
SRCS
tanhf.cpp
HDRS
../tanhf.h
COMPILE_OPTIONS
-O2
)

add_math_entrypoint_gpu_object(
trunc
SRCS
trunc.cpp
HDRS
../trunc.h
COMPILE_OPTIONS
-O2
)

add_math_entrypoint_gpu_object(
truncf
SRCS
truncf.cpp
HDRS
../truncf.h
COMPILE_OPTIONS
-O2
)
18 changes: 18 additions & 0 deletions libc/src/math/gpu/modf.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//===-- Implementation of the GPU modf function ---------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "src/math/modf.h"
#include "src/__support/common.h"

namespace __llvm_libc {

LLVM_LIBC_FUNCTION(double, modf, (double x, double *iptr)) {
return __builtin_modf(x, iptr);
}

} // namespace __llvm_libc
18 changes: 18 additions & 0 deletions libc/src/math/gpu/modff.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//===-- Implementation of the GPU modff function --------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "src/math/modff.h"
#include "src/__support/common.h"

namespace __llvm_libc {

LLVM_LIBC_FUNCTION(float, modff, (float x, float *iptr)) {
return __builtin_modff(x, iptr);
}

} // namespace __llvm_libc
18 changes: 18 additions & 0 deletions libc/src/math/gpu/nearbyint.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//===-- Implementation of the GPU nearbyint function ----------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "src/math/nearbyint.h"
#include "src/__support/common.h"

namespace __llvm_libc {

LLVM_LIBC_FUNCTION(double, nearbyint, (double x)) {
return __builtin_nearbyint(x);
}

} // namespace __llvm_libc
18 changes: 18 additions & 0 deletions libc/src/math/gpu/nearbyintf.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//===-- Implementation of the GPU nearbyintf function ---------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "src/math/nearbyintf.h"
#include "src/__support/common.h"

namespace __llvm_libc {

LLVM_LIBC_FUNCTION(float, nearbyintf, (float x)) {
return __builtin_nearbyintf(x);
}

} // namespace __llvm_libc
18 changes: 18 additions & 0 deletions libc/src/math/gpu/remainder.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//===-- Implementation of the GPU remainder function ----------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "src/math/remainder.h"
#include "src/__support/common.h"

namespace __llvm_libc {

LLVM_LIBC_FUNCTION(double, remainder, (double x, double y)) {
return __builtin_remainder(x, y);
}

} // namespace __llvm_libc
18 changes: 18 additions & 0 deletions libc/src/math/gpu/remainderf.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//===-- Implementation of the GPU remainderf function ---------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "src/math/remainderf.h"
#include "src/__support/common.h"

namespace __llvm_libc {

LLVM_LIBC_FUNCTION(float, remainderf, (float x, float y)) {
return __builtin_remainderf(x, y);
}

} // namespace __llvm_libc
Loading

0 comments on commit 53f5bfd

Please sign in to comment.