Skip to content

Commit

Permalink
Fix CMake formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
matyas-streamhpc committed Jul 29, 2024
1 parent 02a08e6 commit 78b09a2
Show file tree
Hide file tree
Showing 5 changed files with 181 additions and 173 deletions.
2 changes: 1 addition & 1 deletion Tutorials/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ file(RELATIVE_PATH folder_bin ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/${folder_bin})

if(NOT ("${GPU_RUNTIME}" STREQUAL "CUDA"))
add_subdirectory(reduction)
add_subdirectory(reduction)
endif()
23 changes: 10 additions & 13 deletions Tutorials/Reduction/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
# SOFTWARE.

if(NOT "${GPU_RUNTIME}" STREQUAL "CUDA")
message(STATUS "Reduction tutorial does not support the CUDA runtime")
return()
message(STATUS "Reduction tutorial does not support the CUDA runtime")
return()
endif()

cmake_minimum_required(VERSION 3.21)
Expand All @@ -38,23 +38,20 @@ option(REDUCTION_BUILD_EXAMPLES "Build Reduction examples" ON)

add_library(Reduction IMPORTED INTERFACE)

target_include_directories(Reduction
INTERFACE
include
)
target_include_directories(Reduction INTERFACE include)

if(REDUCTION_BUILD_TESTING)
enable_testing()
enable_language(CXX) # GTest::GTest depends on Threads::Threads
add_subdirectory(test)
enable_testing()
enable_language(CXX) # GTest::GTest depends on Threads::Threads
add_subdirectory(test)
endif()

if(REDUCTION_BUILD_BENCHMARKS)
enable_language(CXX) # benchmark::benchmark depends on Threads::Threads
add_subdirectory(benchmark)
enable_language(CXX) # benchmark::benchmark depends on Threads::Threads
add_subdirectory(benchmark)
endif()

if(REDUCTION_BUILD_EXAMPLES)
enable_language(CXX) # TBB::tbb depends on Threads::Threads
add_subdirectory(example)
enable_language(CXX) # TBB::tbb depends on Threads::Threads
add_subdirectory(example)
endif()
115 changes: 62 additions & 53 deletions Tutorials/Reduction/benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
# SOFTWARE.

if(NOT "${GPU_RUNTIME}" STREQUAL "CUDA")
message(STATUS "Reduction tutorial does not support the CUDA runtime")
return()
message(STATUS "Reduction tutorial does not support the CUDA runtime")
return()
endif()

cmake_minimum_required(VERSION 3.21)
Expand Down Expand Up @@ -70,70 +70,79 @@ endif()

# libstdc++ Parallel STL on Ubuntu 20.04 requires explicit linking to TBB
if(CMAKE_HOST_APPLE)
# TODO: The macro name used to detect TBB dependence differs on MacOS
set(STL_DEPENDS_ON_TBB ON)
# TODO: The macro name used to detect TBB dependence differs on MacOS
set(STL_DEPENDS_ON_TBB ON)
else()
include(CMakePrintHelpers)
include(CheckCXXSymbolExists)
set(CMAKE_REQUIRED_FLAGS "-std=c++17")
check_cxx_symbol_exists(
__PSTL_PAR_BACKEND_TBB "cstddef" STL_DEPENDS_ON_TBB0)
if (NOT STL_DEPENDS_ON_TBB0)
check_cxx_symbol_exists(
_PSTL_PAR_BACKEND_TBB "cstddef" STL_DEPENDS_ON_TBB1)
endif ()
include(CMakePrintHelpers)
include(CheckCXXSymbolExists)
set(CMAKE_REQUIRED_FLAGS "-std=c++17")
check_cxx_symbol_exists(
__PSTL_PAR_BACKEND_TBB
"cstddef"
STL_DEPENDS_ON_TBB0
)
if(NOT STL_DEPENDS_ON_TBB0)
check_cxx_symbol_exists(
_PSTL_PAR_BACKEND_TBB
"cstddef"
STL_DEPENDS_ON_TBB1
)
endif()
endif()
if (STL_DEPENDS_ON_TBB0 OR STL_DEPENDS_ON_TBB1)
find_package(TBB REQUIRED)
if(STL_DEPENDS_ON_TBB0 OR STL_DEPENDS_ON_TBB1)
find_package(TBB REQUIRED)
endif()

find_package(benchmark CONFIG QUIET)
if(NOT TARGET benchmark::benchmark)
message(STATUS "Google Benchmark not found. Fetching...")
option(BENCHMARK_ENABLE_TESTING "Enable testing of the benchmark library." OFF)
option(BENCHMARK_ENABLE_INSTALL "Enable installation of benchmark." OFF)
include(FetchContent)
FetchContent_Declare(
googlebench
GIT_REPOSITORY https://github.com/google/benchmark.git
GIT_TAG v1.6.1
)
FetchContent_MakeAvailable(googlebench)
if(NOT TARGET benchmark::benchmark)
add_library(benchmark::benchmark ALIAS benchmark)
endif()
message(STATUS "Google Benchmark not found. Fetching...")
option(
BENCHMARK_ENABLE_TESTING
"Enable testing of the benchmark library."
OFF
)
option(BENCHMARK_ENABLE_INSTALL "Enable installation of benchmark." OFF)
include(FetchContent)
FetchContent_Declare(
googlebench
GIT_REPOSITORY https://github.com/google/benchmark.git
GIT_TAG v1.6.1
)
FetchContent_MakeAvailable(googlebench)
if(NOT TARGET benchmark::benchmark)
add_library(benchmark::benchmark ALIAS benchmark)
endif()
else()
find_package(benchmark CONFIG REQUIRED)
find_package(benchmark CONFIG REQUIRED)
endif()

