Skip to content

Commit

Permalink
[SYCL-PTX] Libclc binding for SYCL device
Browse files Browse the repository at this point in the history
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 <victor@codeplay.com>
  • Loading branch information
Naghasan committed Jun 19, 2020
1 parent 358ec04 commit 65a4390
Show file tree
Hide file tree
Showing 4 changed files with 2,612 additions and 2 deletions.
15 changes: 13 additions & 2 deletions libclc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
LIB_DIR lib
DIRS ${dirs} ${DARCH} ${DARCH}-${OS} ${DARCH}-${VENDOR}-${OS}
DEPS convert-clc.cl )
set( libspirv_files )
libclc_configure_lib_source(libspirv_files
set( libspirv_files_base )
libclc_configure_lib_source(libspirv_files_base
LIB_DIR libspirv
DIRS ${dirs} ${DARCH} ${DARCH}-${OS} ${DARCH}-${VENDOR}-${OS}
DEPS convert-spirv.cl convert-core.cl)
Expand All @@ -244,6 +244,17 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
endif()
message( " DEVICE: ${d} ( ${${d}_aliases} )" )

# FIXME: this is a hack, remove once we can use sycldevice in the triple
# without changing the language
# see issue: https://github.com/intel/llvm/issues/1814
set(libspirv_files ${libspirv_files_base})
if( ${ARCH} STREQUAL nvptx OR ${ARCH} STREQUAL nvptx64 )
add_libclc_sycl_binding(libspirv_files
TRIPLE ${t}
COMPILE_OPT ${mcpu}
FILES generic/libspirv/sycldevice-binding.cpp)
endif()

add_libclc_builtin_set(libspirv-${arch_suffix}
TRIPLE ${t}
TARGET_ENV libspirv
Expand Down
52 changes: 52 additions & 0 deletions libclc/cmake/modules/AddLibclc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,55 @@ function(libclc_configure_lib_source OUT_LIST)
set( ${OUT_LIST} ${rel_files} PARENT_SCOPE )

endfunction(libclc_configure_lib_source OUT_LIST)

# add_libclc_sycl_binding(arch_suffix
# TRIPLE string
# Triple used to compile
# FILES string ...
# List of file that should be built for this library
# COMPILE_OPT
# Compilation options
# )
#
# Build the sycl binding file for SYCLDEVICE.
# The path to the generated object file are appended in OUT_LIST.
#
# The mangling for sycl device is not yet fully
# compatible with standard mangling.
# For various reason, we need a mangling specific
# for the Default address space (mapping to generic in SYCL).
# The Default address space is not accessible in CL mode,
# so we build this file in sycl mode for mangling purposes.
#
# FIXME: all the files should be compiled with the sycldevice triple
# but this is not possible at the moment as this will trigger
# the SYCL mode which we don't want.
#
function(add_libclc_sycl_binding OUT_LIST)
cmake_parse_arguments(ARG
""
"TRIPLE"
"FILES;COMPILE_OPT"
${ARGN})

foreach( file ${ARG_FILES} )
file( TO_CMAKE_PATH ${LIBCLC_ROOT_DIR}/${file} SYCLDEVICE_BINDING )
if( EXISTS ${SYCLDEVICE_BINDING} )
set( SYCLDEVICE_BINDING_OUT ${CMAKE_CURRENT_BINARY_DIR}/sycldevice-binding-${ARG_TRIPLE}/sycldevice-binding.bc )
add_custom_command( OUTPUT ${SYCLDEVICE_BINDING_OUT}
COMMAND ${LLVM_CLANG}
-target ${ARG_TRIPLE}-sycldevice
-fsycl
-fsycl-device-only
-Dcl_khr_fp64
-I${LIBCLC_ROOT_DIR}/generic/include
${ARG_COMPILE_OPT}
${SYCLDEVICE_BINDING}
-o ${SYCLDEVICE_BINDING_OUT}
MAIN_DEPENDENCY ${SYCLDEVICE_BINDING}
DEPENDS ${SYCLDEVICE_BINDING} ${LLVM_CLANG}
VERBATIM )
set( ${OUT_LIST} "${${OUT_LIST}};${SYCLDEVICE_BINDING_OUT}" PARENT_SCOPE )
endif()
endforeach()
endfunction(add_libclc_sycl_binding OUT_LIST)
4 changes: 4 additions & 0 deletions libclc/generic/include/lp64_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ typedef half __clc_vec16_fp16_t __attribute__((ext_vector_type(16)));

typedef __clc_int64_t __clc_size_t;

#ifdef __SYCL_DEVICE_ONLY__
typedef __ocl_event_t __clc_event_t;
#else
typedef event_t __clc_event_t;
#endif

#endif // CLC_LP64_TYPES
Loading

0 comments on commit 65a4390

Please sign in to comment.