Skip to content

[libc] Add support for powi as an LLVM libc extension on the GPU #98236

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions libc/config/gpu/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,8 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.nexttowardf
libc.src.math.pow
libc.src.math.powf
libc.src.math.powi
libc.src.math.powif
libc.src.math.remainder
libc.src.math.remainderf
libc.src.math.remquo
Expand Down
2 changes: 2 additions & 0 deletions libc/docs/math/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,8 @@ Higher Math Functions
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| pow | |check| | | | | | 7.12.7.5 | F.10.4.5 |
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| powi\* | | | | | | | |
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| pown | | | | | | 7.12.7.6 | F.10.4.6 |
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| powr | | | | | | 7.12.7.7 | F.10.4.7 |
Expand Down
3 changes: 3 additions & 0 deletions libc/spec/llvm_libc_ext.td
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ def LLVMLibcExt : StandardSpec<"llvm_libc_ext"> {
GuardedFunctionSpec<"f16sqrt", RetValSpec<Float16Type>, [ArgSpec<DoubleType>], "LIBC_TYPES_HAS_FLOAT16">,
GuardedFunctionSpec<"f16sqrtf", RetValSpec<Float16Type>, [ArgSpec<FloatType>], "LIBC_TYPES_HAS_FLOAT16">,
GuardedFunctionSpec<"f16sqrtl", RetValSpec<Float16Type>, [ArgSpec<LongDoubleType>], "LIBC_TYPES_HAS_FLOAT16">,

FunctionSpec<"powi", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<IntType>]>,
FunctionSpec<"powif", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<IntType>]>,
]
>;

Expand Down
2 changes: 2 additions & 0 deletions libc/src/math/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,8 @@ add_math_entrypoint_object(nextupf128)

add_math_entrypoint_object(pow)
add_math_entrypoint_object(powf)
add_math_entrypoint_object(powi)
add_math_entrypoint_object(powif)

add_math_entrypoint_object(remainder)
add_math_entrypoint_object(remainderf)
Expand Down
24 changes: 24 additions & 0 deletions libc/src/math/amdgpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,30 @@ add_entrypoint_object(
VENDOR
)

add_entrypoint_object(
powi
SRCS
powi.cpp
HDRS
../powi.h
COMPILE_OPTIONS
${bitcode_link_flags}
-O2
VENDOR
)

add_entrypoint_object(
powif
SRCS
powif.cpp
HDRS
../powif.h
COMPILE_OPTIONS
${bitcode_link_flags}
-O2
VENDOR
)

add_entrypoint_object(
sinh
SRCS
Expand Down
2 changes: 2 additions & 0 deletions libc/src/math/amdgpu/declarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ float __ocml_nextafter_f32(float, float);
double __ocml_nextafter_f64(double, double);
float __ocml_pow_f32(float, float);
double __ocml_pow_f64(double, double);
float __ocml_pown_f32(float, int);
double __ocml_pown_f64(double, int);
float __ocml_sin_f32(float);
double __ocml_sin_f64(double);
float __ocml_sincos_f32(float, float *);
Expand Down
20 changes: 20 additions & 0 deletions libc/src/math/amdgpu/powi.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation of the powi 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/powi.h"
#include "src/__support/common.h"

#include "declarations.h"

namespace LIBC_NAMESPACE {

LLVM_LIBC_FUNCTION(double, powi, (double x, int y)) {
return __ocml_pown_f64(x, y);
}

} // namespace LIBC_NAMESPACE
20 changes: 20 additions & 0 deletions libc/src/math/amdgpu/powif.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation of the powi 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/powif.h"
#include "src/__support/common.h"

#include "declarations.h"

namespace LIBC_NAMESPACE {

LLVM_LIBC_FUNCTION(float, powif, (float x, int y)) {
return __ocml_pown_f32(x, y);
}

} // namespace LIBC_NAMESPACE
24 changes: 24 additions & 0 deletions libc/src/math/nvptx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,30 @@ add_entrypoint_object(
VENDOR
)

add_entrypoint_object(
powi
SRCS
powi.cpp
HDRS
../powi.h
COMPILE_OPTIONS
${bitcode_link_flags}
-O2
VENDOR
)

add_entrypoint_object(
powif
SRCS
powif.cpp
HDRS
../powif.h
COMPILE_OPTIONS
${bitcode_link_flags}
-O2
VENDOR
)

add_entrypoint_object(
sinh
SRCS
Expand Down
2 changes: 2 additions & 0 deletions libc/src/math/nvptx/declarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ double __nv_nextafter(double, double);
float __nv_nextafterf(float, float);
double __nv_pow(double, double);
float __nv_powf(float, float);
double __nv_powi(double, int);
float __nv_powif(float, int);
double __nv_sin(double);
float __nv_sinf(float);
void __nv_sincos(double, double *, double *);
Expand Down
18 changes: 18 additions & 0 deletions libc/src/math/nvptx/powi.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//===-- Implementation of the powi 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/powi.h"
#include "src/__support/common.h"

#include "declarations.h"

namespace LIBC_NAMESPACE {

LLVM_LIBC_FUNCTION(double, powi, (double x, int y)) { return __nv_powi(x, y); }

} // namespace LIBC_NAMESPACE
18 changes: 18 additions & 0 deletions libc/src/math/nvptx/powif.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//===-- Implementation of the powif 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/powif.h"
#include "src/__support/common.h"

#include "declarations.h"

namespace LIBC_NAMESPACE {

LLVM_LIBC_FUNCTION(float, powif, (float x, int y)) { return __nv_powif(x, y); }

} // namespace LIBC_NAMESPACE
18 changes: 18 additions & 0 deletions libc/src/math/powi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//===-- Implementation header for powi --------------------------*- 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_POWI_H
#define LLVM_LIBC_SRC_MATH_POWI_H

namespace LIBC_NAMESPACE {

double powi(double x, int y);

} // namespace LIBC_NAMESPACE

#endif // LLVM_LIBC_SRC_MATH_POW_H
18 changes: 18 additions & 0 deletions libc/src/math/powif.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//===-- Implementation header for powif -------------------------*- 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_POWIF_H
#define LLVM_LIBC_SRC_MATH_POWIF_H

namespace LIBC_NAMESPACE {

float powif(float x, int y);

} // namespace LIBC_NAMESPACE

#endif // LLVM_LIBC_SRC_MATH_POW_H
Loading