Skip to content
This repository was archived by the owner on Jan 26, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ include_directories("include")

add_subdirectory (src)
add_subdirectory (examples)
add_subdirectory (tests)

if (NOT WIN32)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment explaining why tests are disabled on windows

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment explaining why tests are disabled on windows

I'm partial to changing this from a Windows thing to all systems. If you don't have the tests pre-installed on any system, then you can't actually run them.

Comment still valid, just needs to be broadened.

add_subdirectory (tests)
endif()

if (PARALLEL_STL_BENCHMARKS)
add_subdirectory (benchmarks)
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ foreach(file ${EXAMPLE_FILES})

target_link_libraries(${SOURCE_NAME} PUBLIC ${CMAKE_THREAD_LIBS_INIT})

add_sycl_to_target(${SOURCE_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/${SOURCE_NAME}.cpp
${CMAKE_CURRENT_BINARY_DIR})
add_sycl_to_target(${SOURCE_NAME} ${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/${SOURCE_NAME}.cpp)


endforeach()
173 changes: 137 additions & 36 deletions cmake/Modules/FindComputeCpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
# limitations under the License.

#########################
# FindComputeCpp.cmake
# FindComputeCpp.cmake
#########################
#
# Tools for finding and building with ComputeCpp.
#
# User must define COMPUTECPP_PACKAGE_ROOT_DIR pointing to the ComputeCpp
# User must define COMPUTECPP_PACKAGE_ROOT_DIR pointing to the ComputeCpp
# installation.
#
#
# Latest version of this file can be found at:
# https://github.com/codeplaysoftware/computecpp-sdk

Expand All @@ -38,11 +38,6 @@ if(CMAKE_COMPILER_IS_GNUCXX)
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()
Expand All @@ -54,27 +49,36 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
else()
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)

option(COMPUTECPP_DISABLE_GCC_DUAL_ABI "Compile with pre-5.1 ABI" OFF)
mark_as_advanced(COMPUTECPP_DISABLE_GCC_DUAL_ABI)

set(COMPUTECPP_USER_FLAGS "" CACHE STRING "User flags for compute++")
mark_as_advanced(COMPUTECPP_USER_FLAGS)

# Platform-specific arguments
if(MSVC)
# Workaround to an unfixed Clang bug, rationale:
# https://github.com/codeplaysoftware/computecpp-sdk/pull/51#discussion_r139399093
set (COMPUTECPP_PLATFORM_SPECIFIC_ARGS "-fno-ms-compatibility")
endif()

# Find OpenCL package
find_package(OpenCL REQUIRED)

# Find ComputeCpp packagee
# Find ComputeCpp package
if(NOT COMPUTECPP_PACKAGE_ROOT_DIR)
message(FATAL_ERROR
"ComputeCpp package - Not found! (please set COMPUTECPP_PACKAGE_ROOT_DIR")
"ComputeCpp package - Not found! (please set COMPUTECPP_PACKAGE_ROOT_DIR)")
else()
message(STATUS "ComputeCpp package - Found")
endif()
option(COMPUTECPP_PACKAGE_ROOT_DIR "Path to the ComputeCpp Package")

