From c8aa06b959e96814b8da9031a707a0f5868268b3 Mon Sep 17 00:00:00 2001 From: Christoph Junghans Date: Mon, 21 Aug 2017 11:12:36 -0600 Subject: [PATCH 01/27] cmake: build libs separate --- cmake/CMakeLists.txt | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 76c28fcb72..d917fef714 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -348,12 +348,26 @@ endforeach() foreach(SIMPLE_LIB REAX MEAM POEMS USER-ATC USER-AWPMD USER-COLVARS USER-H5MD USER-MOLFILE USER-QMMM) if(ENABLE_${SIMPLE_LIB}) - string(REGEX REPLACE "^USER-" "" SIMPLE_LIB "${SIMPLE_LIB}") - string(TOLOWER "${SIMPLE_LIB}" INC_DIR) - file(GLOB_RECURSE ${SIMPLE_LIB}_SOURCES ${LAMMPS_LIB_SOURCE_DIR}/${INC_DIR}/*.F - ${LAMMPS_LIB_SOURCE_DIR}/${INC_DIR}/*.c ${LAMMPS_LIB_SOURCE_DIR}/${INC_DIR}/*.cpp) - list(APPEND LIB_SOURCES ${${SIMPLE_LIB}_SOURCES}) - include_directories(${LAMMPS_LIB_SOURCE_DIR}/${INC_DIR}) + string(REGEX REPLACE "^USER-" "" PKG_LIB "${SIMPLE_LIB}") + string(TOLOWER "${PKG_LIB}" PKG_LIB) + file(GLOB_RECURSE ${PKG_LIB}_SOURCES ${LAMMPS_LIB_SOURCE_DIR}/${PKG_LIB}/*.F + ${LAMMPS_LIB_SOURCE_DIR}/${PKG_LIB}/*.c ${LAMMPS_LIB_SOURCE_DIR}/${PKG_LIB}/*.cpp) + option(BUILD_SHARED_PKG_LIBS "Build package libs shared" OFF) + if(BUILD_SHARED_PKG_LIBS) + add_library(${PKG_LIB} SHARED ${${PKG_LIB}_SOURCES}) + set_target_properties(${PKG_LIB} PROPERTIES SOVERSION ${SOVERSION}) + if(INSTALL_LIB) + install(TARGETS ${PKG_LIB} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + else() + message(FATAL_ERROR "Shared library has to be installed, use -DINSTALL_LIB=ON to install lammps with a library") + endif() + else() + add_library(${PKG_LIB} STATIC ${${PKG_LIB}_SOURCES}) + endif() + list(APPEND LAMMPS_LINK_LIBS ${PKG_LIB}) + foreach(PKG_SRC ${${SIMPLE_LIB}_SOURCES}) + set_property(SOURCE ${PKG_SRC} APPEND PROPERTY COMPILE_FLAGS -I${LAMMPS_LIB_SOURCE_DIR}/${PKG_LIB}) + endforeach() endif() endforeach() From 1f4c550f9fab00198f687af9fd2312b0fb02b66c Mon Sep 17 00:00:00 2001 From: Christoph Junghans Date: Mon, 21 Aug 2017 13:09:52 -0600 Subject: [PATCH 02/27] cmake: make awpmd includes local --- cmake/CMakeLists.txt | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index d917fef714..22b1759ddc 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -248,11 +248,6 @@ if(ENABLE_USER-QMMM) list(APPEND LAMMPS_LINK_LIBS ${QE_LIBRARIES} ${CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES}) endif() -if(ENABLE_USER-AWPMD) - include_directories(${LAMMPS_LIB_SOURCE_DIR}/awpmd/systems/interact - ${LAMMPS_LIB_SOURCE_DIR}/awpmd/ivutils/include) -endif() - if(ENABLE_USER-H5MD) find_package(HDF5 REQUIRED) list(APPEND LAMMPS_LINK_LIBS ${HDF5_LIBRARIES}) @@ -366,11 +361,21 @@ foreach(SIMPLE_LIB REAX MEAM POEMS USER-ATC USER-AWPMD USER-COLVARS USER-H5MD endif() list(APPEND LAMMPS_LINK_LIBS ${PKG_LIB}) foreach(PKG_SRC ${${SIMPLE_LIB}_SOURCES}) - set_property(SOURCE ${PKG_SRC} APPEND PROPERTY COMPILE_FLAGS -I${LAMMPS_LIB_SOURCE_DIR}/${PKG_LIB}) + if(PKG_LIB STREQUAL awpmd) + set_property(SOURCE ${PKG_SRC} APPEND PROPERTY COMPILE_FLAGS -I${LAMMPS_LIB_SOURCE_DIR}/${PKG_LIB}/systems/interact) + set_property(SOURCE ${PKG_SRC} APPEND APPEND_STRING PROPERTY COMPILE_FLAGS " -I${LAMMPS_LIB_SOURCE_DIR}/${PKG_LIB}/ivutils/include") + else() + set_property(SOURCE ${PKG_SRC} APPEND PROPERTY COMPILE_FLAGS -I${LAMMPS_LIB_SOURCE_DIR}/${PKG_LIB}) + endif() endforeach() endif() endforeach() +if(ENABLE_USER-AWPMD) + set_target_properties(awpmd PROPERTIES INCLUDE_DIRECTORIES + "${LAMMPS_LIB_SOURCE_DIR}/awpmd/systems/interact;${LAMMPS_LIB_SOURCE_DIR}/awpmd/ivutils/include") +endif() + ###################################################################### # packages which selectively include variants based on enabled styles # e.g. accelerator packages From 5fcc19777c075e8749217ae27d0d0283eee8c903 Mon Sep 17 00:00:00 2001 From: Christoph Junghans Date: Mon, 21 Aug 2017 14:24:00 -0600 Subject: [PATCH 03/27] cmake: fix molfile compile --- cmake/CMakeLists.txt | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 22b1759ddc..1f8a0322f5 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -347,19 +347,21 @@ foreach(SIMPLE_LIB REAX MEAM POEMS USER-ATC USER-AWPMD USER-COLVARS USER-H5MD string(TOLOWER "${PKG_LIB}" PKG_LIB) file(GLOB_RECURSE ${PKG_LIB}_SOURCES ${LAMMPS_LIB_SOURCE_DIR}/${PKG_LIB}/*.F ${LAMMPS_LIB_SOURCE_DIR}/${PKG_LIB}/*.c ${LAMMPS_LIB_SOURCE_DIR}/${PKG_LIB}/*.cpp) - option(BUILD_SHARED_PKG_LIBS "Build package libs shared" OFF) - if(BUILD_SHARED_PKG_LIBS) - add_library(${PKG_LIB} SHARED ${${PKG_LIB}_SOURCES}) - set_target_properties(${PKG_LIB} PROPERTIES SOVERSION ${SOVERSION}) - if(INSTALL_LIB) - install(TARGETS ${PKG_LIB} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + if(${PKG_LIB}_SOURCES) #some libs (e.g. molfile have headers only) + if(BUILD_SHARED_PKG_LIBS) + option(BUILD_SHARED_PKG_LIBS "Build package libs shared" OFF) + add_library(${PKG_LIB} SHARED ${${PKG_LIB}_SOURCES}) + set_target_properties(${PKG_LIB} PROPERTIES SOVERSION ${SOVERSION}) + if(INSTALL_LIB) + install(TARGETS ${PKG_LIB} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + else() + message(FATAL_ERROR "Shared library has to be installed, use -DINSTALL_LIB=ON to install lammps with a library") + endif() else() - message(FATAL_ERROR "Shared library has to be installed, use -DINSTALL_LIB=ON to install lammps with a library") + add_library(${PKG_LIB} STATIC ${${PKG_LIB}_SOURCES}) endif() - else() - add_library(${PKG_LIB} STATIC ${${PKG_LIB}_SOURCES}) + list(APPEND LAMMPS_LINK_LIBS ${PKG_LIB}) endif() - list(APPEND LAMMPS_LINK_LIBS ${PKG_LIB}) foreach(PKG_SRC ${${SIMPLE_LIB}_SOURCES}) if(PKG_LIB STREQUAL awpmd) set_property(SOURCE ${PKG_SRC} APPEND PROPERTY COMPILE_FLAGS -I${LAMMPS_LIB_SOURCE_DIR}/${PKG_LIB}/systems/interact) From cf3f15b0a5b3b0f68add1b65c5655e132ec2d0fe Mon Sep 17 00:00:00 2001 From: Christoph Junghans Date: Mon, 21 Aug 2017 15:04:03 -0600 Subject: [PATCH 04/27] cmake: make h5md includes local --- cmake/CMakeLists.txt | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 1f8a0322f5..7ac0294f09 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -248,12 +248,6 @@ if(ENABLE_USER-QMMM) list(APPEND LAMMPS_LINK_LIBS ${QE_LIBRARIES} ${CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES}) endif() -if(ENABLE_USER-H5MD) - find_package(HDF5 REQUIRED) - list(APPEND LAMMPS_LINK_LIBS ${HDF5_LIBRARIES}) - include_directories(${HDF5_INCLUDE_DIRS} ${LAMMPS_LIB_SOURCE_DIR}/h5md/include) -endif() - if(ENABLE_USER-VTK) find_package(VTK REQUIRED NO_MODULE) include(${VTK_USE_FILE}) @@ -366,6 +360,8 @@ foreach(SIMPLE_LIB REAX MEAM POEMS USER-ATC USER-AWPMD USER-COLVARS USER-H5MD if(PKG_LIB STREQUAL awpmd) set_property(SOURCE ${PKG_SRC} APPEND PROPERTY COMPILE_FLAGS -I${LAMMPS_LIB_SOURCE_DIR}/${PKG_LIB}/systems/interact) set_property(SOURCE ${PKG_SRC} APPEND APPEND_STRING PROPERTY COMPILE_FLAGS " -I${LAMMPS_LIB_SOURCE_DIR}/${PKG_LIB}/ivutils/include") + elseif(PKG_LIB STREQUAL h5md) + include_directories(${LAMMPS_LIB_SOURCE_DIR}/h5md/include) #ch5md.h is included indirectly in style.h else() set_property(SOURCE ${PKG_SRC} APPEND PROPERTY COMPILE_FLAGS -I${LAMMPS_LIB_SOURCE_DIR}/${PKG_LIB}) endif() @@ -378,6 +374,13 @@ if(ENABLE_USER-AWPMD) "${LAMMPS_LIB_SOURCE_DIR}/awpmd/systems/interact;${LAMMPS_LIB_SOURCE_DIR}/awpmd/ivutils/include") endif() +if(ENABLE_USER-H5MD) + find_package(HDF5 REQUIRED) + target_link_libraries(h5md ${HDF5_LIBRARIES}) + set_target_properties(h5md PROPERTIES INCLUDE_DIRECTORIES + "${HDF5_INCLUDE_DIRS};${LAMMPS_LIB_SOURCE_DIR}/h5md/include") +endif() + ###################################################################### # packages which selectively include variants based on enabled styles # e.g. accelerator packages From 67ae2719a877a0cfd2605abeafbbe396c67d6b08 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Sun, 27 Aug 2017 03:04:32 -0400 Subject: [PATCH 05/27] Simplify lib build by using target_include_directories --- cmake/CMakeLists.txt | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 7ac0294f09..53984cbf17 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -355,30 +355,23 @@ foreach(SIMPLE_LIB REAX MEAM POEMS USER-ATC USER-AWPMD USER-COLVARS USER-H5MD add_library(${PKG_LIB} STATIC ${${PKG_LIB}_SOURCES}) endif() list(APPEND LAMMPS_LINK_LIBS ${PKG_LIB}) - endif() - foreach(PKG_SRC ${${SIMPLE_LIB}_SOURCES}) if(PKG_LIB STREQUAL awpmd) - set_property(SOURCE ${PKG_SRC} APPEND PROPERTY COMPILE_FLAGS -I${LAMMPS_LIB_SOURCE_DIR}/${PKG_LIB}/systems/interact) - set_property(SOURCE ${PKG_SRC} APPEND APPEND_STRING PROPERTY COMPILE_FLAGS " -I${LAMMPS_LIB_SOURCE_DIR}/${PKG_LIB}/ivutils/include") + target_include_directories(awpmd PUBLIC ${LAMMPS_LIB_SOURCE_DIR}/awpmd/systems/interact ${LAMMPS_LIB_SOURCE_DIR}/awpmd/ivutils/include) elseif(PKG_LIB STREQUAL h5md) - include_directories(${LAMMPS_LIB_SOURCE_DIR}/h5md/include) #ch5md.h is included indirectly in style.h + target_include_directories(h5md PUBLIC ${LAMMPS_LIB_SOURCE_DIR}/h5md/include) else() - set_property(SOURCE ${PKG_SRC} APPEND PROPERTY COMPILE_FLAGS -I${LAMMPS_LIB_SOURCE_DIR}/${PKG_LIB}) + target_include_directories(${PKG_LIB} PUBLIC ${LAMMPS_LIB_SOURCE_DIR}/${PKG_LIB}) endif() - endforeach() + else() + include_directories(${LAMMPS_LIB_SOURCE_DIR}/${PKG_LIB}) + endif() endif() endforeach() -if(ENABLE_USER-AWPMD) - set_target_properties(awpmd PROPERTIES INCLUDE_DIRECTORIES - "${LAMMPS_LIB_SOURCE_DIR}/awpmd/systems/interact;${LAMMPS_LIB_SOURCE_DIR}/awpmd/ivutils/include") -endif() - if(ENABLE_USER-H5MD) find_package(HDF5 REQUIRED) target_link_libraries(h5md ${HDF5_LIBRARIES}) - set_target_properties(h5md PROPERTIES INCLUDE_DIRECTORIES - "${HDF5_INCLUDE_DIRS};${LAMMPS_LIB_SOURCE_DIR}/h5md/include") + target_include_directories(h5md PRIVATE ${HDF5_INCLUDE_DIRS}) endif() ###################################################################### From 76926b7fcf9828b774d2cf6fbfd4da3be4898b01 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Sun, 27 Aug 2017 03:54:40 -0400 Subject: [PATCH 06/27] Compile linalg as library and track link dependencies for correct link order --- cmake/CMakeLists.txt | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 53984cbf17..6abf445f3d 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -162,12 +162,23 @@ endif() if(ENABLE_MSCG OR ENABLE_USER-ATC OR ENABLE_USER-AWPMD OR ENABLE_USER-QUIP) find_package(LAPACK) - if(LAPACK_FOUND) - list(APPEND LAMMPS_LINK_LIBS ${LAPACK_LIBRARIES}) - else() + if(NOT LAPACK_FOUND) enable_language(Fortran) file(GLOB LAPACK_SOURCES ${LAMMPS_LIB_SOURCE_DIR}/linalg/*.f) - list(APPEND LIB_SOURCES ${LAPACK_SOURCES}) + + if(BUILD_SHARED_PKG_LIBS) + add_library(linalg SHARED ${LAPACK_SOURCES}) + set_target_properties(${PKG_LIB} PROPERTIES SOVERSION ${SOVERSION}) + if(INSTALL_LIB) + install(TARGETS linalg LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + else() + message(FATAL_ERROR "Shared library has to be installed, use -DINSTALL_LIB=ON to install lammps with a library") + endif() + else() + add_library(linalg STATIC ${LAPACK_SOURCES}) + endif() + target_compile_options(linalg PRIVATE -fno-second-underscore) + set(LAPACK_LIBRARIES linalg) endif() endif() @@ -368,6 +379,14 @@ foreach(SIMPLE_LIB REAX MEAM POEMS USER-ATC USER-AWPMD USER-COLVARS USER-H5MD endif() endforeach() +if(ENABLE_USER-AWPMD) + target_link_libraries(awpmd ${LAPACK_LIBRARIES}) +endif() + +if(ENABLE_USER-ATC) + target_link_libraries(atc ${LAPACK_LIBRARIES}) +endif() + if(ENABLE_USER-H5MD) find_package(HDF5 REQUIRED) target_link_libraries(h5md ${HDF5_LIBRARIES}) From 47f16c0d70b349198aba02bfc94805062339ed57 Mon Sep 17 00:00:00 2001 From: Christoph Junghans Date: Sun, 27 Aug 2017 07:06:08 -0600 Subject: [PATCH 07/27] cmake: move shared libs install warning in one place --- cmake/CMakeLists.txt | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 6abf445f3d..c130b9d090 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -43,7 +43,11 @@ include(CheckCCompilerFlag) # User input options # ######################################################################## option(BUILD_SHARED_LIBS "Build shared libs" OFF) +option(BUILD_SHARED_PKG_LIBS "Build package libs shared" OFF) option(INSTALL_LIB "Install lammps library and header" ON) +if(NOT INSTALL_LIB AND ( BUILD_SHARED_LIBS OR BUILD_SHARED_PKG_LIBS ) ) + message(FATAL_ERROR "Shared libs need to be installed, enable install with -DINSTALL_LIB=ON") +endif() include(GNUInstallDirs) set(LAMMPS_LINK_LIBS) @@ -171,8 +175,6 @@ if(ENABLE_MSCG OR ENABLE_USER-ATC OR ENABLE_USER-AWPMD OR ENABLE_USER-QUIP) set_target_properties(${PKG_LIB} PROPERTIES SOVERSION ${SOVERSION}) if(INSTALL_LIB) install(TARGETS linalg LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) - else() - message(FATAL_ERROR "Shared library has to be installed, use -DINSTALL_LIB=ON to install lammps with a library") endif() else() add_library(linalg STATIC ${LAPACK_SOURCES}) @@ -354,13 +356,10 @@ foreach(SIMPLE_LIB REAX MEAM POEMS USER-ATC USER-AWPMD USER-COLVARS USER-H5MD ${LAMMPS_LIB_SOURCE_DIR}/${PKG_LIB}/*.c ${LAMMPS_LIB_SOURCE_DIR}/${PKG_LIB}/*.cpp) if(${PKG_LIB}_SOURCES) #some libs (e.g. molfile have headers only) if(BUILD_SHARED_PKG_LIBS) - option(BUILD_SHARED_PKG_LIBS "Build package libs shared" OFF) add_library(${PKG_LIB} SHARED ${${PKG_LIB}_SOURCES}) set_target_properties(${PKG_LIB} PROPERTIES SOVERSION ${SOVERSION}) if(INSTALL_LIB) install(TARGETS ${PKG_LIB} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) - else() - message(FATAL_ERROR "Shared library has to be installed, use -DINSTALL_LIB=ON to install lammps with a library") endif() else() add_library(${PKG_LIB} STATIC ${${PKG_LIB}_SOURCES}) @@ -562,8 +561,6 @@ set_target_properties(lammps PROPERTIES SOVERSION ${SOVERSION}) if(INSTALL_LIB) install(TARGETS lammps LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) install(FILES ${LAMMPS_SOURCE_DIR}/lammps.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) -elseif(BUILD_SHARED_LIBS) - message(FATAL_ERROR "Shared library has to be installed, use -DINSTALL_LIB=ON to install lammps with a library") endif() add_executable(lmp ${LMP_SOURCES}) From b7ec720f91fcda0513fa5757ff0d95f6755a6c39 Mon Sep 17 00:00:00 2001 From: Christoph Junghans Date: Sun, 27 Aug 2017 07:13:55 -0600 Subject: [PATCH 08/27] link QUIP against LAPACK_LIB too --- cmake/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index c130b9d090..b15e7183e7 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -252,7 +252,7 @@ endif() if(ENABLE_USER-QUIP) find_package(QUIP REQUIRED) - list(APPEND LAMMPS_LINK_LIBS ${QUIP_LIBRARIES} ${CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES}) + list(APPEND LAMMPS_LINK_LIBS ${QUIP_LIBRARIES} ${LAPACK_LIBRARIES} ${CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES}) endif() if(ENABLE_USER-QMMM) From bdc117bf1089ea63dd18226cb9b495e7d6332463 Mon Sep 17 00:00:00 2001 From: Christoph Junghans Date: Sun, 27 Aug 2017 07:15:00 -0600 Subject: [PATCH 09/27] cmake: convert mscg into a lib --- cmake/CMakeLists.txt | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index b15e7183e7..aec40ca852 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -291,13 +291,11 @@ if(ENABLE_MSCG) WORKING_DIRECTORY ${LAMMPS_LIB_BINARY_DIR}/mscg) endif() file(GLOB MSCG_SOURCES ${LAMMPS_LIB_MSCG_BIN_DIR}/*.cpp) - list(APPEND LIB_SOURCES ${MSCG_SOURCES}) - foreach(MSCG_SOURCE ${MSCG_SOURCES}) - set_property(SOURCE ${MSCG_SOURCE} APPEND PROPERTY COMPILE_DEFINITIONS - DIMENSION=3 _exclude_gromacs=1) - endforeach() - include_directories(${LAMMPS_LIB_MSCG_BIN_DIR} ${GSL_INCLUDE_DIRS}) - list(APPEND LAMMPS_LINK_LIBS ${GSL_LIBRARIES}) + add_library(mscg ${MSCG_SOURCES}) + list(APPEND LAMMPS_LINK_LIBS mscg) + target_compile_options(mscg PRIVATE -DDIMENSION=3 -D_exclude_gromacs=1) + target_include_directories(mscg PUBLIC ${LAMMPS_LIB_MSCG_BIN_DIR}) + target_link_libraries(mscg ${GSL_LIBRARIES} ${LAPACK_LIBRARIES}) endif() ######################################################################## From 98f27162ba6aea6bbb554b6a544756dac5a9cba1 Mon Sep 17 00:00:00 2001 From: Christoph Junghans Date: Sun, 27 Aug 2017 08:58:47 -0600 Subject: [PATCH 10/27] make libmpi_stubs --- cmake/CMakeLists.txt | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index aec40ca852..ea06528daa 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -62,8 +62,17 @@ if(ENABLE_MPI) endif() else() file(GLOB MPI_SOURCES ${LAMMPS_SOURCE_DIR}/STUBS/mpi.c) - list(APPEND LIB_SOURCES ${MPI_SOURCES}) + if(BUILD_SHARED_PKG_LIBS) + add_library(mpi_stubs SHARED ${MPI_SOURCES}) + set_target_properties(${PKG_LIB} PROPERTIES SOVERSION ${SOVERSION}) + if(INSTALL_LIB) + install(TARGETS mpi_stubs LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + endif() + else() + add_library(mpi_stubs STATIC ${MPI_SOURCES}) + endif() include_directories(${LAMMPS_SOURCE_DIR}/STUBS) + list(APPEND LAMMPS_LINK_LIBS mpi_stubs) endif() set(LAMMPS_SIZE_LIMIT "LAMMPS_SMALLBIG" CACHE STRING "Lammps size limit") @@ -160,7 +169,8 @@ endif() if(ENABLE_MISC) option(LAMMPS_XDR "include XDR compatibility files for doing particle dumps in XTC format" OFF) if(LAMMPS_XDR) - add_definitions(-DLAMMPS_XDR) + target_compile_options(pkg_MISC PRIVATE -DLAMMPS_XDR) + add_definitions(-DLAMMPS_XDR) # for liblammps endif() endif() From e4415735f2e53a7486bf2f68fd6326789041d68c Mon Sep 17 00:00:00 2001 From: Christoph Junghans Date: Sun, 27 Aug 2017 12:10:46 -0600 Subject: [PATCH 11/27] check for '-fno-second-underscore' --- cmake/CMakeLists.txt | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index ea06528daa..ecffc0484d 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -135,6 +135,8 @@ endif() ###################################################### if(ENABLE_REAX OR ENABLE_MEAM OR ENABLE_USER-QUIP OR ENABLE_USER-QMMM) enable_language(Fortran) + include(CheckFortranCompilerFlag) + check_Fortran_compiler_flag("-fno-second-underscore" FC_HAS_NO_SECOND_UNDERSCORE) endif() if(ENABLE_KOKKOS OR ENABLE_MSCG) @@ -189,7 +191,11 @@ if(ENABLE_MSCG OR ENABLE_USER-ATC OR ENABLE_USER-AWPMD OR ENABLE_USER-QUIP) else() add_library(linalg STATIC ${LAPACK_SOURCES}) endif() - target_compile_options(linalg PRIVATE -fno-second-underscore) + include(CheckFortranCompilerFlag) + check_Fortran_compiler_flag("-fno-second-underscore" FC_HAS_NO_SECOND_UNDERSCORE) + if(FC_HAS_NO_SECOND_UNDERSCORE) + target_compile_options(linalg PRIVATE -fno-second-underscore) + endif() set(LAPACK_LIBRARIES linalg) endif() endif() @@ -399,6 +405,19 @@ if(ENABLE_USER-H5MD) target_link_libraries(h5md ${HDF5_LIBRARIES}) target_include_directories(h5md PRIVATE ${HDF5_INCLUDE_DIRS}) endif() + +if(ENABLE_MEAM AND FC_HAS_NO_SECOND_UNDERSCORE) + foreach(FSRC ${meam_SOURCES}) + if(FSRC MATCHES "\.F$") + set_property(SOURCE ${MSCG_SOURCE} APPEND PROPERTY COMPILE_FLAGS "-fno-second-underscore") + endif() + endforeach() +endif() + +if(ENABLE_REAX AND FC_HAS_NO_SECOND_UNDERSCORE) + target_compile_options(reax PRIVATE -fno-second-underscore) +endif() + ###################################################################### # packages which selectively include variants based on enabled styles From bc1186898697aa0bf28f79c0c4e74f26002153e5 Mon Sep 17 00:00:00 2001 From: Christoph Junghans Date: Sun, 27 Aug 2017 12:13:35 -0600 Subject: [PATCH 12/27] cmake: fixed a typo --- cmake/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index ecffc0484d..96a4082c31 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -171,7 +171,6 @@ endif() if(ENABLE_MISC) option(LAMMPS_XDR "include XDR compatibility files for doing particle dumps in XTC format" OFF) if(LAMMPS_XDR) - target_compile_options(pkg_MISC PRIVATE -DLAMMPS_XDR) add_definitions(-DLAMMPS_XDR) # for liblammps endif() endif() From c196025ea958d4809c35f6775eda32995ef88e34 Mon Sep 17 00:00:00 2001 From: Christoph Junghans Date: Sun, 27 Aug 2017 12:23:30 -0600 Subject: [PATCH 13/27] make molfile less special --- cmake/CMakeLists.txt | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 96a4082c31..503adeb3e8 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -250,7 +250,10 @@ if(ENABLE_VORONOI) endif() if(ENABLE_USER-MOLFILE) - list(APPEND LAMMPS_LINK_LIBS ${CMAKE_DL_LIBS}) + add_library(molfile INTERFACE) + target_include_directories(molfile INTERFACE ${LAMMPS_LIB_SOURCE_DIR}/molfile) + target_link_libraries(molfile INTERFACE ${CMAKE_DL_LIBS}) + list(APPEND LAMMPS_LINK_LIBS molfile) endif() if(ENABLE_USER-NETCDF) @@ -361,32 +364,28 @@ endforeach() # add lib sources of (simple) enabled packages ############################################ foreach(SIMPLE_LIB REAX MEAM POEMS USER-ATC USER-AWPMD USER-COLVARS USER-H5MD - USER-MOLFILE USER-QMMM) + USER-QMMM) if(ENABLE_${SIMPLE_LIB}) string(REGEX REPLACE "^USER-" "" PKG_LIB "${SIMPLE_LIB}") string(TOLOWER "${PKG_LIB}" PKG_LIB) file(GLOB_RECURSE ${PKG_LIB}_SOURCES ${LAMMPS_LIB_SOURCE_DIR}/${PKG_LIB}/*.F ${LAMMPS_LIB_SOURCE_DIR}/${PKG_LIB}/*.c ${LAMMPS_LIB_SOURCE_DIR}/${PKG_LIB}/*.cpp) - if(${PKG_LIB}_SOURCES) #some libs (e.g. molfile have headers only) - if(BUILD_SHARED_PKG_LIBS) - add_library(${PKG_LIB} SHARED ${${PKG_LIB}_SOURCES}) - set_target_properties(${PKG_LIB} PROPERTIES SOVERSION ${SOVERSION}) - if(INSTALL_LIB) - install(TARGETS ${PKG_LIB} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) - endif() - else() - add_library(${PKG_LIB} STATIC ${${PKG_LIB}_SOURCES}) - endif() - list(APPEND LAMMPS_LINK_LIBS ${PKG_LIB}) - if(PKG_LIB STREQUAL awpmd) - target_include_directories(awpmd PUBLIC ${LAMMPS_LIB_SOURCE_DIR}/awpmd/systems/interact ${LAMMPS_LIB_SOURCE_DIR}/awpmd/ivutils/include) - elseif(PKG_LIB STREQUAL h5md) - target_include_directories(h5md PUBLIC ${LAMMPS_LIB_SOURCE_DIR}/h5md/include) - else() - target_include_directories(${PKG_LIB} PUBLIC ${LAMMPS_LIB_SOURCE_DIR}/${PKG_LIB}) + if(BUILD_SHARED_PKG_LIBS) + add_library(${PKG_LIB} SHARED ${${PKG_LIB}_SOURCES}) + set_target_properties(${PKG_LIB} PROPERTIES SOVERSION ${SOVERSION}) + if(INSTALL_LIB) + install(TARGETS ${PKG_LIB} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif() else() - include_directories(${LAMMPS_LIB_SOURCE_DIR}/${PKG_LIB}) + add_library(${PKG_LIB} STATIC ${${PKG_LIB}_SOURCES}) + endif() + list(APPEND LAMMPS_LINK_LIBS ${PKG_LIB}) + if(PKG_LIB STREQUAL awpmd) + target_include_directories(awpmd PUBLIC ${LAMMPS_LIB_SOURCE_DIR}/awpmd/systems/interact ${LAMMPS_LIB_SOURCE_DIR}/awpmd/ivutils/include) + elseif(PKG_LIB STREQUAL h5md) + target_include_directories(h5md PUBLIC ${LAMMPS_LIB_SOURCE_DIR}/h5md/include) + else() + target_include_directories(${PKG_LIB} PUBLIC ${LAMMPS_LIB_SOURCE_DIR}/${PKG_LIB}) endif() endif() endforeach() From 5308ee67fa378e65fcb8f066520c19a894bc0fbe Mon Sep 17 00:00:00 2001 From: Christoph Junghans Date: Sun, 27 Aug 2017 13:45:48 -0600 Subject: [PATCH 14/27] fix shared build and mscg install --- cmake/CMakeLists.txt | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 503adeb3e8..9fec9bc306 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -64,7 +64,7 @@ else() file(GLOB MPI_SOURCES ${LAMMPS_SOURCE_DIR}/STUBS/mpi.c) if(BUILD_SHARED_PKG_LIBS) add_library(mpi_stubs SHARED ${MPI_SOURCES}) - set_target_properties(${PKG_LIB} PROPERTIES SOVERSION ${SOVERSION}) + set_target_properties(mpi_stubs PROPERTIES SOVERSION ${SOVERSION}) if(INSTALL_LIB) install(TARGETS mpi_stubs LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif() @@ -190,6 +190,9 @@ if(ENABLE_MSCG OR ENABLE_USER-ATC OR ENABLE_USER-AWPMD OR ENABLE_USER-QUIP) else() add_library(linalg STATIC ${LAPACK_SOURCES}) endif() + if(BUILD_SHARED_LIBS) + set_target_properties(linalg PROPERTIES POSITION_INDEPENDENT_CODE ON) + endif() include(CheckFortranCompilerFlag) check_Fortran_compiler_flag("-fno-second-underscore" FC_HAS_NO_SECOND_UNDERSCORE) if(FC_HAS_NO_SECOND_UNDERSCORE) @@ -309,7 +312,18 @@ if(ENABLE_MSCG) WORKING_DIRECTORY ${LAMMPS_LIB_BINARY_DIR}/mscg) endif() file(GLOB MSCG_SOURCES ${LAMMPS_LIB_MSCG_BIN_DIR}/*.cpp) - add_library(mscg ${MSCG_SOURCES}) + if(BUILD_SHARED_PKG_LIBS) + add_library(mscg SHARED ${MSCG_SOURCES}) + set_target_properties(mscg PROPERTIES SOVERSION ${SOVERSION}) + if(INSTALL_LIB) + install(TARGETS mscg LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + endif() + else() + add_library(mscg STATIC ${MSCG_SOURCES}) + endif() + if(BUILD_SHARED_LIBS) + set_target_properties(mscg PROPERTIES POSITION_INDEPENDENT_CODE ON) + endif() list(APPEND LAMMPS_LINK_LIBS mscg) target_compile_options(mscg PRIVATE -DDIMENSION=3 -D_exclude_gromacs=1) target_include_directories(mscg PUBLIC ${LAMMPS_LIB_MSCG_BIN_DIR}) @@ -379,6 +393,9 @@ foreach(SIMPLE_LIB REAX MEAM POEMS USER-ATC USER-AWPMD USER-COLVARS USER-H5MD else() add_library(${PKG_LIB} STATIC ${${PKG_LIB}_SOURCES}) endif() + if(BUILD_SHARED_LIBS) + set_target_properties(${PKG_LIB} PROPERTIES POSITION_INDEPENDENT_CODE ON) + endif() list(APPEND LAMMPS_LINK_LIBS ${PKG_LIB}) if(PKG_LIB STREQUAL awpmd) target_include_directories(awpmd PUBLIC ${LAMMPS_LIB_SOURCE_DIR}/awpmd/systems/interact ${LAMMPS_LIB_SOURCE_DIR}/awpmd/ivutils/include) From 313b8bc2fad06dabf96469b7bb25740295eada08 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Sun, 27 Aug 2017 16:58:19 -0400 Subject: [PATCH 15/27] build lib/gpu as a library --- cmake/CMakeLists.txt | 58 +++++++++++++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 19 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 9fec9bc306..03f9b2f7f3 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -535,36 +535,31 @@ if(ENABLE_GPU) if(NOT BIN2C) message(FATAL_ERROR "Couldn't find bin2c, use -DBIN2C helping cmake to find it.") endif() - include_directories(${CUDA_INCLUDE_DIRS}) - list(APPEND LAMMPS_LINK_LIBS ${CUDA_LIBRARIES} ${CUDA_CUDA_LIBRARY}) set(GPU_PREC "SINGLE_DOUBLE" CACHE STRING "Lammps gpu precision size") set_property(CACHE GPU_PREC PROPERTY STRINGS SINGLE_DOUBLE SINGLE_SINGLE DOUBLE_DOUBLE) - add_definitions(-D_${GPU_PREC}) - add_definitions(-DNV_KERNEL -DUCL_CUDADR) option(CUDPP_OPT "Enable CUDPP_OPT" ON) - - set(GPU_SOURCES_DIR ${LAMMPS_SOURCE_DIR}/GPU) - set(GPU_SOURCES ${GPU_SOURCES_DIR}/gpu_extra.h) - - set_property(GLOBAL PROPERTY "GPU_SOURCES" "${GPU_SOURCES}") - - # detects styles which have GPU version - RegisterStylesExt(${GPU_SOURCES_DIR} opt GPU_SOURCES) - - get_property(GPU_SOURCES GLOBAL PROPERTY GPU_SOURCES) file(GLOB GPU_LIB_SOURCES ${LAMMPS_LIB_SOURCE_DIR}/gpu/*.cpp) file(GLOB GPU_LIB_CU ${LAMMPS_LIB_SOURCE_DIR}/gpu/*.cu ${CMAKE_SOURCE_DIR}/gpu/*.cu) file(GLOB_RECURSE GPU_NOT_LIB_CU ${LAMMPS_LIB_SOURCE_DIR}/gpu/lal_pppm.cu) list(REMOVE_ITEM GPU_LIB_CU ${GPU_NOT_LIB_CU}) - include_directories(${GPU_SOURCES_DIR} ${LAMMPS_LIB_SOURCE_DIR}/gpu ${LAMMPS_LIB_BINARY_DIR}/gpu) + + # still missing a way to limit defines to GPU build only + # something like cuda_compile_definitions() + # one way is this, the other adding it to OPTIONS + add_definitions(-D_${GPU_PREC}) + add_definitions(-DNV_KERNEL -DUCL_CUDADR) + + cuda_include_directories(${LAMMPS_LIB_SOURCE_DIR}/gpu ${LAMMPS_LIB_BINARY_DIR}/gpu) + if(CUDPP_OPT) - include_directories(${LAMMPS_LIB_SOURCE_DIR}/gpu/cudpp_mini) - add_definitions(-DCUDPP_OPT) + cuda_include_directories(${LAMMPS_LIB_SOURCE_DIR}/gpu/cudpp_mini) file(GLOB GPU_LIB_CUDPP_SOURCES ${LAMMPS_LIB_SOURCE_DIR}/gpu/cudpp_mini/*.cpp) file(GLOB GPU_LIB_CUDPP_CU ${LAMMPS_LIB_SOURCE_DIR}/gpu/cudpp_mini/*.cu) endif() + cuda_compile(GPU_OBJS ${GPU_LIB_CU} ${GPU_LIB_CUDPP_CU} OPTIONS $<$:-Xcompiler=-fPIC>) + file(MAKE_DIRECTORY ${LAMMPS_LIB_BINARY_DIR}/gpu) foreach(CU_OBJ ${GPU_OBJS}) get_filename_component(CU_NAME ${CU_OBJ} NAME_WE) @@ -573,14 +568,39 @@ if(ENABLE_GPU) COMMAND ${BIN2C} -c -n ${CU_NAME} ${CU_OBJ} > ${LAMMPS_LIB_BINARY_DIR}/gpu/${CU_NAME}_cubin.h DEPENDS ${CU_OBJ} COMMENT "Generating ${CU_NAME}_cubin.h") - list(APPEND LIB_SOURCES ${LAMMPS_LIB_BINARY_DIR}/gpu/${CU_NAME}_cubin.h) + list(APPEND GPU_LIB_SOURCES ${LAMMPS_LIB_BINARY_DIR}/gpu/${CU_NAME}_cubin.h) if(${CU_NAME} STREQUAL "pppm_d") #pppm_d doesn't get linked into the lib set(CU_FORBIDDEN_OBJ "${CU_OBJ}") endif() endforeach() list(REMOVE_ITEM GPU_OBJS "${CU_FORBIDDEN_OBJ}") - list(APPEND LIB_SOURCES ${GPU_SOURCES} ${GPU_LIB_SOURCES} ${GPU_LIB_CUDPP_SOURCES} ${GPU_OBJS}) set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${LAMMPS_LIB_BINARY_DIR}/gpu/*_cubin.h") + + + cuda_add_library(gpu ${GPU_LIB_SOURCES} ${GPU_LIB_CUDPP_SOURCES} ${GPU_OBJS} STATIC) + target_include_directories(gpu PRIVATE ${LAMMPS_LIB_BINARY_DIR}/gpu) + if(CUDPP_OPT) + target_include_directories(gpu PRIVATE ${LAMMPS_LIB_SOURCE_DIR}/gpu/cudpp_mini) + target_compile_definitions(gpu PRIVATE -DUSE_CUDPP) + endif() + + list(APPEND LAMMPS_LINK_LIBS gpu) + + + # GPU package + + set(GPU_SOURCES_DIR ${LAMMPS_SOURCE_DIR}/GPU) + set(GPU_SOURCES ${GPU_SOURCES_DIR}/gpu_extra.h) + include_directories(${GPU_SOURCES_DIR}) + + set_property(GLOBAL PROPERTY "GPU_SOURCES" "${GPU_SOURCES}") + + # detects styles which have GPU version + RegisterStylesExt(${GPU_SOURCES_DIR} opt GPU_SOURCES) + + get_property(GPU_SOURCES GLOBAL PROPERTY GPU_SOURCES) + + list(APPEND LIB_SOURCES ${GPU_SOURCES}) endif() ###################################################### From 153c771a6ddc58df97b2ef860208a25a7437a4e4 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Sun, 27 Aug 2017 17:27:43 -0400 Subject: [PATCH 16/27] Use PIC in mpi_stubs when BUILD_SHARED_LIBS=on --- cmake/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 03f9b2f7f3..877f8d3e44 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -71,6 +71,9 @@ else() else() add_library(mpi_stubs STATIC ${MPI_SOURCES}) endif() + if(BUILD_SHARED_LIBS) + set_target_properties(mpi_stubs PROPERTIES POSITION_INDEPENDENT_CODE ON) + endif() include_directories(${LAMMPS_SOURCE_DIR}/STUBS) list(APPEND LAMMPS_LINK_LIBS mpi_stubs) endif() From 4bff0087779d9819cd74080fbedb8568f26ff1a1 Mon Sep 17 00:00:00 2001 From: Christoph Junghans Date: Sun, 27 Aug 2017 18:40:55 -0600 Subject: [PATCH 17/27] enable PIC globally --- cmake/CMakeLists.txt | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 877f8d3e44..e038f4d619 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -48,6 +48,9 @@ option(INSTALL_LIB "Install lammps library and header" ON) if(NOT INSTALL_LIB AND ( BUILD_SHARED_LIBS OR BUILD_SHARED_PKG_LIBS ) ) message(FATAL_ERROR "Shared libs need to be installed, enable install with -DINSTALL_LIB=ON") endif() +if(BUILD_SHARED_LIBS OR BUILD_SHARED_PKG_LIBS) + set(CMAKE_POSITION_INDEPENDENT_CODE ON) +endif() include(GNUInstallDirs) set(LAMMPS_LINK_LIBS) @@ -71,9 +74,6 @@ else() else() add_library(mpi_stubs STATIC ${MPI_SOURCES}) endif() - if(BUILD_SHARED_LIBS) - set_target_properties(mpi_stubs PROPERTIES POSITION_INDEPENDENT_CODE ON) - endif() include_directories(${LAMMPS_SOURCE_DIR}/STUBS) list(APPEND LAMMPS_LINK_LIBS mpi_stubs) endif() @@ -193,9 +193,6 @@ if(ENABLE_MSCG OR ENABLE_USER-ATC OR ENABLE_USER-AWPMD OR ENABLE_USER-QUIP) else() add_library(linalg STATIC ${LAPACK_SOURCES}) endif() - if(BUILD_SHARED_LIBS) - set_target_properties(linalg PROPERTIES POSITION_INDEPENDENT_CODE ON) - endif() include(CheckFortranCompilerFlag) check_Fortran_compiler_flag("-fno-second-underscore" FC_HAS_NO_SECOND_UNDERSCORE) if(FC_HAS_NO_SECOND_UNDERSCORE) @@ -324,9 +321,6 @@ if(ENABLE_MSCG) else() add_library(mscg STATIC ${MSCG_SOURCES}) endif() - if(BUILD_SHARED_LIBS) - set_target_properties(mscg PROPERTIES POSITION_INDEPENDENT_CODE ON) - endif() list(APPEND LAMMPS_LINK_LIBS mscg) target_compile_options(mscg PRIVATE -DDIMENSION=3 -D_exclude_gromacs=1) target_include_directories(mscg PUBLIC ${LAMMPS_LIB_MSCG_BIN_DIR}) @@ -396,9 +390,6 @@ foreach(SIMPLE_LIB REAX MEAM POEMS USER-ATC USER-AWPMD USER-COLVARS USER-H5MD else() add_library(${PKG_LIB} STATIC ${${PKG_LIB}_SOURCES}) endif() - if(BUILD_SHARED_LIBS) - set_target_properties(${PKG_LIB} PROPERTIES POSITION_INDEPENDENT_CODE ON) - endif() list(APPEND LAMMPS_LINK_LIBS ${PKG_LIB}) if(PKG_LIB STREQUAL awpmd) target_include_directories(awpmd PUBLIC ${LAMMPS_LIB_SOURCE_DIR}/awpmd/systems/interact ${LAMMPS_LIB_SOURCE_DIR}/awpmd/ivutils/include) From 57872c8b60be02590788c23f32d5d4e2541e2fd6 Mon Sep 17 00:00:00 2001 From: Christoph Junghans Date: Sun, 27 Aug 2017 18:42:32 -0600 Subject: [PATCH 18/27] drop INSTALL_LIB option --- cmake/CMakeLists.txt | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index e038f4d619..a63a67e6cc 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -44,10 +44,6 @@ include(CheckCCompilerFlag) ######################################################################## option(BUILD_SHARED_LIBS "Build shared libs" OFF) option(BUILD_SHARED_PKG_LIBS "Build package libs shared" OFF) -option(INSTALL_LIB "Install lammps library and header" ON) -if(NOT INSTALL_LIB AND ( BUILD_SHARED_LIBS OR BUILD_SHARED_PKG_LIBS ) ) - message(FATAL_ERROR "Shared libs need to be installed, enable install with -DINSTALL_LIB=ON") -endif() if(BUILD_SHARED_LIBS OR BUILD_SHARED_PKG_LIBS) set(CMAKE_POSITION_INDEPENDENT_CODE ON) endif() @@ -68,12 +64,10 @@ else() if(BUILD_SHARED_PKG_LIBS) add_library(mpi_stubs SHARED ${MPI_SOURCES}) set_target_properties(mpi_stubs PROPERTIES SOVERSION ${SOVERSION}) - if(INSTALL_LIB) - install(TARGETS mpi_stubs LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) - endif() else() add_library(mpi_stubs STATIC ${MPI_SOURCES}) endif() + install(TARGETS mpi_stubs LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) include_directories(${LAMMPS_SOURCE_DIR}/STUBS) list(APPEND LAMMPS_LINK_LIBS mpi_stubs) endif() @@ -187,12 +181,10 @@ if(ENABLE_MSCG OR ENABLE_USER-ATC OR ENABLE_USER-AWPMD OR ENABLE_USER-QUIP) if(BUILD_SHARED_PKG_LIBS) add_library(linalg SHARED ${LAPACK_SOURCES}) set_target_properties(${PKG_LIB} PROPERTIES SOVERSION ${SOVERSION}) - if(INSTALL_LIB) - install(TARGETS linalg LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) - endif() else() add_library(linalg STATIC ${LAPACK_SOURCES}) endif() + install(TARGETS linalg LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) include(CheckFortranCompilerFlag) check_Fortran_compiler_flag("-fno-second-underscore" FC_HAS_NO_SECOND_UNDERSCORE) if(FC_HAS_NO_SECOND_UNDERSCORE) @@ -315,12 +307,10 @@ if(ENABLE_MSCG) if(BUILD_SHARED_PKG_LIBS) add_library(mscg SHARED ${MSCG_SOURCES}) set_target_properties(mscg PROPERTIES SOVERSION ${SOVERSION}) - if(INSTALL_LIB) - install(TARGETS mscg LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) - endif() else() add_library(mscg STATIC ${MSCG_SOURCES}) endif() + install(TARGETS mscg LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) list(APPEND LAMMPS_LINK_LIBS mscg) target_compile_options(mscg PRIVATE -DDIMENSION=3 -D_exclude_gromacs=1) target_include_directories(mscg PUBLIC ${LAMMPS_LIB_MSCG_BIN_DIR}) @@ -384,12 +374,10 @@ foreach(SIMPLE_LIB REAX MEAM POEMS USER-ATC USER-AWPMD USER-COLVARS USER-H5MD if(BUILD_SHARED_PKG_LIBS) add_library(${PKG_LIB} SHARED ${${PKG_LIB}_SOURCES}) set_target_properties(${PKG_LIB} PROPERTIES SOVERSION ${SOVERSION}) - if(INSTALL_LIB) - install(TARGETS ${PKG_LIB} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) - endif() else() add_library(${PKG_LIB} STATIC ${${PKG_LIB}_SOURCES}) endif() + install(TARGETS ${PKG_LIB} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) list(APPEND LAMMPS_LINK_LIBS ${PKG_LIB}) if(PKG_LIB STREQUAL awpmd) target_include_directories(awpmd PUBLIC ${LAMMPS_LIB_SOURCE_DIR}/awpmd/systems/interact ${LAMMPS_LIB_SOURCE_DIR}/awpmd/ivutils/include) @@ -614,10 +602,8 @@ include_directories(${LAMMPS_STYLE_HEADERS_DIR}) add_library(lammps ${LIB_SOURCES}) target_link_libraries(lammps ${LAMMPS_LINK_LIBS}) set_target_properties(lammps PROPERTIES SOVERSION ${SOVERSION}) -if(INSTALL_LIB) - install(TARGETS lammps LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) - install(FILES ${LAMMPS_SOURCE_DIR}/lammps.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) -endif() +install(TARGETS lammps LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) +install(FILES ${LAMMPS_SOURCE_DIR}/lammps.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) add_executable(lmp ${LMP_SOURCES}) target_link_libraries(lmp lammps) From f47cc0aab5515bb0790c65a73e8982c79f81551e Mon Sep 17 00:00:00 2001 From: Christoph Junghans Date: Sun, 27 Aug 2017 18:55:28 -0600 Subject: [PATCH 19/27] simpilfy pkg lib build --- cmake/CMakeLists.txt | 38 +++++++++++++------------------------- 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index a63a67e6cc..a0fc2a9801 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -47,6 +47,11 @@ option(BUILD_SHARED_PKG_LIBS "Build package libs shared" OFF) if(BUILD_SHARED_LIBS OR BUILD_SHARED_PKG_LIBS) set(CMAKE_POSITION_INDEPENDENT_CODE ON) endif() +if(BUILD_SHARED_PKG_LIBS) + set(PKG_LIBS_BUILD_TYPE "SHARED") +else() + set(PKG_LIBS_BUILD_TYPE "STATIC") +endif() include(GNUInstallDirs) set(LAMMPS_LINK_LIBS) @@ -61,12 +66,8 @@ if(ENABLE_MPI) endif() else() file(GLOB MPI_SOURCES ${LAMMPS_SOURCE_DIR}/STUBS/mpi.c) - if(BUILD_SHARED_PKG_LIBS) - add_library(mpi_stubs SHARED ${MPI_SOURCES}) - set_target_properties(mpi_stubs PROPERTIES SOVERSION ${SOVERSION}) - else() - add_library(mpi_stubs STATIC ${MPI_SOURCES}) - endif() + add_library(mpi_stubs ${PKG_LIBS_BUILD_TYPE} ${MPI_SOURCES}) + set_target_properties(mpi_stubs PROPERTIES SOVERSION ${SOVERSION}) install(TARGETS mpi_stubs LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) include_directories(${LAMMPS_SOURCE_DIR}/STUBS) list(APPEND LAMMPS_LINK_LIBS mpi_stubs) @@ -177,13 +178,8 @@ if(ENABLE_MSCG OR ENABLE_USER-ATC OR ENABLE_USER-AWPMD OR ENABLE_USER-QUIP) if(NOT LAPACK_FOUND) enable_language(Fortran) file(GLOB LAPACK_SOURCES ${LAMMPS_LIB_SOURCE_DIR}/linalg/*.f) - - if(BUILD_SHARED_PKG_LIBS) - add_library(linalg SHARED ${LAPACK_SOURCES}) - set_target_properties(${PKG_LIB} PROPERTIES SOVERSION ${SOVERSION}) - else() - add_library(linalg STATIC ${LAPACK_SOURCES}) - endif() + add_library(linalg ${PKG_LIBS_BUILD_TYPE} ${LAPACK_SOURCES}) + set_target_properties(${PKG_LIB} PROPERTIES SOVERSION ${SOVERSION}) install(TARGETS linalg LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) include(CheckFortranCompilerFlag) check_Fortran_compiler_flag("-fno-second-underscore" FC_HAS_NO_SECOND_UNDERSCORE) @@ -304,12 +300,8 @@ if(ENABLE_MSCG) WORKING_DIRECTORY ${LAMMPS_LIB_BINARY_DIR}/mscg) endif() file(GLOB MSCG_SOURCES ${LAMMPS_LIB_MSCG_BIN_DIR}/*.cpp) - if(BUILD_SHARED_PKG_LIBS) - add_library(mscg SHARED ${MSCG_SOURCES}) - set_target_properties(mscg PROPERTIES SOVERSION ${SOVERSION}) - else() - add_library(mscg STATIC ${MSCG_SOURCES}) - endif() + add_library(mscg ${PKG_LIBS_BUILD_TYPE} ${MSCG_SOURCES}) + set_target_properties(mscg PROPERTIES SOVERSION ${SOVERSION}) install(TARGETS mscg LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) list(APPEND LAMMPS_LINK_LIBS mscg) target_compile_options(mscg PRIVATE -DDIMENSION=3 -D_exclude_gromacs=1) @@ -371,12 +363,8 @@ foreach(SIMPLE_LIB REAX MEAM POEMS USER-ATC USER-AWPMD USER-COLVARS USER-H5MD string(TOLOWER "${PKG_LIB}" PKG_LIB) file(GLOB_RECURSE ${PKG_LIB}_SOURCES ${LAMMPS_LIB_SOURCE_DIR}/${PKG_LIB}/*.F ${LAMMPS_LIB_SOURCE_DIR}/${PKG_LIB}/*.c ${LAMMPS_LIB_SOURCE_DIR}/${PKG_LIB}/*.cpp) - if(BUILD_SHARED_PKG_LIBS) - add_library(${PKG_LIB} SHARED ${${PKG_LIB}_SOURCES}) - set_target_properties(${PKG_LIB} PROPERTIES SOVERSION ${SOVERSION}) - else() - add_library(${PKG_LIB} STATIC ${${PKG_LIB}_SOURCES}) - endif() + add_library(${PKG_LIB} ${PKG_LIBS_BUILD_TYPE} ${${PKG_LIB}_SOURCES}) + set_target_properties(${PKG_LIB} PROPERTIES SOVERSION ${SOVERSION}) install(TARGETS ${PKG_LIB} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) list(APPEND LAMMPS_LINK_LIBS ${PKG_LIB}) if(PKG_LIB STREQUAL awpmd) From c8dfe0c3de6f70c1dc65326ca33b1c97f2168e70 Mon Sep 17 00:00:00 2001 From: Christoph Junghans Date: Mon, 28 Aug 2017 13:17:27 -0600 Subject: [PATCH 20/27] drop BUILD_SHARED_PKG_LIBS and make all pkglibs static --- cmake/CMakeLists.txt | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index a0fc2a9801..638a79e891 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -43,15 +43,9 @@ include(CheckCCompilerFlag) # User input options # ######################################################################## option(BUILD_SHARED_LIBS "Build shared libs" OFF) -option(BUILD_SHARED_PKG_LIBS "Build package libs shared" OFF) -if(BUILD_SHARED_LIBS OR BUILD_SHARED_PKG_LIBS) +if(BUILD_SHARED_LIBS) # for all pkg libs, mpi_stubs and linalg set(CMAKE_POSITION_INDEPENDENT_CODE ON) endif() -if(BUILD_SHARED_PKG_LIBS) - set(PKG_LIBS_BUILD_TYPE "SHARED") -else() - set(PKG_LIBS_BUILD_TYPE "STATIC") -endif() include(GNUInstallDirs) set(LAMMPS_LINK_LIBS) @@ -66,9 +60,8 @@ if(ENABLE_MPI) endif() else() file(GLOB MPI_SOURCES ${LAMMPS_SOURCE_DIR}/STUBS/mpi.c) - add_library(mpi_stubs ${PKG_LIBS_BUILD_TYPE} ${MPI_SOURCES}) + add_library(mpi_stubs STATIC ${MPI_SOURCES}) set_target_properties(mpi_stubs PROPERTIES SOVERSION ${SOVERSION}) - install(TARGETS mpi_stubs LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) include_directories(${LAMMPS_SOURCE_DIR}/STUBS) list(APPEND LAMMPS_LINK_LIBS mpi_stubs) endif() @@ -178,9 +171,8 @@ if(ENABLE_MSCG OR ENABLE_USER-ATC OR ENABLE_USER-AWPMD OR ENABLE_USER-QUIP) if(NOT LAPACK_FOUND) enable_language(Fortran) file(GLOB LAPACK_SOURCES ${LAMMPS_LIB_SOURCE_DIR}/linalg/*.f) - add_library(linalg ${PKG_LIBS_BUILD_TYPE} ${LAPACK_SOURCES}) + add_library(linalg STATIC ${LAPACK_SOURCES}) set_target_properties(${PKG_LIB} PROPERTIES SOVERSION ${SOVERSION}) - install(TARGETS linalg LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) include(CheckFortranCompilerFlag) check_Fortran_compiler_flag("-fno-second-underscore" FC_HAS_NO_SECOND_UNDERSCORE) if(FC_HAS_NO_SECOND_UNDERSCORE) @@ -300,9 +292,8 @@ if(ENABLE_MSCG) WORKING_DIRECTORY ${LAMMPS_LIB_BINARY_DIR}/mscg) endif() file(GLOB MSCG_SOURCES ${LAMMPS_LIB_MSCG_BIN_DIR}/*.cpp) - add_library(mscg ${PKG_LIBS_BUILD_TYPE} ${MSCG_SOURCES}) + add_library(mscg STATIC ${MSCG_SOURCES}) set_target_properties(mscg PROPERTIES SOVERSION ${SOVERSION}) - install(TARGETS mscg LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) list(APPEND LAMMPS_LINK_LIBS mscg) target_compile_options(mscg PRIVATE -DDIMENSION=3 -D_exclude_gromacs=1) target_include_directories(mscg PUBLIC ${LAMMPS_LIB_MSCG_BIN_DIR}) @@ -363,9 +354,8 @@ foreach(SIMPLE_LIB REAX MEAM POEMS USER-ATC USER-AWPMD USER-COLVARS USER-H5MD string(TOLOWER "${PKG_LIB}" PKG_LIB) file(GLOB_RECURSE ${PKG_LIB}_SOURCES ${LAMMPS_LIB_SOURCE_DIR}/${PKG_LIB}/*.F ${LAMMPS_LIB_SOURCE_DIR}/${PKG_LIB}/*.c ${LAMMPS_LIB_SOURCE_DIR}/${PKG_LIB}/*.cpp) - add_library(${PKG_LIB} ${PKG_LIBS_BUILD_TYPE} ${${PKG_LIB}_SOURCES}) + add_library(${PKG_LIB} STATIC ${${PKG_LIB}_SOURCES}) set_target_properties(${PKG_LIB} PROPERTIES SOVERSION ${SOVERSION}) - install(TARGETS ${PKG_LIB} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) list(APPEND LAMMPS_LINK_LIBS ${PKG_LIB}) if(PKG_LIB STREQUAL awpmd) target_include_directories(awpmd PUBLIC ${LAMMPS_LIB_SOURCE_DIR}/awpmd/systems/interact ${LAMMPS_LIB_SOURCE_DIR}/awpmd/ivutils/include) @@ -590,8 +580,10 @@ include_directories(${LAMMPS_STYLE_HEADERS_DIR}) add_library(lammps ${LIB_SOURCES}) target_link_libraries(lammps ${LAMMPS_LINK_LIBS}) set_target_properties(lammps PROPERTIES SOVERSION ${SOVERSION}) -install(TARGETS lammps LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) -install(FILES ${LAMMPS_SOURCE_DIR}/lammps.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) +if(BUILD_SHARED_LIBS) + install(TARGETS lammps LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + install(FILES ${LAMMPS_SOURCE_DIR}/lammps.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) +endif() add_executable(lmp ${LMP_SOURCES}) target_link_libraries(lmp lammps) From 62928a16377bc449449f2597093af66b2da91596 Mon Sep 17 00:00:00 2001 From: Christoph Junghans Date: Mon, 28 Aug 2017 13:24:41 -0600 Subject: [PATCH 21/27] make GPU flags local to libgpu --- cmake/CMakeLists.txt | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 638a79e891..4296a040c8 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -504,12 +504,6 @@ if(ENABLE_GPU) file(GLOB_RECURSE GPU_NOT_LIB_CU ${LAMMPS_LIB_SOURCE_DIR}/gpu/lal_pppm.cu) list(REMOVE_ITEM GPU_LIB_CU ${GPU_NOT_LIB_CU}) - # still missing a way to limit defines to GPU build only - # something like cuda_compile_definitions() - # one way is this, the other adding it to OPTIONS - add_definitions(-D_${GPU_PREC}) - add_definitions(-DNV_KERNEL -DUCL_CUDADR) - cuda_include_directories(${LAMMPS_LIB_SOURCE_DIR}/gpu ${LAMMPS_LIB_BINARY_DIR}/gpu) if(CUDPP_OPT) @@ -518,7 +512,9 @@ if(ENABLE_GPU) file(GLOB GPU_LIB_CUDPP_CU ${LAMMPS_LIB_SOURCE_DIR}/gpu/cudpp_mini/*.cu) endif() - cuda_compile(GPU_OBJS ${GPU_LIB_CU} ${GPU_LIB_CUDPP_CU} OPTIONS $<$:-Xcompiler=-fPIC>) + cuda_compile(GPU_OBJS ${GPU_LIB_CU} ${GPU_LIB_CUDPP_CU} OPTIONS + $<$:-Xcompiler=-fPIC> + -DNV_KERNEL -DUCL_CUDADR -D_${GPU_PREC}) file(MAKE_DIRECTORY ${LAMMPS_LIB_BINARY_DIR}/gpu) foreach(CU_OBJ ${GPU_OBJS}) From 9207f6540e848212d6fe2512edc3a52880cbcbc3 Mon Sep 17 00:00:00 2001 From: Christoph Junghans Date: Mon, 28 Aug 2017 14:11:21 -0600 Subject: [PATCH 22/27] fix liblammps install --- cmake/CMakeLists.txt | 7 ++++++- cmake/pkgconfig/liblammps.pc.in | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 cmake/pkgconfig/liblammps.pc.in diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 4296a040c8..d143f5bc2f 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -49,6 +49,7 @@ endif() include(GNUInstallDirs) set(LAMMPS_LINK_LIBS) +set(LAMMPS_API_DEFINES) option(ENABLE_MPI "Build MPI version" OFF) if(ENABLE_MPI) find_package(MPI REQUIRED) @@ -69,6 +70,7 @@ endif() set(LAMMPS_SIZE_LIMIT "LAMMPS_SMALLBIG" CACHE STRING "Lammps size limit") set_property(CACHE LAMMPS_SIZE_LIMIT PROPERTY STRINGS LAMMPS_SMALLBIG LAMMPS_BIGBIG LAMMPS_SMALLSMALL) add_definitions(-D${LAMMPS_SIZE_LIMIT}) +set(LAMMPS_API_DEFINES "${LAMMPS_API_DEFINES} -D${LAMMPS_SIZE_LIMIT}") set(LAMMPS_MEMALIGN "64" CACHE STRING "enables the use of the posix_memalign() call instead of malloc() when large chunks or memory are allocated by LAMMPS") add_definitions(-DLAMMPS_MEMALIGN=${LAMMPS_MEMALIGN}) @@ -76,6 +78,7 @@ add_definitions(-DLAMMPS_MEMALIGN=${LAMMPS_MEMALIGN}) option(LAMMPS_EXCEPTIONS "enable the use of C++ exceptions for error messages (useful for library interface)" OFF) if(LAMMPS_EXCEPTIONS) add_definitions(-DLAMMPS_EXCEPTIONS) + set(LAMMPS_API_DEFINES "${LAMMPS_API_DEFINES -DLAMMPS_EXCEPTIONS") endif() option(CMAKE_VERBOSE_MAKEFILE "Verbose makefile" OFF) @@ -578,7 +581,9 @@ target_link_libraries(lammps ${LAMMPS_LINK_LIBS}) set_target_properties(lammps PROPERTIES SOVERSION ${SOVERSION}) if(BUILD_SHARED_LIBS) install(TARGETS lammps LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) - install(FILES ${LAMMPS_SOURCE_DIR}/lammps.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + install(FILES ${LAMMPS_SOURCE_DIR}/library.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/lammps) + configure_file(pkgconfig/liblammps.pc.in ${CMAKE_CURRENT_BINARY_DIR}/liblammps.pc @ONLY) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/liblammps.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) endif() add_executable(lmp ${LMP_SOURCES}) diff --git a/cmake/pkgconfig/liblammps.pc.in b/cmake/pkgconfig/liblammps.pc.in new file mode 100644 index 0000000000..643b4ba501 --- /dev/null +++ b/cmake/pkgconfig/liblammps.pc.in @@ -0,0 +1,18 @@ +# pkg-config file for lammps +# https://people.freedesktop.org/~dbn/pkg-config-guide.html +# Usage: cc `pkg-config --cflags --libs liblammps` -o myapp myapp.c +# after you added @CMAKE_INSTALL_FULL_LIBDIR@/pkg-config to PKG_CONFIG_PATH, +# e.g. export PKG_CONFIG_PATH=@CMAKE_INSTALL_FULL_LIBDIR@/pkgconfig + +prefix=@CMAKE_INSTALL_FULL_PREFIX@ +libdir=@CMAKE_INSTALL_FULL_LIBDIR@ +includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ + +Name: liblammps +Description: Large-scale Atomic/Molecular Massively Parallel Simulator Library +URL: http://lammps.sandia.gov +Version: +Requires: +Libs: -L${libdir} -llammps +Libs.private: -lm +Cflags: -I${includedir} @LAMMPS_API_DEFINES@ From 19b77857dc3efbe51a949b82d3251fa20ba3abe7 Mon Sep 17 00:00:00 2001 From: Christoph Junghans Date: Mon, 28 Aug 2017 14:59:01 -0600 Subject: [PATCH 23/27] fix Fortran flags for MEAM --- cmake/CMakeLists.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index d143f5bc2f..f49dfb977e 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -386,8 +386,10 @@ endif() if(ENABLE_MEAM AND FC_HAS_NO_SECOND_UNDERSCORE) foreach(FSRC ${meam_SOURCES}) - if(FSRC MATCHES "\.F$") - set_property(SOURCE ${MSCG_SOURCE} APPEND PROPERTY COMPILE_FLAGS "-fno-second-underscore") + string(REGEX REPLACE "^.*\\." "" FEXT "${FSRC}") + list(FIND CMAKE_Fortran_SOURCE_FILE_EXTENSIONS "${FEXT}" FINDEX) + if(FINDEX GREATER -1) + set_property(SOURCE ${FSRC} APPEND PROPERTY COMPILE_FLAGS "-fno-second-underscore") endif() endforeach() endif() From 098861375bf08d5a64b8353b7f69e18bca7c5922 Mon Sep 17 00:00:00 2001 From: Christoph Junghans Date: Mon, 28 Aug 2017 16:18:58 -0600 Subject: [PATCH 24/27] SOVERSION not needed for STATIC libs --- cmake/CMakeLists.txt | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index f49dfb977e..aee928ed9a 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -62,7 +62,6 @@ if(ENABLE_MPI) else() file(GLOB MPI_SOURCES ${LAMMPS_SOURCE_DIR}/STUBS/mpi.c) add_library(mpi_stubs STATIC ${MPI_SOURCES}) - set_target_properties(mpi_stubs PROPERTIES SOVERSION ${SOVERSION}) include_directories(${LAMMPS_SOURCE_DIR}/STUBS) list(APPEND LAMMPS_LINK_LIBS mpi_stubs) endif() @@ -175,7 +174,6 @@ if(ENABLE_MSCG OR ENABLE_USER-ATC OR ENABLE_USER-AWPMD OR ENABLE_USER-QUIP) enable_language(Fortran) file(GLOB LAPACK_SOURCES ${LAMMPS_LIB_SOURCE_DIR}/linalg/*.f) add_library(linalg STATIC ${LAPACK_SOURCES}) - set_target_properties(${PKG_LIB} PROPERTIES SOVERSION ${SOVERSION}) include(CheckFortranCompilerFlag) check_Fortran_compiler_flag("-fno-second-underscore" FC_HAS_NO_SECOND_UNDERSCORE) if(FC_HAS_NO_SECOND_UNDERSCORE) @@ -296,7 +294,6 @@ if(ENABLE_MSCG) endif() file(GLOB MSCG_SOURCES ${LAMMPS_LIB_MSCG_BIN_DIR}/*.cpp) add_library(mscg STATIC ${MSCG_SOURCES}) - set_target_properties(mscg PROPERTIES SOVERSION ${SOVERSION}) list(APPEND LAMMPS_LINK_LIBS mscg) target_compile_options(mscg PRIVATE -DDIMENSION=3 -D_exclude_gromacs=1) target_include_directories(mscg PUBLIC ${LAMMPS_LIB_MSCG_BIN_DIR}) @@ -358,7 +355,6 @@ foreach(SIMPLE_LIB REAX MEAM POEMS USER-ATC USER-AWPMD USER-COLVARS USER-H5MD file(GLOB_RECURSE ${PKG_LIB}_SOURCES ${LAMMPS_LIB_SOURCE_DIR}/${PKG_LIB}/*.F ${LAMMPS_LIB_SOURCE_DIR}/${PKG_LIB}/*.c ${LAMMPS_LIB_SOURCE_DIR}/${PKG_LIB}/*.cpp) add_library(${PKG_LIB} STATIC ${${PKG_LIB}_SOURCES}) - set_target_properties(${PKG_LIB} PROPERTIES SOVERSION ${SOVERSION}) list(APPEND LAMMPS_LINK_LIBS ${PKG_LIB}) if(PKG_LIB STREQUAL awpmd) target_include_directories(awpmd PUBLIC ${LAMMPS_LIB_SOURCE_DIR}/awpmd/systems/interact ${LAMMPS_LIB_SOURCE_DIR}/awpmd/ivutils/include) @@ -580,8 +576,8 @@ include_directories(${LAMMPS_STYLE_HEADERS_DIR}) ############################################ add_library(lammps ${LIB_SOURCES}) target_link_libraries(lammps ${LAMMPS_LINK_LIBS}) -set_target_properties(lammps PROPERTIES SOVERSION ${SOVERSION}) if(BUILD_SHARED_LIBS) + set_target_properties(lammps PROPERTIES SOVERSION ${SOVERSION}) install(TARGETS lammps LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) install(FILES ${LAMMPS_SOURCE_DIR}/library.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/lammps) configure_file(pkgconfig/liblammps.pc.in ${CMAKE_CURRENT_BINARY_DIR}/liblammps.pc @ONLY) From 34b3fc21572c02b0f0128dc4dfe7b902ece53bb1 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Tue, 29 Aug 2017 01:04:39 -0400 Subject: [PATCH 25/27] Fix GPU CMake compilation --- cmake/CMakeLists.txt | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index aee928ed9a..6b29c80e61 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -499,11 +499,13 @@ if(ENABLE_GPU) set(GPU_PREC "SINGLE_DOUBLE" CACHE STRING "Lammps gpu precision size") set_property(CACHE GPU_PREC PROPERTY STRINGS SINGLE_DOUBLE SINGLE_SINGLE DOUBLE_DOUBLE) option(CUDPP_OPT "Enable CUDPP_OPT" ON) + + set(GPU_ARCH "sm_30" CACHE STRING "LAMMPS GPU CUDA SM architecture") + set_property(CACHE GPU_ARCH PROPERTY STRINGS sm_10 sm_20 sm_30 sm_60) file(GLOB GPU_LIB_SOURCES ${LAMMPS_LIB_SOURCE_DIR}/gpu/*.cpp) file(GLOB GPU_LIB_CU ${LAMMPS_LIB_SOURCE_DIR}/gpu/*.cu ${CMAKE_SOURCE_DIR}/gpu/*.cu) - file(GLOB_RECURSE GPU_NOT_LIB_CU ${LAMMPS_LIB_SOURCE_DIR}/gpu/lal_pppm.cu) - list(REMOVE_ITEM GPU_LIB_CU ${GPU_NOT_LIB_CU}) + list(REMOVE_ITEM GPU_LIB_CU ${LAMMPS_LIB_SOURCE_DIR}/gpu/lal_pppm.cu) cuda_include_directories(${LAMMPS_LIB_SOURCE_DIR}/gpu ${LAMMPS_LIB_BINARY_DIR}/gpu) @@ -513,12 +515,14 @@ if(ENABLE_GPU) file(GLOB GPU_LIB_CUDPP_CU ${LAMMPS_LIB_SOURCE_DIR}/gpu/cudpp_mini/*.cu) endif() - cuda_compile(GPU_OBJS ${GPU_LIB_CU} ${GPU_LIB_CUDPP_CU} OPTIONS - $<$:-Xcompiler=-fPIC> - -DNV_KERNEL -DUCL_CUDADR -D_${GPU_PREC}) + 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}) + + 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}) file(MAKE_DIRECTORY ${LAMMPS_LIB_BINARY_DIR}/gpu) - foreach(CU_OBJ ${GPU_OBJS}) + foreach(CU_OBJ ${GPU_GEN_OBJS}) get_filename_component(CU_NAME ${CU_OBJ} NAME_WE) string(REGEX REPLACE "^.*_lal_" "" CU_NAME "${CU_NAME}") add_custom_command(OUTPUT ${LAMMPS_LIB_BINARY_DIR}/gpu/${CU_NAME}_cubin.h @@ -526,16 +530,13 @@ if(ENABLE_GPU) DEPENDS ${CU_OBJ} COMMENT "Generating ${CU_NAME}_cubin.h") list(APPEND GPU_LIB_SOURCES ${LAMMPS_LIB_BINARY_DIR}/gpu/${CU_NAME}_cubin.h) - if(${CU_NAME} STREQUAL "pppm_d") #pppm_d doesn't get linked into the lib - set(CU_FORBIDDEN_OBJ "${CU_OBJ}") - endif() endforeach() - list(REMOVE_ITEM GPU_OBJS "${CU_FORBIDDEN_OBJ}") set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${LAMMPS_LIB_BINARY_DIR}/gpu/*_cubin.h") - cuda_add_library(gpu ${GPU_LIB_SOURCES} ${GPU_LIB_CUDPP_SOURCES} ${GPU_OBJS} STATIC) - target_include_directories(gpu PRIVATE ${LAMMPS_LIB_BINARY_DIR}/gpu) + add_library(gpu STATIC ${GPU_LIB_SOURCES} ${GPU_LIB_CUDPP_SOURCES} ${GPU_OBJS}) + target_include_directories(gpu PRIVATE ${LAMMPS_LIB_BINARY_DIR}/gpu ${CUDA_INCLUDE_DIRS}) + target_compile_definitions(gpu PRIVATE -D_${GPU_PREC} -DMPI_GERYON -DUCL_NO_EXIT) if(CUDPP_OPT) target_include_directories(gpu PRIVATE ${LAMMPS_LIB_SOURCE_DIR}/gpu/cudpp_mini) target_compile_definitions(gpu PRIVATE -DUSE_CUDPP) @@ -543,21 +544,31 @@ if(ENABLE_GPU) list(APPEND LAMMPS_LINK_LIBS gpu) + add_executable(nvc_get_devices ${LAMMPS_LIB_SOURCE_DIR}/gpu/geryon/ucl_get_devices.cpp) + target_compile_definitions(nvc_get_devices PRIVATE -DUCL_CUDADR) + target_link_libraries(nvc_get_devices PRIVATE ${CUDA_LIBRARIES} ${CUDA_CUDA_LIBRARY}) + target_include_directories(nvc_get_devices PRIVATE ${CUDA_INCLUDE_DIRS}) + # GPU package + list(APPEND LAMMPS_LINK_LIBS ${CUDA_LIBRARIES} ${CUDA_CUDA_LIBRARY}) set(GPU_SOURCES_DIR ${LAMMPS_SOURCE_DIR}/GPU) - set(GPU_SOURCES ${GPU_SOURCES_DIR}/gpu_extra.h) + set(GPU_SOURCES ${GPU_SOURCES_DIR}/gpu_extra.h + ${GPU_SOURCES_DIR}/fix_gpu.h + ${GPU_SOURCES_DIR}/fix_gpu.cpp) + FindStyleHeaders(${GPU_SOURCES_DIR} FIX_CLASS fix_ FIX) include_directories(${GPU_SOURCES_DIR}) set_property(GLOBAL PROPERTY "GPU_SOURCES" "${GPU_SOURCES}") # detects styles which have GPU version - RegisterStylesExt(${GPU_SOURCES_DIR} opt GPU_SOURCES) + RegisterStylesExt(${GPU_SOURCES_DIR} gpu GPU_SOURCES) get_property(GPU_SOURCES GLOBAL PROPERTY GPU_SOURCES) list(APPEND LIB_SOURCES ${GPU_SOURCES}) + include_directories(${GPU_SOURCES_DIR}) endif() ###################################################### From 27c962dc3b81a5714fd890b117f4b8c238a02483 Mon Sep 17 00:00:00 2001 From: Christoph Junghans Date: Wed, 30 Aug 2017 09:45:01 -0600 Subject: [PATCH 26/27] link cuda in gpu only, remove duplicated incl. dir --- cmake/CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 6b29c80e61..af51708cad 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -551,14 +551,13 @@ if(ENABLE_GPU) # GPU package - list(APPEND LAMMPS_LINK_LIBS ${CUDA_LIBRARIES} ${CUDA_CUDA_LIBRARY}) + target_link_libraries(gpu ${CUDA_LIBRARIES} ${CUDA_CUDA_LIBRARY}) set(GPU_SOURCES_DIR ${LAMMPS_SOURCE_DIR}/GPU) set(GPU_SOURCES ${GPU_SOURCES_DIR}/gpu_extra.h ${GPU_SOURCES_DIR}/fix_gpu.h ${GPU_SOURCES_DIR}/fix_gpu.cpp) FindStyleHeaders(${GPU_SOURCES_DIR} FIX_CLASS fix_ FIX) - include_directories(${GPU_SOURCES_DIR}) set_property(GLOBAL PROPERTY "GPU_SOURCES" "${GPU_SOURCES}") From 8a06a7bc6bfec056477653d9e5dc2c09668e0512 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Fri, 8 Sep 2017 22:20:47 -0400 Subject: [PATCH 27/27] Add OpenCL support to CMake build --- cmake/CMakeLists.txt | 176 ++++++++++++++++++++------------ cmake/Modules/OpenCLUtils.cmake | 18 ++++ 2 files changed, 128 insertions(+), 66 deletions(-) create mode 100644 cmake/Modules/OpenCLUtils.cmake diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index af51708cad..79445c4b1e 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -95,7 +95,7 @@ set(OTHER_PACKAGES KIM PYTHON MSCG MPIIO VORONOI POEMS USER-ATC USER-AWPMD USER-CGDNA USER-CGSDK USER-COLVARS USER-DIFFRACTION USER-DPD USER-DRUDE USER-EFF USER-FEP USER-H5MD USER-LB USER-MANIFOLD USER-MEAMC USER-MGPT USER-MISC - USER-MOLFILE USER-NETCDF USER-PHONON USER-QTB USER-REAXC USER-SMD + USER-MOLFILE USER-NETCDF USER-PHONON USER-QTB USER-REAXC USER-SMD USER-SMTBQ USER-SPH USER-TALLY USER-VTK USER-QUIP USER-QMMM) set(ACCEL_PACKAGES USER-OMP KOKKOS OPT USER-INTEL GPU) foreach(PKG ${DEFAULT_PACKAGES}) @@ -323,7 +323,7 @@ endforeach(FUNC) list(APPEND LAMMPS_LINK_LIBS ${MATH_LIBRARIES}) ###################################### -# Generate Basic Style files +# Generate Basic Style files ###################################### include(StyleHeaderUtils) RegisterStyles(${LAMMPS_SOURCE_DIR}) @@ -379,7 +379,7 @@ if(ENABLE_USER-H5MD) target_link_libraries(h5md ${HDF5_LIBRARIES}) target_include_directories(h5md PRIVATE ${HDF5_INCLUDE_DIRS}) endif() - + if(ENABLE_MEAM AND FC_HAS_NO_SECOND_UNDERSCORE) foreach(FSRC ${meam_SOURCES}) string(REGEX REPLACE "^.*\\." "" FEXT "${FSRC}") @@ -491,72 +491,116 @@ if(ENABLE_USER-INTEL) endif() if(ENABLE_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.") - endif() - set(GPU_PREC "SINGLE_DOUBLE" CACHE STRING "Lammps gpu precision size") - set_property(CACHE GPU_PREC PROPERTY STRINGS SINGLE_DOUBLE SINGLE_SINGLE DOUBLE_DOUBLE) - option(CUDPP_OPT "Enable CUDPP_OPT" ON) - - set(GPU_ARCH "sm_30" CACHE STRING "LAMMPS GPU CUDA SM architecture") - set_property(CACHE GPU_ARCH PROPERTY STRINGS sm_10 sm_20 sm_30 sm_60) - - file(GLOB GPU_LIB_SOURCES ${LAMMPS_LIB_SOURCE_DIR}/gpu/*.cpp) - file(GLOB GPU_LIB_CU ${LAMMPS_LIB_SOURCE_DIR}/gpu/*.cu ${CMAKE_SOURCE_DIR}/gpu/*.cu) - list(REMOVE_ITEM GPU_LIB_CU ${LAMMPS_LIB_SOURCE_DIR}/gpu/lal_pppm.cu) - - cuda_include_directories(${LAMMPS_LIB_SOURCE_DIR}/gpu ${LAMMPS_LIB_BINARY_DIR}/gpu) - - if(CUDPP_OPT) - cuda_include_directories(${LAMMPS_LIB_SOURCE_DIR}/gpu/cudpp_mini) - file(GLOB GPU_LIB_CUDPP_SOURCES ${LAMMPS_LIB_SOURCE_DIR}/gpu/cudpp_mini/*.cpp) - 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}) - - 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}) - - file(MAKE_DIRECTORY ${LAMMPS_LIB_BINARY_DIR}/gpu) - foreach(CU_OBJ ${GPU_GEN_OBJS}) - get_filename_component(CU_NAME ${CU_OBJ} NAME_WE) - string(REGEX REPLACE "^.*_lal_" "" CU_NAME "${CU_NAME}") - add_custom_command(OUTPUT ${LAMMPS_LIB_BINARY_DIR}/gpu/${CU_NAME}_cubin.h - COMMAND ${BIN2C} -c -n ${CU_NAME} ${CU_OBJ} > ${LAMMPS_LIB_BINARY_DIR}/gpu/${CU_NAME}_cubin.h - DEPENDS ${CU_OBJ} - COMMENT "Generating ${CU_NAME}_cubin.h") - list(APPEND GPU_LIB_SOURCES ${LAMMPS_LIB_BINARY_DIR}/gpu/${CU_NAME}_cubin.h) - endforeach() - set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${LAMMPS_LIB_BINARY_DIR}/gpu/*_cubin.h") - - - add_library(gpu STATIC ${GPU_LIB_SOURCES} ${GPU_LIB_CUDPP_SOURCES} ${GPU_OBJS}) - target_include_directories(gpu PRIVATE ${LAMMPS_LIB_BINARY_DIR}/gpu ${CUDA_INCLUDE_DIRS}) - target_compile_definitions(gpu PRIVATE -D_${GPU_PREC} -DMPI_GERYON -DUCL_NO_EXIT) - if(CUDPP_OPT) - target_include_directories(gpu PRIVATE ${LAMMPS_LIB_SOURCE_DIR}/gpu/cudpp_mini) - target_compile_definitions(gpu PRIVATE -DUSE_CUDPP) - endif() - - list(APPEND LAMMPS_LINK_LIBS gpu) - - add_executable(nvc_get_devices ${LAMMPS_LIB_SOURCE_DIR}/gpu/geryon/ucl_get_devices.cpp) - target_compile_definitions(nvc_get_devices PRIVATE -DUCL_CUDADR) - target_link_libraries(nvc_get_devices PRIVATE ${CUDA_LIBRARIES} ${CUDA_CUDA_LIBRARY}) - target_include_directories(nvc_get_devices PRIVATE ${CUDA_INCLUDE_DIRS}) - - - # GPU package - target_link_libraries(gpu ${CUDA_LIBRARIES} ${CUDA_CUDA_LIBRARY}) - set(GPU_SOURCES_DIR ${LAMMPS_SOURCE_DIR}/GPU) set(GPU_SOURCES ${GPU_SOURCES_DIR}/gpu_extra.h ${GPU_SOURCES_DIR}/fix_gpu.h ${GPU_SOURCES_DIR}/fix_gpu.cpp) + + set(GPU_API "OpenCL" CACHE STRING "API used by GPU package") + set_property(CACHE GPU_API PROPERTY STRINGS OpenCL CUDA) + + set(GPU_PREC "SINGLE_DOUBLE" CACHE STRING "LAMMPS GPU precision size") + set_property(CACHE GPU_PREC PROPERTY STRINGS SINGLE_DOUBLE SINGLE_SINGLE DOUBLE_DOUBLE) + + file(GLOB GPU_LIB_SOURCES ${LAMMPS_LIB_SOURCE_DIR}/gpu/*.cpp) + file(MAKE_DIRECTORY ${LAMMPS_LIB_BINARY_DIR}/gpu) + + if(GPU_API STREQUAL "CUDA") + 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.") + endif() + option(CUDPP_OPT "Enable CUDPP_OPT" ON) + + set(GPU_ARCH "sm_30" CACHE STRING "LAMMPS GPU CUDA SM architecture") + set_property(CACHE GPU_ARCH PROPERTY STRINGS sm_10 sm_20 sm_30 sm_60) + + file(GLOB GPU_LIB_CU ${LAMMPS_LIB_SOURCE_DIR}/gpu/*.cu ${CMAKE_SOURCE_DIR}/gpu/*.cu) + list(REMOVE_ITEM GPU_LIB_CU ${LAMMPS_LIB_SOURCE_DIR}/gpu/lal_pppm.cu) + + cuda_include_directories(${LAMMPS_LIB_SOURCE_DIR}/gpu ${LAMMPS_LIB_BINARY_DIR}/gpu) + + if(CUDPP_OPT) + cuda_include_directories(${LAMMPS_LIB_SOURCE_DIR}/gpu/cudpp_mini) + file(GLOB GPU_LIB_CUDPP_SOURCES ${LAMMPS_LIB_SOURCE_DIR}/gpu/cudpp_mini/*.cpp) + 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}) + + 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}) + + foreach(CU_OBJ ${GPU_GEN_OBJS}) + get_filename_component(CU_NAME ${CU_OBJ} NAME_WE) + string(REGEX REPLACE "^.*_lal_" "" CU_NAME "${CU_NAME}") + add_custom_command(OUTPUT ${LAMMPS_LIB_BINARY_DIR}/gpu/${CU_NAME}_cubin.h + COMMAND ${BIN2C} -c -n ${CU_NAME} ${CU_OBJ} > ${LAMMPS_LIB_BINARY_DIR}/gpu/${CU_NAME}_cubin.h + DEPENDS ${CU_OBJ} + COMMENT "Generating ${CU_NAME}_cubin.h") + list(APPEND GPU_LIB_SOURCES ${LAMMPS_LIB_BINARY_DIR}/gpu/${CU_NAME}_cubin.h) + endforeach() + set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${LAMMPS_LIB_BINARY_DIR}/gpu/*_cubin.h") + + + add_library(gpu STATIC ${GPU_LIB_SOURCES} ${GPU_LIB_CUDPP_SOURCES} ${GPU_OBJS}) + target_link_libraries(gpu ${CUDA_LIBRARIES} ${CUDA_CUDA_LIBRARY}) + target_include_directories(gpu PRIVATE ${LAMMPS_LIB_BINARY_DIR}/gpu ${CUDA_INCLUDE_DIRS}) + target_compile_definitions(gpu PRIVATE -D_${GPU_PREC} -DMPI_GERYON -DUCL_NO_EXIT) + if(CUDPP_OPT) + target_include_directories(gpu PRIVATE ${LAMMPS_LIB_SOURCE_DIR}/gpu/cudpp_mini) + target_compile_definitions(gpu PRIVATE -DUSE_CUDPP) + endif() + + list(APPEND LAMMPS_LINK_LIBS gpu) + + add_executable(nvc_get_devices ${LAMMPS_LIB_SOURCE_DIR}/gpu/geryon/ucl_get_devices.cpp) + target_compile_definitions(nvc_get_devices PRIVATE -DUCL_CUDADR) + target_link_libraries(nvc_get_devices PRIVATE ${CUDA_LIBRARIES} ${CUDA_CUDA_LIBRARY}) + target_include_directories(nvc_get_devices PRIVATE ${CUDA_INCLUDE_DIRS}) + + + elseif(GPU_API STREQUAL "OpenCL") + find_package(OpenCL REQUIRED) + if(OpenCL_FOUND) + set(OCL_TUNE "GENERIC" CACHE STRING "OpenCL Device Tuning") + set_property(CACHE OCL_TUNE PROPERTY STRINGS INTEL FERMI KEPLER CYPRESS GENERIC) + + include(OpenCLUtils) + set(OCL_COMMON_HEADERS ${LAMMPS_LIB_SOURCE_DIR}/gpu/lal_preprocessor.h ${LAMMPS_LIB_SOURCE_DIR}/gpu/lal_aux_fun1.h) + + file(GLOB GPU_LIB_CU ${LAMMPS_LIB_SOURCE_DIR}/gpu/*.cu) + list(REMOVE_ITEM GPU_LIB_CU ${LAMMPS_LIB_SOURCE_DIR}/gpu/lal_gayberne.cu ${LAMMPS_LIB_SOURCE_DIR}/gpu/lal_gayberne_lj.cu) + + foreach(GPU_KERNEL ${GPU_LIB_CU}) + get_filename_component(basename ${GPU_KERNEL} NAME_WE) + string(SUBSTRING ${basename} 4 -1 KERNEL_NAME) + GenerateOpenCLHeader(${KERNEL_NAME} ${CMAKE_CURRENT_BINARY_DIR}/gpu/${KERNEL_NAME}_cl.h ${OCL_COMMON_HEADERS} ${GPU_KERNEL}) + list(APPEND GPU_LIB_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/gpu/${KERNEL_NAME}_cl.h) + endforeach() + + GenerateOpenCLHeader(gayberne ${CMAKE_CURRENT_BINARY_DIR}/gpu/gayberne_cl.h ${OCL_COMMON_HEADERS} ${LAMMPS_LIB_SOURCE_DIR}/gpu/lal_ellipsoid_extra.h ${LAMMPS_LIB_SOURCE_DIR}/gpu/lal_gayberne.cu) + GenerateOpenCLHeader(gayberne_lj ${CMAKE_CURRENT_BINARY_DIR}/gpu/gayberne_lj_cl.h ${OCL_COMMON_HEADERS} ${LAMMPS_LIB_SOURCE_DIR}/gpu/lal_ellipsoid_extra.h ${LAMMPS_LIB_SOURCE_DIR}/gpu/lal_gayberne_lj.cu) + list(APPEND GPU_LIB_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/gpu/gayberne_cl.h ${CMAKE_CURRENT_BINARY_DIR}/gpu/gayberne_lj_cl.h) + + add_library(gpu STATIC ${GPU_LIB_SOURCES}) + target_link_libraries(gpu ${OpenCL_LIBRARIES}) + target_include_directories(gpu PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/gpu ${OpenCL_INCLUDE_DIRS}) + target_compile_definitions(gpu PRIVATE -D_${GPU_PREC} -DMPI_GERYON -DUCL_NO_EXIT) + target_compile_definitions(gpu PRIVATE -DUSE_OPENCL) + + list(APPEND LAMMPS_LINK_LIBS gpu) + + add_executable(ocl_get_devices ${LAMMPS_LIB_SOURCE_DIR}/gpu/geryon/ucl_get_devices.cpp) + target_compile_definitions(ocl_get_devices PRIVATE -DUCL_OPENCL) + target_link_libraries(ocl_get_devices PRIVATE ${OpenCL_LIBRARIES}) + target_include_directories(ocl_get_devices PRIVATE ${OpenCL_INCLUDE_DIRS}) + endif() + endif() + + # GPU package FindStyleHeaders(${GPU_SOURCES_DIR} FIX_CLASS fix_ FIX) set_property(GLOBAL PROPERTY "GPU_SOURCES" "${GPU_SOURCES}") @@ -572,7 +616,7 @@ endif() ###################################################### # Generate style headers based on global list of -# styles registered during package selection +# styles registered during package selection ###################################################### set(LAMMPS_STYLE_HEADERS_DIR ${CMAKE_CURRENT_BINARY_DIR}/styles) diff --git a/cmake/Modules/OpenCLUtils.cmake b/cmake/Modules/OpenCLUtils.cmake new file mode 100644 index 0000000000..5c147a685c --- /dev/null +++ b/cmake/Modules/OpenCLUtils.cmake @@ -0,0 +1,18 @@ +function(GenerateOpenCLHeader varname outfile files) + message("Creating ${outfile}...") + file(WRITE ${outfile} "const char * ${varname} = \n") + math(EXPR ARG_END "${ARGC}-1") + + foreach(IDX RANGE 2 ${ARG_END}) + list(GET ARGV ${IDX} filename) + file(READ ${filename} content) + string(REGEX REPLACE "\\s*//[^\n]*\n" "" content "${content}") + string(REGEX REPLACE "\\\\" "\\\\\\\\" content "${content}") + string(REGEX REPLACE "\"" "\\\\\"" content "${content}") + string(REGEX REPLACE "([^\n]+)\n" "\"\\1\\\\n\"\n" content "${content}") + string(REGEX REPLACE "\n+" "\n" content "${content}") + file(APPEND ${outfile} "${content}") + endforeach() + + file(APPEND ${outfile} ";\n") +endfunction(GenerateOpenCLHeader)