diff options
Diffstat (limited to 'libclc')
-rw-r--r-- | libclc/CMakeLists.txt | 48 | ||||
-rw-r--r-- | libclc/clc/include/clc/math/unary_def_via_fp32.inc | 11 | ||||
-rw-r--r-- | libclc/clc/lib/amdgcn/SOURCES | 2 | ||||
-rw-r--r-- | libclc/clc/lib/generic/geometric/clc_normalize.inc | 17 | ||||
-rw-r--r-- | libclc/clc/lib/generic/math/clc_erf.cl | 26 | ||||
-rw-r--r-- | libclc/clc/lib/generic/math/clc_erfc.cl | 24 | ||||
-rw-r--r-- | libclc/clc/lib/generic/math/clc_fmax.cl | 47 | ||||
-rw-r--r-- | libclc/clc/lib/generic/math/clc_fmin.cl | 46 | ||||
-rw-r--r-- | libclc/clc/lib/generic/math/clc_tgamma.cl | 26 | ||||
-rw-r--r-- | libclc/clc/lib/r600/SOURCES | 2 | ||||
-rw-r--r-- | libclc/clc/lib/r600/math/clc_fmax.cl | 41 | ||||
-rw-r--r-- | libclc/clc/lib/r600/math/clc_fmin.cl | 42 | ||||
-rw-r--r-- | libclc/clc/lib/spirv/SOURCES | 2 | ||||
-rw-r--r-- | libclc/clc/lib/spirv/math/clc_fmax.cl (renamed from libclc/clc/lib/amdgcn/math/clc_fmax.cl) | 21 | ||||
-rw-r--r-- | libclc/clc/lib/spirv/math/clc_fmin.cl (renamed from libclc/clc/lib/amdgcn/math/clc_fmin.cl) | 20 | ||||
-rw-r--r-- | libclc/cmake/modules/AddLibclc.cmake | 33 |
16 files changed, 96 insertions, 312 deletions
diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt index e4e9a74..5b95edc 100644 --- a/libclc/CMakeLists.txt +++ b/libclc/CMakeLists.txt @@ -42,6 +42,16 @@ set( LIBCLC_TARGETS_TO_BUILD "all" option( ENABLE_RUNTIME_SUBNORMAL "Enable runtime linking of subnormal support." OFF ) +option( + LIBCLC_USE_SPIRV_BACKEND "Build SPIR-V targets with the SPIR-V backend." OFF +) + +# Top level target used to build all Libclc libraries. +add_custom_target( libclc ALL ) + +add_custom_target( libclc-opencl-builtins COMMENT "Build libclc OpenCL builtins" ) +add_dependencies( libclc libclc-opencl-builtins ) + if( LIBCLC_STANDALONE_BUILD OR CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR ) # Out-of-tree configuration set( LIBCLC_STANDALONE_BUILD TRUE ) @@ -109,14 +119,17 @@ foreach( tool IN ITEMS clang opt llvm-as llvm-link ) endif() endforeach() -# llvm-spirv is an optional dependency, used to build spirv-* targets. -# It may be provided in-tree or externally. -if( TARGET llvm-spirv ) - get_host_tool_path( llvm-spirv LLVM_SPIRV llvm-spirv_exe llvm-spirv_target ) -else() - find_program( LLVM_SPIRV llvm-spirv HINTS ${LLVM_TOOLS_BINARY_DIR} ) - set( llvm-spirv_exe "${LLVM_SPIRV}" ) - set( llvm-spirv_target ) +if( NOT LIBCLC_USE_SPIRV_BACKEND ) + # llvm-spirv is an optional dependency, used to build spirv-* targets when + # the SPIR-V backend hasn't been requested. It may be provided in-tree or + # externally. + if( TARGET llvm-spirv ) + get_host_tool_path( llvm-spirv LLVM_SPIRV llvm-spirv_exe llvm-spirv_target ) + else() + find_program( LLVM_SPIRV llvm-spirv HINTS ${LLVM_TOOLS_BINARY_DIR} ) + set( llvm-spirv_exe "${LLVM_SPIRV}" ) + set( llvm-spirv_target ) + endif() endif() # List of all targets. Note that some are added dynamically below. @@ -132,22 +145,24 @@ set( LIBCLC_TARGETS_ALL nvptx64--nvidiacl ) -# mesa3d environment is only available since LLVM 4.0 +# The mesa3d environment is only available since LLVM 4.0 if( LLVM_PACKAGE_VERSION VERSION_GREATER_EQUAL 4.0.0 ) list( APPEND LIBCLC_TARGETS_ALL amdgcn-mesa-mesa3d ) endif() -# spirv-mesa3d and spirv64-mesa3d targets can only be built with the (optional) -# llvm-spirv external tool. -if( llvm-spirv_exe ) - list( APPEND LIBCLC_TARGETS_ALL spirv-mesa3d- spirv64-mesa3d- ) +# The spirv-mesa3d and spirv64-mesa3d targets are optional and can be built +# with either the LLVM SPIR-V backend or the external llvm-spirv tool. +if( LIBCLC_USE_SPIRV_BACKEND OR llvm-spirv_exe ) + list( APPEND LIBCLC_TARGETS_ALL spirv-mesa3d- spirv64-mesa3d- ) endif() # Verify that the user hasn't requested mesa3d targets without an available # llvm-spirv tool. -if( "spirv-mesa3d-" IN_LIST LIBCLC_TARGETS_TO_BUILD OR "spirv64-mesa3d-" IN_LIST LIBCLC_TARGETS_TO_BUILD ) - if( NOT llvm-spirv_exe ) - message( FATAL_ERROR "SPIR-V targets requested, but spirv-tools is not installed" ) +if( spirv-mesa3d- IN_LIST LIBCLC_TARGETS_TO_BUILD + OR spirv64-mesa3d- IN_LIST LIBCLC_TARGETS_TO_BUILD ) + if( NOT LIBCLC_USE_SPIRV_BACKEND AND NOT llvm-spirv_exe ) + message( FATAL_ERROR "SPIR-V targets requested, but spirv-tools is not " + "installed and the SPIR-V backend has not been requested." ) endif() endif() @@ -463,6 +478,7 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} ) LIB_FILES ${opencl_lib_files} GEN_FILES ${opencl_gen_files} ALIASES ${${d}_aliases} + PARENT_TARGET libclc-opencl-builtins # Link in the CLC builtins and internalize their symbols INTERNAL_LINK_DEPENDENCIES builtins.link.clc-${arch_suffix} ) diff --git a/libclc/clc/include/clc/math/unary_def_via_fp32.inc b/libclc/clc/include/clc/math/unary_def_via_fp32.inc deleted file mode 100644 index f109e8e..0000000 --- a/libclc/clc/include/clc/math/unary_def_via_fp32.inc +++ /dev/null @@ -1,11 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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 FUNCTION(__CLC_GENTYPE x) { - return __CLC_CONVERT_GENTYPE(FUNCTION(__CLC_CONVERT_FLOATN(x))); -} diff --git a/libclc/clc/lib/amdgcn/SOURCES b/libclc/clc/lib/amdgcn/SOURCES index 7bec174..d91f085 100644 --- a/libclc/clc/lib/amdgcn/SOURCES +++ b/libclc/clc/lib/amdgcn/SOURCES @@ -1,5 +1,3 @@ -math/clc_fmax.cl -math/clc_fmin.cl math/clc_ldexp_override.cl workitem/clc_get_global_offset.cl workitem/clc_get_global_size.cl diff --git a/libclc/clc/lib/generic/geometric/clc_normalize.inc b/libclc/clc/lib/generic/geometric/clc_normalize.inc index 8a47c6d..9b2cbc8 100644 --- a/libclc/clc/lib/generic/geometric/clc_normalize.inc +++ b/libclc/clc/lib/generic/geometric/clc_normalize.inc @@ -10,15 +10,8 @@ #if (__CLC_VECSIZE_OR_1 == 1 || __CLC_VECSIZE_OR_1 == 2 || \ __CLC_VECSIZE_OR_1 == 3 || __CLC_VECSIZE_OR_1 == 4) -// Until we have a native FP16 implementation, go via FP32 -#if __CLC_FPSIZE == 16 - -_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_normalize(__CLC_GENTYPE p) { - return __CLC_CONVERT_GENTYPE(__clc_normalize(__CLC_CONVERT_FLOATN(p))); -} - // Scalar normalize -#elif defined(__CLC_SCALAR) +#if defined(__CLC_SCALAR) _CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_normalize(__CLC_GENTYPE p) { return __clc_sign(p); @@ -27,7 +20,13 @@ _CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_normalize(__CLC_GENTYPE p) { // Vector normalize #else -#if __CLC_FPSIZE == 32 +#if __CLC_FPSIZE == 16 + +#define MIN_VAL HALF_MIN +#define MAX_SQRT 0x1.0p+8h +#define MIN_SQRT 0x1.0p-8h + +#elif __CLC_FPSIZE == 32 #define MIN_VAL FLT_MIN #define MAX_SQRT 0x1.0p+86F diff --git a/libclc/clc/lib/generic/math/clc_erf.cl b/libclc/clc/lib/generic/math/clc_erf.cl index 17fee3e..bea3924 100644 --- a/libclc/clc/lib/generic/math/clc_erf.cl +++ b/libclc/clc/lib/generic/math/clc_erf.cl @@ -6,7 +6,6 @@ // //===----------------------------------------------------------------------===// -#include <clc/clcmacro.h> #include <clc/internal/clc.h> #include <clc/math/clc_exp.h> #include <clc/math/clc_fabs.h> @@ -211,12 +210,6 @@ _CLC_OVERLOAD _CLC_DEF float __clc_erf(float x) { return ret; } -#define __FLOAT_ONLY -#define FUNCTION __clc_erf -#define __CLC_BODY <clc/shared/unary_def_scalarize.inc> -#include <clc/math/gentype.inc> -#undef FUNCTION - #ifdef cl_khr_fp64 #pragma OPENCL EXTENSION cl_khr_fp64 : enable @@ -500,24 +493,19 @@ _CLC_OVERLOAD _CLC_DEF double __clc_erf(double y) { return y < 0.0 ? -ret : ret; } -#define __DOUBLE_ONLY -#define FUNCTION __clc_erf -#define __CLC_BODY <clc/shared/unary_def_scalarize.inc> -#include <clc/math/gentype.inc> -#undef FUNCTION - #endif #ifdef cl_khr_fp16 -#include <clc/clc_convert.h> - #pragma OPENCL EXTENSION cl_khr_fp16 : enable // Forward the half version of this builtin onto the float one -#define __HALF_ONLY -#define FUNCTION __clc_erf -#define __CLC_BODY <clc/math/unary_def_via_fp32.inc> -#include <clc/math/gentype.inc> +_CLC_OVERLOAD _CLC_DEF half __clc_erf(half x) { + return (half)__clc_erf((float)x); +} #endif + +#define FUNCTION __clc_erf +#define __CLC_BODY <clc/shared/unary_def_scalarize.inc> +#include <clc/math/gentype.inc> diff --git a/libclc/clc/lib/generic/math/clc_erfc.cl b/libclc/clc/lib/generic/math/clc_erfc.cl index 77f8959..fab6960 100644 --- a/libclc/clc/lib/generic/math/clc_erfc.cl +++ b/libclc/clc/lib/generic/math/clc_erfc.cl @@ -6,7 +6,6 @@ // //===----------------------------------------------------------------------===// -#include <clc/clcmacro.h> #include <clc/internal/clc.h> #include <clc/math/clc_exp.h> #include <clc/math/clc_fabs.h> @@ -211,12 +210,6 @@ _CLC_OVERLOAD _CLC_DEF float __clc_erfc(float x) { return ret; } -#define __FLOAT_ONLY -#define FUNCTION __clc_erfc -#define __CLC_BODY <clc/shared/unary_def_scalarize.inc> -#include <clc/math/gentype.inc> -#undef FUNCTION - #ifdef cl_khr_fp64 #pragma OPENCL EXTENSION cl_khr_fp64 : enable @@ -509,12 +502,6 @@ _CLC_OVERLOAD _CLC_DEF double __clc_erfc(double x) { return ret; } -#define __DOUBLE_ONLY -#define FUNCTION __clc_erfc -#define __CLC_BODY <clc/shared/unary_def_scalarize.inc> -#include <clc/math/gentype.inc> -#undef FUNCTION - #endif #ifdef cl_khr_fp16 @@ -524,9 +511,12 @@ _CLC_OVERLOAD _CLC_DEF double __clc_erfc(double x) { #pragma OPENCL EXTENSION cl_khr_fp16 : enable // Forward the half version of this builtin onto the float one -#define __HALF_ONLY -#define FUNCTION __clc_erfc -#define __CLC_BODY <clc/math/unary_def_via_fp32.inc> -#include <clc/math/gentype.inc> +_CLC_OVERLOAD _CLC_DEF half __clc_erfc(half x) { + return (half)__clc_erfc((float)x); +} #endif + +#define FUNCTION __clc_erfc +#define __CLC_BODY <clc/shared/unary_def_scalarize.inc> +#include <clc/math/gentype.inc> diff --git a/libclc/clc/lib/generic/math/clc_fmax.cl b/libclc/clc/lib/generic/math/clc_fmax.cl index 5ebbf1b..b334207 100644 --- a/libclc/clc/lib/generic/math/clc_fmax.cl +++ b/libclc/clc/lib/generic/math/clc_fmax.cl @@ -6,53 +6,10 @@ // //===----------------------------------------------------------------------===// -#include <clc/clcmacro.h> #include <clc/internal/clc.h> -#include <clc/relational/clc_isnan.h> -#define __FLOAT_ONLY -#define __CLC_MIN_VECSIZE 1 #define FUNCTION __clc_fmax -#define __IMPL_FUNCTION __builtin_fmaxf -#define __CLC_BODY <clc/shared/binary_def_scalarize.inc> -#include <clc/math/gentype.inc> -#undef __CLC_MIN_VECSIZE -#undef FUNCTION -#undef __IMPL_FUNCTION - -#ifdef cl_khr_fp64 - -#pragma OPENCL EXTENSION cl_khr_fp64 : enable - -#define __DOUBLE_ONLY -#define __CLC_MIN_VECSIZE 1 -#define FUNCTION __clc_fmax -#define __IMPL_FUNCTION __builtin_fmax -#define __CLC_BODY <clc/shared/binary_def_scalarize.inc> -#include <clc/math/gentype.inc> -#undef __CLC_MIN_VECSIZE -#undef FUNCTION -#undef __IMPL_FUNCTION +#define __IMPL_FUNCTION(x) __builtin_elementwise_maximumnum +#define __CLC_BODY <clc/shared/binary_def.inc> -#endif - -#ifdef cl_khr_fp16 - -#pragma OPENCL EXTENSION cl_khr_fp16 : enable - -_CLC_DEF _CLC_OVERLOAD half __clc_fmax(half x, half y) { - if (__clc_isnan(x)) - return y; - if (__clc_isnan(y)) - return x; - return (x < y) ? y : x; -} - -#define __HALF_ONLY -#define __CLC_SUPPORTED_VECSIZE_OR_1 2 -#define FUNCTION __clc_fmax -#define __CLC_BODY <clc/shared/binary_def_scalarize.inc> #include <clc/math/gentype.inc> -#undef FUNCTION - -#endif diff --git a/libclc/clc/lib/generic/math/clc_fmin.cl b/libclc/clc/lib/generic/math/clc_fmin.cl index 5bddbb8..d21bb8d 100644 --- a/libclc/clc/lib/generic/math/clc_fmin.cl +++ b/libclc/clc/lib/generic/math/clc_fmin.cl @@ -6,52 +6,10 @@ // //===----------------------------------------------------------------------===// -#include <clc/clcmacro.h> #include <clc/internal/clc.h> -#include <clc/relational/clc_isnan.h> -#define __FLOAT_ONLY -#define __CLC_MIN_VECSIZE 1 #define FUNCTION __clc_fmin -#define __IMPL_FUNCTION __builtin_fminf -#define __CLC_BODY <clc/shared/binary_def_scalarize.inc> -#include <clc/math/gentype.inc> -#undef __CLC_MIN_VECSIZE -#undef FUNCTION -#undef __IMPL_FUNCTION - -#ifdef cl_khr_fp64 - -#pragma OPENCL EXTENSION cl_khr_fp64 : enable - -#define __DOUBLE_ONLY -#define __CLC_MIN_VECSIZE 1 -#define FUNCTION __clc_fmin -#define __IMPL_FUNCTION __builtin_fmin -#define __CLC_BODY <clc/shared/binary_def_scalarize.inc> -#include <clc/math/gentype.inc> -#undef __CLC_MIN_VECSIZE -#undef FUNCTION -#undef __IMPL_FUNCTION +#define __IMPL_FUNCTION(x) __builtin_elementwise_minimumnum +#define __CLC_BODY <clc/shared/binary_def.inc> -#endif - -#ifdef cl_khr_fp16 - -#pragma OPENCL EXTENSION cl_khr_fp16 : enable - -_CLC_DEF _CLC_OVERLOAD half __clc_fmin(half x, half y) { - if (__clc_isnan(x)) - return y; - if (__clc_isnan(y)) - return x; - return (y < x) ? y : x; -} - -#define __HALF_ONLY -#define __CLC_SUPPORTED_VECSIZE_OR_1 2 -#define FUNCTION __clc_fmin -#define __CLC_BODY <clc/shared/binary_def_scalarize.inc> #include <clc/math/gentype.inc> - -#endif diff --git a/libclc/clc/lib/generic/math/clc_tgamma.cl b/libclc/clc/lib/generic/math/clc_tgamma.cl index e0fed98..83b09cc 100644 --- a/libclc/clc/lib/generic/math/clc_tgamma.cl +++ b/libclc/clc/lib/generic/math/clc_tgamma.cl @@ -6,7 +6,6 @@ // //===----------------------------------------------------------------------===// -#include <clc/clcmacro.h> #include <clc/float/definitions.h> #include <clc/internal/clc.h> #include <clc/math/clc_exp.h> @@ -32,12 +31,6 @@ _CLC_OVERLOAD _CLC_DEF float __clc_tgamma(float x) { return g; } -#define __FLOAT_ONLY -#define FUNCTION __clc_tgamma -#define __CLC_BODY <clc/shared/unary_def_scalarize.inc> -#include <clc/math/gentype.inc> -#undef FUNCTION - #ifdef cl_khr_fp64 #pragma OPENCL EXTENSION cl_khr_fp64 : enable @@ -59,24 +52,19 @@ _CLC_OVERLOAD _CLC_DEF double __clc_tgamma(double x) { return g; } -#define __DOUBLE_ONLY -#define FUNCTION __clc_tgamma -#define __CLC_BODY <clc/shared/unary_def_scalarize.inc> -#include <clc/math/gentype.inc> -#undef FUNCTION - #endif #ifdef cl_khr_fp16 -#include <clc/clc_convert.h> - #pragma OPENCL EXTENSION cl_khr_fp16 : enable // Forward the half version of this builtin onto the float one -#define __HALF_ONLY -#define FUNCTION __clc_tgamma -#define __CLC_BODY <clc/math/unary_def_via_fp32.inc> -#include <clc/math/gentype.inc> +_CLC_OVERLOAD _CLC_DEF half __clc_tgamma(half x) { + return (half)__clc_tgamma((float)x); +} #endif + +#define FUNCTION __clc_tgamma +#define __CLC_BODY <clc/shared/unary_def_scalarize.inc> +#include <clc/math/gentype.inc> diff --git a/libclc/clc/lib/r600/SOURCES b/libclc/clc/lib/r600/SOURCES index 75d32f4..8d5caf1 100644 --- a/libclc/clc/lib/r600/SOURCES +++ b/libclc/clc/lib/r600/SOURCES @@ -1,4 +1,2 @@ -math/clc_fmax.cl -math/clc_fmin.cl math/clc_native_rsqrt.cl math/clc_rsqrt_override.cl diff --git a/libclc/clc/lib/r600/math/clc_fmax.cl b/libclc/clc/lib/r600/math/clc_fmax.cl deleted file mode 100644 index 689e51a..0000000 --- a/libclc/clc/lib/r600/math/clc_fmax.cl +++ /dev/null @@ -1,41 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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 <clc/clcmacro.h> -#include <clc/internal/clc.h> -#include <clc/math/math.h> - -_CLC_DEF _CLC_OVERLOAD float __clc_fmax(float x, float y) { - // Flush denormals if not enabled. Otherwise fmax instruction flushes the - // values for comparison, but outputs original denormal - x = __clc_flush_denormal_if_not_supported(x); - y = __clc_flush_denormal_if_not_supported(y); - return __builtin_fmaxf(x, y); -} - -#define __FLOAT_ONLY -#define FUNCTION __clc_fmax -#define __CLC_BODY <clc/shared/binary_def_scalarize.inc> -#include <clc/math/gentype.inc> -#undef FUNCTION - -#ifdef cl_khr_fp64 - -#pragma OPENCL EXTENSION cl_khr_fp64 : enable - -_CLC_DEF _CLC_OVERLOAD double __clc_fmax(double x, double y) { - return __builtin_fmax(x, y); -} - -#define __DOUBLE_ONLY -#define FUNCTION __clc_fmax -#define __CLC_BODY <clc/shared/binary_def_scalarize.inc> -#include <clc/math/gentype.inc> -#undef FUNCTION - -#endif diff --git a/libclc/clc/lib/r600/math/clc_fmin.cl b/libclc/clc/lib/r600/math/clc_fmin.cl deleted file mode 100644 index 22cb704..0000000 --- a/libclc/clc/lib/r600/math/clc_fmin.cl +++ /dev/null @@ -1,42 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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 <clc/clcmacro.h> -#include <clc/internal/clc.h> -#include <clc/math/math.h> - -_CLC_DEF _CLC_OVERLOAD float __clc_fmin(float x, float y) { - // fcanonicalize removes sNaNs and flushes denormals if not enabled. Otherwise - // fmin instruction flushes the values for comparison, but outputs original - // denormal - x = __clc_flush_denormal_if_not_supported(x); - y = __clc_flush_denormal_if_not_supported(y); - return __builtin_fminf(x, y); -} - -#define __FLOAT_ONLY -#define FUNCTION __clc_fmin -#define __CLC_BODY <clc/shared/binary_def_scalarize.inc> -#include <clc/math/gentype.inc> -#undef FUNCTION - -#ifdef cl_khr_fp64 - -#pragma OPENCL EXTENSION cl_khr_fp64 : enable - -_CLC_DEF _CLC_OVERLOAD double __clc_fmin(double x, double y) { - return __builtin_fmin(x, y); -} - -#define __DOUBLE_ONLY -#define FUNCTION __clc_fmin -#define __CLC_BODY <clc/shared/binary_def_scalarize.inc> -#include <clc/math/gentype.inc> -#undef FUNCTION - -#endif diff --git a/libclc/clc/lib/spirv/SOURCES b/libclc/clc/lib/spirv/SOURCES index cd6e0b2..07bc7aa 100644 --- a/libclc/clc/lib/spirv/SOURCES +++ b/libclc/clc/lib/spirv/SOURCES @@ -1 +1,3 @@ +math/clc_fmax.cl +math/clc_fmin.cl math/clc_runtime_has_hw_fma32.cl diff --git a/libclc/clc/lib/amdgcn/math/clc_fmax.cl b/libclc/clc/lib/spirv/math/clc_fmax.cl index cea90a7..be660fe 100644 --- a/libclc/clc/lib/amdgcn/math/clc_fmax.cl +++ b/libclc/clc/lib/spirv/math/clc_fmax.cl @@ -8,40 +8,23 @@ #include <clc/clcmacro.h> #include <clc/internal/clc.h> -#include <clc/relational/clc_isnan.h> _CLC_DEF _CLC_OVERLOAD float __clc_fmax(float x, float y) { - // fcanonicalize removes sNaNs and flushes denormals if not enabled. Otherwise - // fmax instruction flushes the values for comparison, but outputs original - // denormal - x = __builtin_canonicalizef(x); - y = __builtin_canonicalizef(y); return __builtin_fmaxf(x, y); } #ifdef cl_khr_fp64 - #pragma OPENCL EXTENSION cl_khr_fp64 : enable - _CLC_DEF _CLC_OVERLOAD double __clc_fmax(double x, double y) { - x = __builtin_canonicalize(x); - y = __builtin_canonicalize(y); return __builtin_fmax(x, y); } - #endif -#ifdef cl_khr_fp16 +#ifdef cl_khr_fp16 #pragma OPENCL EXTENSION cl_khr_fp16 : enable - _CLC_DEF _CLC_OVERLOAD half __clc_fmax(half x, half y) { - if (__clc_isnan(x)) - return y; - if (__clc_isnan(y)) - return x; - return (y < x) ? x : y; + return __builtin_fmaxf16(x, y); } - #endif #define FUNCTION __clc_fmax diff --git a/libclc/clc/lib/amdgcn/math/clc_fmin.cl b/libclc/clc/lib/spirv/math/clc_fmin.cl index 12bb0c6..9f3fa66 100644 --- a/libclc/clc/lib/amdgcn/math/clc_fmin.cl +++ b/libclc/clc/lib/spirv/math/clc_fmin.cl @@ -8,41 +8,23 @@ #include <clc/clcmacro.h> #include <clc/internal/clc.h> -#include <clc/relational/clc_isnan.h> _CLC_DEF _CLC_OVERLOAD float __clc_fmin(float x, float y) { - // fcanonicalize removes sNaNs and flushes denormals if not enabled. Otherwise - // fmin instruction flushes the values for comparison, but outputs original - // denormal - x = __builtin_canonicalizef(x); - y = __builtin_canonicalizef(y); return __builtin_fminf(x, y); } #ifdef cl_khr_fp64 - #pragma OPENCL EXTENSION cl_khr_fp64 : enable - _CLC_DEF _CLC_OVERLOAD double __clc_fmin(double x, double y) { - x = __builtin_canonicalize(x); - y = __builtin_canonicalize(y); return __builtin_fmin(x, y); } - #endif #ifdef cl_khr_fp16 - #pragma OPENCL EXTENSION cl_khr_fp16 : enable - _CLC_DEF _CLC_OVERLOAD half __clc_fmin(half x, half y) { - if (__clc_isnan(x)) - return y; - if (__clc_isnan(y)) - return x; - return (y < x) ? y : x; + return __builtin_fminf16(x, y); } - #endif #define FUNCTION __clc_fmin diff --git a/libclc/cmake/modules/AddLibclc.cmake b/libclc/cmake/modules/AddLibclc.cmake index dc4b1e8..47185586 100644 --- a/libclc/cmake/modules/AddLibclc.cmake +++ b/libclc/cmake/modules/AddLibclc.cmake @@ -164,7 +164,9 @@ function(get_libclc_device_info) list( GET TRIPLE 0 ARCH ) # Some targets don't have a specific device architecture to target - if( ARG_DEVICE STREQUAL none OR ARCH STREQUAL spirv OR ARCH STREQUAL spirv64 ) + if( ARG_DEVICE STREQUAL none + OR ((ARCH STREQUAL spirv OR ARCH STREQUAL spirv64) + AND NOT LIBCLC_USE_SPIRV_BACKEND) ) set( cpu ) set( arch_suffix "${ARG_TRIPLE}" ) else() @@ -182,7 +184,11 @@ function(get_libclc_device_info) # Some libclc targets are not real clang triples: return their canonical # triples. - if( ARCH STREQUAL spirv OR ARCH STREQUAL clspv ) + if( ARCH STREQUAL spirv AND LIBCLC_USE_SPIRV_BACKEND ) + set( ARG_TRIPLE "spirv32--" ) + elseif( ARCH STREQUAL spirv64 AND LIBCLC_USE_SPIRV_BACKEND ) + set( ARG_TRIPLE "spirv64--" ) + elseif( ARCH STREQUAL spirv OR ARCH STREQUAL clspv ) set( ARG_TRIPLE "spir--" ) elseif( ARCH STREQUAL spirv64 OR ARCH STREQUAL clspv64 ) set( ARG_TRIPLE "spir64--" ) @@ -207,6 +213,8 @@ endfunction() # libclc architecture/triple suffix # * TRIPLE <string> # Triple used to compile +# * PARENT_TARGET <string> +# Target into which to group the target builtins # # Optional Arguments: # * CLC_INTERNAL @@ -229,7 +237,7 @@ endfunction() function(add_libclc_builtin_set) cmake_parse_arguments(ARG "CLC_INTERNAL" - "ARCH;TRIPLE;ARCH_SUFFIX" + "ARCH;TRIPLE;ARCH_SUFFIX;PARENT_TARGET" "LIB_FILES;GEN_FILES;COMPILE_FLAGS;OPT_FLAGS;ALIASES;INTERNAL_LINK_DEPENDENCIES" ${ARGN} ) @@ -361,10 +369,17 @@ function(add_libclc_builtin_set) if( ARG_ARCH STREQUAL spirv OR ARG_ARCH STREQUAL spirv64 ) set( obj_suffix ${ARG_ARCH_SUFFIX}.spv ) set( libclc_builtins_lib ${LIBCLC_OUTPUT_LIBRARY_DIR}/${obj_suffix} ) - add_custom_command( OUTPUT ${libclc_builtins_lib} - COMMAND ${llvm-spirv_exe} ${spvflags} -o ${libclc_builtins_lib} ${builtins_link_lib} - DEPENDS ${llvm-spirv_target} ${builtins_link_lib} ${builtins_link_lib_tgt} - ) + if ( LIBCLC_USE_SPIRV_BACKEND ) + add_custom_command( OUTPUT ${libclc_builtins_lib} + COMMAND ${clang_exe} --target=${ARG_TRIPLE} -x ir -o ${libclc_builtins_lib} ${builtins_link_lib} + DEPENDS ${clang_target} ${builtins_link_lib} ${builtins_link_lib_tgt} + ) + else() + add_custom_command( OUTPUT ${libclc_builtins_lib} + COMMAND ${llvm-spirv_exe} ${spvflags} -o ${libclc_builtins_lib} ${builtins_link_lib} + DEPENDS ${llvm-spirv_target} ${builtins_link_lib} ${builtins_link_lib_tgt} + ) + endif() else() # Non-SPIR-V targets add an extra step to optimize the bytecode set( builtins_opt_lib_tgt builtins.opt.${ARG_ARCH_SUFFIX} ) @@ -403,6 +418,9 @@ function(add_libclc_builtin_set) add_custom_target( prepare-${ARG_TRIPLE} ALL ) endif() add_dependencies( prepare-${ARG_TRIPLE} prepare-${obj_suffix} ) + # Add dependency to top-level pseudo target to ease making other + # targets dependent on libclc. + add_dependencies( ${ARG_PARENT_TARGET} prepare-${ARG_TRIPLE} ) install( FILES ${libclc_builtins_lib} @@ -445,6 +463,7 @@ function(add_libclc_builtin_set) add_custom_target( alias-${alias_suffix} ALL DEPENDS ${LIBCLC_OUTPUT_LIBRARY_DIR}/${alias_suffix} ) + add_dependencies( ${ARG_PARENT_TARGET} alias-${alias_suffix} ) set_target_properties( alias-${alias_suffix} PROPERTIES FOLDER "libclc/Device IR/Aliases" ) |