foreach(VER RANGE 0 10)
set(Sources v${VER}.hip)
set(TargetName reduction_benchmark_v${VER})
set(Sources v${VER}.hip)
set(TargetName reduction_benchmark_v${VER})

add_executable(${TargetName}
${Sources}
)
add_executable(${TargetName} ${Sources})

target_include_directories(${TargetName} PRIVATE ${include_dirs})
target_include_directories(${TargetName} PRIVATE ${include_dirs})

set_target_properties(${TargetName} PROPERTIES LINKER_LANGUAGE CXX)
set_target_properties(${TargetName} PROPERTIES LINKER_LANGUAGE CXX)

target_link_libraries(${TargetName}
PRIVATE
Reduction
benchmark::benchmark
$<$<TARGET_EXISTS:TBB::tbb>:TBB::tbb>
)

if(ROCM_EXAMPLES_HIP_PLATFORM STREQUAL "nvidia")
set_source_files_properties(${Sources}
PROPERTIES
LANGUAGE ${GPU_RUNTIME}
)
find_package(HIP MODULE REQUIRED)
target_include_directories(${TargetName}
PRIVATE
"${HIP_ROOT_DIR}/include"
target_link_libraries(
${TargetName}
PRIVATE
Reduction
benchmark::benchmark
$<$<TARGET_EXISTS:TBB::tbb>:TBB::tbb>
)
endif()

if(ROCM_EXAMPLES_HIP_PLATFORM STREQUAL "nvidia")
set_source_files_properties(
${Sources}
PROPERTIES LANGUAGE ${GPU_RUNTIME}
)
find_package(HIP MODULE REQUIRED)
target_include_directories(
${TargetName}
PRIVATE "${HIP_ROOT_DIR}/include"
)
endif()
endforeach()
74 changes: 38 additions & 36 deletions Tutorials/Reduction/example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
# SOFTWARE.

if(NOT "${GPU_RUNTIME}" STREQUAL "CUDA")
message(STATUS "Reduction tutorial does not support the CUDA runtime")
return()
message(STATUS "Reduction tutorial does not support the CUDA runtime")
return()
endif()

cmake_minimum_required(VERSION 3.21)
Expand Down Expand Up @@ -70,50 +70,52 @@ endif()

# libstdc++ Parallel STL on Ubuntu 20.04 requires explicit linking to TBB
if(CMAKE_HOST_APPLE)
# TODO: The macro name used to detect TBB dependence differs on MacOS
set(STL_DEPENDS_ON_TBB ON)
# TODO: The macro name used to detect TBB dependence differs on MacOS
set(STL_DEPENDS_ON_TBB ON)
else()
include(CMakePrintHelpers)
include(CheckCXXSymbolExists)
set(CMAKE_REQUIRED_FLAGS "-std=c++17")
check_cxx_symbol_exists(
__PSTL_PAR_BACKEND_TBB "cstddef" STL_DEPENDS_ON_TBB0)
if (NOT STL_DEPENDS_ON_TBB0)
check_cxx_symbol_exists(
_PSTL_PAR_BACKEND_TBB "cstddef" STL_DEPENDS_ON_TBB1)
endif ()
include(CMakePrintHelpers)
include(CheckCXXSymbolExists)
set(CMAKE_REQUIRED_FLAGS "-std=c++17")
check_cxx_symbol_exists(
__PSTL_PAR_BACKEND_TBB
"cstddef"
STL_DEPENDS_ON_TBB0
)
if(NOT STL_DEPENDS_ON_TBB0)
check_cxx_symbol_exists(
_PSTL_PAR_BACKEND_TBB
"cstddef"
STL_DEPENDS_ON_TBB1
)
endif()
endif()
if (STL_DEPENDS_ON_TBB0 OR STL_DEPENDS_ON_TBB1)
find_package(TBB REQUIRED)
if(STL_DEPENDS_ON_TBB0 OR STL_DEPENDS_ON_TBB1)
find_package(TBB REQUIRED)
endif()

foreach(VER RANGE 1 9)
set(Sources v${VER}.hip)
set(TargetName reduction_example_v${VER})

add_executable(${TargetName}
${Sources}
)
set(Sources v${VER}.hip)
set(TargetName reduction_example_v${VER})

target_include_directories(${TargetName} PRIVATE ${include_dirs})
add_executable(${TargetName} ${Sources})

set_target_properties(${TargetName} PROPERTIES LINKER_LANGUAGE CXX)
target_include_directories(${TargetName} PRIVATE ${include_dirs})

if(ROCM_EXAMPLES_HIP_PLATFORM STREQUAL "nvidia")
set_target_properties(${TargetName} PROPERTIES CUDA_STANDARD 20)
endif()
set_target_properties(${TargetName} PROPERTIES LINKER_LANGUAGE CXX)

target_link_libraries(${TargetName}
PRIVATE
Reduction
$<$<TARGET_EXISTS:TBB::tbb>:TBB::tbb>
)
if(ROCM_EXAMPLES_HIP_PLATFORM STREQUAL "nvidia")
set_target_properties(${TargetName} PROPERTIES CUDA_STANDARD 20)
endif()

set_source_files_properties(${Sources}
PROPERTIES
LANGUAGE ${ROCM_EXAMPLES_GPU_LANGUAGE}
)
target_link_libraries(
${TargetName}
PRIVATE Reduction $<$<TARGET_EXISTS:TBB::tbb>:TBB::tbb>
)

install(TARGETS ${TargetName})
set_source_files_properties(
${Sources}
PROPERTIES LANGUAGE ${ROCM_EXAMPLES_GPU_LANGUAGE}
)

install(TARGETS ${TargetName})
endforeach()
Loading

0 comments on commit 78b09a2

Please sign in to comment.