Merged in a-doumoulakis/opencl (pull request PR-12)

Enable triSYCL with Eigen
This commit is contained in:
Benoit Steiner 2017-05-25 18:18:23 +00:00
commit 615aff4d6e
6 changed files with 221 additions and 44 deletions

View File

@ -437,10 +437,17 @@ endif()
# add SYCL
option(EIGEN_TEST_SYCL "Add Sycl support." OFF)
option(EIGEN_SYCL_TRISYCL "Use the triSYCL Sycl implementation (ComputeCPP by default)." OFF)
if(EIGEN_TEST_SYCL)
set (CMAKE_MODULE_PATH "${CMAKE_ROOT}/Modules" "cmake/Modules/" "${CMAKE_MODULE_PATH}")
include(FindComputeCpp)
endif()
if(EIGEN_SYCL_TRISYCL)
message(STATUS "Using triSYCL")
include(FindTriSYCL)
else(EIGEN_SYCL_TRISYCL)
message(STATUS "Using ComputeCPP SYCL")
include(FindComputeCpp)
endif(EIGEN_SYCL_TRISYCL)
endif(EIGEN_TEST_SYCL)
add_subdirectory(unsupported)

View File

@ -111,7 +111,6 @@ 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)
@ -124,18 +123,26 @@ macro(ei_add_test_internal_sycl testname testname_with_suffix)
set( bc_file "${CMAKE_CURRENT_BINARY_DIR}/${filename}.sycl")
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}\\\"" >> ${include_file}
DEPENDS ${host_file} ${bc_file}
COMMENT "Building ComputeCpp integration header file ${include_file}"
)
# Add a custom target for the generated integration header
add_custom_target("${testname}_integration_header_sycl" DEPENDS ${include_file})
if(NOT EIGEN_SYCL_TRISYCL)
include_directories( SYSTEM ${COMPUTECPP_PACKAGE_ROOT_DIR}/include)
ADD_CUSTOM_COMMAND(
OUTPUT ${include_file}
COMMAND ${CMAKE_COMMAND} -E echo "\\#include \\\"${host_file}\\\"" > ${include_file}
COMMAND ${CMAKE_COMMAND} -E echo "\\#include \\\"${bc_file}\\\"" >> ${include_file}
DEPENDS ${filename} ${bc_file}
COMMENT "Building ComputeCpp integration header file ${include_file}"
)
# Add a custom target for the generated integration header
add_custom_target("${testname}_integration_header_sycl" DEPENDS ${include_file})
add_executable(${targetname} ${include_file})
add_dependencies(${targetname} "${testname}_integration_header_sycl")
else()
add_executable(${targetname} ${host_file})
endif()
add_executable(${targetname} ${include_file})
add_dependencies(${targetname} "${testname}_integration_header_sycl")
add_sycl_to_target(${targetname} ${CMAKE_CURRENT_BINARY_DIR} ${filename})
if (targetname MATCHES "^eigen2_")
@ -467,7 +474,11 @@ macro(ei_testing_print_summary)
endif()
if(EIGEN_TEST_SYCL)
message(STATUS "SYCL: ON")
if(EIGEN_SYCL_TRISYCL)
message(STATUS "SYCL: ON (using triSYCL)")
else()
message(STATUS "SYCL: ON (using computeCPP)")
endif()
else()
message(STATUS "SYCL: OFF")
endif()
@ -720,4 +731,4 @@ macro(ei_test_get_compilerver_from_cxx_version_string)
ei_test1_get_compilerver_from_cxx_version_string("i686-apple-darwin11-llvm-g++-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)" "llvm-g++" "4.2.1")
ei_test1_get_compilerver_from_cxx_version_string("g++-mp-4.4 (GCC) 4.4.6" "g++" "4.4.6")
ei_test1_get_compilerver_from_cxx_version_string("g++-mp-4.4 (GCC) 2011" "g++" "4.4")
endmacro(ei_test_get_compilerver_from_cxx_version_string)
endmacro(ei_test_get_compilerver_from_cxx_version_string)

152
cmake/FindTriSYCL.cmake Normal file
View File

