Skip to content

Commit

Permalink
[libclc] Reorganize libspirv library (#16283)
Browse files Browse the repository at this point in the history
This moves the libspirv libraries to their own subdirectory of libclc,
reflecting how the CLC library is organized, and how the OpenCL library
may be reorganized in the future.

The libspirv bindings are organized in a similar way to CLC, with a
single root directory and then a 'generic' directory containing the
target-agnostic implementations, as well as top-level target-specific
subdirectories to override specific builtins.

The libspirv bindings still do a lot of the CLC implementations so the
separation isn't as clean as it needs to be, but this patch should help
to keep our downstream modifications better separated from upstream
changes.

Headers that were previously 'spirv' have now been renamed to 'libspirv'
to reflect this, and to better distinguish them from the 'spirv' and
'spirv64' libclc targets. That accounts for a majority of the churn.

Using llvm-diff shows no change to either OpenCL/libspirv bitcode
library on nvidia targets.
  • Loading branch information
frasercrmck authored Dec 9, 2024
1 parent b453dcc commit fc44c0b
Show file tree
Hide file tree
Showing 1,806 changed files with 2,944 additions and 2,657 deletions.
38 changes: 24 additions & 14 deletions libclc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,30 @@ include( AddLibclc )
include( GNUInstallDirs )
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS
amdgcn-amdhsa/lib/SOURCES;
amdgcn-amdhsa/libspirv/SOURCES;
amdgcn/lib/SOURCES;
amdgcn/libspirv/SOURCES;
amdgcn-mesa3d/lib/SOURCES;
amdgpu/lib/SOURCES;
clspv/lib/SOURCES;
clspv64/lib/SOURCES;
generic/lib/SOURCES;
generic/libspirv/SOURCES;
ptx/lib/SOURCES;
ptx-nvidiacl/lib/SOURCES;
ptx-nvidiacl/libspirv/SOURCES;
r600/lib/SOURCES;
r600/libspirv/SOURCES;
spirv/lib/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;
# libspirv libraries
libspirv/lib/generic/SOURCES;
libspirv/lib/amdgcn-amdhsa/SOURCES;
libspirv/lib/amdgcn/SOURCES;
libspirv/lib/ptx-nvidiacl/SOURCES;
libspirv/lib/r600/SOURCES;
libspirv/lib/native_cpu-unknown-linux/SOURCES;
)

set( LIBCLC_MIN_LLVM 3.9.0 )
Expand Down Expand Up @@ -264,8 +265,8 @@ endif()

find_package( Python3 REQUIRED COMPONENTS Interpreter )
file( TO_CMAKE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/generic/lib/gen_convert.py clc_script_loc )
file( TO_CMAKE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/generic/libspirv/gen_core_convert.py core_script_loc )
file( TO_CMAKE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/generic/libspirv/gen_convert.py spirv_script_loc )
file( TO_CMAKE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/libspirv/lib/generic/gen_core_convert.py core_script_loc )
file( TO_CMAKE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/libspirv/lib/generic/gen_convert.py spirv_script_loc )
file( TO_CMAKE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/generic/lib/gen_convert.py script_loc )
add_custom_command(
OUTPUT convert.cl
Expand Down Expand Up @@ -363,7 +364,7 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
list( APPEND opencl_gen_files clspv-convert.cl )
elseif ( NOT ENABLE_RUNTIME_SUBNORMAL )
list( APPEND opencl_gen_files convert-clc.cl )
list( APPEND opencl_lib_files generic/libspirv/subnormal_use_default.ll )
list( APPEND opencl_lib_files generic/lib/subnormal_use_default.ll )
endif()
endif()

Expand All @@ -380,13 +381,13 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
list( APPEND libspirv_gen_files clspv-convert.cl )
elseif ( NOT ENABLE_RUNTIME_SUBNORMAL )
list( APPEND libspirv_gen_files convert-spirv.cl convert-core.cl )
list( APPEND libspirv_lib_files generic/libspirv/subnormal_use_default.ll )
list( APPEND libspirv_lib_files libspirv/lib/generic/subnormal_use_default.ll )
endif()
endif()

libclc_configure_lib_source(
libspirv_lib_files
LIB_DIR libspirv
LIB_ROOT_DIR libspirv
DIRS ${dirs} ${DARCH} ${DARCH}-${OS} ${DARCH}-${VENDOR}-${OS}
)

Expand Down Expand Up @@ -531,16 +532,18 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
LIB_FILES ${clc_lib_files}
)

