Skip to content
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
41 changes: 36 additions & 5 deletions libclc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down Expand Up @@ -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 )

Expand Down Expand Up @@ -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
)
Expand All @@ -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}
Expand All @@ -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 $<TARGET_PROPERTY:builtins.link.clc-${arch_suffix},TARGET_FILE>
)

add_libclc_builtin_set(
Expand All @@ -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 $<TARGET_PROPERTY:builtins.link.clc-${arch_suffix},TARGET_FILE>
)
endforeach( d )
endforeach( t )
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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_
Original file line number Diff line number Diff line change
@@ -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 */

Expand All @@ -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
Expand Down Expand Up @@ -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_
2 changes: 2 additions & 0 deletions libclc/clc/include/clc/geometric/clc_dot.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#define __CLC_BODY <clc/geometric/clc_dot.inc>
#include <clc/geometric/floatn.inc>
1 change: 1 addition & 0 deletions libclc/clc/include/clc/geometric/clc_dot.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_CLC_OVERLOAD _CLC_DECL __CLC_FLOAT __clc_dot(__CLC_FLOATN p0, __CLC_FLOATN p1);
26 changes: 26 additions & 0 deletions libclc/clc/include/clc/internal/clc.h
Original file line number Diff line number Diff line change
@@ -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 <clc/clcfunc.h>

/* 6.1 Supported Data Types */
#include <clc/clctypes.h>

#pragma OPENCL EXTENSION all : disable

#endif // __CLC_INTERNAL_CLC_H_
1 change: 1 addition & 0 deletions libclc/clc/lib/clspv/SOURCES
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dummy.cl
1 change: 1 addition & 0 deletions libclc/clc/lib/clspv/dummy.cl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Empty file
1 change: 1 addition & 0 deletions libclc/clc/lib/clspv64
1 change: 1 addition & 0 deletions libclc/clc/lib/generic/SOURCES
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
geometric/clc_dot.cl
57 changes: 57 additions & 0 deletions libclc/clc/lib/generic/geometric/clc_dot.cl
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include <clc/internal/clc.h>

_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
2 changes: 2 additions & 0 deletions libclc/clc/lib/spirv/SOURCES
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
../generic/geometric/clc_dot.cl

1 change: 1 addition & 0 deletions libclc/clc/lib/spirv64/SOURCES
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
../generic/geometric/clc_dot.cl
73 changes: 60 additions & 13 deletions libclc/cmake/modules/AddLibclc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ endfunction()
# Links together one or more bytecode files
#
# Arguments:
# * INTERNALIZE
# Set if -internalize flag should be passed when linking
# * TARGET <string>
# Custom target to create
# * INPUT <string> ...
Expand All @@ -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}
Expand All @@ -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}
Expand All @@ -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} $<$<BOOL:${ARG_INTERNALIZE}>:--internalize> -o ${ARG_TARGET}.bc ${LINK_INPUT_ARG}
DEPENDS ${llvm-link_target} ${ARG_DEPENDENCIES} ${ARG_INPUTS} ${RSP_FILE}
)

Expand Down Expand Up @@ -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 <string> ...
# List of files that should be built for this library
# * GEN_FILES <string> ...
Expand All @@ -294,11 +299,14 @@ endfunction()
# Prefix to give the final builtin library aliases
# * ALIASES <string> ...
# List of aliases
# * INTERNAL_LINK_DEPENDENCIES <string> ...
# 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}
)

Expand Down Expand Up @@ -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 $<TARGET_PROPERTY:${builtins_link_lib_tmp_tgt},TARGET_FILE>
${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 $<TARGET_PROPERTY:${builtins_link_lib_tgt},TARGET_FILE> )

Expand Down Expand Up @@ -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 <string>
# Root directory containing target's lib files, relative to libclc root
# directory. If not provided, is set to '.'.
Expand All @@ -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}
Expand All @@ -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
Expand Down
Loading
Loading