From c61da28f0ae3d865c026a0e67bccc2379a4b370e Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 26 Nov 2018 17:03:09 -0500 Subject: [PATCH 01/15] allow building "fat" GPU binaries in CUDA mode, resulting in executables compatible with all GPUs supported by the used CUDA toolkit --- cmake/CMakeLists.txt | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 3c431b0325..ce6bcb6bbf 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -1143,11 +1143,44 @@ if(PKG_GPU) file(GLOB GPU_LIB_CUDPP_CU ${LAMMPS_LIB_SOURCE_DIR}/gpu/cudpp_mini/[^.]*.cu) endif() - cuda_compile_cubin(GPU_GEN_OBJS ${GPU_LIB_CU} OPTIONS - -DUNIX -O3 -Xptxas -v --use_fast_math -DNV_KERNEL -DUCL_CUDADR -arch=${GPU_ARCH} -D_${GPU_PREC_SETTING}) + # build arch/gencode commands for nvcc based on CUDA toolkit version and use choice + # --arch translates directly instead of JIT, so this should be for the preferred or most common architecture + set(GPU_CUDA_GENCODE "-arch=${GPU_ARCH} ") + # Fermi (GPU Arch 2.x) is supported by CUDA 3.2 to CUDA 8.0 + if((CUDA_VERSION VERSION_GREATER "3.1") AND (CUDA_VERSION VERSION_LESS "9.0")) + string(APPEND GPU_CUDA_GENCODE "-gencode arch=compute_20,code=[sm_20,compute_20] ") + endif() + # Kepler (GPU Arch 3.x) is supported by CUDA 5 and later + if(CUDA_VERSION VERSION_GREATER "4.9") + string(APPEND GPU_CUDA_GENCODE "-gencode arch=compute_30,code=[sm_30,compute_30] -gencode arch=compute_35,code=[sm_35,compute_35] ") + endif() + # Maxwell (GPU Arch 5.x) is supported by CUDA 6 and later + if(CUDA_VERSION VERSION_GREATER "5.9") + string(APPEND GPU_CUDA_GENCODE "-gencode arch=compute_50,code=[sm_50,compute_50] -gencode arch=compute_52,code=[sm_52,compute_52] ") + endif() + # Pascal (GPU Arch 6.x) is supported by CUDA 8 and later + if(CUDA_VERSION VERSION_GREATER "7.9") + string(APPEND GPU_CUDA_GENCODE "-gencode arch=compute_60,code=[sm_60,compute_60] -gencode arch=compute_61,code=[sm_61,compute_61] ") + endif() + # Volta (GPU Arch 7.0) is supported by CUDA 9 and later + if(CUDA_VERSION VERSION_GREATER "8.9") + string(APPEND GPU_CUDA_GENCODE "-gencode arch=compute_70,code=[sm_70,compute_70] ") + endif() + # Turing (GPU Arch 7.5) is supported by CUDA 10 and later + if(CUDA_VERSION VERSION_GREATER "9.9") + string(APPEND GPU_CUDA_GENCODE "-gencode arch=compute_75,code=[sm_75,compute_75] ") + endif() - cuda_compile(GPU_OBJS ${GPU_LIB_CUDPP_CU} OPTIONS $<$:-Xcompiler=-fPIC> - -DUNIX -O3 -Xptxas -v --use_fast_math -DUCL_CUDADR -arch=${GPU_ARCH} -D_${GPU_PREC_SETTING}) + cuda_compile_fatbin(GPU_GEN_OBJS ${GPU_LIB_CU} OPTIONS + -DUNIX -O3 -Xptxas -v --use_fast_math -DNV_KERNEL -DUCL_CUDADR ${GPU_CUDA_GENCODE} -D_${GPU_PREC_SETTING}) + + if(${BUILD_SHARED_LIBS}) + cuda_compile(GPU_OBJS ${GPU_LIB_CUDPP_CU} OPTIONS -Xcompiler=-fPIC + -DUNIX -O3 -Xptxas -v --use_fast_math -DUCL_CUDADR ${GPU_CUDA_GENCODE} -D_${GPU_PREC_SETTING}) + else() + cuda_compile(GPU_OBJS ${GPU_LIB_CUDPP_CU} OPTIONS + -DUNIX -O3 -Xptxas -v --use_fast_math -DUCL_CUDADR ${GPU_CUDA_GENCODE} -D_${GPU_PREC_SETTING}) + endif() foreach(CU_OBJ ${GPU_GEN_OBJS}) get_filename_component(CU_NAME ${CU_OBJ} NAME_WE) From b3975f4b1453864cccacaa8738f402581b4baa77 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 26 Nov 2018 17:03:32 -0500 Subject: [PATCH 02/15] reword a few options for clarity --- cmake/CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index ce6bcb6bbf..311a57a27f 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -1026,7 +1026,7 @@ if(PKG_USER-INTEL) endif() if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 16) - message(FATAL_ERROR "USER-INTEL is needed at least 2016 intel compiler, found ${CMAKE_CXX_COMPILER_VERSION}") + message(FATAL_ERROR "USER-INTEL needs at least a 2016 intel compiler, found ${CMAKE_CXX_COMPILER_VERSION}") endif() if(NOT BUILD_OMP) @@ -1091,7 +1091,7 @@ if(PKG_USER-INTEL) endif() if(PKG_GPU) - if (CMAKE_VERSION VERSION_LESS "3.1") + if (CMAKE_VERSION VERSION_LESS "3.1") message(FATAL_ERROR "For the GPU package you need at least cmake-3.1") endif() set(GPU_SOURCES_DIR ${LAMMPS_SOURCE_DIR}/GPU) @@ -1126,11 +1126,11 @@ if(PKG_GPU) find_package(CUDA REQUIRED) find_program(BIN2C bin2c) if(NOT BIN2C) - message(FATAL_ERROR "Couldn't find bin2c, use -DBIN2C helping cmake to find it.") + message(FATAL_ERROR "Could not find bin2c, use -DBIN2C=/path/to/bin2c to help cmake finding it.") endif() option(CUDPP_OPT "Enable CUDPP_OPT" ON) - set(GPU_ARCH "sm_30" CACHE STRING "LAMMPS GPU CUDA SM architecture (e.g. sm_60)") + set(GPU_ARCH "sm_30" CACHE STRING "LAMMPS GPU CUDA SM primary architecture (e.g. sm_60)") file(GLOB GPU_LIB_CU ${LAMMPS_LIB_SOURCE_DIR}/gpu/[^.]*.cu ${CMAKE_CURRENT_SOURCE_DIR}/gpu/[^.]*.cu) list(REMOVE_ITEM GPU_LIB_CU ${LAMMPS_LIB_SOURCE_DIR}/gpu/lal_pppm.cu) From e0ff23026870b8bd9060ce31823abaa414245d8d Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 26 Nov 2018 17:03:48 -0500 Subject: [PATCH 03/15] remove comment-in-comment --- lib/gpu/lal_device.cu | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/gpu/lal_device.cu b/lib/gpu/lal_device.cu index 6761b23fbb..37d0758845 100644 --- a/lib/gpu/lal_device.cu +++ b/lib/gpu/lal_device.cu @@ -11,7 +11,7 @@ // // begin : // email : brownw@ornl.gov -// ***************************************************************************/ +// *************************************************************************** #ifdef NV_KERNEL #include "lal_preprocessor.h" @@ -42,3 +42,4 @@ __kernel void kernel_info(__global int *info) { info[13]=THREADS_PER_CHARGE; info[14]=BLOCK_ELLIPSE; } + From 55359789fb1d3e4f08faf46727c71cff6ff35822 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 26 Nov 2018 18:13:50 -0500 Subject: [PATCH 04/15] improve docs for building the GPU library with CUDA and CMake/make with fat binaries --- doc/src/Build_extras.txt | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/doc/src/Build_extras.txt b/doc/src/Build_extras.txt index bc03b5c8ce..fb2fe95341 100644 --- a/doc/src/Build_extras.txt +++ b/doc/src/Build_extras.txt @@ -87,22 +87,30 @@ which GPU hardware to build for. # value = double or mixed (default) or single -D OCL_TUNE=value # hardware choice for GPU_API=opencl # generic (default) or intel (Intel CPU) or fermi, kepler, cypress (NVIDIA) --D GPU_ARCH=value # hardware choice for GPU_API=cuda +-D GPU_ARCH=value # primary GPU hardware choice for GPU_API=cuda # value = sm_XX, see below # default is Cuda-compiler dependent, but typically sm_20 --D CUDPP_OPT=value # optimization setting for GPU_API=cudea +-D CUDPP_OPT=value # optimization setting for GPU_API=cuda # enables CUDA Performance Primitives Optimizations # yes (default) or no :pre GPU_ARCH settings for different GPU hardware is as follows: -sm_20 for Fermi (C2050/C2070, deprecated as of CUDA 8.0) or GeForce GTX 580 or similar -sm_30 for Kepler (K10) -sm_35 for Kepler (K40) or GeForce GTX Titan or similar -sm_37 for Kepler (dual K80) -sm_50 for Maxwell -sm_60 for Pascal (P100) -sm_70 for Volta :ul +sm_20 or sm_21 for Fermi (supported by CUDA 3.2 until CUDA 7.5) +sm_30 or sm_35 or sm_37 for Kepler (supported since CUDA 5) +sm_50 or sm_52 for Maxwell (supported since CUDA 6) +sm_60 or sm_61 for Pascal (supported since CUDA 8) +sm_70 for Volta (supported since CUDA 9) +sm_75 for Turing (supported since CUDA 10) :ul + +A more detailed list can be found, for example, +at "Wikipedia's CUDA article"_https://en.wikipedia.org/wiki/CUDA#GPUs_supported + +CMake can detect which version of the CUDA toolkit is used and thus can +include support for [all] major GPU architectures supported by this toolkit. +Thus the GPU_ARCH setting is merely an optimization, to have code for +the preferred GPU architecture directly included rather than having to wait +for the JIT compiler of the CUDA driver to translate it. [Traditional make]: @@ -137,6 +145,11 @@ CUDA_ARCH = sm_XX, what GPU hardware you have, same as CMake GPU_ARCH above CUDA_PRECISION = precision (double, mixed, single) EXTRAMAKE = which Makefile.lammps.* file to copy to Makefile.lammps :ul +The file Makefile.linux_multi is set up to include support for multiple +GPU architectures as supported by the CUDA toolkit in use. This is done +through using the "--gencode " flag, which can be used multiple times and +thus support all GPU architectures supported by your CUDA compiler. + If the library build is successful, 3 files should be created: lib/gpu/libgpu.a, lib/gpu/nvc_get_devices, and lib/gpu/Makefile.lammps. The latter has settings that enable LAMMPS @@ -150,6 +163,7 @@ re-build LAMMPS. This is because the compilation of files in the GPU package uses the library settings from the lib/gpu/Makefile.machine used to build the GPU library. + :line KIM package :h4,link(kim) From aa0b9684dc9f3d03053b5ea10cd1b862db1d62a9 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 26 Nov 2018 20:19:28 -0500 Subject: [PATCH 05/15] remove inline expansion from two more cases (of external library builds) --- cmake/CMakeLists.txt | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 311a57a27f..935a2c6246 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -486,15 +486,15 @@ if(PKG_USER-SCAFACOS) ExternalProject_Add(scafacos_build URL https://github.com/scafacos/scafacos/releases/download/v1.0.1/scafacos-1.0.1.tar.gz URL_MD5 bd46d74e3296bd8a444d731bb10c1738 - CONFIGURE_COMMAND /configure --prefix= - --disable-doc + CONFIGURE_COMMAND /configure --prefix= + --disable-doc --enable-fcs-solvers=fmm,p2nfft,direct,ewald,p3m --with-internal-fftw --with-internal-pfft --with-internal-pnfft - $<$:--with-pic> - FC=${CMAKE_MPI_Fortran_COMPILER} - CXX=${CMAKE_MPI_CXX_COMPILER} + --with-pic + FC=${CMAKE_MPI_Fortran_COMPILER} + CXX=${CMAKE_MPI_CXX_COMPILER} CC=${CMAKE_MPI_C_COMPILER} F77= ) @@ -541,11 +541,10 @@ if(PKG_USER-PLUMED) if(DOWNLOAD_PLUMED) include(ExternalProject) ExternalProject_Add(plumed_build - URL https://github.com/plumed/plumed2/releases/download/v2.4.3/plumed-src-2.4.3.tgz + URL https://github.com/plumed/plumed2/releases/download/v2.4.3/plumed-src-2.4.3.tgz URL_MD5 b1be7c48971627febc11c61b70767fc5 BUILD_IN_SOURCE 1 - CONFIGURE_COMMAND /configure --prefix= - $<$:--with-pic> ) + CONFIGURE_COMMAND /configure --prefix= --with-pic) ExternalProject_get_property(plumed_build INSTALL_DIR) set(PLUMED_INSTALL_DIR ${INSTALL_DIR}) list(APPEND LAMMPS_DEPS plumed_build) From 3ad74985eb5ba62d1de87ab59dd1f8883ac542ff Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 26 Nov 2018 20:53:23 -0500 Subject: [PATCH 06/15] replace more inline expansions with explicit code. some general overhaul and better propagation of consistent compiler settings and flags for library builds --- cmake/CMakeLists.txt | 78 +++++++++++++++++++++++++------------------- 1 file changed, 45 insertions(+), 33 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 935a2c6246..c49b1c621b 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -422,15 +422,25 @@ if(WITH_FFMPEG) add_definitions(-DLAMMPS_FFMPEG) endif() +if(BUILD_SHARED_LIBS) + set(CONFIGURE_REQUEST_PIC "--with-pic") + set(CMAKE_REQUEST_PIC "-DCMAKE_POSITION_INDEPENDENT_CODE=${CMAKE_POSITION_INDEPENDENT_CODE}") +else() + set(CONFIGURE_REQUEST_PIC "") + set(CMAKE_REQUEST_PIC "") +endif() + + if(PKG_VORONOI) - option(DOWNLOAD_VORO "Download voro++ (instead of using the system's one)" OFF) + option(DOWNLOAD_VORO "Download and compile the Voro++ library instead of using an already installed one" OFF) if(DOWNLOAD_VORO) + message(STATUS "Voro++ download requested - we will build our own") include(ExternalProject) if(BUILD_SHARED_LIBS) - set(VORO_BUILD_OPTIONS "CFLAGS=-fPIC") + set(VORO_BUILD_OPTIONS CXX="${CMAKE_CXX_COMPILER}" CFLAGS="${CMAKE_POSITION_INDEPENDENT_CODE} ${CMAKE_C_FLAGS}") else() - set(VORO_BUILD_OPTIONS) + set(VORO_BUILD_OPTIONS CXX="${CMAKE_CXX_COMPILER}" CFLAGS="${CMAKE_C_FLAGS}") endif() ExternalProject_Add(voro_build @@ -445,7 +455,7 @@ if(PKG_VORONOI) else() find_package(VORO) if(NOT VORO_FOUND) - message(FATAL_ERROR "VORO not found, help CMake to find it by setting VORO_LIBRARY and VORO_INCLUDE_DIR, or set DOWNLOAD_VORO=ON to download it") + message(FATAL_ERROR "Voro++ library not found. Help CMake to find it by setting VORO_LIBRARY and VORO_INCLUDE_DIR, or set DOWNLOAD_VORO=ON to download it") endif() endif() include_directories(${VORO_INCLUDE_DIRS}) @@ -453,26 +463,27 @@ if(PKG_VORONOI) endif() if(PKG_LATTE) - option(DOWNLOAD_LATTE "Download latte (instead of using the system's one)" OFF) + option(DOWNLOAD_LATTE "Download the LATTE library instead of using an already installed one" OFF) if(DOWNLOAD_LATTE) - if (CMAKE_VERSION VERSION_LESS "3.7") # due to SOURCE_SUBDIR + if (CMAKE_VERSION VERSION_LESS "3.7") # due to SOURCE_SUBDIR message(FATAL_ERROR "For downlading LATTE you need at least cmake-3.7") endif() - message(STATUS "LATTE not found - we will build our own") + message(STATUS "LATTE download requested - we will build our own") include(ExternalProject) ExternalProject_Add(latte_build URL https://github.com/lanl/LATTE/archive/v1.2.1.tar.gz URL_MD5 85ac414fdada2d04619c8f936344df14 SOURCE_SUBDIR cmake - CMAKE_ARGS -DCMAKE_INSTALL_PREFIX= -DCMAKE_POSITION_INDEPENDENT_CODE=${CMAKE_POSITION_INDEPENDENT_CODE} - ) + CMAKE_ARGS -DCMAKE_INSTALL_PREFIX= ${CMAKE_REQUEST_PIC} + ) + endif() ExternalProject_get_property(latte_build INSTALL_DIR) set(LATTE_LIBRARIES ${INSTALL_DIR}/${CMAKE_INSTALL_LIBDIR}/liblatte.a) list(APPEND LAMMPS_DEPS latte_build) else() find_package(LATTE) if(NOT LATTE_FOUND) - message(FATAL_ERROR "LATTE not found, help CMake to find it by setting LATTE_LIBRARY, or set DOWNLOAD_LATTE=ON to download it") + message(FATAL_ERROR "LATTE library not found, help CMake to find it by setting LATTE_LIBRARY, or set DOWNLOAD_LATTE=ON to download it") endif() endif() list(APPEND LAMMPS_LINK_LIBS ${LATTE_LIBRARIES} ${LAPACK_LIBRARIES}) @@ -480,24 +491,22 @@ endif() if(PKG_USER-SCAFACOS) find_package(GSL REQUIRED) - option(DOWNLOAD_SCAFACOS "Download ScaFaCoS (instead of using the system's one)" OFF) + option(DOWNLOAD_SCAFACOS "Download ScaFaCoS library instead of using an already installed one" OFF) if(DOWNLOAD_SCAFACOS) + message(STATUS "ScaFaCoS download requested - we will build our own") include(ExternalProject) ExternalProject_Add(scafacos_build URL https://github.com/scafacos/scafacos/releases/download/v1.0.1/scafacos-1.0.1.tar.gz URL_MD5 bd46d74e3296bd8a444d731bb10c1738 - CONFIGURE_COMMAND /configure --prefix= - --disable-doc + CONFIGURE_COMMAND /configure --prefix= --disable-doc --enable-fcs-solvers=fmm,p2nfft,direct,ewald,p3m - --with-internal-fftw - --with-internal-pfft - --with-internal-pnfft - --with-pic + --with-internal-fftw --with-internal-pfft + --with-internal-pnfft ${CONFIGURE_REQUEST_PIC} FC=${CMAKE_MPI_Fortran_COMPILER} CXX=${CMAKE_MPI_CXX_COMPILER} CC=${CMAKE_MPI_C_COMPILER} F77= - ) + ) ExternalProject_get_property(scafacos_build INSTALL_DIR) set(SCAFACOS_BUILD_DIR ${INSTALL_DIR}) set(SCAFACOS_INCLUDE_DIRS ${SCAFACOS_BUILD_DIR}/include) @@ -537,14 +546,15 @@ if(PKG_USER-PLUMED) validate_option(PLUMED_MODE PLUMED_MODE_VALUES) string(TOUPPER ${PLUMED_MODE} PLUMED_MODE) - option(DOWNLOAD_PLUMED "Download Plumed (instead of using the system's one)" OFF) + option(DOWNLOAD_PLUMED "Download Plumed package instead of using an already installed one" OFF) if(DOWNLOAD_PLUMED) + message(STATUS "PLUMED download requested - we will build our own") include(ExternalProject) ExternalProject_Add(plumed_build URL https://github.com/plumed/plumed2/releases/download/v2.4.3/plumed-src-2.4.3.tgz URL_MD5 b1be7c48971627febc11c61b70767fc5 BUILD_IN_SOURCE 1 - CONFIGURE_COMMAND /configure --prefix= --with-pic) + CONFIGURE_COMMAND /configure --prefix= ${CONFIGURE_REQUEST_PIC}) ExternalProject_get_property(plumed_build INSTALL_DIR) set(PLUMED_INSTALL_DIR ${INSTALL_DIR}) list(APPEND LAMMPS_DEPS plumed_build) @@ -591,11 +601,12 @@ if(PKG_USER-NETCDF) endif() if(PKG_USER-SMD) - option(DOWNLOAD_EIGEN3 "Download Eigen3 (instead of using the system's one)" OFF) + option(DOWNLOAD_EIGEN3 "Download Eigen3 instead of using an already installed one)" OFF) if(DOWNLOAD_EIGEN3) + message(STATUS "Eigen3 download requested - we will build our own") include(ExternalProject) ExternalProject_Add(Eigen3_build - URL http://bitbucket.org/eigen/eigen/get/3.3.4.tar.gz + URL http://bitbucket.org/eigen/eigen/get/3.3.4.tar.gz URL_MD5 1a47e78efe365a97de0c022d127607c3 CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND "" ) @@ -632,8 +643,9 @@ if(PKG_USER-VTK) endif() if(PKG_KIM) - option(DOWNLOAD_KIM "Download kim-api (instead of using the system's one)" OFF) + option(DOWNLOAD_KIM "Download KIM-API v1 from OpenKIM instead of using an already installed one)" OFF) if(DOWNLOAD_KIM) + message(STATUS "KIM-API v1 download requested - we will build our own") include(ExternalProject) ExternalProject_Add(kim_build URL https://github.com/openkim/kim-api/archive/v1.9.5.tar.gz @@ -648,7 +660,7 @@ if(PKG_KIM) else() find_package(KIM) if(NOT KIM_FOUND) - message(FATAL_ERROR "KIM not found, help CMake to find it by setting KIM_LIBRARY and KIM_INCLUDE_DIR, or set DOWNLOAD_KIM=ON to download it") + message(FATAL_ERROR "KIM-API v1 not found, help CMake to find it by setting KIM_LIBRARY and KIM_INCLUDE_DIR, or set DOWNLOAD_KIM=ON to download it") endif() endif() list(APPEND LAMMPS_LINK_LIBS ${KIM_LIBRARIES}) @@ -691,10 +703,10 @@ endif() if(PKG_MSCG) find_package(GSL REQUIRED) - option(DOWNLOAD_MSCG "Download latte (instead of using the system's one)" OFF) + option(DOWNLOAD_MSCG "Download MSCG library instead of using an already installed one)" OFF) if(DOWNLOAD_MSCG) - if (CMAKE_VERSION VERSION_LESS "3.7") # due to SOURCE_SUBDIR - message(FATAL_ERROR "For downlading LATTE you need at least cmake-3.7") + if (CMAKE_VERSION VERSION_LESS "3.7") # due to SOURCE_SUBDIR + message(FATAL_ERROR "For downlading MSCG you need at least cmake-3.7") endif() include(ExternalProject) if(NOT LAPACK_FOUND) @@ -704,7 +716,7 @@ if(PKG_MSCG) URL https://github.com/uchicago-voth/MSCG-release/archive/1.7.3.1.tar.gz URL_MD5 8c45e269ee13f60b303edd7823866a91 SOURCE_SUBDIR src/CMake - CMAKE_ARGS -DCMAKE_INSTALL_PREFIX= -DCMAKE_POSITION_INDEPENDENT_CODE=${CMAKE_POSITION_INDEPENDENT_CODE} ${EXTRA_MSCG_OPTS} + CMAKE_ARGS -DCMAKE_INSTALL_PREFIX= ${CMAKE_REQUEST_PIC} ${EXTRA_MSCG_OPTS} BUILD_COMMAND make mscg INSTALL_COMMAND "" ) ExternalProject_get_property(mscg_build BINARY_DIR) @@ -752,7 +764,7 @@ set(MATH_LIBRARIES "m" CACHE STRING "math library") mark_as_advanced( MATH_LIBRARIES ) include(CheckLibraryExists) if (CMAKE_VERSION VERSION_LESS "3.4") - enable_language(C) # check_library_exists isn't supported without a c compiler before v3.4 + enable_language(C) # check_library_exists isn't supported without a C compiler before v3.4 endif() # RB: disabled this check because it breaks with KOKKOS CUDA enabled #foreach(FUNC sin cos) @@ -1174,7 +1186,7 @@ if(PKG_GPU) -DUNIX -O3 -Xptxas -v --use_fast_math -DNV_KERNEL -DUCL_CUDADR ${GPU_CUDA_GENCODE} -D_${GPU_PREC_SETTING}) if(${BUILD_SHARED_LIBS}) - cuda_compile(GPU_OBJS ${GPU_LIB_CUDPP_CU} OPTIONS -Xcompiler=-fPIC + cuda_compile(GPU_OBJS ${GPU_LIB_CUDPP_CU} OPTIONS -Xcompiler ${CMAKE_POSITION_INDEPENDENT_CODE} -DUNIX -O3 -Xptxas -v --use_fast_math -DUCL_CUDADR ${GPU_CUDA_GENCODE} -D_${GPU_PREC_SETTING}) else() cuda_compile(GPU_OBJS ${GPU_LIB_CUDPP_CU} OPTIONS @@ -1327,7 +1339,7 @@ if(BUILD_EXE) add_dependencies(lmp ${LAMMPS_DEPS}) endif() endif() - + set_target_properties(lmp PROPERTIES OUTPUT_NAME ${LAMMPS_BINARY}) install(TARGETS lmp DESTINATION ${CMAKE_INSTALL_BINDIR}) install(FILES ${LAMMPS_DOC_DIR}/lammps.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 RENAME ${LAMMPS_BINARY}.1) @@ -1464,14 +1476,14 @@ message(STATUS "<<< Build configuration >>> get_property(LANGUAGES GLOBAL PROPERTY ENABLED_LANGUAGES) list (FIND LANGUAGES "Fortran" _index) if (${_index} GREATER -1) - message(STATUS "Fortran Compiler ${CMAKE_Fortran_COMPILER} + message(STATUS "Fortran Compiler ${CMAKE_Fortran_COMPILER} Type ${CMAKE_Fortran_COMPILER_ID} Version ${CMAKE_Fortran_COMPILER_VERSION} Fortran Flags ${CMAKE_Fortran_FLAGS} ${CMAKE_Fortran_FLAGS_${BTYPE}}") endif() list (FIND LANGUAGES "C" _index) if (${_index} GREATER -1) - message(STATUS "C Compiler ${CMAKE_C_COMPILER} + message(STATUS "C Compiler ${CMAKE_C_COMPILER} Type ${CMAKE_C_COMPILER_ID} Version ${CMAKE_C_COMPILER_VERSION} C Flags ${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${BTYPE}}") From c980dd0a56bd73326f568e17a51fcc4dae660a2e Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 26 Nov 2018 20:56:13 -0500 Subject: [PATCH 07/15] remove stray endif() --- cmake/CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index c49b1c621b..78653a6c39 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -476,7 +476,6 @@ if(PKG_LATTE) SOURCE_SUBDIR cmake CMAKE_ARGS -DCMAKE_INSTALL_PREFIX= ${CMAKE_REQUEST_PIC} ) - endif() ExternalProject_get_property(latte_build INSTALL_DIR) set(LATTE_LIBRARIES ${INSTALL_DIR}/${CMAKE_INSTALL_LIBDIR}/liblatte.a) list(APPEND LAMMPS_DEPS latte_build) @@ -1491,7 +1490,7 @@ endif() if(CMAKE_EXE_LINKER_FLAGS) message(STATUS "Linker flags: Executable ${CMAKE_EXE_LINKER_FLAGS}") - endif() +endif() if(BUILD_SHARED_LIBS) message(STATUS "Shared libraries ${CMAKE_SHARED_LINKER_FLAGS}") else() From 91b96fa0c91e920d34a255b68f3b20115d05aa88 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 26 Nov 2018 21:37:23 -0500 Subject: [PATCH 08/15] build MESSAGE package client/server library always as static library --- cmake/CMakeLists.txt | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 78653a6c39..28698c9a03 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -672,12 +672,7 @@ if(PKG_MESSAGE) ${LAMMPS_LIB_SOURCE_DIR}/message/cslib/[^.]*.c ${LAMMPS_LIB_SOURCE_DIR}/message/cslib/[^.]*.cpp) - if(BUILD_SHARED_LIBS) - add_library(cslib SHARED ${cslib_SOURCES}) - else() - add_library(cslib STATIC ${cslib_SOURCES}) - endif() - + add_library(cslib STATIC ${cslib_SOURCES}) if(BUILD_MPI) target_compile_definitions(cslib PRIVATE -DMPI_YES) set_target_properties(cslib PROPERTIES OUTPUT_NAME "csmpi") From d6ea31e14319d0e3ee4842bee8406b06f281ed2f Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 26 Nov 2018 22:06:10 -0500 Subject: [PATCH 09/15] implement changes suggested by @junghans for GPU/CUDA compilation --- cmake/CMakeLists.txt | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 28698c9a03..fe158f512f 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -425,9 +425,11 @@ endif() if(BUILD_SHARED_LIBS) set(CONFIGURE_REQUEST_PIC "--with-pic") set(CMAKE_REQUEST_PIC "-DCMAKE_POSITION_INDEPENDENT_CODE=${CMAKE_POSITION_INDEPENDENT_CODE}") + set(CUDA_REQUEST_PIC "-Xcompiler ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}") else() set(CONFIGURE_REQUEST_PIC "") set(CMAKE_REQUEST_PIC "") + set(CUDA_REQUEST_PIC "") endif() @@ -1179,13 +1181,8 @@ if(PKG_GPU) cuda_compile_fatbin(GPU_GEN_OBJS ${GPU_LIB_CU} OPTIONS -DUNIX -O3 -Xptxas -v --use_fast_math -DNV_KERNEL -DUCL_CUDADR ${GPU_CUDA_GENCODE} -D_${GPU_PREC_SETTING}) - if(${BUILD_SHARED_LIBS}) - cuda_compile(GPU_OBJS ${GPU_LIB_CUDPP_CU} OPTIONS -Xcompiler ${CMAKE_POSITION_INDEPENDENT_CODE} + cuda_compile(GPU_OBJS ${GPU_LIB_CUDPP_CU} OPTIONS ${CUDA_REQUEST_PIC} -DUNIX -O3 -Xptxas -v --use_fast_math -DUCL_CUDADR ${GPU_CUDA_GENCODE} -D_${GPU_PREC_SETTING}) - else() - cuda_compile(GPU_OBJS ${GPU_LIB_CUDPP_CU} OPTIONS - -DUNIX -O3 -Xptxas -v --use_fast_math -DUCL_CUDADR ${GPU_CUDA_GENCODE} -D_${GPU_PREC_SETTING}) - endif() foreach(CU_OBJ ${GPU_GEN_OBJS}) get_filename_component(CU_NAME ${CU_OBJ} NAME_WE) From 1fdfc89d251ca5d151634abaf4e8ea25d55306e7 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 26 Nov 2018 22:27:21 -0500 Subject: [PATCH 10/15] make $HOME/.local the default LAMMPS installation destination --- cmake/CMakeLists.txt | 4 ++++ cmake/README.md | 1 + doc/src/Build_cmake.txt | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index fe158f512f..690ac40957 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -11,6 +11,10 @@ get_filename_component(LAMMPS_LIB_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../lib get_filename_component(LAMMPS_LIB_BINARY_DIR ${CMAKE_BINARY_DIR}/lib ABSOLUTE) get_filename_component(LAMMPS_DOC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../doc ABSOLUTE) +# by default, install into $HOME/.local (not /usr/local), so that no root access (and sudo!!) is needed +if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) + set(CMAKE_INSTALL_PREFIX "$ENV{HOME}/.local" CACHE PATH "default install path" FORCE ) +endif() # To avoid conflicts with the conventional Makefile build system, we build everything here file(GLOB LIB_SOURCES ${LAMMPS_SOURCE_DIR}/[^.]*.cpp) diff --git a/cmake/README.md b/cmake/README.md index 90aba19a41..ae9ea8d1f7 100644 --- a/cmake/README.md +++ b/cmake/README.md @@ -195,6 +195,7 @@ cmake -C ../cmake/presets/std_nolib.cmake -D PKG_GPU=on ../cmake CMAKE_INSTALL_PREFIX Install location where LAMMPS files will be copied to. In the Unix/Linux case with Makefiles this controls what `make install` will do. + Default setting is $HOME/.local. diff --git a/doc/src/Build_cmake.txt b/doc/src/Build_cmake.txt index 1406d290f5..5c29e11280 100644 --- a/doc/src/Build_cmake.txt +++ b/doc/src/Build_cmake.txt @@ -44,7 +44,7 @@ LAMMPS or need to re-compile LAMMPS repeatedly, installation of the ccache (= Compiler Cache) software may speed up compilation even more. After compilation, you can optionally copy the LAMMPS executable and -library into your system folders (by default under /usr/local) with: +library into your system folders (by default under $HOME/.local) with: make install # optional, copy LAMMPS executable & library elsewhere :pre From 00b138f5421c3af7f88dfd678702c5a1fe50c278 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 26 Nov 2018 22:43:08 -0500 Subject: [PATCH 11/15] verbose CUDA assembly processing is more distracting than helping --- cmake/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 690ac40957..99d7f2d0d3 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -1183,10 +1183,10 @@ if(PKG_GPU) endif() cuda_compile_fatbin(GPU_GEN_OBJS ${GPU_LIB_CU} OPTIONS - -DUNIX -O3 -Xptxas -v --use_fast_math -DNV_KERNEL -DUCL_CUDADR ${GPU_CUDA_GENCODE} -D_${GPU_PREC_SETTING}) + -DUNIX -O3 --use_fast_math -DNV_KERNEL -DUCL_CUDADR ${GPU_CUDA_GENCODE} -D_${GPU_PREC_SETTING}) cuda_compile(GPU_OBJS ${GPU_LIB_CUDPP_CU} OPTIONS ${CUDA_REQUEST_PIC} - -DUNIX -O3 -Xptxas -v --use_fast_math -DUCL_CUDADR ${GPU_CUDA_GENCODE} -D_${GPU_PREC_SETTING}) + -DUNIX -O3 --use_fast_math -DUCL_CUDADR ${GPU_CUDA_GENCODE} -D_${GPU_PREC_SETTING}) foreach(CU_OBJ ${GPU_GEN_OBJS}) get_filename_component(CU_NAME ${CU_OBJ} NAME_WE) From d43f2291620ad311ab22df3099adca3d3159de4d Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 26 Nov 2018 22:48:23 -0500 Subject: [PATCH 12/15] do not warn about deprecated GPU target archs --- cmake/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 99d7f2d0d3..c873429d00 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -1183,10 +1183,10 @@ if(PKG_GPU) endif() cuda_compile_fatbin(GPU_GEN_OBJS ${GPU_LIB_CU} OPTIONS - -DUNIX -O3 --use_fast_math -DNV_KERNEL -DUCL_CUDADR ${GPU_CUDA_GENCODE} -D_${GPU_PREC_SETTING}) + -DUNIX -O3 --use_fast_math -Wno-deprecated-gpu-targets -DNV_KERNEL -DUCL_CUDADR ${GPU_CUDA_GENCODE} -D_${GPU_PREC_SETTING}) cuda_compile(GPU_OBJS ${GPU_LIB_CUDPP_CU} OPTIONS ${CUDA_REQUEST_PIC} - -DUNIX -O3 --use_fast_math -DUCL_CUDADR ${GPU_CUDA_GENCODE} -D_${GPU_PREC_SETTING}) + -DUNIX -O3 --use_fast_math -Wno-deprecated-gpu-targets -DUCL_CUDADR ${GPU_CUDA_GENCODE} -D_${GPU_PREC_SETTING}) foreach(CU_OBJ ${GPU_GEN_OBJS}) get_filename_component(CU_NAME ${CU_OBJ} NAME_WE) From dbc798e28672d7a656d0efa7d4aa6fbe0ea7f7ca Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 27 Nov 2018 05:29:42 -0500 Subject: [PATCH 13/15] correct passing flags to local voro++ build --- cmake/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index c873429d00..e6ed5be376 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -444,9 +444,9 @@ if(PKG_VORONOI) include(ExternalProject) if(BUILD_SHARED_LIBS) - set(VORO_BUILD_OPTIONS CXX="${CMAKE_CXX_COMPILER}" CFLAGS="${CMAKE_POSITION_INDEPENDENT_CODE} ${CMAKE_C_FLAGS}") + set(VORO_BUILD_OPTIONS CXX="${CMAKE_CXX_COMPILER}" CFLAGS="${CMAKE_SHARED_LIBRARY_CXX_FLAGS} ${CMAKE_CXX_FLAGS}") else() - set(VORO_BUILD_OPTIONS CXX="${CMAKE_CXX_COMPILER}" CFLAGS="${CMAKE_C_FLAGS}") + set(VORO_BUILD_OPTIONS CXX="${CMAKE_CXX_COMPILER}" CFLAGS="${CMAKE_CXX_FLAGS}") endif() ExternalProject_Add(voro_build From 79fafcb12cb3bead034febc1972cc045a29b456c Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 27 Nov 2018 09:57:21 -0500 Subject: [PATCH 14/15] passing build type specific compiler flags to building the voro++ library --- cmake/CMakeLists.txt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index e6ed5be376..3702647f9d 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -79,6 +79,7 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CXX_FLAGS) #release comes with -O3 by default set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." FORCE) endif(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CXX_FLAGS) +string(TOUPPER "${CMAKE_BUILD_TYPE}" BTYPE) # check for files auto-generated by make-based buildsystem # this is fast, so check for it all the time @@ -444,10 +445,12 @@ if(PKG_VORONOI) include(ExternalProject) if(BUILD_SHARED_LIBS) - set(VORO_BUILD_OPTIONS CXX="${CMAKE_CXX_COMPILER}" CFLAGS="${CMAKE_SHARED_LIBRARY_CXX_FLAGS} ${CMAKE_CXX_FLAGS}") + set(VORO_BUILD_CFLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS} ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${BTYPE}}") else() - set(VORO_BUILD_OPTIONS CXX="${CMAKE_CXX_COMPILER}" CFLAGS="${CMAKE_CXX_FLAGS}") + set(VORO_BUILD_CFLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${BTYPE}}") endif() + string(APPEND VORO_BUILD_CFLAGS ${CMAKE_CXX_FLAGS}) + set(VORO_BUILD_OPTIONS CXX=${CMAKE_CXX_COMPILER} CFLAGS=${VORO_BUILD_CFLAGS}) ExternalProject_Add(voro_build URL http://math.lbl.gov/voro++/download/dir/voro++-0.4.6.tar.gz @@ -1455,7 +1458,6 @@ foreach(PKG ${DEFAULT_PACKAGES} ${ACCEL_PACKAGES} ${OTHER_PACKAGES}) endif() endforeach() -string(TOUPPER "${CMAKE_BUILD_TYPE}" BTYPE) get_directory_property(CPPFLAGS DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_DEFINITIONS) include(FeatureSummary) feature_summary(DESCRIPTION "The following packages have been found:" WHAT PACKAGES_FOUND) From ebacd5ca6b9e00e5cf72629deae4404049ff8a87 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 27 Nov 2018 14:36:59 -0500 Subject: [PATCH 15/15] anti-nitpick hack --- cmake/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 3702647f9d..aa42ed9a87 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -432,9 +432,9 @@ if(BUILD_SHARED_LIBS) set(CMAKE_REQUEST_PIC "-DCMAKE_POSITION_INDEPENDENT_CODE=${CMAKE_POSITION_INDEPENDENT_CODE}") set(CUDA_REQUEST_PIC "-Xcompiler ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}") else() - set(CONFIGURE_REQUEST_PIC "") - set(CMAKE_REQUEST_PIC "") - set(CUDA_REQUEST_PIC "") + set(CONFIGURE_REQUEST_PIC) + set(CMAKE_REQUEST_PIC) + set(CUDA_REQUEST_PIC) endif()