diff options
| author | Joseph Huber <huberjn@outlook.com> | 2024-08-05 14:53:05 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-05 14:53:05 -0500 |
| commit | 88d288489e09a261f6740972dcaf6fedaf87a762 (patch) | |
| tree | cf46dad6cc3be56bcd62ae1e664b8597d6bcf808 /libc/src/math | |
| parent | c4ec19b985815b664cc598a608acc0906d29d902 (diff) | |
[libc] Add `lgamma` and `lgamma_r` stubs for the GPU (#102019)
Summary:
These functions are used by the <random> implementation in libc++ and
cause a lot of tests to fail. For now we provide these through the
vendor abstraction until we have a real version. The NVPTX version
doesn't even update the output correctly so these are just temporary.
Diffstat (limited to 'libc/src/math')
| -rw-r--r-- | libc/src/math/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | libc/src/math/amdgpu/CMakeLists.txt | 24 | ||||
| -rw-r--r-- | libc/src/math/amdgpu/declarations.h | 2 | ||||
| -rw-r--r-- | libc/src/math/amdgpu/lgamma.cpp | 19 | ||||
| -rw-r--r-- | libc/src/math/amdgpu/lgamma_r.cpp | 24 | ||||
| -rw-r--r-- | libc/src/math/lgamma.h | 20 | ||||
| -rw-r--r-- | libc/src/math/lgamma_r.h | 20 | ||||
| -rw-r--r-- | libc/src/math/nvptx/CMakeLists.txt | 24 | ||||
| -rw-r--r-- | libc/src/math/nvptx/declarations.h | 1 | ||||
| -rw-r--r-- | libc/src/math/nvptx/lgamma.cpp | 19 | ||||
| -rw-r--r-- | libc/src/math/nvptx/lgamma_r.cpp | 23 |
11 files changed, 178 insertions, 0 deletions
diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt index e513d72260fb..aec94d41ad08 100644 --- a/libc/src/math/CMakeLists.txt +++ b/libc/src/math/CMakeLists.txt @@ -448,6 +448,8 @@ add_math_entrypoint_object(tanhf) add_math_entrypoint_object(tgamma) add_math_entrypoint_object(tgammaf) +add_math_entrypoint_object(lgamma) +add_math_entrypoint_object(lgamma_r) add_math_entrypoint_object(totalorder) add_math_entrypoint_object(totalorderf) diff --git a/libc/src/math/amdgpu/CMakeLists.txt b/libc/src/math/amdgpu/CMakeLists.txt index 00f87765175b..23fd3169fddf 100644 --- a/libc/src/math/amdgpu/CMakeLists.txt +++ b/libc/src/math/amdgpu/CMakeLists.txt @@ -515,3 +515,27 @@ add_entrypoint_object( -O2 VENDOR ) + +add_entrypoint_object( + lgamma + SRCS + lgamma.cpp + HDRS + ../lgamma.h + COMPILE_OPTIONS + ${bitcode_link_flags} + -O2 + VENDOR +) + +add_entrypoint_object( + lgamma_r + SRCS + lgamma_r.cpp + HDRS + ../lgamma_r.h + COMPILE_OPTIONS + ${bitcode_link_flags} + -O2 + VENDOR +) diff --git a/libc/src/math/amdgpu/declarations.h b/libc/src/math/amdgpu/declarations.h index 98c14ee43cd1..88e2201521b6 100644 --- a/libc/src/math/amdgpu/declarations.h +++ b/libc/src/math/amdgpu/declarations.h @@ -82,6 +82,8 @@ float __ocml_remquo_f32(float, float, gpu::Private<int> *); double __ocml_remquo_f64(double, double, gpu::Private<int> *); double __ocml_tgamma_f64(double); float __ocml_tgamma_f32(float); +double __ocml_lgamma_f64(double); +double __ocml_lgamma_r_f64(double, gpu::Private<int> *); } } // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/math/amdgpu/lgamma.cpp b/libc/src/math/amdgpu/lgamma.cpp new file mode 100644 index 000000000000..acff4c76734e --- /dev/null +++ b/libc/src/math/amdgpu/lgamma.cpp @@ -0,0 +1,19 @@ +//===-- Implementation of the lgamma function for GPU ---------------------===// +// +// 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/lgamma.h" +#include "src/__support/common.h" + +#include "declarations.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { + +LLVM_LIBC_FUNCTION(double, lgamma, (double x)) { return __ocml_lgamma_f64(x); } + +} // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/math/amdgpu/lgamma_r.cpp b/libc/src/math/amdgpu/lgamma_r.cpp new file mode 100644 index 000000000000..0a79988d66e3 --- /dev/null +++ b/libc/src/math/amdgpu/lgamma_r.cpp @@ -0,0 +1,24 @@ +//===-- Implementation of the lgamma_r function for GPU -------------------===// +// +// 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/lgamma_r.h" +#include "src/__support/common.h" + +#include "declarations.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { + +LLVM_LIBC_FUNCTION(double, lgamma_r, (double x, int *signp)) { + int tmp = *signp; + double r = __ocml_lgamma_r_f64(x, (gpu::Private<int> *)&tmp); + *signp = tmp; + return r; +} + +} // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/math/lgamma.h b/libc/src/math/lgamma.h new file mode 100644 index 000000000000..4c7d36567741 --- /dev/null +++ b/libc/src/math/lgamma.h @@ -0,0 +1,20 @@ +//===-- Implementation header for lgamma ------------------------*- C++ -*-===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC_MATH_LGAMMA_H +#define LLVM_LIBC_SRC_MATH_LGAMMA_H + +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { + +double lgamma(double x); + +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC_MATH_LGAMMA_H diff --git a/libc/src/math/lgamma_r.h b/libc/src/math/lgamma_r.h new file mode 100644 index 000000000000..1ca6b94c86bb --- /dev/null +++ b/libc/src/math/lgamma_r.h @@ -0,0 +1,20 @@ +//===-- Implementation header for lgamma_r-----------------------*- C++ -*-===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC_MATH_LGAMMA_R_H +#define LLVM_LIBC_SRC_MATH_LGAMMA_R_H + +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { + +double lgamma_r(double x, int *signp); + +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC_MATH_LGAMMA_R_H diff --git a/libc/src/math/nvptx/CMakeLists.txt b/libc/src/math/nvptx/CMakeLists.txt index 95ee9ff64d20..577d8147df43 100644 --- a/libc/src/math/nvptx/CMakeLists.txt +++ b/libc/src/math/nvptx/CMakeLists.txt @@ -468,3 +468,27 @@ add_entrypoint_object( -O2 VENDOR ) + +add_entrypoint_object( + lgamma + SRCS + lgamma.cpp + HDRS + ../lgamma.h + COMPILE_OPTIONS + ${bitcode_link_flags} + -O2 + VENDOR +) + +add_entrypoint_object( + lgamma_r + SRCS + lgamma_r.cpp + HDRS + ../lgamma_r.h + COMPILE_OPTIONS + ${bitcode_link_flags} + -O2 + VENDOR +) diff --git a/libc/src/math/nvptx/declarations.h b/libc/src/math/nvptx/declarations.h index 7bfa934c0142..6f0bcfe7dce0 100644 --- a/libc/src/math/nvptx/declarations.h +++ b/libc/src/math/nvptx/declarations.h @@ -86,6 +86,7 @@ double __nv_remquo(double, double, int *); float __nv_remquof(float, float, int *); double __nv_tgamma(double); float __nv_tgammaf(float); +float __nv_lgamma(double); } } // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/math/nvptx/lgamma.cpp b/libc/src/math/nvptx/lgamma.cpp new file mode 100644 index 000000000000..0447a97eeae7 --- /dev/null +++ b/libc/src/math/nvptx/lgamma.cpp @@ -0,0 +1,19 @@ +//===-- Implementation of the lgamma function for GPU ---------------------===// +// +// 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/lgamma.h" +#include "src/__support/common.h" + +#include "declarations.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { + +LLVM_LIBC_FUNCTION(double, lgamma, (double x)) { return __nv_lgamma(x); } + +} // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/math/nvptx/lgamma_r.cpp b/libc/src/math/nvptx/lgamma_r.cpp new file mode 100644 index 000000000000..85f66c8ea5d2 --- /dev/null +++ b/libc/src/math/nvptx/lgamma_r.cpp @@ -0,0 +1,23 @@ +//===-- Implementation of the lgamma_r function for GPU -------------------===// +// +// 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/lgamma_r.h" +#include "src/__support/common.h" + +#include "declarations.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { + +LLVM_LIBC_FUNCTION(double, lgamma_r, (double x, int *signp)) { + double result = __nv_lgamma(x); + *signp = (result < 0.0) ? -1 : 1; + return result; +} + +} // namespace LIBC_NAMESPACE_DECL |
