Skip to content

Commit 65a4390

Browse files
committed
[SYCL-PTX] Libclc binding for SYCL device
SYCL uses a custom mangling scheme (mangles target address space 0). This patch adds a "binding" layer (sycldevice-binding.cpp). The binding layer is compiled in sycl device mode which allow to generate the expected mangling when the target address space is 0. Signed-off-by: Victor Lomuller <[email protected]>
1 parent 358ec04 commit 65a4390

File tree

4 files changed

+2612
-2
lines changed

4 files changed

+2612
-2
lines changed

libclc/CMakeLists.txt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,8 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
227227
LIB_DIR lib
228228
DIRS ${dirs} ${DARCH} ${DARCH}-${OS} ${DARCH}-${VENDOR}-${OS}
229229
DEPS convert-clc.cl )
230-
set( libspirv_files )
231-
libclc_configure_lib_source(libspirv_files
230+
set( libspirv_files_base )
231+
libclc_configure_lib_source(libspirv_files_base
232232
LIB_DIR libspirv
233233
DIRS ${dirs} ${DARCH} ${DARCH}-${OS} ${DARCH}-${VENDOR}-${OS}
234234
DEPS convert-spirv.cl convert-core.cl)
@@ -244,6 +244,17 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
244244
endif()
245245
message( " DEVICE: ${d} ( ${${d}_aliases} )" )
246246

247+
# FIXME: this is a hack, remove once we can use sycldevice in the triple
248+
# without changing the language
249+
# see issue: https://github.com/intel/llvm/issues/1814
250+
set(libspirv_files ${libspirv_files_base})
251+
if( ${ARCH} STREQUAL nvptx OR ${ARCH} STREQUAL nvptx64 )
252+
add_libclc_sycl_binding(libspirv_files
253+
TRIPLE ${t}
254+
COMPILE_OPT ${mcpu}
255+
FILES generic/libspirv/sycldevice-binding.cpp)
256+
endif()
257+
247258
add_libclc_builtin_set(libspirv-${arch_suffix}
248259
TRIPLE ${t}
249260
TARGET_ENV libspirv

libclc/cmake/modules/AddLibclc.cmake

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,55 @@ function(libclc_configure_lib_source OUT_LIST)
177177
set( ${OUT_LIST} ${rel_files} PARENT_SCOPE )
178178

179179
endfunction(libclc_configure_lib_source OUT_LIST)
180+
181+
# add_libclc_sycl_binding(arch_suffix
182+
# TRIPLE string
183+
# Triple used to compile
184+
# FILES string ...
185+
# List of file that should be built for this library
186+
# COMPILE_OPT
187+
# Compilation options
188+
# )
189+
#
190+
# Build the sycl binding file for SYCLDEVICE.
191+
# The path to the generated object file are appended in OUT_LIST.
192+
#
193+
# The mangling for sycl device is not yet fully
194+
# compatible with standard mangling.
195+
# For various reason, we need a mangling specific
196+
# for the Default address space (mapping to generic in SYCL).
197+
# The Default address space is not accessible in CL mode,
198+
# so we build this file in sycl mode for mangling purposes.
199+
#
200+
# FIXME: all the files should be compiled with the sycldevice triple
201+
# but this is not possible at the moment as this will trigger
202+
# the SYCL mode which we don't want.
203+
#
204+
function(add_libclc_sycl_binding OUT_LIST)
205+
cmake_parse_arguments(ARG
206+
""
207+
"TRIPLE"
208+
"FILES;COMPILE_OPT"
209+
${ARGN})
210+
211+
foreach( file ${ARG_FILES} )
212+
file( TO_CMAKE_PATH ${LIBCLC_ROOT_DIR}/${file} SYCLDEVICE_BINDING )
213+
if( EXISTS ${SYCLDEVICE_BINDING} )
214+
set( SYCLDEVICE_BINDING_OUT ${CMAKE_CURRENT_BINARY_DIR}/sycldevice-binding-${ARG_TRIPLE}/sycldevice-binding.bc )
215+
add_custom_command( OUTPUT ${SYCLDEVICE_BINDING_OUT}
216+
COMMAND ${LLVM_CLANG}
217+
-target ${ARG_TRIPLE}-sycldevice
218+
-fsycl
219+
-fsycl-device-only
220+
-Dcl_khr_fp64
221+
-I${LIBCLC_ROOT_DIR}/generic/include
222+
${ARG_COMPILE_OPT}
223+
${SYCLDEVICE_BINDING}
224+
-o ${SYCLDEVICE_BINDING_OUT}
225+
MAIN_DEPENDENCY ${SYCLDEVICE_BINDING}
226+
DEPENDS ${SYCLDEVICE_BINDING} ${LLVM_CLANG}
227+
VERBATIM )
228+
set( ${OUT_LIST} "${${OUT_LIST}};${SYCLDEVICE_BINDING_OUT}" PARENT_SCOPE )
229+
endif()
230+
endforeach()
231+
endfunction(add_libclc_sycl_binding OUT_LIST)

libclc/generic/include/lp64_types.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ typedef half __clc_vec16_fp16_t __attribute__((ext_vector_type(16)));
108108

109109
typedef __clc_int64_t __clc_size_t;
110110

111+
#ifdef __SYCL_DEVICE_ONLY__
112+
typedef __ocl_event_t __clc_event_t;
113+
#else
111114
typedef event_t __clc_event_t;
115+
#endif
112116

113117
#endif // CLC_LP64_TYPES

0 commit comments

Comments
 (0)