list( APPEND build_flags
set( spirv_build_flags ${build_flags} )
list( APPEND spirv_build_flags
-I${CMAKE_CURRENT_SOURCE_DIR}/generic/include
-I${CMAKE_CURRENT_SOURCE_DIR}/libspirv/include/
)

add_libclc_builtin_set(
ARCH ${ARCH}
ARCH_SUFFIX libspirv-${arch_suffix}
TRIPLE ${clang_triple}
TARGET_ENV libspirv-
COMPILE_FLAGS ${build_flags}
COMPILE_FLAGS ${spirv_build_flags}
OPT_FLAGS ${opt_flags}
LIB_FILES ${libspirv_lib_files}
GEN_FILES ${libspirv_gen_files}
Expand All @@ -550,11 +553,18 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
INTERNAL_LINK_DEPENDENCIES $<TARGET_PROPERTY:builtins.link.clc-${arch_suffix},TARGET_FILE>
)

set( opencl_build_flags ${build_flags} )
list( APPEND opencl_build_flags
-I${CMAKE_CURRENT_SOURCE_DIR}/generic/include
# FIXME: OpenCL bindings shouldn't depend on libspirv
-I${CMAKE_CURRENT_SOURCE_DIR}/libspirv/include/
)

add_libclc_builtin_set(
ARCH ${ARCH}
ARCH_SUFFIX ${arch_suffix}
TRIPLE ${clang_triple}
COMPILE_FLAGS ${build_flags}
COMPILE_FLAGS ${opencl_build_flags}
OPT_FLAGS ${opt_flags}
LIB_FILES ${opencl_lib_files}
GEN_FILES ${opencl_gen_files}
Expand Down
2 changes: 1 addition & 1 deletion libclc/cmake/modules/AddLibclc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ 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}" )
if( ARG_CLC_INTERNAL )
if( ARG_CLC_INTERNAL OR ARG_LIB_ROOT_DIR STREQUAL libspirv )
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 )
Expand Down
57 changes: 0 additions & 57 deletions libclc/generic/include/spirv/image/image_defines.h

This file was deleted.

2 changes: 1 addition & 1 deletion libclc/generic/lib/async/async_work_group_strided_copy.cl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <clc/clc.h>
#include <spirv/spirv.h>
#include <libspirv/spirv.h>

#define __CLC_BODY <async_work_group_strided_copy.inc>
#include <clc/async/gentype.inc>
2 changes: 1 addition & 1 deletion libclc/generic/lib/async/prefetch.cl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//

#include <clc/clc.h>
#include <spirv/spirv.h>
#include <libspirv/spirv.h>

#define __CLC_BODY <prefetch.inc>
#include <clc/async/gentype.inc>
2 changes: 1 addition & 1 deletion libclc/generic/lib/async/wait_group_events.cl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <spirv/spirv.h>
#include <libspirv/spirv.h>
#include <clc/clc.h>

