Skip to content

Commit

Permalink
Modernize CMake
Browse files Browse the repository at this point in the history
CI_FILTER: ^linux_nvcc.*Debug$
  • Loading branch information
j-stephan committed Jul 31, 2023
1 parent 002dfe2 commit fccd234
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 182 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ env:
alpaka_ACC_GPU_HIP_ENABLE: OFF
alpaka_ACC_GPU_HIP_ONLY_MODE: OFF
alpaka_USE_MDSPAN: OFF
alpaka_ENABLE_WERROR: ON
CMAKE_INSTALL_PREFIX: ${{ github.workspace }}/_install

jobs:
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ option(alpaka_BUILD_EXAMPLES "Build the examples" OFF)

# Enable the test infrastructure only if alpaka is the top-level project
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
option(alpaka_ENABLE_WERROR "Treat all warnings as errors." OFF)
option(BUILD_TESTING "Build the testing tree." OFF)
include(CTest)
endif()
Expand Down
21 changes: 15 additions & 6 deletions cmake/alpakaCommon.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,16 @@ else()
target_link_libraries(alpaka INTERFACE ${RT_LIBRARY})
endif()
endif()

# Add debug optimization levels. CMake doesn't do this by default.
# Note that -Og is the recommended gcc optimization level for debug mode but is equivalent to -O1 for clang (and its derivates).
alpaka_set_compiler_options(HOST_DEVICE target alpaka $<$<AND:$<CONFIG:Debug>,$<CXX_COMPILER_ID:GNU>,$<COMPILE_LANGUAGE:CXX>>:-Og>
$<$<AND:$<CONFIG:Debug>,$<CXX_COMPILER_ID:GNU>,$<COMPILE_LANGUAGE:CUDA>>:-Xcompiler -Og>
$<$<AND:$<CONFIG:Debug>,$<CXX_COMPILER_ID:Clang,AppleClang,IntelLLVM>>:-O0>
$<$<AND:$<CONFIG:Debug>,$<CXX_COMPILER_ID:MSVC>>:/Od>)

target_link_options(alpaka INTERFACE $<$<AND:$<CONFIG:Debug>,$<CXX_COMPILER_ID:GNU>>:-Og>
$<$<AND:$<CONFIG:Debug>,$<CXX_COMPILER_ID:Clang,AppleClang,IntelLLVM>>:-O0>)
endif()

#-------------------------------------------------------------------------------
Expand Down Expand Up @@ -339,7 +349,7 @@ if(alpaka_ACC_GPU_CUDA_ENABLE)
if(CMAKE_CUDA_COMPILER)
if(NOT CMAKE_CUDA_COMPILER_ID STREQUAL "Clang")
# Use user selected CMake CXX compiler or CMAKE_CUDA_HOST_COMPILER as cuda host compiler to avoid fallback to the default system CXX host compiler.
# CMAKE_CUDA_HOST_COMPILER is reset by check_language(CUDA) therefore definition passed by the user via -DCMAKE_CUDA_HOST_COMPILER are
# CMAKE_CUDA_HOST_COMPILER is reset by check_language(CUDA) therefore definitions passed by the user via -DCMAKE_CUDA_HOST_COMPILER are
# ignored by CMake (looks like a CMake bug).
if(_alpaka_CUDA_HOST_COMPILER)
set(CMAKE_CUDA_HOST_COMPILER ${_alpaka_CUDA_HOST_COMPILER})
Expand Down Expand Up @@ -412,13 +422,12 @@ if(alpaka_ACC_GPU_CUDA_ENABLE)
if(alpaka_CUDA_EXPT_EXTENDED_LAMBDA STREQUAL ON)
alpaka_set_compiler_options(DEVICE target alpaka $<$<COMPILE_LANGUAGE:CUDA>:--extended-lambda>)
endif()
# This is mandatory because with c++17 many standard library functions we rely on are constexpr (std::min, std::multiplies, ...)
# This is mandatory because with C++17 many standard library functions we rely on are constexpr (std::min, std::multiplies, ...)
alpaka_set_compiler_options(DEVICE target alpaka $<$<COMPILE_LANGUAGE:CUDA>:--expt-relaxed-constexpr>)

