mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Partial OpenCL support via SYCL compatible with ComputeCpp CE.
This commit is contained in:
@@ -109,6 +109,103 @@ macro(ei_add_test_internal testname testname_with_suffix)
|
||||
|
||||
endmacro(ei_add_test_internal)
|
||||
|
||||
# SYCL
|
||||
macro(ei_add_test_internal_sycl testname testname_with_suffix)
|
||||
include_directories( SYSTEM ${COMPUTECPP_PACKAGE_ROOT_DIR}/include)
|
||||
set(targetname ${testname_with_suffix})
|
||||
|
||||
if(EIGEN_ADD_TEST_FILENAME_EXTENSION)
|
||||
set(filename ${testname}.${EIGEN_ADD_TEST_FILENAME_EXTENSION})
|
||||
else()
|
||||
set(filename ${testname}.cpp)
|
||||
endif()
|
||||
|
||||
set( include_file ${CMAKE_CURRENT_BINARY_DIR}/inc_${filename})
|
||||
set( bc_file ${CMAKE_CURRENT_BINARY_DIR}/${filename})
|
||||
set( host_file ${CMAKE_CURRENT_SOURCE_DIR}/${filename})
|
||||
|
||||
ADD_CUSTOM_COMMAND(
|
||||
OUTPUT ${include_file}
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "\\#include \\\"${host_file}\\\"" > ${include_file}
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "\\#include \\\"${bc_file}.sycl\\\"" >> ${include_file}
|
||||
DEPENDS ${filename}
|
||||
COMMENT "Building ComputeCpp integration header file ${include_file}"
|
||||
)
|
||||
# Add a custom target for the generated integration header
|
||||
add_custom_target(${testname}_integration_header_woho DEPENDS ${include_file})
|
||||
|
||||
add_executable(${targetname} ${include_file})
|
||||
add_dependencies(${targetname} ${testname}_integration_header_woho)
|
||||
add_sycl_to_target(${targetname} ${filename} ${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
if (targetname MATCHES "^eigen2_")
|
||||
add_dependencies(eigen2_buildtests ${targetname})
|
||||
else()
|
||||
add_dependencies(buildtests ${targetname})
|
||||
endif()
|
||||
|
||||
if(EIGEN_NO_ASSERTION_CHECKING)
|
||||
ei_add_target_property(${targetname} COMPILE_FLAGS "-DEIGEN_NO_ASSERTION_CHECKING=1")
|
||||
else(EIGEN_NO_ASSERTION_CHECKING)
|
||||
if(EIGEN_DEBUG_ASSERTS)
|
||||
ei_add_target_property(${targetname} COMPILE_FLAGS "-DEIGEN_DEBUG_ASSERTS=1")
|
||||
endif(EIGEN_DEBUG_ASSERTS)
|
||||
endif(EIGEN_NO_ASSERTION_CHECKING)
|
||||
|
||||
ei_add_target_property(${targetname} COMPILE_FLAGS "-DEIGEN_TEST_MAX_SIZE=${EIGEN_TEST_MAX_SIZE}")
|
||||
|
||||
ei_add_target_property(${targetname} COMPILE_FLAGS "-DEIGEN_TEST_FUNC=${testname}")
|
||||
|
||||
if(MSVC AND NOT EIGEN_SPLIT_LARGE_TESTS)
|
||||
ei_add_target_property(${targetname} COMPILE_FLAGS "/bigobj")
|
||||
endif()
|
||||
|
||||
# let the user pass flags.
|
||||
if(${ARGC} GREATER 2)
|
||||
ei_add_target_property(${targetname} COMPILE_FLAGS "${ARGV2}")
|
||||
endif(${ARGC} GREATER 2)
|
||||
|
||||
if(EIGEN_TEST_CUSTOM_CXX_FLAGS)
|
||||
ei_add_target_property(${targetname} COMPILE_FLAGS "${EIGEN_TEST_CUSTOM_CXX_FLAGS}")
|
||||
endif()
|
||||
|
||||
if(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO)
|
||||
target_link_libraries(${targetname} ${EIGEN_STANDARD_LIBRARIES_TO_LINK_TO})
|
||||
endif()
|
||||
if(EXTERNAL_LIBS)
|
||||
target_link_libraries(${targetname} ${EXTERNAL_LIBS})
|
||||
endif()
|
||||
if(EIGEN_TEST_CUSTOM_LINKER_FLAGS)
|
||||
target_link_libraries(${targetname} ${EIGEN_TEST_CUSTOM_LINKER_FLAGS})
|
||||
endif()
|
||||
|
||||
if(${ARGC} GREATER 3)
|
||||
set(libs_to_link ${ARGV3})
|
||||
# it could be that some cmake module provides a bad library string " " (just spaces),
|
||||
# and that severely breaks target_link_libraries ("can't link to -l-lstdc++" errors).
|
||||
# so we check for strings containing only spaces.
|
||||
string(STRIP "${libs_to_link}" libs_to_link_stripped)
|
||||
string(LENGTH "${libs_to_link_stripped}" libs_to_link_stripped_length)
|
||||
if(${libs_to_link_stripped_length} GREATER 0)
|
||||
# notice: no double quotes around ${libs_to_link} here. It may be a list.
|
||||
target_link_libraries(${targetname} ${libs_to_link})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
add_test(${testname_with_suffix} "${targetname}")
|
||||
|
||||
# Specify target and test labels according to EIGEN_CURRENT_SUBPROJECT
|
||||
get_property(current_subproject GLOBAL PROPERTY EIGEN_CURRENT_SUBPROJECT)
|
||||
if ((current_subproject) AND (NOT (current_subproject STREQUAL "")))
|
||||
set_property(TARGET ${targetname} PROPERTY LABELS "Build${current_subproject}")
|
||||
add_dependencies("Build${current_subproject}" ${targetname})
|
||||
set_property(TEST ${testname_with_suffix} PROPERTY LABELS "${current_subproject}")
|
||||
endif()
|
||||
|
||||
|
||||
endmacro(ei_add_test_internal_sycl)
|
||||
|
||||
|
||||
# Macro to add a test
|
||||
#
|
||||
# the unique mandatory parameter testname must correspond to a file
|
||||
@@ -185,6 +282,39 @@ macro(ei_add_test testname)
|
||||
endif(EIGEN_SPLIT_LARGE_TESTS AND suffixes)
|
||||
endmacro(ei_add_test)
|
||||
|
||||
macro(ei_add_test_sycl testname)
|
||||
get_property(EIGEN_TESTS_LIST GLOBAL PROPERTY EIGEN_TESTS_LIST)
|
||||
set(EIGEN_TESTS_LIST "${EIGEN_TESTS_LIST}${testname}\n")
|
||||
set_property(GLOBAL PROPERTY EIGEN_TESTS_LIST "${EIGEN_TESTS_LIST}")
|
||||
|
||||
if(EIGEN_ADD_TEST_FILENAME_EXTENSION)
|
||||
set(filename ${testname}.${EIGEN_ADD_TEST_FILENAME_EXTENSION})
|
||||
else()
|
||||
set(filename ${testname}.cpp)
|
||||
endif()
|
||||
|
||||
file(READ "${filename}" test_source)
|
||||
set(parts 0)
|
||||
string(REGEX MATCHALL "CALL_SUBTEST_[0-9]+|EIGEN_TEST_PART_[0-9]+|EIGEN_SUFFIXES(;[0-9]+)+"
|
||||
occurences "${test_source}")
|
||||
string(REGEX REPLACE "CALL_SUBTEST_|EIGEN_TEST_PART_|EIGEN_SUFFIXES" "" suffixes "${occurences}")
|
||||
list(REMOVE_DUPLICATES suffixes)
|
||||
if(EIGEN_SPLIT_LARGE_TESTS AND suffixes)
|
||||
add_custom_target(${testname})
|
||||
foreach(suffix ${suffixes})
|
||||
ei_add_test_internal_sycl(${testname} ${testname}_${suffix}
|
||||
"${ARGV1} -DEIGEN_TEST_PART_${suffix}=1" "${ARGV2}")
|
||||
add_dependencies(${testname} ${testname}_${suffix})
|
||||
endforeach(suffix)
|
||||
else(EIGEN_SPLIT_LARGE_TESTS AND suffixes)
|
||||
set(symbols_to_enable_all_parts "")
|
||||
foreach(suffix ${suffixes})
|
||||
set(symbols_to_enable_all_parts
|
||||
"${symbols_to_enable_all_parts} -DEIGEN_TEST_PART_${suffix}=1")
|
||||
endforeach(suffix)
|
||||
ei_add_test_internal_sycl(${testname} ${testname} "${ARGV1} ${symbols_to_enable_all_parts}" "${ARGV2}")
|
||||
endif(EIGEN_SPLIT_LARGE_TESTS AND suffixes)
|
||||
endmacro(ei_add_test_sycl)
|
||||
|
||||
# adds a failtest, i.e. a test that succeed if the program fails to compile
|
||||
# note that the test runner for these is CMake itself, when passed -DEIGEN_FAILTEST=ON
|
||||
@@ -330,6 +460,11 @@ macro(ei_testing_print_summary)
|
||||
message(STATUS "C++11: OFF")
|
||||
endif()
|
||||
|
||||
if(EIGEN_TEST_SYCL)
|
||||
message(STATUS "SYCL: ON")
|
||||
else()
|
||||
message(STATUS "SYCL: OFF")
|
||||
endif()
|
||||
if(EIGEN_TEST_CUDA)
|
||||
if(EIGEN_TEST_CUDA_CLANG)
|
||||
message(STATUS "CUDA: ON (using clang)")
|
||||
|
||||
228
cmake/FindComputeCpp.cmake
Normal file
228
cmake/FindComputeCpp.cmake
Normal file
@@ -0,0 +1,228 @@
|
||||
#.rst:
|
||||
# FindComputeCpp
|
||||
#---------------
|
||||
|
||||
#########################
|
||||
# FindComputeCpp.cmake
|
||||
#########################
|
||||
#
|
||||
# Tools for finding and building with ComputeCpp.
|
||||
#
|
||||
|
||||
# Require CMake version 3.2.2 or higher
|
||||
cmake_minimum_required(VERSION 3.2.2)
|
||||
|
||||
# Check that a supported host compiler can be found
|
||||
if(CMAKE_COMPILER_IS_GNUCXX)
|
||||
# Require at least gcc 4.8
|
||||
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8)
|
||||
message(FATAL_ERROR
|
||||
"host compiler - Not found! (gcc version must be at least 4.8)")
|
||||
# Require the GCC dual ABI to be disabled for 5.1 or higher
|
||||
elseif (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 5.1)
|
||||
set(COMPUTECPP_DISABLE_GCC_DUAL_ABI "True")
|
||||
message(STATUS
|
||||
"host compiler - gcc ${CMAKE_CXX_COMPILER_VERSION} (note pre 5.1 gcc ABI enabled)")
|
||||
else()
|
||||
message(STATUS "host compiler - gcc ${CMAKE_CXX_COMPILER_VERSION}")
|
||||
endif()
|
||||
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
||||
# Require at least clang 3.6
|
||||
if (${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 3.6)
|
||||
message(FATAL_ERROR
|
||||
"host compiler - Not found! (clang version must be at least 3.6)")
|
||||
else()
|
||||
set(COMPUTECPP_DISABLE_GCC_DUAL_ABI "True")
|
||||
message(STATUS "host compiler - clang ${CMAKE_CXX_COMPILER_VERSION}")
|
||||
endif()
|
||||
else()
|
||||
message(WARNING
|
||||
"host compiler - Not found! (ComputeCpp supports GCC and Clang, see readme)")
|
||||
endif()
|
||||
|
||||
set(COMPUTECPP_64_BIT_DEFAULT ON)
|
||||
option(COMPUTECPP_64_BIT_CODE "Compile device code in 64 bit mode"
|
||||
${COMPUTECPP_64_BIT_DEFAULT})
|
||||
mark_as_advanced(COMPUTECPP_64_BIT_CODE)
|
||||
|
||||
# Find OpenCL package
|
||||
find_package(OpenCL REQUIRED)
|
||||
|
||||
# Find ComputeCpp package
|
||||
if(EXISTS ${COMPUTECPP_PACKAGE_ROOT_DIR})
|
||||
message(STATUS "ComputeCpp package - Found (${COMPUTECPP_PACKAGE_ROOT_DIR})")
|
||||
else()
|
||||
message(FATAL_ERROR "ComputeCpp package - Not found! (please set COMPUTECPP_PACKAGE_ROOT_DIR) (${COMPUTECPP_PACKAGE_ROOT_DIR})")
|
||||
endif()
|
||||
option(COMPUTECPP_PACKAGE_ROOT_DIR "Path to the ComputeCpp Package")
|
||||
|
||||
# Obtain the path to compute++
|
||||
find_program(COMPUTECPP_DEVICE_COMPILER compute++ PATHS
|
||||
${COMPUTECPP_PACKAGE_ROOT_DIR} PATH_SUFFIXES bin)
|
||||
if (EXISTS ${COMPUTECPP_DEVICE_COMPILER})
|
||||
mark_as_advanced(COMPUTECPP_DEVICE_COMPILER)
|
||||
message(STATUS "compute++ - Found (${COMPUTECPP_PACKAGE_ROOT_DIR})")
|
||||
else()
|
||||
message(FATAL_ERROR "compute++ - Not found! (${COMPUTECPP_DEVICE_COMPILER}) (${COMPUTECPP_PACKAGE_ROOT_DIR})")
|
||||
endif()
|
||||
|
||||
# Obtain the path to computecpp_info
|
||||
find_program(COMPUTECPP_INFO_TOOL computecpp_info PATHS
|
||||
${COMPUTECPP_PACKAGE_ROOT_DIR} PATH_SUFFIXES bin)
|
||||
if (EXISTS ${COMPUTECPP_INFO_TOOL})
|
||||
mark_as_advanced(${COMPUTECPP_INFO_TOOL})
|
||||
message(STATUS "computecpp_info - Found (${COMPUTECPP_PACKAGE_ROOT_DIR})")
|
||||
else()
|
||||
message(FATAL_ERROR "computecpp_info - Not found! (${COMPUTECPP_INFO_TOOL}) (${COMPUTECPP_PACKAGE_ROOT_DIR})")
|
||||
endif()
|
||||
|
||||
# Obtain the path to the ComputeCpp runtime library
|
||||
find_library(COMPUTECPP_RUNTIME_LIBRARY ComputeCpp PATHS ${COMPUTECPP_PACKAGE_ROOT_DIR}
|
||||
HINTS ${COMPUTECPP_PACKAGE_ROOT_DIR}/lib PATH_SUFFIXES lib
|
||||
DOC "ComputeCpp Runtime Library" NO_DEFAULT_PATH)
|
||||
|
||||
if (EXISTS ${COMPUTECPP_RUNTIME_LIBRARY})
|
||||
mark_as_advanced(COMPUTECPP_RUNTIME_LIBRARY)
|
||||
message(STATUS "libComputeCpp.so - Found")
|
||||
else()
|
||||
message(FATAL_ERROR "libComputeCpp.so - Not found! (${COMPUTECPP_PACKAGE_ROOT_DIR})")
|
||||
endif()
|
||||
|
||||
# Obtain the ComputeCpp include directory
|
||||
set(COMPUTECPP_INCLUDE_DIRECTORY ${COMPUTECPP_PACKAGE_ROOT_DIR}/include/)
|
||||
if (NOT EXISTS ${COMPUTECPP_INCLUDE_DIRECTORY})
|
||||
message(FATAL_ERROR "ComputeCpp includes - Not found! (${COMPUTECPP_PACKAGE_ROOT_DIR}/include/)")
|
||||
else()
|
||||
message(STATUS "ComputeCpp includes - Found (${COMPUTECPP_PACKAGE_ROOT_DIR})")
|
||||
endif()
|
||||
|
||||
# Obtain the package version
|
||||
execute_process(COMMAND ${COMPUTECPP_INFO_TOOL} "--dump-version"
|
||||
OUTPUT_VARIABLE COMPUTECPP_PACKAGE_VERSION
|
||||
RESULT_VARIABLE COMPUTECPP_INFO_TOOL_RESULT OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
if(NOT COMPUTECPP_INFO_TOOL_RESULT EQUAL "0")
|
||||
message(FATAL_ERROR "Package version - Error obtaining version!")
|
||||
else()
|
||||
mark_as_advanced(COMPUTECPP_PACKAGE_VERSION)
|
||||
message(STATUS "Package version - ${COMPUTECPP_PACKAGE_VERSION}")
|
||||
endif()
|
||||
|
||||
# Obtain the device compiler flags
|
||||
execute_process(COMMAND ${COMPUTECPP_INFO_TOOL} "--dump-device-compiler-flags"
|
||||
OUTPUT_VARIABLE COMPUTECPP_DEVICE_COMPILER_FLAGS
|
||||
RESULT_VARIABLE COMPUTECPP_INFO_TOOL_RESULT OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
if(NOT COMPUTECPP_INFO_TOOL_RESULT EQUAL "0")
|
||||
message(FATAL_ERROR "compute++ flags - Error obtaining compute++ flags!")
|
||||
else()
|
||||
mark_as_advanced(COMPUTECPP_COMPILER_FLAGS)
|
||||
message(STATUS "compute++ flags - ${COMPUTECPP_DEVICE_COMPILER_FLAGS}")
|
||||
endif()
|
||||
|
||||
set(COMPUTECPP_DEVICE_COMPILER_FLAGS ${COMPUTECPP_DEVICE_COMPILER_FLAGS} -sycl-compress-name -no-serial-memop -DEIGEN_NO_ASSERTION_CHECKING=1)
|
||||
|
||||
# Check if the platform is supported
|
||||
execute_process(COMMAND ${COMPUTECPP_INFO_TOOL} "--dump-is-supported"
|
||||
OUTPUT_VARIABLE COMPUTECPP_PLATFORM_IS_SUPPORTED
|
||||
RESULT_VARIABLE COMPUTECPP_INFO_TOOL_RESULT OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
if(NOT COMPUTECPP_INFO_TOOL_RESULT EQUAL "0")
|
||||
message(FATAL_ERROR "platform - Error checking platform support!")
|
||||
else()
|
||||
mark_as_advanced(COMPUTECPP_PLATFORM_IS_SUPPORTED)
|
||||
if (COMPUTECPP_PLATFORM_IS_SUPPORTED)
|
||||
message(STATUS "platform - your system can support ComputeCpp")
|
||||
else()
|
||||
message(STATUS "platform - your system CANNOT support ComputeCpp")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
####################
|
||||
# __build_sycl
|
||||
####################
|
||||
#
|
||||
# Adds a custom target for running compute++ and adding a dependency for the
|
||||
# resulting integration header.
|
||||
#
|
||||
# targetName : Name of the target.
|
||||
# sourceFile : Source file to be compiled.
|
||||
# binaryDir : Intermediate output directory for the integration header.
|
||||
#
|
||||
function(__build_spir targetName sourceFile binaryDir)
|
||||
|
||||
# Retrieve source file name.
|
||||
get_filename_component(sourceFileName ${sourceFile} NAME)
|
||||
|
||||
# Set the path to the Sycl file.
|
||||
set(outputSyclFile ${binaryDir}/${sourceFileName}.sycl)
|
||||
|
||||
# Add any user-defined include to the device compiler
|
||||
get_property(includeDirectories DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY
|
||||
INCLUDE_DIRECTORIES)
|
||||
set(device_compiler_includes "")
|
||||
foreach(directory ${includeDirectories})
|
||||
set(device_compiler_includes "-I${directory}" ${device_compiler_includes})
|
||||
endforeach()
|
||||
if (CMAKE_INCLUDE_PATH)
|
||||
foreach(directory ${CMAKE_INCLUDE_PATH})
|
||||
set(device_compiler_includes "-I${directory}"
|
||||
${device_compiler_includes})
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
# Convert argument list format
|
||||
separate_arguments(COMPUTECPP_DEVICE_COMPILER_FLAGS)
|
||||
|
||||
# Add custom command for running compute++
|
||||
add_custom_command(
|
||||
OUTPUT ${outputSyclFile}
|
||||
COMMAND ${COMPUTECPP_DEVICE_COMPILER}
|
||||
${COMPUTECPP_DEVICE_COMPILER_FLAGS}
|
||||
-I${COMPUTECPP_INCLUDE_DIRECTORY}
|
||||
${COMPUTECPP_PLATFORM_SPECIFIC_ARGS}
|
||||
${device_compiler_includes}
|
||||
-o ${outputSyclFile}
|
||||
-c ${CMAKE_CURRENT_SOURCE_DIR}/${sourceFile}
|
||||
DEPENDS ${sourceFile}
|
||||
COMMENT "Building ComputeCpp integration header file ${outputSyclFile}")
|
||||
|
||||
# Add a custom target for the generated integration header
|
||||
add_custom_target(${targetName}_integration_header DEPENDS ${outputSyclFile})
|
||||
|
||||
# Add a dependency on the integration header
|
||||
add_dependencies(${targetName} ${targetName}_integration_header)
|
||||
|
||||
# Force inclusion of the integration header for the host compiler
|
||||
#set(compileFlags -include ${include_file} "-Wall")
|
||||
target_compile_options(${targetName} PUBLIC ${compileFlags})
|
||||
|
||||
# Set the host compiler C++ standard to C++11
|
||||
set_property(TARGET ${targetName} PROPERTY CXX_STANDARD 11)
|
||||
|
||||
# Disable GCC dual ABI on GCC 5.1 and higher
|
||||
if(COMPUTECPP_DISABLE_GCC_DUAL_ABI)
|
||||
set_property(TARGET ${targetName} APPEND PROPERTY COMPILE_DEFINITIONS
|
||||
"_GLIBCXX_USE_CXX11_ABI=0")
|
||||
endif()
|
||||
|
||||
endfunction()
|
||||
|
||||
#######################
|
||||
# add_sycl_to_target
|
||||
#######################
|
||||
#
|
||||
# Adds a SYCL compilation custom command associated with an existing
|
||||
# target and sets a dependency on that new command.
|
||||
#
|
||||
# targetName : Name of the target to add a SYCL to.
|
||||
# sourceFile : Source file to be compiled for SYCL.
|
||||
# binaryDir : Intermediate output directory for the integration header.
|
||||
#
|
||||
function(add_sycl_to_target targetName sourceFile binaryDir)
|
||||
|
||||
# Add custom target to run compute++ and generate the integration header
|
||||
__build_spir(${targetName} ${sourceFile} ${binaryDir})
|
||||
|
||||
# Link with the ComputeCpp runtime library
|
||||
target_link_libraries(${targetName} PUBLIC ${COMPUTECPP_RUNTIME_LIBRARY}
|
||||
PUBLIC ${OpenCL_LIBRARIES})
|
||||
|
||||
endfunction(add_sycl_to_target)
|
||||
Reference in New Issue
Block a user