From 65f1fb0e1dab8d7f5dde72c6c558f2e20a79380a Mon Sep 17 00:00:00 2001 From: Szilard Pall Date: Tue, 18 Jun 2013 00:48:30 +0200 Subject: [PATCH] added CUDA compiler flags to version header The nvcc compiler information, compared to CPU compiler info, was lacking both the full path to the compiler binary as well as the full list of flags used (including the host-compiler flags if these are passed). Change-Id: Ic80a512bc6d5a39b6594c360d2952e48b5d43ee0 --- CMakeLists.txt | 4 +++ cmake/gmxManageGPU.cmake | 40 +++++++++++++++++++++++++-- cmake/gmxManageNvccConfig.cmake | 30 -------------------- src/buildinfo.h.cmakein | 2 ++ src/gmxlib/cuda_tools/copyrite_gpu.cu | 1 + 5 files changed, 44 insertions(+), 33 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8dabe69bb3..c87ad3b23f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1175,6 +1175,10 @@ get_compiler_info(C BUILD_C_COMPILER BUILD_CFLAGS) if (CMAKE_CXX_COMPILER_LOADED) get_compiler_info(CXX BUILD_CXX_COMPILER BUILD_CXXFLAGS) endif () +if(GMX_GPU) + get_cuda_compiler_info(CUDA_NVCC_COMPILER_INFO CUDA_NVCC_COMPILER_FLAGS) +endif(GMX_GPU) + ######################################################################## # Specify install locations and which subdirectories to process # diff --git a/cmake/gmxManageGPU.cmake b/cmake/gmxManageGPU.cmake index 97fee7560e..3c41094061 100644 --- a/cmake/gmxManageGPU.cmake +++ b/cmake/gmxManageGPU.cmake @@ -146,13 +146,47 @@ if(NOT GMX_GPU) mark_as_advanced(CUDA_TOOLKIT_ROOT_DIR) endif() +# Try to execute ${CUDA_NVCC_EXECUTABLE} --version and set the output +# (or an error string) in the argument variable. +# Note that semicolon is used as separator for nvcc. +# +# Parameters: +# COMPILER_INFO - [output variable] string with compiler path, ID and +# some compiler-provided information +# COMPILER_FLAGS - [output variable] flags for the compiler +# +macro(get_cuda_compiler_info COMPILER_INFO COMPILER_FLAGS) + if(CUDA_NVCC_EXECUTABLE) + + # Get the nvcc version string. This is multi-line, but since it is only 4 lines + # and might change in the future it is better to store than trying to parse out + # the version from the current format. + execute_process(COMMAND ${CUDA_NVCC_EXECUTABLE} --version + RESULT_VARIABLE _nvcc_version_res + OUTPUT_VARIABLE _nvcc_version_out + ERROR_VARIABLE _nvcc_version_err + OUTPUT_STRIP_TRAILING_WHITESPACE) + if (${_nvcc_version_res} EQUAL 0) + # Fix multi-line mess: Replace newline with ";" so we can use it in a define + string(REPLACE "\n" ";" _nvcc_info_singleline ${_nvcc_version_out}) + SET(${COMPILER_INFO} "${CUDA_NVCC_EXECUTABLE} ${_nvcc_info_singleline}") + string(TOUPPER ${CMAKE_BUILD_TYPE} _build_type) + SET(_compiler_flags "${CUDA_NVCC_FLAGS_${_build_type}}") + if(CUDA_PROPAGATE_HOST_FLAGS) + string(REGEX REPLACE "[ ]+" ";" _cxx_flags_nospace "${BUILD_CXXFLAGS}") + endif() + SET(${COMPILER_FLAGS} "${CUDA_NVCC_FLAGS}${CUDA_NVCC_FLAGS_${_build_type}}; ${_cxx_flags_nospace}") + else () + SET(${COMPILER_INFO} "N/A") + SET(${COMPILER_FLAGS} "N/A") + endif () + endif () +endmacro () + macro(gmx_gpu_setup) # set up nvcc options include(gmxManageNvccConfig) - # Version info (semicolon used as line separator) for nvcc. - get_nvcc_version_info() - # Atomic operations used for polling wait for GPU # (to avoid the cudaStreamSynchronize + ECC bug). # ThreadMPI is now always included. Thus, we don't check for Atomics anymore here. diff --git a/cmake/gmxManageNvccConfig.cmake b/cmake/gmxManageNvccConfig.cmake index e99ed6bc00..59c8516f86 100644 --- a/cmake/gmxManageNvccConfig.cmake +++ b/cmake/gmxManageNvccConfig.cmake @@ -152,33 +152,3 @@ if (NOT DEFINED CUDA_NVCC_FLAGS_SET) "${_CUDA_ARCH_STR};-use_fast_math;${_HOST_COMPILER_OPTION_STRING}${CUDA_HOST_COMPILER_OPTIONS}" CACHE STRING "Compiler flags for nvcc." FORCE) endif() - - -# Try to execute ${CUDA_NVCC_EXECUTABLE} --version and set the output -# (or an error string) in the argument variable. -# -# returned in argument: CUDA nvcc compiler version string -# -macro(get_nvcc_version_info) - if(CUDA_NVCC_EXECUTABLE AND NOT CUDA_NVCC_COMPILER_INFO) - - # Get the nvcc version string. This is multi-line, but since it is only 4 lines - # and might change in the future it is better to store than trying to parse out - # the version from the current format. - execute_process(COMMAND ${CUDA_NVCC_EXECUTABLE} --version - RESULT_VARIABLE _nvcc_version_res - OUTPUT_VARIABLE _nvcc_version_out - ERROR_VARIABLE _nvcc_version_err - OUTPUT_STRIP_TRAILING_WHITESPACE) - if (${_nvcc_version_res} EQUAL 0) - # Fix multi-line mess: Replace newline with ";" so we can use it in a define - string(REPLACE "\n" ";" _nvcc_info_singleline ${_nvcc_version_out}) - SET(CUDA_NVCC_COMPILER_INFO ${_nvcc_info_singleline} - CACHE STRING "CUDA nvcc compiler version string" FORCE) - else () - SET(CUDA_NVCC_COMPILER_INFO "" - CACHE STRING "CUDA nvcc compiler version string not available" FORCE) - endif () - endif () - mark_as_advanced(CUDA_NVCC_COMPILER_INFO) -endmacro () diff --git a/src/buildinfo.h.cmakein b/src/buildinfo.h.cmakein index 49ca7b57b9..fdbf7da824 100644 --- a/src/buildinfo.h.cmakein +++ b/src/buildinfo.h.cmakein @@ -81,3 +81,5 @@ /** CUDA nvcc compiler version information */ #define CUDA_NVCC_COMPILER_INFO "@CUDA_NVCC_COMPILER_INFO@" +/** CUDA nvcc compiler flags */ +#define CUDA_NVCC_COMPILER_FLAGS "@CUDA_NVCC_COMPILER_FLAGS@" diff --git a/src/gmxlib/cuda_tools/copyrite_gpu.cu b/src/gmxlib/cuda_tools/copyrite_gpu.cu index 001ca53fc2..42f0feb2d0 100644 --- a/src/gmxlib/cuda_tools/copyrite_gpu.cu +++ b/src/gmxlib/cuda_tools/copyrite_gpu.cu @@ -50,6 +50,7 @@ extern "C" void gmx_print_version_info_gpu(FILE *fp) { int cuda_driver,cuda_runtime; fprintf(fp, "CUDA compiler: %s\n",CUDA_NVCC_COMPILER_INFO); + fprintf(fp, "CUDA compiler flags:%s\n",CUDA_NVCC_COMPILER_FLAGS); cuda_driver = 0; cudaDriverGetVersion(&cuda_driver); cuda_runtime = 0; -- 2.22.0