Skip to content
This repository was archived by the owner on Aug 11, 2023. It is now read-only.
24 changes: 12 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
cmake_minimum_required(VERSION 3.4.3)
cmake_minimum_required(VERSION 3.10.2)
project(ComputeCpp-SDK)

option(COMPUTECPP_SDK_USE_OPENMP "Enable OpenMP support in samples" OFF)
option(COMPUTECPP_SDK_BUILD_TESTS "Build the tests for the header utilities in include/" OFF)
option(COMPUTECPP_SDK_BUILD_DEMOS "Build the SDK demos" OFF)

if (COMPUTECPP_SDK_BUILD_DEMOS)
if(COMPUTECPP_SDK_BUILD_DEMOS AND
CMAKE_VERSION VERSION_GREATER_EQUAL 3.15)
# Policy required to enable MSVC_RUNTIME_LIBRARY property
# This needs to be set before the first project for the policy
# to have an effect. This is only needed when building the demos
# This is only needed when building the demos.
cmake_policy(SET CMP0091 NEW)
endif()

project(ComputeCpp-SDK)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules)
list(APPEND COMPUTECPP_USER_FLAGS "-no-serial-memop")
find_package(ComputeCpp REQUIRED)

option(COMPUTECPP_SDK_USE_OPENMP "Enable OpenMP support in samples" OFF)
option(COMPUTECPP_SDK_BUILD_TESTS "Build the tests for the header utilities in include/" OFF)
option(COMPUTECPP_SDK_BUILD_DEMOS "Build the SDK demos" OFF)

set(CMAKE_CXX_STANDARD 14)
enable_testing()

add_subdirectory(samples)

if(COMPUTECPP_SDK_BUILD_TESTS)
add_subdirectory(tests)
endif()

if (COMPUTECPP_SDK_BUILD_DEMOS)
if(COMPUTECPP_SDK_BUILD_DEMOS)
add_subdirectory(demos)
endif()
34 changes: 14 additions & 20 deletions cmake/Modules/FindComputeCpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# Latest version of this file can be found at:
# https://github.com/codeplaysoftware/computecpp-sdk

cmake_minimum_required(VERSION 3.4.3)
cmake_minimum_required(VERSION 3.10.2)
include(FindPackageHandleStandardArgs)

# These should match the types of IR output by compute++
Expand Down Expand Up @@ -63,10 +63,14 @@ set(COMPUTECPP_USER_FLAGS "" CACHE STRING "User flags for compute++")
separate_arguments(COMPUTECPP_USER_FLAGS)
mark_as_advanced(COMPUTECPP_USER_FLAGS)

set(COMPUTECPP_BITCODE "" CACHE STRING
"Bitcode types to use as SYCL targets in compute++.")
set(COMPUTECPP_BITCODE "" CACHE STRING "")
mark_as_advanced(COMPUTECPP_BITCODE)

if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.20)
# Policy enabling rewrites of paths in depfiles when using ninja
cmake_policy(SET CMP0116 NEW)
endif()

set(SYCL_LANGUAGE_VERSION "2017" CACHE STRING "SYCL version to use. Defaults to 1.2.1.")

find_package(OpenCL REQUIRED)
Expand Down Expand Up @@ -343,24 +347,13 @@ function(__build_ir)
set(include_directories "$<TARGET_PROPERTY:${ARG_TARGET},INCLUDE_DIRECTORIES>")
set(compile_definitions "$<TARGET_PROPERTY:${ARG_TARGET},COMPILE_DEFINITIONS>")
set(generated_include_directories
$<$<BOOL:${include_directories}>:-I\"$<JOIN:${include_directories},\"\t-I\">\">)
$<$<BOOL:${include_directories}>:-I$<JOIN:${include_directories},;-I>>)
set(generated_compile_definitions
$<$<BOOL:${compile_definitions}>:-D$<JOIN:${compile_definitions},\t-D>>)
$<$<BOOL:${compile_definitions}>:-D$<JOIN:${compile_definitions},;-D>>)

# Obtain language standard of the file
set(device_compiler_cxx_standard)
get_target_property(targetCxxStandard ${ARG_TARGET} 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 applications cannot be compiled using C++98")
else ()
set(device_compiler_cxx_standard "")
endif()
set(device_compiler_cxx_standard
"-std=c++$<TARGET_PROPERTY:${ARG_TARGET},CXX_STANDARD>")

get_property(source_compile_flags
SOURCE ${ARG_SOURCE}
Expand Down Expand Up @@ -401,12 +394,13 @@ function(__build_ir)
OUTPUT ${outputDeviceFile} ${outputSyclFile}
COMMAND ${ComputeCpp_DEVICE_COMPILER_EXECUTABLE}
${COMPUTECPP_DEVICE_COMPILER_FLAGS}
${generated_include_directories}
${generated_compile_definitions}
"${generated_include_directories}"
"${generated_compile_definitions}"
-sycl-ih ${outputSyclFile}
-o ${outputDeviceFile}
-c ${ARG_SOURCE}
${generate_depfile}
COMMAND_EXPAND_LISTS
DEPENDS ${ir_dependencies}
IMPLICIT_DEPENDS CXX ${ARG_SOURCE}
${enable_depfile}
Expand Down
11 changes: 3 additions & 8 deletions samples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
cmake_minimum_required(VERSION 3.10.2)
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
Expand All @@ -16,6 +17,7 @@ function(add_sample)
${ARGN}
)
add_executable(${ARG_TARGET} ${ARG_SOURCES})
set_property(TARGET ${ARG_TARGET} PROPERTY CXX_STANDARD 14)
add_sycl_to_target(TARGET ${ARG_TARGET}
SOURCES ${ARG_SOURCES})
if(NOT ARG_NO_TEST)
Expand All @@ -37,14 +39,7 @@ add_sample(TARGET images SOURCES images.cpp)
add_sample(TARGET matrix-multiply SOURCES matrix-multiply.cpp NO_TEST)
if(COMPUTECPP_SDK_USE_OPENMP)
find_package(OpenMP REQUIRED)
if(TARGET OpenMP::OpenMP_CXX)
target_link_libraries(matrix-multiply PRIVATE OpenMP::OpenMP_CXX)
else()
# Workaround for CMake <3.9 - FindOpenMP does not provide the
# linker flags and no imported target
target_compile_options(matrix-multiply PRIVATE ${OpenMP_CXX_FLAGS})
target_link_libraries( matrix-multiply PRIVATE ${OpenMP_CXX_FLAGS})
endif()
target_link_libraries(matrix-multiply PRIVATE OpenMP::OpenMP_CXX)
add_test(NAME matrix-multiply_omp COMMAND matrix-multiply 64 omp)
endif()
add_test(NAME matrix-multiply_sycl COMMAND matrix-multiply 64 sycl)
Expand Down