_CLC_DEF _CLC_OVERLOAD void wait_group_events(int num_events,
Expand Down
2 changes: 1 addition & 1 deletion libclc/generic/lib/atomic/atomic_add.cl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <clc/clc.h>
#include <spirv/spirv.h>
#include <libspirv/spirv.h>

#define IMPL(TYPE, TYPE_MANGLED, AS, AS_MANGLED) \
_CLC_OVERLOAD _CLC_DEF TYPE atomic_add(volatile AS TYPE *p, TYPE val) { \
Expand Down
2 changes: 1 addition & 1 deletion libclc/generic/lib/atomic/atomic_and.cl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <clc/clc.h>
#include <spirv/spirv.h>
#include <libspirv/spirv.h>

#define IMPL(TYPE, TYPE_MANGLED, AS, AS_MANGLED) \
_CLC_OVERLOAD _CLC_DEF TYPE atomic_and(volatile AS TYPE *p, TYPE val) { \
Expand Down
2 changes: 1 addition & 1 deletion libclc/generic/lib/atomic/atomic_cmpxchg.cl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <clc/clc.h>
#include <spirv/spirv.h>
#include <libspirv/spirv.h>

#define IMPL(TYPE, TYPE_MANGLED, AS, AS_MANGLED) \
_CLC_OVERLOAD _CLC_DEF TYPE atomic_cmpxchg(volatile AS TYPE *p, TYPE cmp, \
Expand Down
2 changes: 1 addition & 1 deletion libclc/generic/lib/atomic/atomic_dec.cl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <clc/clc.h>
#include <spirv/spirv.h>
#include <libspirv/spirv.h>

#define IMPL(TYPE, TYPE_MANGLED, AS, AS_MANGLED) \
_CLC_OVERLOAD _CLC_DEF TYPE atomic_dec(volatile AS TYPE *p) { \
Expand Down
2 changes: 1 addition & 1 deletion libclc/generic/lib/atomic/atomic_inc.cl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <clc/clc.h>
#include <spirv/spirv.h>
#include <libspirv/spirv.h>

#define IMPL(TYPE, TYPE_MANGLED, AS, AS_MANGLED) \
_CLC_OVERLOAD _CLC_DEF TYPE atomic_inc(volatile AS TYPE *p) { \
Expand Down
2 changes: 1 addition & 1 deletion libclc/generic/lib/atomic/atomic_max.cl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <clc/clc.h>
#include <spirv/spirv.h>
#include <libspirv/spirv.h>

#define IMPL(TYPE, TYPE_MANGLED, AS, AS_MANGLED, OP) \
_CLC_OVERLOAD _CLC_DEF TYPE atomic_max(volatile AS TYPE *p, TYPE val) { \
Expand Down
2 changes: 1 addition & 1 deletion libclc/generic/lib/atomic/atomic_min.cl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <clc/clc.h>
#include <spirv/spirv.h>
#include <libspirv/spirv.h>

#define IMPL(TYPE, TYPE_MANGLED, AS, AS_MANGLED, OP) \
_CLC_OVERLOAD _CLC_DEF TYPE atomic_min(volatile AS TYPE *p, TYPE val) { \
Expand Down
2 changes: 1 addition & 1 deletion libclc/generic/lib/atomic/atomic_or.cl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <clc/clc.h>
#include <spirv/spirv.h>
#include <libspirv/spirv.h>

#define IMPL(TYPE, TYPE_MANGLED, AS, AS_MANGLED) \
_CLC_OVERLOAD _CLC_DEF TYPE atomic_or(volatile AS TYPE *p, TYPE val) { \
Expand Down
2 changes: 1 addition & 1 deletion libclc/generic/lib/atomic/atomic_sub.cl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <clc/clc.h>
#include <spirv/spirv.h>
#include <libspirv/spirv.h>

#define IMPL(TYPE, TYPE_MANGLED, AS, AS_MANGLED) \
_CLC_OVERLOAD _CLC_DEF TYPE atomic_sub(volatile AS TYPE *p, TYPE val) { \
Expand Down
2 changes: 1 addition & 1 deletion libclc/generic/lib/atomic/atomic_xchg.cl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <clc/clc.h>
#include <spirv/spirv.h>
#include <libspirv/spirv.h>

_CLC_OVERLOAD _CLC_DEF float atomic_xchg(volatile global float *p, float val) {
/* TODO: Stop manually mangling this name. Need C++ namespaces to get the exact mangling. */
Expand Down
2 changes: 1 addition & 1 deletion libclc/generic/lib/atomic/atomic_xor.cl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <clc/clc.h>
#include <spirv/spirv.h>
#include <libspirv/spirv.h>

#define IMPL(TYPE, TYPE_MANGLED, AS, AS_MANGLED) \
_CLC_OVERLOAD _CLC_DEF TYPE atomic_xor(volatile AS TYPE *p, TYPE val) { \
Expand Down
2 changes: 1 addition & 1 deletion libclc/generic/lib/cl_khr_int64_base_atomics/atom_add.cl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <clc/clc.h>
#include <spirv/spirv.h>
#include <libspirv/spirv.h>

// TODO: Stop manually mangling this name. Need C++ namespaces to get the exact mangling.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <clc/clc.h>
#include <spirv/spirv.h>
#include <libspirv/spirv.h>

#ifdef cl_khr_int64_base_atomics

Expand Down
2 changes: 1 addition & 1 deletion libclc/generic/lib/cl_khr_int64_base_atomics/atom_sub.cl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <clc/clc.h>
#include <spirv/spirv.h>
#include <libspirv/spirv.h>

// TODO: Stop manually mangling this name. Need C++ namespaces to get the exact mangling.

Expand Down
2 changes: 1 addition & 1 deletion libclc/generic/lib/cl_khr_int64_base_atomics/atom_xchg.cl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <clc/clc.h>
#include <spirv/spirv.h>
#include <libspirv/spirv.h>

#ifdef cl_khr_int64_base_atomics

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <clc/clc.h>
#include <spirv/spirv.h>
#include <libspirv/spirv.h>

#ifdef cl_khr_int64_extended_atomics

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <clc/clc.h>
#include <spirv/spirv.h>
#include <libspirv/spirv.h>

#ifdef cl_khr_int64_extended_atomics

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <clc/clc.h>
#include <spirv/spirv.h>
#include <libspirv/spirv.h>

#ifdef cl_khr_int64_extended_atomics

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <clc/clc.h>
#include <spirv/spirv.h>
#include <libspirv/spirv.h>

#ifdef cl_khr_int64_extended_atomics

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <clc/clc.h>
#include <spirv/spirv.h>
#include <libspirv/spirv.h>

#ifdef cl_khr_int64_extended_atomics

Expand Down
2 changes: 1 addition & 1 deletion libclc/generic/lib/common/degrees.cl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#include <clc/clc.h>
#include <clc/clcmacro.h>
#include <spirv/spirv.h>
#include <libspirv/spirv.h>

_CLC_OVERLOAD _CLC_DEF float degrees(float radians) {
return __spirv_ocl_degrees(radians);
Expand Down
2 changes: 1 addition & 1 deletion libclc/generic/lib/common/mix.cl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <clc/clc.h>
#include <spirv/spirv.h>
#include <libspirv/spirv.h>

#define __CLC_BODY <mix.inc>
#include <clc/math/gentype.inc>
2 changes: 1 addition & 1 deletion libclc/generic/lib/common/radians.cl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#include <clc/clc.h>
#include <clc/clcmacro.h>
#include <spirv/spirv.h>
#include <libspirv/spirv.h>

_CLC_OVERLOAD _CLC_DEF float radians(float degrees) {
return __spirv_ocl_radians(degrees);
Expand Down
2 changes: 1 addition & 1 deletion libclc/generic/lib/common/sign.cl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <clc/clc.h>
#include <clc/clcmacro.h>
#include <spirv/spirv.h>
#include <libspirv/spirv.h>

#define SIGN(TYPE, F) \
_CLC_DEF _CLC_OVERLOAD TYPE sign(TYPE x) { \
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 @@ -22,7 +22,7 @@

#include <clc/clc.h>
#include <clc/clcmacro.h>
#include <spirv/spirv.h>
#include <libspirv/spirv.h>

#define SMOOTH_STEP_DEF(edge_type, x_type, impl) \
_CLC_OVERLOAD _CLC_DEF x_type smoothstep(edge_type edge0, edge_type edge1, \
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 @@ -22,7 +22,7 @@

#include <clc/clc.h>
#include <clc/clcmacro.h>
#include <spirv/spirv.h>
#include <libspirv/spirv.h>

#define STEP_DEF(edge_type, x_type) \
_CLC_OVERLOAD _CLC_DEF x_type step(edge_type edge, x_type x) { \
Expand Down
Loading

0 comments on commit fc44c0b

Please sign in to comment.