From 0bda8e719b607cfb1d03dabff0575e656b8df6fe Mon Sep 17 00:00:00 2001 From: Mark Abraham Date: Mon, 27 Jun 2016 19:18:12 +0200 Subject: [PATCH] Work around glibc 2.23 with CUDA Note: Cherry-pick of e2cd2e2e from the 2016 branch. Fixes #2022 Change-Id: Id9881efb3f26af341b9c89b4bd1f983a2149c9e4 --- cmake/TestGlibcVersion.cpp | 11 +++++++++++ cmake/gmxManageNvccConfig.cmake | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 cmake/TestGlibcVersion.cpp diff --git a/cmake/TestGlibcVersion.cpp b/cmake/TestGlibcVersion.cpp new file mode 100644 index 0000000000..ae63eb4cf1 --- /dev/null +++ b/cmake/TestGlibcVersion.cpp @@ -0,0 +1,11 @@ +#include + +int main() +{ + // This compiles if the C++ compiler is using glibc with version 2.23+ +#if (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 23) + return 0; +#else +#error A glibc version prior to 2.23 was found +#endif +} diff --git a/cmake/gmxManageNvccConfig.cmake b/cmake/gmxManageNvccConfig.cmake index 028a83ff1c..3fb17418da 100644 --- a/cmake/gmxManageNvccConfig.cmake +++ b/cmake/gmxManageNvccConfig.cmake @@ -99,6 +99,23 @@ if (NOT DEFINED CUDA_HOST_COMPILER AND NOT MSVC) endif() endif() +# glibc 2.23 changed string.h in a way that breaks CUDA compilation in +# many projects, but which has a trivial workaround. It would be nicer +# to compile with nvcc and see that the workaround is necessary and +# effective, but it is unclear how to do that. Also, grepping in the +# glibc source shows that _FORCE_INLINES is only used in this string.h +# feature and performance of memcpy variants is unimportant for CUDA +# code in GROMACS. So this workaround is good enough to keep problems +# away from users installing GROMACS. See Redmine 1942. +function(work_around_glibc_2_23) + try_compile(IS_GLIBC_2_23_OR_HIGHER ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/cmake/TestGlibcVersion.cpp) + if(IS_GLIBC_2_23_OR_HIGHER) + message(STATUS "Adding work-around for issue compiling CUDA code with glibc 2.23 string.h") + list(APPEND CUDA_HOST_COMPILER_OPTIONS "-D_FORCE_INLINES") + set(CUDA_HOST_COMPILER_OPTIONS ${CUDA_HOST_COMPILER_OPTIONS} PARENT_SCOPE) + endif() +endfunction() + # set up host compiler and its options if(CUDA_HOST_COMPILER_CHANGED) # FindCUDA in CMake 2.8.10 sets the host compiler internally @@ -134,6 +151,8 @@ if(CUDA_HOST_COMPILER_CHANGED) list(APPEND CUDA_HOST_COMPILER_OPTIONS "-D__STRICT_ANSI__") endif() + work_around_glibc_2_23() + set(CUDA_HOST_COMPILER_OPTIONS "${CUDA_HOST_COMPILER_OPTIONS}" CACHE STRING "Options for nvcc host compiler (do not edit!).") -- 2.11.4.GIT