# Obtain the path to compute++
find_program(COMPUTECPP_DEVICE_COMPILER compute++ PATHS
Expand All @@ -97,15 +101,37 @@ else()
endif()

# Obtain the path to the ComputeCpp runtime library
find_library(COMPUTECPP_RUNTIME_LIBRARY ComputeCpp PATHS ${COMPUTECPP_PACKAGE_ROOT_DIR}
find_library(COMPUTECPP_RUNTIME_LIBRARY
NAMES ComputeCpp ComputeCpp_vs2015
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!")
message(FATAL_ERROR "ComputeCpp Runtime Library - Not found!")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to know what is the file name as well

endif()

find_library(COMPUTECPP_RUNTIME_LIBRARY_DEBUG
NAMES ComputeCpp ComputeCpp_vs2015_d
PATHS ${COMPUTECPP_PACKAGE_ROOT_DIR}
HINTS ${COMPUTECPP_PACKAGE_ROOT_DIR}/lib PATH_SUFFIXES lib
DOC "ComputeCpp Debug Runtime Library" NO_DEFAULT_PATH)

if (EXISTS ${COMPUTECPP_RUNTIME_LIBRARY_DEBUG})
mark_as_advanced(COMPUTECPP_RUNTIME_LIBRARY_DEBUG)
else()
message(FATAL_ERROR "ComputeCpp Debug Runtime Library - Not found!")
endif()

# NOTE: Having two sets of libraries is Windows specific, not MSVC specific.
# Compiling with Clang on Windows would still require linking to both of them.
if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
message(STATUS "ComputeCpp runtime (Release): ${COMPUTECPP_RUNTIME_LIBRARY} - Found")
message(STATUS "ComputeCpp runtime (Debug) : ${COMPUTECPP_RUNTIME_LIBRARY_DEBUG} - Found")
else()
message(STATUS "ComputeCpp runtime: ${COMPUTECPP_RUNTIME_LIBRARY} - Found")
endif()

# Obtain the ComputeCpp include directory
Expand Down Expand Up @@ -153,8 +179,21 @@ else()
endif()
endif()

# This property allows targets to specify that their sources should be
# compiled with the integration header included after the user's
# sources, not before (e.g. when an enum is used in a kernel name, this
# is not technically valid SYCL code but can work with ComputeCpp)
define_property(
TARGET PROPERTY COMPUTECPP_INCLUDE_AFTER
BRIEF_DOCS "Include integration header after user source"
FULL_DOCS "Changes compiler arguments such that the source file is
actually the integration header, and the .cpp file is included on
the command line so that it is seen by the compiler first. Enables
non-standards-conformant SYCL code to compile with ComputeCpp."
)

####################
# __build_sycl
# __build_sycl
####################
#
# Adds a custom target for running compute++ and adding a dependency for the
Expand All @@ -163,29 +202,55 @@ endif()
# targetName : Name of the target.
# sourceFile : Source file to be compiled.
# binaryDir : Intermediate directory to output the integration header.
# fileCounter : Counter included in name of custom target. Different counter
# values prevent duplicated names of custom target when source files with the same name,
# but located in different directories, are used for the same target.
#
function(__build_spir targetName sourceFile binaryDir)
function(__build_spir targetName sourceFile binaryDir fileCounter)

# 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
set(device_compiler_includes "")
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()
get_target_property(targetIncludeDirectories ${targetName} INCLUDE_DIRECTORIES)
foreach(directory ${targetIncludeDirectories})
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()

# Obtain language standard of the file
set(device_compiler_cxx_standard)
get_target_property(targetCxxStandard ${targetName} CXX_STANDARD)
if (targetCxxStandard MATCHES 17)
set(device_compiler_cxx_standard "-std=c++1z")
elseif (targetCxxStandard MATCHES 14)
set(device_compiler_cxx_standard "-std=c++14")
elseif (targetCxxStandard MATCHES 11)
set(device_compiler_cxx_standard "-std=c++11")
elseif (targetCxxStandard MATCHES 98)
message(FATAL_ERROR "SYCL implementations cannot be compiled using C++98")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SYCL implementations -> SYCL applications

else ()
set(device_compiler_cxx_standard "")
endif()

set(COMPUTECPP_DEVICE_COMPILER_FLAGS
${device_compiler_cxx_standard}
${COMPUTECPP_DEVICE_COMPILER_FLAGS}
${COMPUTECPP_USER_FLAGS})
# Convert argument list format
separate_arguments(COMPUTECPP_DEVICE_COMPILER_FLAGS)

Expand All @@ -200,22 +265,48 @@ function(__build_spir targetName sourceFile binaryDir)
-o ${outputSyclFile}
-c ${sourceFile}
DEPENDS ${sourceFile}
IMPLICIT_DEPENDS CXX ${sourceFile}
WORKING_DIRECTORY ${binaryDir}
COMMENT "Building ComputeCpp integration header file ${outputSyclFile}")
COMMENT "Building ComputeCpp integration header file ${outputSyclFile}")

# Name:
# (user-defined name)_(source file)_(counter)_ih
set(headerTargetName
${targetName}_${sourceFileName}_${fileCounter}_ih)

# Add a custom target for the generated integration header
add_custom_target(${targetName}_integration_header DEPENDS ${outputSyclFile})
add_custom_target(${headerTargetName} DEPENDS ${outputSyclFile})

# Add a dependency on the integration header
add_dependencies(${targetName} ${targetName}_integration_header)
add_dependencies(${targetName} ${headerTargetName})

# Force inclusion of the integration header for the host compiler
set(compileFlags -include ${outputSyclFile} "-Wall")
target_compile_options(${targetName} PUBLIC ${compileFlags})
if(MSVC)
# NOTE: The Visual Studio generators parse compile flags differently,
# hence the different argument syntax
if(CMAKE_GENERATOR MATCHES "Visual Studio")
set(forceIncludeFlags "/FI\"${outputSyclFile}\"")
else()
set(forceIncludeFlags /FI ${outputSyclFile})
endif()
else()
# This property can be set on a per-target basis to indicate that the
# integration header should appear after the main source listing
get_property(includeAfter TARGET ${targetName}
PROPERTY COMPUTECPP_INCLUDE_AFTER)
if(includeAfter)
# Change the source file to the integration header - i.e.
# g++ -c source_file_name.cpp.sycl
set_property(TARGET ${targetName} PROPERTY SOURCES ${outputSyclFile})
# CMake/gcc don't know what language a .sycl file is, so tell them
set_property(SOURCE ${outputSyclFile} PROPERTY LANGUAGE CXX)
set(forceIncludeFlags -include ${sourceFile} -x c++)
else()
set(forceIncludeFlags -include ${outputSyclFile})
endif()
endif()
target_compile_options(${targetName} PUBLIC ${forceIncludeFlags})

# 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
Expand All @@ -232,17 +323,27 @@ endfunction()
# target and sets a dependancy on that new command.
#
# 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.
# sourceFiles : Source files to be compiled for SYCL.
#
function(add_sycl_to_target targetName sourceFile binaryDir)
function(add_sycl_to_target targetName binaryDir sourceFiles)

set(sourceFiles ${sourceFiles} ${ARGN})
set(fileCounter 0)
target_include_directories(
${targetName} SYSTEM
PRIVATE ${OpenCL_INCLUDE_DIR}
PRIVATE ${COMPUTECPP_INCLUDE_DIRECTORY}
)
# Add custom target to run compute++ and generate the integration header
__build_spir(${targetName} ${sourceFile} ${binaryDir})
foreach(sourceFile ${sourceFiles})
__build_spir(${targetName} ${sourceFile} ${binaryDir} ${fileCounter})
MATH(EXPR fileCounter "${fileCounter} + 1")
endforeach()

# Link with the ComputeCpp runtime library
target_link_libraries(${targetName} PUBLIC ${COMPUTECPP_RUNTIME_LIBRARY}
PUBLIC ${OpenCL_LIBRARIES})

endfunction(add_sycl_to_target)
target_link_libraries(${targetName} PUBLIC $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:${COMPUTECPP_RUNTIME_LIBRARY_DEBUG}>
$<$<NOT:$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>>:${COMPUTECPP_RUNTIME_LIBRARY}>
${OpenCL_LIBRARIES})

endfunction(add_sycl_to_target)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this different from the module in the computecpp-sdk? If so we can possible update the sdk one?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually copied from the SDK to here!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good then :-)

4 changes: 2 additions & 2 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ foreach(file ${BENCHMARK_FILES})
target_compile_options(${SOURCE_NAME} PUBLIC ${HOST_COMPILER_OPTIONS})
target_link_libraries(${SOURCE_NAME} PUBLIC ${CMAKE_THREAD_LIBS_INIT})

add_sycl_to_target(${SOURCE_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/${SOURCE_NAME}.cpp
${CMAKE_CURRENT_BINARY_DIR})
add_sycl_to_target(${SOURCE_NAME} ${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/${SOURCE_NAME}.cpp)

endforeach()
4 changes: 2 additions & 2 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ if (EXISTS ${GMOCK_LIB_PATH})
target_link_libraries(${TEST_NAME} PUBLIC ${CMAKE_THREAD_LIBS_INIT})

add_sycl_to_target(${TEST_NAME}
${CMAKE_CURRENT_SOURCE_DIR}/${SOURCE_NAME}.cpp
${CMAKE_CURRENT_BINARY_DIR})
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/${SOURCE_NAME}.cpp)

add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME})
endforeach()
Expand Down