Skip to content

Commit

Permalink
Merge pull request KhronosGroup#119 from bb-sycl/intel/SYCL-2020-2021…
Browse files Browse the repository at this point in the history
…0913

Auto pulldown for intel/SYCL-2020 branch on 20210913
Product issues are tracked by CMPLRLLVM-29161 and CMPLRLLVM-26834
  • Loading branch information
jiezzhang committed Sep 17, 2021
2 parents 32807c4 + c0c0de5 commit 49cb3f2
Show file tree
Hide file tree
Showing 121 changed files with 4,715 additions and 568 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Expand Up @@ -52,10 +52,10 @@ endif()
option(SYCL_CTS_ENABLE_DOUBLE_TESTS "Enable Double tests." ON)
option(SYCL_CTS_ENABLE_HALF_TESTS "Enable Half tests." ON)
if(SYCL_CTS_ENABLE_DOUBLE_TESTS)
add_definitions(-DSYCL_CTS_TEST_DOUBLE)
add_host_and_device_compiler_definitions(-DSYCL_CTS_TEST_DOUBLE)
endif()
if(SYCL_CTS_ENABLE_HALF_TESTS)
add_definitions(-DSYCL_CTS_TEST_HALF)
add_host_and_device_compiler_definitions(-DSYCL_CTS_TEST_HALF)
endif()
# ------------------

Expand All @@ -64,7 +64,7 @@ endif()
option(SYCL_CTS_ENABLE_OPENCL_INTEROP_TESTS
"Enable OpenCL interoperability tests." ON)
if(SYCL_CTS_ENABLE_OPENCL_INTEROP_TESTS)
add_definitions(-DSYCL_CTS_TEST_OPENCL_INTEROP)
add_host_and_device_compiler_definitions(-DSYCL_CTS_TEST_OPENCL_INTEROP)
endif()
# ------------------

Expand Down
19 changes: 17 additions & 2 deletions cmake/AddSYCLExecutable.cmake
Expand Up @@ -3,11 +3,11 @@ if (NOT SYCL_IMPLEMENTATION)
set (SYCL_IMPLEMENTATION ComputeCpp)
endif()

set (KNOWN_SYCL_IMPLEMENTATIONS "Intel_SYCL;ComputeCpp;hipSYCL")
set (KNOWN_SYCL_IMPLEMENTATIONS "Intel_SYCL;DPCPP;ComputeCpp;hipSYCL")
if (NOT ${SYCL_IMPLEMENTATION} IN_LIST KNOWN_SYCL_IMPLEMENTATIONS)
message(FATAL_ERROR
"The SYCL CTS requires specifying a SYCL implementation with "
"-DSYCL_IMPLEMENTATION=[Intel_SYCL,ComputeCpp,hipSYCL]")
"-DSYCL_IMPLEMENTATION=[Intel_SYCL,DPCPP;ComputeCpp,hipSYCL]")
endif()

find_package(${SYCL_IMPLEMENTATION} REQUIRED)
Expand Down Expand Up @@ -58,3 +58,18 @@ function(add_sycl_executable)
OBJECT_LIBRARY "${args_OBJECT_LIBRARY}"
TESTS "${args_TESTS}")
endfunction()

# Adds preprocessor definitions to the device compiler,
# to mimic the add_definitions CMake function, but only for the device compiler
# If the implementation uses a single compiler for host and device code,
# then this function is expected to be a no-op
# because add_definitions should take care of everything
function(add_device_compiler_definitions)
add_device_compiler_definitions_implementation(${ARGN})
endfunction()

# Adds preprocessor definitions to both host and device compilers
function(add_host_and_device_compiler_definitions)
add_definitions(${ARGN})
add_device_compiler_definitions(${ARGN})
endfunction()
14 changes: 14 additions & 0 deletions cmake/FindComputeCpp.cmake
Expand Up @@ -52,6 +52,11 @@ set(COMPUTECPP_USER_FLAGS "" CACHE STRING "User flags for compute++")
separate_arguments(COMPUTECPP_USER_FLAGS)
mark_as_advanced(COMPUTECPP_USER_FLAGS)

