Skip to content

Commit

Permalink
[Build] use different flags for NVCC and CC (dmlc#2342)
Browse files Browse the repository at this point in the history
  • Loading branch information
jermainewang authored Nov 14, 2020
1 parent cb2bc69 commit 77968e3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,11 @@ if(MSVC)
endif()
else(MSVC)
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-std=c++14" SUPPORT_CXX14)
check_cxx_compiler_flag("-std=c++11" SUPPORT_CXX11)
set(CMAKE_C_FLAGS "-O2 -Wall -fPIC ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "-O2 -Wall -fPIC -std=c++14 ${CMAKE_CXX_FLAGS}")
# We still use c++11 flag in CPU build because gcc5.4 (our default compiler) is
# not fully compatible with c++14 feature.
set(CMAKE_CXX_FLAGS "-O2 -Wall -fPIC -std=c++11 ${CMAKE_CXX_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--warn-common ${CMAKE_SHARED_LINKER_FLAGS}")
endif(MSVC)

Expand Down
34 changes: 23 additions & 11 deletions cmake/modules/CUDA.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -239,18 +239,30 @@ macro(dgl_config_cuda out_variable)
src/geometry/cuda/*.cu
)

# NVCC flags
# Manually set everything
set(CUDA_PROPAGATE_HOST_FLAGS OFF)

# 0. Add host flags
message(STATUS "${CMAKE_CXX_FLAGS}")
string(REGEX REPLACE "[ \t\n\r]" "," CXX_HOST_FLAGS "${CMAKE_CXX_FLAGS}")
list(APPEND CUDA_NVCC_FLAGS "-Xcompiler ,${CXX_HOST_FLAGS}")

# 1. Add arch flags
dgl_select_nvcc_arch_flags(NVCC_FLAGS_ARCH)
string(REPLACE ";" " " NVCC_FLAGS_ARCH "${NVCC_FLAGS_ARCH}")
set(NVCC_FLAGS_EXTRA ${NVCC_FLAGS_ARCH})
# for lambda support in moderngpu
set(NVCC_FLAGS_EXTRA "${NVCC_FLAGS_EXTRA} --expt-extended-lambda")
# suppress deprecated warning in moderngpu
set(NVCC_FLAGS_EXTRA "${NVCC_FLAGS_EXTRA} -Wno-deprecated-declarations")
# for compile with c++14
set(NVCC_FLAGS_EXTRA "${NVCC_FLAGS_EXTRA} --expt-extended-lambda --std=c++14")
message(STATUS "NVCC extra flags: ${NVCC_FLAGS_EXTRA}")
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} ${NVCC_FLAGS_EXTRA}")
list(APPEND CMAKE_CUDA_FLAGS "${NVCC_FLAGS_EXTRA}")
list(APPEND CUDA_NVCC_FLAGS ${NVCC_FLAGS_ARCH})

# 2. flags in third_party/moderngpu
list(APPEND CUDA_NVCC_FLAGS "--expt-extended-lambda;-Wno-deprecated-declarations")


# 3. CUDA 11 requires c++14 by default
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-std=c++14" SUPPORT_CXX14)
string(REPLACE "-std=c++11" "" CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS}")
list(APPEND CUDA_NVCC_FLAGS "--std=c++14")

message(STATUS "CUDA flags: ${CUDA_NVCC_FLAGS}")

list(APPEND DGL_LINKER_LIBS
${CUDA_CUDART_LIBRARY}
Expand Down

0 comments on commit 77968e3

Please sign in to comment.