From 602d7179a9b758050448673b256c53c721435928 Mon Sep 17 00:00:00 2001 From: David van der Spoel Date: Tue, 13 May 2014 15:46:53 +0200 Subject: [PATCH] Added cmake profiling support Support for using gprof with gromacs executables is added to allow basic profiling using gmx command [options] gprof gmx Removed explicit -fomit-frame-pointer, since this has been default behaviour in gcc at most optimization levels since at least version 4.4. This lets "-O3 -pg" in the Profile build-type CFLAGS fight it out themselves. Change-Id: I99710f9cdd406f866d663a9610e0e9cccb87c07c --- CMakeLists.txt | 7 +++--- cmake/gmxBuildTypeProfile.cmake | 40 +++++++++++++++++++++++++++++++++ cmake/gmxCFlags.cmake | 6 ++--- 3 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 cmake/gmxBuildTypeProfile.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index d5ba67ab89..12e1ece2cc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -103,15 +103,16 @@ set(GMX_INSTALL_PREFIX "" CACHE STRING "Prefix gets appended to CMAKE_INSTALL_PR mark_as_advanced(GMX_INSTALL_PREFIX) include(gmxBuildTypeReference) +include(gmxBuildTypeProfile) include(gmxBuildTypeThreadSanitizer) include(gmxBuildTypeReleaseWithAssert) if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel Reference RelWithAssert." FORCE) + set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel Reference RelWithAssert Profile." FORCE) # There's no need to offer a user the choice of ThreadSanitizer # Set the possible values of build type for cmake-gui set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" - "MinSizeRel" "RelWithDebInfo" "Reference" "RelWithAssert") + "MinSizeRel" "RelWithDebInfo" "Reference" "RelWithAssert" "Profile") endif() if(CMAKE_CONFIGURATION_TYPES) # Add appropriate GROMACS-specific build types for the Visual @@ -123,7 +124,7 @@ if(CMAKE_CONFIGURATION_TYPES) "List of configuration types" FORCE) endif() -set(build_types_with_explicit_flags RELEASE DEBUG RELWITHDEBUGINFO RELWITHASSERT MINSIZEREL) +set(build_types_with_explicit_flags RELEASE DEBUG RELWITHDEBUGINFO RELWITHASSERT MINSIZEREL PROFILE) enable_language(C) enable_language(CXX) diff --git a/cmake/gmxBuildTypeProfile.cmake b/cmake/gmxBuildTypeProfile.cmake new file mode 100644 index 0000000000..b752bf45f4 --- /dev/null +++ b/cmake/gmxBuildTypeProfile.cmake @@ -0,0 +1,40 @@ +# +# This file is part of the GROMACS molecular simulation package. +# +# Copyright (c) 2014, by the GROMACS development team, led by +# Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, +# and including many others, as listed in the AUTHORS file in the +# top-level source directory and at http://www.gromacs.org. +# +# GROMACS is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. +# +# GROMACS is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with GROMACS; if not, see +# http://www.gnu.org/licenses, or write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +# If you want to redistribute modifications to GROMACS, please +# consider that scientific software is very special. Version +# control is crucial - bugs must be traceable. We will be happy to +# consider code for inclusion in the official distribution, but +# derived work must not be called official GROMACS. Details are found +# in the README & COPYING files - if they are missing, get the +# official version at http://www.gromacs.org. +# +# To help us fund GROMACS development, we humbly ask that you cite +# the research papers on the package. Check out http://www.gromacs.org. + +# Custom build type "Profile", based on "RelWithAssert". +set( CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE_INIT} -pg" CACHE STRING "C flags for profile builds.") +set( CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE_INIT} -pg" CACHE STRING "C++ flags for profile builds.") +set( CMAKE_LD_FLAGS_PROFILE "${CMAKE_LD_FLAGS_RELEASE_INIT} -pg" CACHE STRING "Linking flags for profile builds.") +mark_as_advanced( CMAKE_CXX_FLAGS_PROFILE CMAKE_C_FLAGS_PROFILE CMAKE_LD_FLAGS_PROFILE) + diff --git a/cmake/gmxCFlags.cmake b/cmake/gmxCFlags.cmake index 955811745d..7db9539430 100644 --- a/cmake/gmxCFlags.cmake +++ b/cmake/gmxCFlags.cmake @@ -64,7 +64,7 @@ function(gmx_set_cmake_compiler_flags) # be set up elsewhere and passed to this function, but it is # inconvenient in CMake to pass more than one list, and such a # list is only used here. - foreach(build_type RELWITHDEBUGINFO RELWITHASSERT MINSIZEREL) + foreach(build_type RELWITHDEBUGINFO RELWITHASSERT MINSIZEREL PROFILE) set(GMXC_${language}FLAGS_${build_type} "${GMXC_${language}FLAGS_RELEASE}") endforeach() # Copy the flags that are only used by the real Release build @@ -112,7 +112,7 @@ MACRO(gmx_c_flags) GMX_TEST_CFLAG(CFLAGS_WARN_REL "-Wno-array-bounds" GMXC_CFLAGS_RELEASE_ONLY) # new in gcc 4.5 GMX_TEST_CFLAG(CFLAGS_EXCESS_PREC "-fexcess-precision=fast" GMXC_CFLAGS_RELEASE) - GMX_TEST_CFLAG(CFLAGS_COPT "-fomit-frame-pointer -funroll-all-loops" + GMX_TEST_CFLAG(CFLAGS_COPT "-funroll-all-loops" GMXC_CFLAGS_RELEASE) GMX_TEST_CFLAG(CFLAGS_NOINLINE "-fno-inline" GMXC_CFLAGS_DEBUG) endif() @@ -128,7 +128,7 @@ MACRO(gmx_c_flags) GMX_TEST_CFLAG(CXXFLAGS_WARN_REL "-Wno-array-bounds" GMXC_CXXFLAGS_RELEASE_ONLY) # new in gcc 4.5 GMX_TEST_CXXFLAG(CXXFLAGS_EXCESS_PREC "-fexcess-precision=fast" GMXC_CXXFLAGS_RELEASE) - GMX_TEST_CXXFLAG(CXXFLAGS_COPT "-fomit-frame-pointer -funroll-all-loops" + GMX_TEST_CXXFLAG(CXXFLAGS_COPT "-funroll-all-loops" GMXC_CXXFLAGS_RELEASE) GMX_TEST_CXXFLAG(CXXFLAGS_NOINLINE "-fno-inline" GMXC_CXXFLAGS_DEBUG) endif() -- 2.22.0