if((CMAKE_BUILD_TYPE STREQUAL "Debug") OR (CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo"))
alpaka_set_compiler_options(DEVICE target alpaka $<$<COMPILE_LANGUAGE:CUDA>:-g>)
alpaka_set_compiler_options(DEVICE target alpaka $<$<COMPILE_LANGUAGE:CUDA>:-lineinfo>)
endif()
# CMake automatically sets '-g' in debug mode
alpaka_set_compiler_options(DEVICE target alpaka $<$<AND:$<CONFIG:Debug>,$<COMPILE_LANGUAGE:CUDA>>:-G> # -G overrides -lineinfo
$<$<AND:$<CONFIG:RelWithDebInfo>,$<COMPILE_LANGUAGE:CUDA>>:-g -lineinfo>)

if(alpaka_FAST_MATH STREQUAL ON)
alpaka_set_compiler_options(DEVICE target alpaka $<$<COMPILE_LANGUAGE:CUDA>:--use_fast_math>)
Expand Down
4 changes: 4 additions & 0 deletions script/docker_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -179,5 +179,9 @@ if [ ! -z "${alpaka_USE_MDSPAN+x}" ]
then
ALPAKA_DOCKER_ENV_LIST+=("--env" "alpaka_USE_MDSPAN=${alpaka_USE_MDSPAN}")
fi
if [ ! -z "${alpaka_ENABLE_WERROR+x}" ]
then
ALPAKA_DOCKER_ENV_LIST+=("--env" "alpaka_ENABLE_WERROR=${alpaka_ENABLE_WERROR}")
fi

docker_retry docker run -v "$(pwd)":"$(pwd)" -w "$(pwd)" "${ALPAKA_DOCKER_ENV_LIST[@]}" "${ALPAKA_CI_DOCKER_BASE_IMAGE_NAME}" /bin/bash -c "source ./script/install.sh && ./script/run.sh"
4 changes: 3 additions & 1 deletion script/job_generator/generate_job_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ def job_variables(job: Dict[str, Tuple[str, str]]) -> Dict[str, str]:
variables["ALPAKA_CI_CUDA_DIR"] = "$HOME/cuda"
# hip install path, if hip version is not already installed
variables["ALPAKA_CI_HIP_ROOT_DIR"] = "$HOME/hip"
# Alway enable -Werror in the CI
variables["alpaka_ENABLE_WERROR"] = "ON"

################################################################################################
### job dependent environment variables
Expand Down Expand Up @@ -288,7 +290,6 @@ def global_variables() -> Dict[str, str]:
variables["ALPAKA_CI_OS_NAME"] = "Linux"
variables[ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLE] = "ON"
variables[ALPAKA_ACC_CPU_B_SEQ_T_THREADS_ENABLE] = "ON"
variables[ALPAKA_ACC_CPU_B_SEQ_T_FIBERS_ENABLE] = "OFF"
variables[ALPAKA_ACC_CPU_B_TBB_T_SEQ_ENABLE] = "OFF"
variables[ALPAKA_ACC_CPU_B_OMP2_T_SEQ_ENABLE] = "ON"
variables[ALPAKA_ACC_CPU_B_SEQ_T_OMP2_ENABLE] = "ON"
Expand All @@ -310,6 +311,7 @@ def global_variables() -> Dict[str, str]:
variables["ALPAKA_CI_BOOST_LIB_DIR"] = "$HOME/boost_libs"
variables["ALPAKA_CI_CUDA_DIR"] = "$HOME/cuda"
variables["ALPAKA_CI_HIP_ROOT_DIR"] = "$HOME/hip"
variables["alpaka_ENABLE_WERROR"] ="ON"

return variables

Expand Down
8 changes: 3 additions & 5 deletions test/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@ if(MSVC)
target_compile_options(${_COMMON_TARGET_NAME} INTERFACE $<$<COMPILE_LANGUAGE:CXX>:/bigobj> $<$<COMPILE_LANGUAGE:CUDA>:-Xcompiler=/bigobj>)
endif()

if(alpaka_ACC_GPU_CUDA_ENABLE OR (alpaka_ACC_GPU_HIP_ENABLE AND HIP_PLATFORM MATCHES "nvcc"))
if(alpaka_ACC_GPU_CUDA_ENABLE)
# CUDA driver API is used by EventHostManualTrigger
target_link_libraries(${_COMMON_TARGET_NAME} INTERFACE CUDA::cuda_driver)
target_compile_definitions(${_COMMON_TARGET_NAME} INTERFACE "CUDA_API_PER_THREAD_DEFAULT_STREAM")
endif()
if(alpaka_ACC_GPU_CUDA_ENABLE AND CMAKE_CUDA_COMPILER_ID STREQUAL "Clang")
# nvcc supports werror starting with 10.2
if(CUDA_VERSION GREATER_EQUAL 10.2)
message(STATUS "adding -Werror=all-warnings")
if(alpaka_ACC_GPU_CUDA_ENABLE AND CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA")
if(alpaka_ENABLE_WERROR)
target_compile_options(${_COMMON_TARGET_NAME} INTERFACE $<$<COMPILE_LANGUAGE:CUDA>:-Werror=all-warnings>)
endif()
endif()
Expand Down
Loading

0 comments on commit fccd234

Please sign in to comment.