Skip to content

[libclc] Move several 'native' builtins to CLC library #129679

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 3 commits into from
Apr 1, 2025
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
21 changes: 17 additions & 4 deletions libclc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,23 @@ if ( clspv-- IN_LIST LIBCLC_TARGETS_TO_BUILD OR clspv64-- IN_LIST LIBCLC_TARGETS
endif()

set_source_files_properties(
# CLC builtins
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_cos.cl
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_exp2.cl
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_exp.cl
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_log10.cl
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_log2.cl
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_log.cl
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_rsqrt.cl
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_sin.cl
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_sqrt.cl
# Target-specific CLC builtins
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/amdgpu/math/clc_native_exp2.cl
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/amdgpu/math/clc_native_exp.cl
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/amdgpu/math/clc_native_log10.cl
# Target-specific OpenCL builtins
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/r600/math/clc_native_rsqrt.cl
# OpenCL builtins
${CMAKE_CURRENT_SOURCE_DIR}/generic/lib/math/native_cos.cl
${CMAKE_CURRENT_SOURCE_DIR}/generic/lib/math/native_divide.cl
${CMAKE_CURRENT_SOURCE_DIR}/generic/lib/math/native_exp.cl
Expand All @@ -277,10 +294,6 @@ set_source_files_properties(
${CMAKE_CURRENT_SOURCE_DIR}/generic/lib/math/native_sin.cl
${CMAKE_CURRENT_SOURCE_DIR}/generic/lib/math/native_sqrt.cl
${CMAKE_CURRENT_SOURCE_DIR}/generic/lib/math/native_tan.cl
${CMAKE_CURRENT_SOURCE_DIR}/amdgpu/lib/math/native_exp.cl
${CMAKE_CURRENT_SOURCE_DIR}/amdgpu/lib/math/native_log.cl
${CMAKE_CURRENT_SOURCE_DIR}/amdgpu/lib/math/native_log10.cl
${CMAKE_CURRENT_SOURCE_DIR}/r600/lib/math/native_rsqrt.cl
PROPERTIES COMPILE_OPTIONS -fapprox-func
)

Expand Down
4 changes: 0 additions & 4 deletions libclc/amdgpu/lib/SOURCES
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
math/native_exp.cl
math/native_exp2.cl
math/native_log.cl
math/native_log10.cl
math/half_exp.cl
math/half_exp10.cl
math/half_exp2.cl
Expand Down
11 changes: 0 additions & 11 deletions libclc/amdgpu/lib/math/native_log.inc

This file was deleted.

22 changes: 22 additions & 0 deletions libclc/clc/include/clc/math/clc_native_cos.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===----------------------------------------------------------------------===//
//
// 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 __CLC_MATH_CLC_NATIVE_COS_H__
#define __CLC_MATH_CLC_NATIVE_COS_H__

#define __FLOAT_ONLY
#define __CLC_FUNCTION __clc_native_cos
#define __CLC_BODY <clc/shared/unary_decl.inc>

#include <clc/math/gentype.inc>

#undef __CLC_BODY
#undef __CLC_FUNCTION
#undef __FLOAT_ONLY

#endif // __CLC_MATH_CLC_NATIVE_COS_H__
22 changes: 22 additions & 0 deletions libclc/clc/include/clc/math/clc_native_exp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===----------------------------------------------------------------------===//
//
// 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 __CLC_MATH_CLC_NATIVE_EXP_H__
#define __CLC_MATH_CLC_NATIVE_EXP_H__

#define __FLOAT_ONLY
#define __CLC_FUNCTION __clc_native_exp
#define __CLC_BODY <clc/shared/unary_decl.inc>

#include <clc/math/gentype.inc>

#undef __CLC_BODY
#undef __CLC_FUNCTION
#undef __FLOAT_ONLY

#endif // __CLC_MATH_CLC_NATIVE_EXP_H__
22 changes: 22 additions & 0 deletions libclc/clc/include/clc/math/clc_native_exp2.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===----------------------------------------------------------------------===//
//
// 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 __CLC_MATH_CLC_NATIVE_EXP2_H__
#define __CLC_MATH_CLC_NATIVE_EXP2_H__

#define __FLOAT_ONLY
#define __CLC_FUNCTION __clc_native_exp2
#define __CLC_BODY <clc/shared/unary_decl.inc>

#include <clc/math/gentype.inc>

#undef __CLC_BODY
#undef __CLC_FUNCTION
#undef __FLOAT_ONLY

#endif // __CLC_MATH_CLC_NATIVE_EXP2_H__
22 changes: 22 additions & 0 deletions libclc/clc/include/clc/math/clc_native_log.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===----------------------------------------------------------------------===//
//
// 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 __CLC_MATH_CLC_NATIVE_LOG_H__
#define __CLC_MATH_CLC_NATIVE_LOG_H__

#define __FLOAT_ONLY
#define __CLC_FUNCTION __clc_native_log
#define __CLC_BODY <clc/shared/unary_decl.inc>

#include <clc/math/gentype.inc>

#undef __CLC_BODY
#undef __CLC_FUNCTION
#undef __FLOAT_ONLY

#endif // __CLC_MATH_CLC_NATIVE_LOG_H__
22 changes: 22 additions & 0 deletions libclc/clc/include/clc/math/clc_native_log10.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===----------------------------------------------------------------------===//
//
// 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 __CLC_MATH_CLC_NATIVE_LOG10_H__
#define __CLC_MATH_CLC_NATIVE_LOG10_H__

#define __FLOAT_ONLY
#define __CLC_FUNCTION __clc_native_log10
#define __CLC_BODY <clc/shared/unary_decl.inc>

#include <clc/math/gentype.inc>

#undef __CLC_BODY
#undef __CLC_FUNCTION
#undef __FLOAT_ONLY

#endif // __CLC_MATH_CLC_NATIVE_LOG10_H__
22 changes: 22 additions & 0 deletions libclc/clc/include/clc/math/clc_native_log2.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===----------------------------------------------------------------------===//
//
// 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 __CLC_MATH_CLC_NATIVE_LOG2_H__
#define __CLC_MATH_CLC_NATIVE_LOG2_H__

#define __FLOAT_ONLY
#define __CLC_FUNCTION __clc_native_log2
#define __CLC_BODY <clc/shared/unary_decl.inc>

#include <clc/math/gentype.inc>

#undef __CLC_BODY
#undef __CLC_FUNCTION
#undef __FLOAT_ONLY

#endif // __CLC_MATH_CLC_NATIVE_LOG2_H__
22 changes: 22 additions & 0 deletions libclc/clc/include/clc/math/clc_native_rsqrt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===----------------------------------------------------------------------===//
//
// 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 __CLC_MATH_CLC_NATIVE_RSQRT_H__
#define __CLC_MATH_CLC_NATIVE_RSQRT_H__

#define __FLOAT_ONLY
#define __CLC_FUNCTION __clc_native_rsqrt
#define __CLC_BODY <clc/shared/unary_decl.inc>

#include <clc/math/gentype.inc>

#undef __CLC_BODY
#undef __CLC_FUNCTION
#undef __FLOAT_ONLY

#endif // __CLC_MATH_CLC_NATIVE_RSQRT_H__
22 changes: 22 additions & 0 deletions libclc/clc/include/clc/math/clc_native_sin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===----------------------------------------------------------------------===//
//
// 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 __CLC_MATH_CLC_NATIVE_SIN_H__
#define __CLC_MATH_CLC_NATIVE_SIN_H__

#define __FLOAT_ONLY
#define __CLC_FUNCTION __clc_native_sin
#define __CLC_BODY <clc/shared/unary_decl.inc>

#include <clc/math/gentype.inc>

#undef __CLC_BODY
#undef __CLC_FUNCTION
#undef __FLOAT_ONLY

#endif // __CLC_MATH_CLC_NATIVE_SIN_H__
22 changes: 22 additions & 0 deletions libclc/clc/include/clc/math/clc_native_sqrt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===----------------------------------------------------------------------===//
//
// 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 __CLC_MATH_CLC_NATIVE_SQRT_H__
#define __CLC_MATH_CLC_NATIVE_SQRT_H__

#define __FLOAT_ONLY
#define __CLC_FUNCTION __clc_native_sqrt
#define __CLC_BODY <clc/shared/unary_decl.inc>

#include <clc/math/gentype.inc>

#undef __CLC_BODY
#undef __CLC_FUNCTION
#undef __FLOAT_ONLY

#endif // __CLC_MATH_CLC_NATIVE_SQRT_H__
42 changes: 0 additions & 42 deletions libclc/clc/include/clc/math/unary_intrin.inc

This file was deleted.

3 changes: 3 additions & 0 deletions libclc/clc/lib/amdgpu/SOURCES
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
math/clc_native_exp2.cl
math/clc_native_exp.cl
math/clc_native_log10.cl
math/clc_sqrt_fp64.cl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
//
//===----------------------------------------------------------------------===//

#include <clc/clc.h>
#include <clc/float/definitions.h>
#include <clc/internal/clc.h>
#include <clc/math/clc_native_exp2.h>

#define __CLC_BODY <native_log10.inc>
#define __CLC_BODY <clc_native_exp.inc>
#define __FLOAT_ONLY
#include <clc/math/gentype.inc>
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
//
//===----------------------------------------------------------------------===//

_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE native_exp(__CLC_GENTYPE val) {
return native_exp2(val * M_LOG2E_F);
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_native_exp(__CLC_GENTYPE val) {
return __clc_native_exp2(val * M_LOG2E_F);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
//
//===----------------------------------------------------------------------===//

#include <clc/clc.h>
#include <clc/clcmacro.h>
#include <clc/internal/clc.h>

_CLC_OVERLOAD _CLC_DEF float native_exp2(float val) {
_CLC_OVERLOAD _CLC_DEF float __clc_native_exp2(float val) {
return __builtin_amdgcn_exp2f(val);
}

_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, float, native_exp2, float)
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, float, __clc_native_exp2, float)
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
//
//===----------------------------------------------------------------------===//

#include <clc/clc.h>
#include <clc/float/definitions.h>
#include <clc/internal/clc.h>
#include <clc/math/clc_native_log2.h>

#define __CLC_BODY <native_log.inc>
#define __CLC_BODY <clc_native_log10.inc>
#define __FLOAT_ONLY
#include <clc/math/gentype.inc>
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
//
//===----------------------------------------------------------------------===//

_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE native_log10(__CLC_GENTYPE val) {
return native_log2(val) * (M_LN2_F / M_LN10_F);
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_native_log10(__CLC_GENTYPE val) {
return __clc_native_log2(val) * (M_LN2_F / M_LN10_F);
}
9 changes: 9 additions & 0 deletions libclc/clc/lib/generic/SOURCES
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ math/clc_log2.cl
math/clc_mad.cl
math/clc_modf.cl
math/clc_nan.cl
math/clc_native_cos.cl
math/clc_native_exp.cl
math/clc_native_exp2.cl
math/clc_native_log.cl
math/clc_native_log10.cl
math/clc_native_log2.cl
math/clc_native_rsqrt.cl
math/clc_native_sin.cl
math/clc_native_sqrt.cl
math/clc_nextafter.cl
math/clc_pow.cl
math/clc_pown.cl
Expand Down
Loading