@ -0,0 +1,152 @@
#.rst:
# FindTriSYCL
#---------------
#
# TODO : insert Copyright and licence
#########################
# FindTriSYCL.cmake
#########################
#
# Tools for finding and building with TriSYCL.
#
# User must define TRISYCL_INCLUDE_DIR pointing to the triSYCL
# include directory.
#
# Latest version of this file can be found at:
# https://github.com/triSYCL/triSYCL
# Requite CMake version 3.5 or higher
cmake_minimum_required (VERSION 3.5)
# Check that a supported host compiler can be found
if(CMAKE_COMPILER_IS_GNUCXX)
# Require at least gcc 5.4
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.4)
message(FATAL_ERROR
"host compiler - Not found! (gcc version must be at least 5.4)")
else()
message(STATUS "host compiler - gcc ${CMAKE_CXX_COMPILER_VERSION}")
endif()
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
# Require at least clang 3.9
if (${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 3.9)
message(FATAL_ERROR
"host compiler - Not found! (clang version must be at least 3.9)")
else()
message(STATUS "host compiler - clang ${CMAKE_CXX_COMPILER_VERSION}")
endif()
else()
message(WARNING
"host compiler - Not found! (triSYCL supports GCC and Clang)")
endif()
#triSYCL options
option(TRISYCL_OPENMP "triSYCL multi-threading with OpenMP" ON)
option(TRISYCL_OPENCL "triSYCL OpenCL interoperability mode" OFF)
option(TRISYCL_NO_ASYNC "triSYCL use synchronous kernel execution" OFF)
option(TRISYCL_DEBUG "triSCYL use debug mode" OFF)
option(TRISYCL_DEBUG_STRUCTORS "triSYCL trace of object lifetimes" OFF)
option(TRISYCL_TRACE_KERNEL "triSYCL trace of kernel execution" OFF)
mark_as_advanced(TRISYCL_OPENMP)
mark_as_advanced(TRISYCL_OPENCL)
mark_as_advanced(TRISYCL_NO_ASYNC)
mark_as_advanced(TRISYCL_DEBUG)
mark_as_advanced(TRISYCL_DEBUG_STRUCTORS)
mark_as_advanced(TRISYCL_TRACE_KERNEL)
#triSYCL definitions
set(CL_SYCL_LANGUAGE_VERSION 220 CACHE VERSION
"Host language version to be used by trisYCL (default is: 220)")
set(TRISYCL_CL_LANGUAGE_VERSION 220 CACHE VERSION
"Device language version to be used by trisYCL (default is: 220)")
#set(TRISYCL_COMPILE_OPTIONS "-std=c++1z -Wall -Wextra")
set(CMAKE_CXX_STANDARD 14)
set(CXX_STANDARD_REQUIRED ON)
# Find OpenCL package
if(TRISYCL_OPENCL)
find_package(OpenCL REQUIRED)
if(UNIX)
set(BOOST_COMPUTE_INCPATH /usr/include/compute CACHE PATH
"Path to Boost.Compute headers (default is: /usr/include/compute)")
endif(UNIX)
endif()
# Find OpenMP package
if(TRISYCL_OPENMP)
find_package(OpenMP REQUIRED)
endif()
# Find Boost
find_package(Boost 1.58 REQUIRED COMPONENTS chrono log)
# If debug or trace we need boost log
if(TRISYCL_DEBUG OR TRISYCL_DEBUG_STRUCTORS OR TRISYCL_TRACE_KERNEL)
set(LOG_NEEDED ON)
else()
set(LOG_NEEDED OFF)
endif()
find_package(Threads REQUIRED)
# Find triSYCL directory
if(NOT TRISYCL_INCLUDE_DIR)
message(FATAL_ERROR
"triSYCL include directory - Not found! (please set TRISYCL_INCLUDE_DIR")
else()
message(STATUS "triSYCL include directory - Found ${TRISYCL_INCLUDE_DIR}")
endif()
#######################
# add_sycl_to_target
#######################
#
# Sets the proper flags and includes for the target compilation.
#
# targetName : Name of the target to add a SYCL to.
# sourceFile : Source file to be compiled for SYCL.
# binaryDir : Intermediate directory to output the integration header.
#
function(add_sycl_to_target targetName sourceFile binaryDir)
# Add include directories to the "#include <>" paths
target_include_directories (${targetName} PUBLIC
${TRISYCL_INCLUDE_DIR}
${Boost_INCLUDE_DIRS}
$<$<BOOL:${TRISYCL_OPENCL}>:${OpenCL_INCLUDE_DIRS}>
$<$<BOOL:${TRISYCL_OPENCL}>:${BOOST_COMPUTE_INCPATH}>)
# Link dependencies
target_link_libraries(${targetName} PUBLIC
$<$<BOOL:${TRISYCL_OPENCL}>:${OpenCL_LIBRARIES}>
Threads::Threads
$<$<BOOL:${LOG_NEEDED}>:Boost::log>
Boost::chrono)
# Compile definitions
target_compile_definitions(${targetName} PUBLIC
$<$<BOOL:${TRISYCL_NO_ASYNC}>:TRISYCL_NO_ASYNC>
$<$<BOOL:${TRISYCL_OPENCL}>:TRISYCL_OPENCL>
$<$<BOOL:${TRISYCL_DEBUG}>:TRISYCL_DEBUG>
$<$<BOOL:${TRISYCL_DEBUG_STRUCTORS}>:TRISYCL_DEBUG_STRUCTORS>
$<$<BOOL:${TRISYCL_TRACE_KERNEL}>:TRISYCL_TRACE_KERNEL>
$<$<BOOL:${LOG_NEEDED}>:BOOST_LOG_DYN_LINK>)
# C++ and OpenMP requirements
target_compile_options(${targetName} PUBLIC
${TRISYCL_COMPILE_OPTIONS}
$<$<BOOL:${TRISYCL_OPENMP}>:${OpenMP_CXX_FLAGS}>)
if(${TRISYCL_OPENMP} AND (NOT WIN32))
# Does not support generator expressions
set_target_properties(${targetName}
PROPERTIES
LINK_FLAGS ${OpenMP_CXX_FLAGS})
endif(${TRISYCL_OPENMP} AND (NOT WIN32))
endfunction(add_sycl_to_target)

View File

@ -19,7 +19,7 @@
#undef isnan
#undef isinf
#undef isfinite
#include <SYCL/sycl.hpp>
#include <CL/sycl.hpp>
#include <iostream>
#include <map>
#include <memory>

View File

@ -195,7 +195,7 @@ typename HostExpr::Index LocalThreadSizeM, typename HostExpr::Index LocalThreadS
m_j_strides(m_j_strides_), m_right_nocontract_strides(m_right_nocontract_strides_),
left_tuple_of_accessors(left_tuple_of_accessors_), right_tuple_of_accessors(right_tuple_of_accessors_), dev(dev_){}
void operator()(cl::sycl::nd_item<1> itemID) {
void operator()(cl::sycl::nd_item<2> itemID) {
typedef typename Eigen::TensorSycl::internal::ConvertToDeviceExpression<HostExpr>::Type DevExpr;
typedef typename Eigen::TensorSycl::internal::ConvertToDeviceExpression<LHSHostExpr>::Type LHSDevExpr;
typedef typename Eigen::TensorSycl::internal::ConvertToDeviceExpression<RHSHostExpr>::Type RHSDevExpr;

View File

@ -152,33 +152,40 @@ endif()
if(EIGEN_TEST_CXX11)
if(EIGEN_TEST_SYCL)
ei_add_test_sycl(cxx11_tensor_sycl "-std=c++11")
ei_add_test_sycl(cxx11_tensor_forced_eval_sycl "-std=c++11")
ei_add_test_sycl(cxx11_tensor_broadcast_sycl "-std=c++11")
ei_add_test_sycl(cxx11_tensor_device_sycl "-std=c++11")
ei_add_test_sycl(cxx11_tensor_reduction_sycl "-std=c++11")
ei_add_test_sycl(cxx11_tensor_morphing_sycl "-std=c++11")
ei_add_test_sycl(cxx11_tensor_shuffling_sycl "-std=c++11")
ei_add_test_sycl(cxx11_tensor_padding_sycl "-std=c++11")
ei_add_test_sycl(cxx11_tensor_builtins_sycl "-std=c++11")
ei_add_test_sycl(cxx11_tensor_contract_sycl "-std=c++11")
ei_add_test_sycl(cxx11_tensor_concatenation_sycl "-std=c++11")
ei_add_test_sycl(cxx11_tensor_reverse_sycl "-std=c++11")
ei_add_test_sycl(cxx11_tensor_convolution_sycl "-std=c++11")
ei_add_test_sycl(cxx11_tensor_striding_sycl "-std=c++11")
ei_add_test_sycl(cxx11_tensor_chipping_sycl "-std=c++11")
ei_add_test_sycl(cxx11_tensor_layout_swap_sycl "-std=c++11")
ei_add_test_sycl(cxx11_tensor_inflation_sycl "-std=c++11")
ei_add_test_sycl(cxx11_tensor_generator_sycl "-std=c++11")
ei_add_test_sycl(cxx11_tensor_patch_sycl "-std=c++11")
ei_add_test_sycl(cxx11_tensor_image_patch_sycl "-std=c++11")
ei_add_test_sycl(cxx11_tensor_volume_patch_sycl "-std=c++11")
ei_add_test_sycl(cxx11_tensor_argmax_sycl "-std=c++11")
ei_add_test_sycl(cxx11_tensor_custom_op_sycl "-std=c++11")
if(EIGEN_SYCL_TRISYCL)
set(CMAKE_CXX_STANDARD 14)
set(STD_CXX_FLAG "-std=c++1z")
else(EIGEN_SYCL_TRISYCL)
# It should be safe to always run these tests as there is some fallback code for
# older compiler that don't support cxx11.
set(CMAKE_CXX_STANDARD 11)
set(STD_CXX_FLAG "-std=c++11")
endif(EIGEN_SYCL_TRISYCL)
ei_add_test_sycl(cxx11_tensor_sycl ${STD_CXX_FLAG})
ei_add_test_sycl(cxx11_tensor_forced_eval_sycl ${STD_CXX_FLAG})
ei_add_test_sycl(cxx11_tensor_broadcast_sycl ${STD_CXX_FLAG})
ei_add_test_sycl(cxx11_tensor_device_sycl ${STD_CXX_FLAG})
ei_add_test_sycl(cxx11_tensor_reduction_sycl ${STD_CXX_FLAG})
ei_add_test_sycl(cxx11_tensor_morphing_sycl ${STD_CXX_FLAG})
ei_add_test_sycl(cxx11_tensor_shuffling_sycl ${STD_CXX_FLAG})
ei_add_test_sycl(cxx11_tensor_padding_sycl ${STD_CXX_FLAG})
ei_add_test_sycl(cxx11_tensor_builtins_sycl ${STD_CXX_FLAG})
ei_add_test_sycl(cxx11_tensor_contract_sycl ${STD_CXX_FLAG})
ei_add_test_sycl(cxx11_tensor_concatenation_sycl ${STD_CXX_FLAG})
ei_add_test_sycl(cxx11_tensor_reverse_sycl ${STD_CXX_FLAG})
ei_add_test_sycl(cxx11_tensor_convolution_sycl ${STD_CXX_FLAG})
ei_add_test_sycl(cxx11_tensor_striding_sycl ${STD_CXX_FLAG})
ei_add_test_sycl(cxx11_tensor_chipping_sycl ${STD_CXX_FLAG})
ei_add_test_sycl(cxx11_tensor_layout_swap_sycl ${STD_CXX_FLAG})
ei_add_test_sycl(cxx11_tensor_inflation_sycl ${STD_CXX_FLAG})
ei_add_test_sycl(cxx11_tensor_generator_sycl ${STD_CXX_FLAG})
ei_add_test_sycl(cxx11_tensor_patch_sycl ${STD_CXX_FLAG})
ei_add_test_sycl(cxx11_tensor_image_patch_sycl ${STD_CXX_FLAG})
ei_add_test_sycl(cxx11_tensor_volume_patch_sycl ${STD_CXX_FLAG})
ei_add_test_sycl(cxx11_tensor_argmax_sycl ${STD_CXX_FLAG})
ei_add_test_sycl(cxx11_tensor_custom_op_sycl ${STD_CXX_FLAG})
endif(EIGEN_TEST_SYCL)
# It should be safe to always run these tests as there is some fallback code for
# older compiler that don't support cxx11.
set(CMAKE_CXX_STANDARD 11)
ei_add_test(cxx11_eventcount "-pthread" "${CMAKE_THREAD_LIBS_INIT}")
ei_add_test(cxx11_runqueue "-pthread" "${CMAKE_THREAD_LIBS_INIT}")