# Device compiler definitions, should not be set by the user on the command line
# Must be a cache entry because that's the only way
# it can be modified in a function
set(computecpp_device_compiler_defs "" CACHE STRING "")

# build_spir
# Runs the device compiler on a single source file, creating the stub and the bc files.
function(build_spir exe_name spir_target_name source_file output_path)
Expand All @@ -78,6 +83,7 @@ function(build_spir exe_name spir_target_name source_file output_path)
-O2
-mllvm -inline-threshold=1000
-intelspirmetadata
${computecpp_device_compiler_defs}
${COMPUTECPP_USER_FLAGS}
${platform_specific_args}
$<$<BOOL:${include_directories}>:-I\"$<JOIN:${include_directories},\"\t-I\">\">
Expand Down Expand Up @@ -136,3 +142,11 @@ function(add_sycl_executable_implementation)
LINK_LIBRARIES "ComputeCpp::Runtime;$<$<BOOL:${WIN32}>:-SAFESEH:NO>"
BUILD_RPATH "$<TARGET_FILE_DIR:ComputeCpp::Runtime>")
endfunction()

# Adds preprocessor definitions to the device compiler
function(add_device_compiler_definitions_implementation)
set(computecpp_device_compiler_defs
${computecpp_device_compiler_defs} ${ARGN}
CACHE STRING "" FORCE
)
endfunction()
93 changes: 93 additions & 0 deletions cmake/FindDPCPP.cmake
@@ -0,0 +1,93 @@
if(${CMAKE_CXX_COMPILER_ID} MATCHES "GNU" OR
${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
find_program(DPCPP_CXX_EXECUTABLE NAMES dpcpp clang++
HINTS ${DPCPP_INSTALL_DIR}
PATH_SUFFIXES bin)
else()
# Remove /machine: option which is not supported by clang-cl
string(REPLACE "/machine:x64" "" CMAKE_EXE_LINKER_FLAGS
"${CMAKE_EXE_LINKER_FLAGS}")
# Remove /subsystem option which is not supported by clang-cl
string(REPLACE "/subsystem:console" "" CMAKE_CREATE_CONSOLE_EXE
${CMAKE_CREATE_CONSOLE_EXE})
find_program(DPCPP_CXX_EXECUTABLE NAMES dpcpp clang-cl
HINTS ${DPCPP_INSTALL_DIR}
PATH_SUFFIXES bin)
endif()

# Set SYCL compilation mode, SYCL 2020 standard version and user provided flags
set(DPCPP_FLAGS "-fsycl;-sycl-std=2020;${DPCPP_FLAGS}")
# Set target triple(s) if specified
if(DEFINED DPCPP_TARGET_TRIPLES)
set(DPCPP_FLAGS "${DPCPP_FLAGS};-fsycl-targets=${DPCPP_TARGET_TRIPLES};")
message("DPC++: compiling tests to ${DPCPP_TARGET_TRIPLES}")
if(${DPCPP_TARGET_TRIPLES} MATCHES ".*-nvidia-cuda-.*")
add_definitions(-DSYCL_CTS_INTEL_PI_CUDA)
endif()
endif()
message("DPC++ compiler flags: `${DPCPP_FLAGS}`")

# Explicitly set fp-model to precise to produce reliable results for floating
# point operations.
if(WIN32)
set(DPCPP_FP_FLAG "/fp:precise")
else()
set(DPCPP_FP_FLAG "-ffp-model=precise")
endif()
set(CMAKE_CXX_FLAGS "${DPCPP_FP_FLAG} ${CMAKE_CXX_FLAGS}")

add_library(DPCPP::Runtime INTERFACE IMPORTED GLOBAL)
set_target_properties(DPCPP::Runtime PROPERTIES
INTERFACE_LINK_LIBRARIES OpenCL::OpenCL
INTERFACE_COMPILE_OPTIONS "${DPCPP_FLAGS}"
INTERFACE_LINK_OPTIONS "${DPCPP_FLAGS}")

set(CMAKE_CXX_COMPILER ${DPCPP_CXX_EXECUTABLE})
# Use DPC++ compiler instead of default linker for building SYCL application
set(CMAKE_CXX_LINK_EXECUTABLE "${DPCPP_CXX_EXECUTABLE} <FLAGS> \
<CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")

add_library(SYCL::SYCL INTERFACE IMPORTED GLOBAL)
set_target_properties(SYCL::SYCL PROPERTIES
INTERFACE_LINK_LIBRARIES DPCPP::Runtime)

# add_sycl_executable_implementation function
# Builds a SYCL program, compiling multiple SYCL test case source files into a
# test executable, invoking a single-source/device compiler
# Parameters are:
# - NAME Name of the test executable
# - OBJECT_LIBRARY Name of the object library of all the compiled test cases
# - TESTS List of SYCL test case source files to be built into the
# test executable
function(add_sycl_executable_implementation)
cmake_parse_arguments(args "" "NAME;OBJECT_LIBRARY" "TESTS" ${ARGN})
set(exe_name ${args_NAME})
set(object_lib_name ${args_OBJECT_LIBRARY})
set(test_cases_list ${args_TESTS})

add_library(${object_lib_name} OBJECT ${test_cases_list})
add_executable(${exe_name} $<TARGET_OBJECTS:${object_lib_name}>)

set_target_properties(${object_lib_name} PROPERTIES
INCLUDE_DIRECTORIES $<TARGET_PROPERTY:${exe_name},INCLUDE_DIRECTORIES>
COMPILE_DEFINITIONS $<TARGET_PROPERTY:${exe_name},COMPILE_DEFINITIONS>
COMPILE_OPTIONS $<TARGET_PROPERTY:${exe_name},COMPILE_OPTIONS>
COMPILE_FEATURES $<TARGET_PROPERTY:${exe_name},COMPILE_FEATURES>
POSITION_INDEPENDENT_CODE ON)

target_compile_options(${object_lib_name} PRIVATE
$<TARGET_PROPERTY:DPCPP::Runtime,INTERFACE_COMPILE_OPTIONS>)

target_link_libraries(${exe_name} PUBLIC DPCPP::Runtime)
# CMake < 3.14 doesn't support INTERFACE_LINK_OPTIONS otherwise we just use
# LINK_LIBRARIES
if(${CMAKE_VERSION} VERSION_LESS 3.14)
target_link_options(${exe_name} PRIVATE
$<TARGET_PROPERTY:DPCPP::Runtime,INTERFACE_LINK_OPTIONS>)
endif()
endfunction()

# Adds device compiler definitions
# This functions is a no-op because add_definitions should take care of it
function(add_device_compiler_definitions_implementation)
endfunction()
82 changes: 7 additions & 75 deletions cmake/FindIntel_SYCL.cmake
@@ -1,78 +1,10 @@
if(${CMAKE_CXX_COMPILER_ID} MATCHES "GNU" OR
${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
find_program(INTEL_SYCL_CXX_EXECUTABLE NAMES dpcpp clang++ HINTS ${INTEL_SYCL_ROOT}
PATH_SUFFIXES bin)
else()
# Remove /machine: option which is not supported by clang-cl
string(REPLACE "/machine:x64" "" CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
# Remove /subsystem option which is not supported by clang-cl
string(REPLACE "/subsystem:console" "" CMAKE_CREATE_CONSOLE_EXE ${CMAKE_CREATE_CONSOLE_EXE})
find_program(INTEL_SYCL_CXX_EXECUTABLE NAMES dpcpp clang-cl HINTS ${INTEL_SYCL_ROOT}
PATH_SUFFIXES bin)
endif()

if(NOT DEFINED INTEL_SYCL_TRIPLE)
set(INTEL_SYCL_TRIPLE spir64-unknown-unknown-sycldevice)
endif()
message("Intel SYCL: compiling tests to ${INTEL_SYCL_TRIPLE}")
message(WARNING
"Intel_SYCL is deprecated and will be removed, use DPCPP instead")

# Set precise fp-model for Intel Compiler
if(WIN32)
set(INTEL_FP_FLAG "/fp:precise")
else()
set(INTEL_FP_FLAG "-ffp-model=precise")
set(DPCPP_INSTALL_DIR ${INTEL_SYCL_ROOT})
set(DPCPP_FLAGS ${INTEL_SYCL_FLAGS})
if(DEFINED INTEL_SYCL_TRIPLE)
set(DPCPP_TARGET_TRIPLES ${INTEL_SYCL_TRIPLE})
endif()
set(CMAKE_CXX_FLAGS "${INTEL_FP_FLAG} ${CMAKE_CXX_FLAGS}")

set(INTEL_SYCL_FLAGS "-fsycl;-fsycl-targets=${INTEL_SYCL_TRIPLE};-sycl-std=2020;${INTEL_SYCL_FLAGS}")
message("Intel SYCL compiler flags: `${INTEL_SYCL_FLAGS}`")

add_library(INTEL_SYCL::Runtime INTERFACE IMPORTED GLOBAL)
set_target_properties(INTEL_SYCL::Runtime PROPERTIES
INTERFACE_LINK_LIBRARIES OpenCL::OpenCL
INTERFACE_COMPILE_OPTIONS "${INTEL_SYCL_FLAGS}"
INTERFACE_LINK_OPTIONS "${INTEL_SYCL_FLAGS}")

set(CMAKE_CXX_COMPILER ${INTEL_SYCL_CXX_EXECUTABLE})
# Use SYCL compiler instead of default linker for building SYCL application
set(CMAKE_CXX_LINK_EXECUTABLE "${INTEL_SYCL_CXX_EXECUTABLE} <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")

add_library(SYCL::SYCL INTERFACE IMPORTED GLOBAL)
set_target_properties(SYCL::SYCL PROPERTIES
INTERFACE_LINK_LIBRARIES INTEL_SYCL::Runtime)

# add_sycl_executable_implementation function
# Builds a SYCL program, compiling multiple SYCL test case source files into a
# test executable, invoking a single-source/device compiler
# Parameters are:
# - NAME Name of the test executable
# - OBJECT_LIBRARY Name of the object library of all the compiled test cases
# - TESTS List of SYCL test case source files to be built into the
# test executable
function(add_sycl_executable_implementation)
cmake_parse_arguments(args "" "NAME;OBJECT_LIBRARY" "TESTS" ${ARGN})
set(exe_name ${args_NAME})
set(object_lib_name ${args_OBJECT_LIBRARY})
set(test_cases_list ${args_TESTS})

add_library(${object_lib_name} OBJECT ${test_cases_list})
add_executable(${exe_name} $<TARGET_OBJECTS:${object_lib_name}>)

set_target_properties(${object_lib_name} PROPERTIES
INCLUDE_DIRECTORIES $<TARGET_PROPERTY:${exe_name},INCLUDE_DIRECTORIES>
COMPILE_DEFINITIONS $<TARGET_PROPERTY:${exe_name},COMPILE_DEFINITIONS>
COMPILE_OPTIONS $<TARGET_PROPERTY:${exe_name},COMPILE_OPTIONS>
COMPILE_FEATURES $<TARGET_PROPERTY:${exe_name},COMPILE_FEATURES>
POSITION_INDEPENDENT_CODE ON)

target_compile_options(${object_lib_name} PRIVATE
$<TARGET_PROPERTY:INTEL_SYCL::Runtime,INTERFACE_COMPILE_OPTIONS>)

target_link_libraries(${exe_name} PUBLIC INTEL_SYCL::Runtime)
# CMake < 3.14 doesn't support INTERFACE_LINK_OPTIONS otherwise we just use
# LINK_LIBRARIES
if(${CMAKE_VERSION} VERSION_LESS 3.14)
target_link_options(${exe_name} PRIVATE
$<TARGET_PROPERTY:INTEL_SYCL::Runtime,INTERFACE_LINK_OPTIONS>)
endif()
endfunction()
include(FindDPCPP)
5 changes: 5 additions & 0 deletions cmake/FindhipSYCL.cmake
Expand Up @@ -33,3 +33,8 @@ function(add_sycl_executable_implementation)
POSITION_INDEPENDENT_CODE ON)

endfunction()

# Adds device compiler definitions
# This functions is a no-op because add_definitions should take care of it
function(add_device_compiler_definitions_implementation)
endfunction()

0 comments on commit 49cb3f2

Please sign in to comment.