Skip to content

[libclc] Move min/max/clamp into the CLC builtins library (#114386) #15948

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
Nov 5, 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
13 changes: 12 additions & 1 deletion libclc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -424,9 +424,19 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
set ( has_distinct_generic_addrspace TRUE )
if ( ARCH STREQUAL spirv OR ARCH STREQUAL spirv64 )
set( opt_flags -O3 )
list( APPEND build_flags -DCLC_SPIRV )
set( spvflags --spirv-max-version=1.1 )
set( MACRO_ARCH SPIRV32 )
if( ARCH STREQUAL spirv64 )
set( MACRO_ARCH SPIRV64 )
endif()
elseif( ARCH STREQUAL clspv OR ARCH STREQUAL clspv64 )
set( opt_flags -O3 )
list( APPEND build_flags -DCLC_CLSPV )
set( MACRO_ARCH CLSPV32 )
if( ARCH STREQUAL clspv64 )
set( MACRO_ARCH CLSPV64 )
endif()
elseif( ARCH STREQUAL nvptx OR ARCH STREQUAL nvptx64 )
set( opt_flags -O3 "--nvvm-reflect-enable=false" )
set( has_distinct_generic_addrspace FALSE )
Expand All @@ -437,6 +447,7 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
set( has_distinct_generic_addrspace FALSE )
else()
set( opt_flags -O3 )
set( MACRO_ARCH ${ARCH} )
endif()

# Enable SPIR-V builtin function declarations, so they don't
Expand Down Expand Up @@ -483,7 +494,7 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
list(APPEND build_flags -D__unix__)
endif()

string( TOUPPER "CLC_${ARCH}" CLC_TARGET_DEFINE )
string( TOUPPER "CLC_${MACRO_ARCH}" CLC_TARGET_DEFINE )

list( APPEND build_flags
-D__CLC_INTERNAL
Expand Down
4 changes: 2 additions & 2 deletions libclc/clc/include/clc/clcfunc.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

// avoid inlines for SPIR-V related targets since we'll optimise later in the
// chain
#if defined(CLC_SPIRV) || defined(CLC_SPIRV64)
#if defined(CLC_SPIRV)
#define _CLC_DEF
#elif defined(CLC_CLSPV) || defined(CLC_CLSPV64)
#elif defined(CLC_CLSPV)
#define _CLC_DEF __attribute__((noinline)) __attribute__((clspv_libclc_builtin))
#else
#define _CLC_DEF __attribute__((always_inline))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//

//These 2 defines only change when switching between data sizes or base types to
//keep this file manageable.
// These 2 defines only change when switching between data sizes or base types
// to keep this file manageable.

#define __CLC_GENSIZE 8
#define __CLC_SCALAR_GENTYPE char
Expand Down
15 changes: 15 additions & 0 deletions libclc/clc/include/clc/shared/clc_clamp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#if defined(CLC_CLSPV) || defined(CLC_SPIRV)
// clspv and spir-v targets provide their own OpenCL-compatible clamp
#define __clc_clamp clamp
#else

#include <clc/clcfunc.h>
#include <clc/clctypes.h>

#define __CLC_BODY <clc/shared/clc_clamp.inc>
#include <clc/integer/gentype.inc>

#define __CLC_BODY <clc/shared/clc_clamp.inc>
#include <clc/math/gentype.inc>

#endif
9 changes: 9 additions & 0 deletions libclc/clc/include/clc/shared/clc_clamp.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __clc_clamp(__CLC_GENTYPE x,
__CLC_GENTYPE y,
__CLC_GENTYPE z);

#ifndef __CLC_SCALAR
_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __clc_clamp(__CLC_GENTYPE x,
__CLC_SCALAR_GENTYPE y,
__CLC_SCALAR_GENTYPE z);
#endif
12 changes: 12 additions & 0 deletions libclc/clc/include/clc/shared/clc_max.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#if defined(CLC_CLSPV) || defined(CLC_SPIRV)
// clspv and spir-v targets provide their own OpenCL-compatible max
#define __clc_max max
#else

#define __CLC_BODY <clc/shared/clc_max.inc>
#include <clc/integer/gentype.inc>

#define __CLC_BODY <clc/shared/clc_max.inc>
#include <clc/math/gentype.inc>

#endif
7 changes: 7 additions & 0 deletions libclc/clc/include/clc/shared/clc_max.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __clc_max(__CLC_GENTYPE a,
__CLC_GENTYPE b);

#ifndef __CLC_SCALAR
_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __clc_max(__CLC_GENTYPE a,
__CLC_SCALAR_GENTYPE b);
#endif
12 changes: 12 additions & 0 deletions libclc/clc/include/clc/shared/clc_min.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#if defined(CLC_CLSPV) || defined(CLC_SPIRV)
// clspv and spir-v targets provide their own OpenCL-compatible min
#define __clc_min min
#else

#define __CLC_BODY <clc/shared/clc_min.inc>
#include <clc/integer/gentype.inc>

#define __CLC_BODY <clc/shared/clc_min.inc>
#include <clc/math/gentype.inc>

#endif
7 changes: 7 additions & 0 deletions libclc/clc/include/clc/shared/clc_min.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __clc_min(__CLC_GENTYPE a,
__CLC_GENTYPE b);

#ifndef __CLC_SCALAR
_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __clc_min(__CLC_GENTYPE a,
__CLC_SCALAR_GENTYPE b);
#endif
3 changes: 3 additions & 0 deletions libclc/clc/lib/generic/SOURCES
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
geometric/clc_dot.cl
shared/clc_clamp.cl
shared/clc_max.cl
shared/clc_min.cl
7 changes: 7 additions & 0 deletions libclc/clc/lib/generic/shared/clc_clamp.cl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <clc/internal/clc.h>

#define __CLC_BODY <clc_clamp.inc>
#include <clc/integer/gentype.inc>

#define __CLC_BODY <clc_clamp.inc>
#include <clc/math/gentype.inc>
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//

_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_clamp(__CLC_GENTYPE x,
__CLC_GENTYPE y,
__CLC_GENTYPE z) {
Expand Down
7 changes: 7 additions & 0 deletions libclc/clc/lib/generic/shared/clc_max.cl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <clc/internal/clc.h>

#define __CLC_BODY <clc_max.inc>
#include <clc/integer/gentype.inc>

#define __CLC_BODY <clc_max.inc>
#include <clc/math/gentype.inc>
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//

_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_max(__CLC_GENTYPE a,
__CLC_GENTYPE b) {
return (a > b ? a : b);
Expand Down
7 changes: 7 additions & 0 deletions libclc/clc/lib/generic/shared/clc_min.cl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <clc/internal/clc.h>

#define __CLC_BODY <clc_min.inc>
#include <clc/integer/gentype.inc>

#define __CLC_BODY <clc_min.inc>
#include <clc/math/gentype.inc>
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//

_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_min(__CLC_GENTYPE a,
__CLC_GENTYPE b) {
return (b < a ? b : a);
Expand Down
2 changes: 1 addition & 1 deletion libclc/generic/lib/common/smoothstep.cl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ _CLC_TERNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, smoothstep, double,
_CLC_V_S_S_V_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, smoothstep, double,
double, double);

#if !defined(CLC_SPIRV) && !defined(CLC_SPIRV64)
#if !defined(CLC_SPIRV)
SMOOTH_STEP_DEF(float, double, SMOOTH_STEP_IMPL_D);
SMOOTH_STEP_DEF(double, float, SMOOTH_STEP_IMPL_D);

Expand Down
2 changes: 1 addition & 1 deletion libclc/generic/lib/common/step.cl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ STEP_DEF(double, double);
_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, step, double, double);
_CLC_V_S_V_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, step, double, double);

#if !defined(CLC_SPIRV) && !defined(CLC_SPIRV64)
#if !defined(CLC_SPIRV)
STEP_DEF(float, double);
STEP_DEF(double, float);

Expand Down
Loading
Loading