From 6d1436df373a8217bf43cb106b51cf17a2ee0713 Mon Sep 17 00:00:00 2001 From: Fraser Cormack Date: Tue, 24 Sep 2024 17:34:50 +0100 Subject: [PATCH 1/3] [libclc] Create an internal 'clc' builtins library Some libclc builtins currently use internal builtins prefixed with '__clc_' for various reasons, e.g., to avoid naming clashes. This commit formalizes this concept by starting to isolate the definitions of these internal clc builtins into a separate self-contained bytecode library, which is linked into each target's libclc OpenCL builtins before optimization takes place. The goal of this step is to allow additional libraries of builtins that provide entry points (or bindings) that are not written in OpenCL C but still wish to expose OpenCL-compatible builtins. By moving the implementations into a separate self-contained library, entry points can share as much code as possible without going through OpenCL C. The overall structure of the internal clc library is similar to the current OpenCL structure, with SOURCES files and targets being able to override the definitions of builtins as needed. The idea is that the OpenCL builtins will begin to need fewer target-specific overrides, as those will slowly move over to the clc builtins instead. Another advantage of having a separate bytecode library with the CLC implementations is that we can internalize the symbols when linking it (separately), whereas currently the CLC symbols make it into the final builtins library (and perhaps even the final compiled binary). This patch starts of with 'dot' as it's relatively self-contained, as opposed to most of the maths builtins which tend to pull in other builtins. We can also start to clang-format the builtins as we go, which should help to modernize the codebase. --- libclc/CMakeLists.txt | 41 +++++++++-- .../func.h => clc/include/clc/clcfunc.h} | 15 ++-- .../types.h => clc/include/clc/clctypes.h} | 12 +-- libclc/clc/include/clc/geometric/clc_dot.h | 2 + libclc/clc/include/clc/geometric/clc_dot.inc | 1 + libclc/clc/include/clc/internal/clc.h | 26 +++++++ libclc/clc/lib/clspv/SOURCES | 1 + libclc/clc/lib/clspv/dummy.cl | 1 + libclc/clc/lib/clspv64 | 1 + libclc/clc/lib/generic/SOURCES | 1 + libclc/clc/lib/generic/geometric/clc_dot.cl | 57 +++++++++++++++ libclc/clc/lib/spirv/SOURCES | 2 + libclc/clc/lib/spirv64/SOURCES | 1 + libclc/cmake/modules/AddLibclc.cmake | 73 +++++++++++++++---- libclc/generic/include/clc/clc.h | 4 +- libclc/generic/include/config.h | 2 +- libclc/generic/include/core/clc_core.h | 4 +- libclc/generic/include/math/math.h | 2 +- libclc/generic/include/spirv/spirv.h | 4 +- libclc/generic/include/spirv/spirv_builtins.h | 2 +- libclc/generic/lib/geometric/dot.cl | 27 ++++--- libclc/generic/lib/math/math.h | 2 +- libclc/generic/libspirv/math/sincos_helpers.h | 2 +- 23 files changed, 227 insertions(+), 56 deletions(-) rename libclc/{generic/include/func.h => clc/include/clc/clcfunc.h} (88%) rename libclc/{generic/include/types.h => clc/include/clc/clctypes.h} (94%) create mode 100644 libclc/clc/include/clc/geometric/clc_dot.h create mode 100644 libclc/clc/include/clc/geometric/clc_dot.inc create mode 100644 libclc/clc/include/clc/internal/clc.h create mode 100644 libclc/clc/lib/clspv/SOURCES create mode 100644 libclc/clc/lib/clspv/dummy.cl create mode 120000 libclc/clc/lib/clspv64 create mode 100644 libclc/clc/lib/generic/SOURCES create mode 100644 libclc/clc/lib/generic/geometric/clc_dot.cl create mode 100644 libclc/clc/lib/spirv/SOURCES create mode 100644 libclc/clc/lib/spirv64/SOURCES diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt index 09845614b21dc..ab1a18f49557e 100644 --- a/libclc/CMakeLists.txt +++ b/libclc/CMakeLists.txt @@ -34,8 +34,14 @@ set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS r600/lib/SOURCES; r600/libspirv/SOURCES; spirv/lib/SOURCES; - spirv64/lib/SOURCES - native_cpu-unknown-linux/libspirv/SOURCES + spirv64/lib/SOURCES; + native_cpu-unknown-linux/libspirv/SOURCES; + # CLC internal libraries + clc/lib/generic/SOURCES; + clc/lib/clspv/SOURCES; + clc/lib/clspv64/SOURCES; + clc/lib/spirv/SOURCES; + clc/lib/spirv64/SOURCES; ) set( LIBCLC_MIN_LLVM 3.9.0 ) @@ -329,6 +335,14 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} ) " configuration, some SYCL programs may fail to build.") endif() + set( clc_lib_files ) + libclc_configure_lib_source( + clc_lib_files + CLC_INTERNAL + LIB_ROOT_DIR clc + DIRS ${dirs} ${DARCH} ${DARCH}-${OS} ${DARCH}-${VENDOR}-${OS} + ) + set( opencl_lib_files ) set( opencl_gen_files ) @@ -474,7 +488,8 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} ) list( APPEND build_flags -D__CLC_INTERNAL -D${CLC_TARGET_DEFINE} - -I${CMAKE_CURRENT_SOURCE_DIR}/generic/include + # All libclc builtin libraries see CLC headers + -I${CMAKE_CURRENT_SOURCE_DIR}/clc/include # FIXME: Fix libclc to not require disabling this noisy warning -Wno-bitwise-conditional-parentheses ) @@ -483,6 +498,20 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} ) list( APPEND build_flags -mcpu=${cpu} ) endif() + add_libclc_builtin_set( + CLC_INTERNAL + ARCH ${ARCH} + ARCH_SUFFIX clc-${arch_suffix} + TRIPLE ${clang_triple} + COMPILE_FLAGS ${build_flags} + OPT_FLAGS ${opt_flags} + LIB_FILES ${clc_lib_files} + ) + + list( APPEND build_flags + -I${CMAKE_CURRENT_SOURCE_DIR}/generic/include + ) + add_libclc_builtin_set( ARCH ${ARCH} ARCH_SUFFIX libspirv-${arch_suffix} @@ -493,8 +522,9 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} ) LIB_FILES ${libspirv_lib_files} GEN_FILES ${libspirv_gen_files} ALIASES ${${d}_aliases} - GENERATE_TARGET "generate_convert_spirv.cl" "generate_convert_core.cl" PARENT_TARGET libspirv-builtins + # Link in the CLC builtins and internalize their symbols + INTERNAL_LINK_DEPENDENCIES $ ) add_libclc_builtin_set( @@ -506,8 +536,9 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} ) LIB_FILES ${opencl_lib_files} GEN_FILES ${opencl_gen_files} ALIASES ${${d}_aliases} - GENERATE_TARGET "generate_convert_clc.cl" PARENT_TARGET libopencl-builtins + # Link in the CLC builtins and internalize their symbols + INTERNAL_LINK_DEPENDENCIES $ ) endforeach( d ) endforeach( t ) diff --git a/libclc/generic/include/func.h b/libclc/clc/include/clc/clcfunc.h similarity index 88% rename from libclc/generic/include/func.h rename to libclc/clc/include/clc/clcfunc.h index 4af288736fe49..e04a405a94be7 100644 --- a/libclc/generic/include/func.h +++ b/libclc/clc/include/clc/clcfunc.h @@ -1,8 +1,13 @@ -#ifndef CLC_FUNC -#define CLC_FUNC +#ifndef __CLC_CLCFUNC_H_ +#define __CLC_CLCFUNC_H_ #define _CLC_OVERLOAD __attribute__((overloadable)) #define _CLC_DECL +#define _CLC_INLINE __attribute__((always_inline)) inline +#define _CLC_CONVERGENT __attribute__((convergent)) +#define _CLC_PURE __attribute__((pure)) +#define _CLC_CONSTFN __attribute__((const)) + // avoid inlines for SPIR-V related targets since we'll optimise later in the // chain #if defined(CLC_SPIRV) || defined(CLC_SPIRV64) @@ -12,9 +17,5 @@ #else #define _CLC_DEF __attribute__((always_inline)) #endif -#define _CLC_INLINE __attribute__((always_inline)) inline -#define _CLC_CONVERGENT __attribute__((convergent)) -#define _CLC_PURE __attribute__((pure)) -#define _CLC_CONSTFN __attribute__((const)) -#endif // CLC_FUNC +#endif // __CLC_CLCFUNC_H_ diff --git a/libclc/generic/include/types.h b/libclc/clc/include/clc/clctypes.h similarity index 94% rename from libclc/generic/include/types.h rename to libclc/clc/include/clc/clctypes.h index ba435f9c8c729..adabac150bca0 100644 --- a/libclc/generic/include/types.h +++ b/libclc/clc/include/clc/clctypes.h @@ -1,5 +1,5 @@ -#ifndef CLC_TYPES -#define CLC_TYPES +#ifndef __CLC_CLCTYPES_H_ +#define __CLC_CLCTYPES_H_ /* 6.1.1 Built-in Scalar Data Types */ @@ -12,12 +12,12 @@ typedef unsigned long ulong; typedef __SIZE_TYPE__ size_t; typedef __PTRDIFF_TYPE__ ptrdiff_t; -#define __stdint_join3(a,b,c) a ## b ## c +#define __stdint_join3(a, b, c) a##b##c -#define __intn_t(n) __stdint_join3(__INT, n, _TYPE__) +#define __intn_t(n) __stdint_join3(__INT, n, _TYPE__) #define __uintn_t(n) __stdint_join3(unsigned __INT, n, _TYPE__) -typedef __intn_t(__INTPTR_WIDTH__) intptr_t; +typedef __intn_t(__INTPTR_WIDTH__) intptr_t; typedef __uintn_t(__INTPTR_WIDTH__) uintptr_t; #undef __uintn_t @@ -104,4 +104,4 @@ typedef __attribute__((ext_vector_type(8))) half half8; typedef __attribute__((ext_vector_type(16))) half half16; #endif -#endif // CLC_TYPES +#endif // __CLC_CLCTYPES_H_ diff --git a/libclc/clc/include/clc/geometric/clc_dot.h b/libclc/clc/include/clc/geometric/clc_dot.h new file mode 100644 index 0000000000000..e0e47ab2093ef --- /dev/null +++ b/libclc/clc/include/clc/geometric/clc_dot.h @@ -0,0 +1,2 @@ +#define __CLC_BODY +#include diff --git a/libclc/clc/include/clc/geometric/clc_dot.inc b/libclc/clc/include/clc/geometric/clc_dot.inc new file mode 100644 index 0000000000000..016b564df362d --- /dev/null +++ b/libclc/clc/include/clc/geometric/clc_dot.inc @@ -0,0 +1 @@ +_CLC_OVERLOAD _CLC_DECL __CLC_FLOAT __clc_dot(__CLC_FLOATN p0, __CLC_FLOATN p1); diff --git a/libclc/clc/include/clc/internal/clc.h b/libclc/clc/include/clc/internal/clc.h new file mode 100644 index 0000000000000..c3bdfd754105f --- /dev/null +++ b/libclc/clc/include/clc/internal/clc.h @@ -0,0 +1,26 @@ +#ifndef __CLC_INTERNAL_CLC_H_ +#define __CLC_INTERNAL_CLC_H_ + +#ifndef cl_clang_storage_class_specifiers +#error Implementation requires cl_clang_storage_class_specifiers extension! +#endif + +#pragma OPENCL EXTENSION cl_clang_storage_class_specifiers : enable + +#ifdef cl_khr_fp64 +#pragma OPENCL EXTENSION cl_khr_fp64 : enable +#endif + +#ifdef cl_khr_fp16 +#pragma OPENCL EXTENSION cl_khr_fp16 : enable +#endif + +/* Function Attributes */ +#include + +/* 6.1 Supported Data Types */ +#include + +#pragma OPENCL EXTENSION all : disable + +#endif // __CLC_INTERNAL_CLC_H_ diff --git a/libclc/clc/lib/clspv/SOURCES b/libclc/clc/lib/clspv/SOURCES new file mode 100644 index 0000000000000..75a3130357c34 --- /dev/null +++ b/libclc/clc/lib/clspv/SOURCES @@ -0,0 +1 @@ +dummy.cl diff --git a/libclc/clc/lib/clspv/dummy.cl b/libclc/clc/lib/clspv/dummy.cl new file mode 100644 index 0000000000000..fab17ac780e37 --- /dev/null +++ b/libclc/clc/lib/clspv/dummy.cl @@ -0,0 +1 @@ +// Empty file diff --git a/libclc/clc/lib/clspv64 b/libclc/clc/lib/clspv64 new file mode 120000 index 0000000000000..ea01ba94bc636 --- /dev/null +++ b/libclc/clc/lib/clspv64 @@ -0,0 +1 @@ +clspv \ No newline at end of file diff --git a/libclc/clc/lib/generic/SOURCES b/libclc/clc/lib/generic/SOURCES new file mode 100644 index 0000000000000..fa2e4f50b99cd --- /dev/null +++ b/libclc/clc/lib/generic/SOURCES @@ -0,0 +1 @@ +geometric/clc_dot.cl diff --git a/libclc/clc/lib/generic/geometric/clc_dot.cl b/libclc/clc/lib/generic/geometric/clc_dot.cl new file mode 100644 index 0000000000000..bf0f19b51bc05 --- /dev/null +++ b/libclc/clc/lib/generic/geometric/clc_dot.cl @@ -0,0 +1,57 @@ +#include + +_CLC_OVERLOAD _CLC_DEF float __clc_dot(float p0, float p1) { return p0 * p1; } + +_CLC_OVERLOAD _CLC_DEF float __clc_dot(float2 p0, float2 p1) { + return p0.x * p1.x + p0.y * p1.y; +} + +_CLC_OVERLOAD _CLC_DEF float __clc_dot(float3 p0, float3 p1) { + return p0.x * p1.x + p0.y * p1.y + p0.z * p1.z; +} + +_CLC_OVERLOAD _CLC_DEF float __clc_dot(float4 p0, float4 p1) { + return p0.x * p1.x + p0.y * p1.y + p0.z * p1.z + p0.w * p1.w; +} + +#ifdef cl_khr_fp64 + +#pragma OPENCL EXTENSION cl_khr_fp64 : enable + +_CLC_OVERLOAD _CLC_DEF double __clc_dot(double p0, double p1) { + return p0 * p1; +} + +_CLC_OVERLOAD _CLC_DEF double __clc_dot(double2 p0, double2 p1) { + return p0.x * p1.x + p0.y * p1.y; +} + +_CLC_OVERLOAD _CLC_DEF double __clc_dot(double3 p0, double3 p1) { + return p0.x * p1.x + p0.y * p1.y + p0.z * p1.z; +} + +_CLC_OVERLOAD _CLC_DEF double __clc_dot(double4 p0, double4 p1) { + return p0.x * p1.x + p0.y * p1.y + p0.z * p1.z + p0.w * p1.w; +} + +#endif + +#ifdef cl_khr_fp16 + +#pragma OPENCL EXTENSION cl_khr_fp16 : enable + +_CLC_OVERLOAD _CLC_DEF half __clc_dot(half p0, half p1) { return p0 * p1; } + +_CLC_OVERLOAD _CLC_DEF half __clc_dot(half2 p0, half2 p1) { + return p0.x * p1.x + p0.y * p1.y; +} + +_CLC_OVERLOAD _CLC_DEF half __clc_dot(half3 p0, half3 p1) { + return p0.x * p1.x + p0.y * p1.y + p0.z * p1.z; +} + +_CLC_OVERLOAD _CLC_DEF half __clc_dot(half4 p0, half4 p1) { + return p0.x * p1.x + p0.y * p1.y + p0.z * p1.z + p0.w * p1.w; +} + +#endif diff --git a/libclc/clc/lib/spirv/SOURCES b/libclc/clc/lib/spirv/SOURCES new file mode 100644 index 0000000000000..d8effd19613c8 --- /dev/null +++ b/libclc/clc/lib/spirv/SOURCES @@ -0,0 +1,2 @@ +../generic/geometric/clc_dot.cl + diff --git a/libclc/clc/lib/spirv64/SOURCES b/libclc/clc/lib/spirv64/SOURCES new file mode 100644 index 0000000000000..9200810ace38e --- /dev/null +++ b/libclc/clc/lib/spirv64/SOURCES @@ -0,0 +1 @@ +../generic/geometric/clc_dot.cl diff --git a/libclc/cmake/modules/AddLibclc.cmake b/libclc/cmake/modules/AddLibclc.cmake index 50c25961d0310..c42c610220663 100644 --- a/libclc/cmake/modules/AddLibclc.cmake +++ b/libclc/cmake/modules/AddLibclc.cmake @@ -82,6 +82,8 @@ endfunction() # Links together one or more bytecode files # # Arguments: +# * INTERNALIZE +# Set if -internalize flag should be passed when linking # * TARGET # Custom target to create # * INPUT ... @@ -93,7 +95,7 @@ endfunction() # List of extra dependencies to inject function(link_bc) cmake_parse_arguments(ARG - "" + "INTERNALIZE" "TARGET;RSP_DIR" "INPUTS;DEPENDENCIES" ${ARGN} @@ -106,7 +108,7 @@ function(link_bc) file( TO_CMAKE_PATH ${ARG_RSP_DIR}/${ARG_TARGET}.rsp RSP_FILE ) # Turn it into a space-separate list of input files list( JOIN ARG_INPUTS " " RSP_INPUT ) - file( WRITE ${RSP_FILE} ${RSP_INPUT} ) + file( GENERATE OUTPUT ${RSP_FILE} CONTENT ${RSP_INPUT} ) # Ensure that if this file is removed, we re-run CMake set_property( DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${RSP_FILE} @@ -116,7 +118,7 @@ function(link_bc) add_custom_command( OUTPUT ${ARG_TARGET}.bc - COMMAND ${llvm-link_exe} -o ${ARG_TARGET}.bc ${LINK_INPUT_ARG} + COMMAND ${llvm-link_exe} $<$:--internalize> -o ${ARG_TARGET}.bc ${LINK_INPUT_ARG} DEPENDS ${llvm-link_target} ${ARG_DEPENDENCIES} ${ARG_INPUTS} ${RSP_FILE} ) @@ -282,6 +284,9 @@ endfunction() # Triple used to compile # # Optional Arguments: +# * CLC_INTERNAL +# Pass if compiling the internal CLC builtin libraries, which are not +# optimized and do not have aliases created. # * LIB_FILES ... # List of files that should be built for this library # * GEN_FILES ... @@ -294,11 +299,14 @@ endfunction() # Prefix to give the final builtin library aliases # * ALIASES ... # List of aliases +# * INTERNAL_LINK_DEPENDENCIES ... +# A list of extra bytecode files to link into the builtin library. Symbols +# from these link dependencies will be internalized during linking. function(add_libclc_builtin_set) cmake_parse_arguments(ARG - "" + "CLC_INTERNAL" "ARCH;TRIPLE;ARCH_SUFFIX;TARGET_ENV;PARENT_TARGET" - "LIB_FILES;GEN_FILES;COMPILE_FLAGS;OPT_FLAGS;ALIASES" + "LIB_FILES;GEN_FILES;COMPILE_FLAGS;OPT_FLAGS;ALIASES;INTERNAL_LINK_DEPENDENCIES" ${ARGN} ) @@ -347,13 +355,45 @@ function(add_libclc_builtin_set) ) set_target_properties( ${builtins_comp_lib_tgt} PROPERTIES FOLDER "libclc/Device IR/Comp" ) + if( NOT bytecode_files ) + message(FATAL_ERROR "Cannot create an empty builtins library") + endif() + set( builtins_link_lib_tgt builtins.link.${ARG_ARCH_SUFFIX} ) - link_bc( - TARGET ${builtins_link_lib_tgt} - INPUTS ${bytecode_files} - RSP_DIR ${LIBCLC_ARCH_OBJFILE_DIR} - DEPENDENCIES ${builtins_comp_lib_tgt} - ) + + if( NOT ARG_INTERNAL_LINK_DEPENDENCIES ) + link_bc( + TARGET ${builtins_link_lib_tgt} + INPUTS ${bytecode_files} + RSP_DIR ${LIBCLC_ARCH_OBJFILE_DIR} + DEPENDENCIES ${builtins_comp_lib_tgt} + ) + else() + # If we have libraries to link while internalizing their symbols, we need + # two separate link steps; the --internalize flag applies to all link + # inputs but the first. + set( builtins_link_lib_tmp_tgt builtins.link.pre-deps.${ARG_ARCH_SUFFIX} ) + link_bc( + TARGET ${builtins_link_lib_tmp_tgt} + INPUTS ${bytecode_files} + RSP_DIR ${LIBCLC_ARCH_OBJFILE_DIR} + DEPENDENCIES ${builtins_comp_lib_tgt} + ) + link_bc( + INTERNALIZE + TARGET ${builtins_link_lib_tgt} + INPUTS $ + ${ARG_INTERNAL_LINK_DEPENDENCIES} + RSP_DIR ${LIBCLC_ARCH_OBJFILE_DIR} + DEPENDENCIES ${builtins_link_lib_tmp_tgt} + ) + endif() + + # For the CLC internal builtins, exit here - we only optimize the targets' + # entry points once we've linked the CLC buitins into them + if( ARG_CLC_INTERNAL ) + return() + endif() set( builtins_link_lib $ ) @@ -483,6 +523,9 @@ endfunction(add_libclc_builtin_set) # LIB_FILE_LIST may be pre-populated and is appended to. # # Arguments: +# * CLC_INTERNAL +# Pass if compiling the internal CLC builtin libraries, which have a +# different directory structure. # * LIB_ROOT_DIR # Root directory containing target's lib files, relative to libclc root # directory. If not provided, is set to '.'. @@ -494,7 +537,7 @@ endfunction(add_libclc_builtin_set) # files function(libclc_configure_lib_source LIB_FILE_LIST) cmake_parse_arguments(ARG - "" + "CLC_INTERNAL" "LIB_DIR;LIB_ROOT_DIR" "DIRS" ${ARGN} @@ -512,7 +555,11 @@ function(libclc_configure_lib_source LIB_FILE_LIST) set( source_list ) foreach( l ${ARG_DIRS} ) foreach( s "SOURCES" "SOURCES_${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}" ) - file( TO_CMAKE_PATH ${ARG_LIB_ROOT_DIR}/${l}/${ARG_LIB_DIR}/${s} file_loc ) + if( ARG_CLC_INTERNAL ) + file( TO_CMAKE_PATH ${ARG_LIB_ROOT_DIR}/${ARG_LIB_DIR}/${l}/${s} file_loc ) + else() + file( TO_CMAKE_PATH ${ARG_LIB_ROOT_DIR}/${l}/${ARG_LIB_DIR}/${s} file_loc ) + endif() file( TO_CMAKE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/${file_loc} loc ) # Prepend the location to give higher priority to # specialized implementation diff --git a/libclc/generic/include/clc/clc.h b/libclc/generic/include/clc/clc.h index e01947c4680c0..7b940f258f4ef 100644 --- a/libclc/generic/include/clc/clc.h +++ b/libclc/generic/include/clc/clc.h @@ -31,10 +31,10 @@ #endif /* Function Attributes */ -#include +#include /* 6.1 Supported Data Types */ -#include +#include /* 6.2.3 Explicit Conversions */ #include diff --git a/libclc/generic/include/config.h b/libclc/generic/include/config.h index fbfa22e6b6f6b..7aa5967f4eb68 100644 --- a/libclc/generic/include/config.h +++ b/libclc/generic/include/config.h @@ -20,7 +20,7 @@ * THE SOFTWARE. */ -#include "func.h" +#include _CLC_DECL bool __clc_subnormals_disabled(); _CLC_DECL bool __clc_fp16_subnormals_supported(); diff --git a/libclc/generic/include/core/clc_core.h b/libclc/generic/include/core/clc_core.h index 8459903022cd5..dcb218772c954 100644 --- a/libclc/generic/include/core/clc_core.h +++ b/libclc/generic/include/core/clc_core.h @@ -29,9 +29,9 @@ #endif #include -#include +#include #include -#include +#include #include #include diff --git a/libclc/generic/include/math/math.h b/libclc/generic/include/math/math.h index 24d7e91a7baba..825966c5f2844 100644 --- a/libclc/generic/include/math/math.h +++ b/libclc/generic/include/math/math.h @@ -11,7 +11,7 @@ #include "as_type.h" #include "config.h" -#include "func.h" +#include #define SNAN 0x001 #define QNAN 0x002 diff --git a/libclc/generic/include/spirv/spirv.h b/libclc/generic/include/spirv/spirv.h index a22c376e5263e..73b590dff18a2 100644 --- a/libclc/generic/include/spirv/spirv.h +++ b/libclc/generic/include/spirv/spirv.h @@ -37,10 +37,10 @@ #endif /* Function Attributes */ -#include +#include /* Supported Data Types */ -#include +#include #include /* Supported builtins */ diff --git a/libclc/generic/include/spirv/spirv_builtins.h b/libclc/generic/include/spirv/spirv_builtins.h index 5812039a0e73b..cd576b4a94ea4 100644 --- a/libclc/generic/include/spirv/spirv_builtins.h +++ b/libclc/generic/include/spirv/spirv_builtins.h @@ -10,7 +10,7 @@ // Automatically generated file, do not edit! // -#include +#include #include #ifndef CLC_SPIRV_BINDING diff --git a/libclc/generic/lib/geometric/dot.cl b/libclc/generic/lib/geometric/dot.cl index e58bc26f4333a..e790d02636563 100644 --- a/libclc/generic/lib/geometric/dot.cl +++ b/libclc/generic/lib/geometric/dot.cl @@ -1,19 +1,20 @@ #include +#include _CLC_OVERLOAD _CLC_DEF float dot(float p0, float p1) { - return p0*p1; + return __clc_dot(p0, p1); } _CLC_OVERLOAD _CLC_DEF float dot(float2 p0, float2 p1) { - return p0.x*p1.x + p0.y*p1.y; + return __clc_dot(p0, p1); } _CLC_OVERLOAD _CLC_DEF float dot(float3 p0, float3 p1) { - return p0.x*p1.x + p0.y*p1.y + p0.z*p1.z; + return __clc_dot(p0, p1); } _CLC_OVERLOAD _CLC_DEF float dot(float4 p0, float4 p1) { - return p0.x*p1.x + p0.y*p1.y + p0.z*p1.z + p0.w*p1.w; + return __clc_dot(p0, p1); } #ifdef cl_khr_fp64 @@ -21,19 +22,19 @@ _CLC_OVERLOAD _CLC_DEF float dot(float4 p0, float4 p1) { #pragma OPENCL EXTENSION cl_khr_fp64 : enable _CLC_OVERLOAD _CLC_DEF double dot(double p0, double p1) { - return p0*p1; + return __clc_dot(p0, p1); } _CLC_OVERLOAD _CLC_DEF double dot(double2 p0, double2 p1) { - return p0.x*p1.x + p0.y*p1.y; + return __clc_dot(p0, p1); } _CLC_OVERLOAD _CLC_DEF double dot(double3 p0, double3 p1) { - return p0.x*p1.x + p0.y*p1.y + p0.z*p1.z; + return __clc_dot(p0, p1); } _CLC_OVERLOAD _CLC_DEF double dot(double4 p0, double4 p1) { - return p0.x*p1.x + p0.y*p1.y + p0.z*p1.z + p0.w*p1.w; + return __clc_dot(p0, p1); } #endif @@ -42,20 +43,18 @@ _CLC_OVERLOAD _CLC_DEF double dot(double4 p0, double4 p1) { #pragma OPENCL EXTENSION cl_khr_fp16 : enable -_CLC_OVERLOAD _CLC_DEF half dot(half p0, half p1) { - return p0*p1; -} +_CLC_OVERLOAD _CLC_DEF half dot(half p0, half p1) { return __clc_dot(p0, p1); } _CLC_OVERLOAD _CLC_DEF half dot(half2 p0, half2 p1) { - return p0.x*p1.x + p0.y*p1.y; + return __clc_dot(p0, p1); } _CLC_OVERLOAD _CLC_DEF half dot(half3 p0, half3 p1) { - return p0.x*p1.x + p0.y*p1.y + p0.z*p1.z; + return __clc_dot(p0, p1); } _CLC_OVERLOAD _CLC_DEF half dot(half4 p0, half4 p1) { - return p0.x*p1.x + p0.y*p1.y + p0.z*p1.z + p0.w*p1.w; + return __clc_dot(p0, p1); } #endif diff --git a/libclc/generic/lib/math/math.h b/libclc/generic/lib/math/math.h index 9c37633f57e4c..15065aedee384 100644 --- a/libclc/generic/lib/math/math.h +++ b/libclc/generic/lib/math/math.h @@ -23,7 +23,7 @@ #ifndef __CLC_MATH_H_ #define __CLC_MATH_H_ -#include "func.h" +#include #include "as_type.h" #include "config.h" diff --git a/libclc/generic/libspirv/math/sincos_helpers.h b/libclc/generic/libspirv/math/sincos_helpers.h index 8b300d786bce5..2a3c40ddb58b7 100644 --- a/libclc/generic/libspirv/math/sincos_helpers.h +++ b/libclc/generic/libspirv/math/sincos_helpers.h @@ -20,7 +20,7 @@ * THE SOFTWARE. */ -#include +#include _CLC_DECL float __clc_sinf_piby4(float x, float y); _CLC_DECL float __clc_cosf_piby4(float x, float y); From 31544f4aa65b989d0ebc2f7d94d985bc61daaef8 Mon Sep 17 00:00:00 2001 From: Fraser Cormack Date: Tue, 29 Oct 2024 17:37:19 +0000 Subject: [PATCH 2/3] fix formatting --- libclc/generic/include/core/clc_core.h | 2 +- libclc/generic/lib/math/math.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libclc/generic/include/core/clc_core.h b/libclc/generic/include/core/clc_core.h index dcb218772c954..df2a56bd117c7 100644 --- a/libclc/generic/include/core/clc_core.h +++ b/libclc/generic/include/core/clc_core.h @@ -30,8 +30,8 @@ #include #include -#include #include +#include #include #include diff --git a/libclc/generic/lib/math/math.h b/libclc/generic/lib/math/math.h index 15065aedee384..62a4c925db51b 100644 --- a/libclc/generic/lib/math/math.h +++ b/libclc/generic/lib/math/math.h @@ -23,9 +23,9 @@ #ifndef __CLC_MATH_H_ #define __CLC_MATH_H_ -#include #include "as_type.h" #include "config.h" +#include #define SNAN 0x001 #define QNAN 0x002 From 3cad9875f28357cd1f765d34e1852d883ccc77fc Mon Sep 17 00:00:00 2001 From: Fraser Cormack Date: Tue, 29 Oct 2024 22:14:17 +0000 Subject: [PATCH 3/3] fix formatting --- libclc/native_cpu-unknown-linux/libspirv/integer/popcount.cl | 2 +- libclc/native_cpu-unknown-linux/libspirv/math/helpers.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libclc/native_cpu-unknown-linux/libspirv/integer/popcount.cl b/libclc/native_cpu-unknown-linux/libspirv/integer/popcount.cl index 62cfd83a59d75..55e29b041bb18 100644 --- a/libclc/native_cpu-unknown-linux/libspirv/integer/popcount.cl +++ b/libclc/native_cpu-unknown-linux/libspirv/integer/popcount.cl @@ -1,4 +1,4 @@ -#include +#include #include #include diff --git a/libclc/native_cpu-unknown-linux/libspirv/math/helpers.h b/libclc/native_cpu-unknown-linux/libspirv/math/helpers.h index db99f3429e511..2f4498e6cd4c7 100644 --- a/libclc/native_cpu-unknown-linux/libspirv/math/helpers.h +++ b/libclc/native_cpu-unknown-linux/libspirv/math/helpers.h @@ -1,5 +1,5 @@ -#include "func.h" -#include "types.h" +#include +#include #ifdef cl_khr_fp16 #pragma OPENCL EXTENSION cl_khr_fp16 : enable