From 7214ee56351b6605b4849240b81b58aab6fa41ed Mon Sep 17 00:00:00 2001 From: dekken Date: Sat, 9 Dec 2023 18:46:24 +0100 Subject: [PATCH] profile guided optimization release --- res/cmake/def.cmake | 19 +++++++++- res/cmake/options.cmake | 6 +++ res/cmake_pgo_go.sh | 38 +++++++++++++++++++ src/amr/CMakeLists.txt | 1 + src/core/CMakeLists.txt | 2 +- src/core/data/particles/particle.hpp | 4 +- src/core/numerics/ion_updater/ion_updater.hpp | 1 + src/core/numerics/ohm/ohm.hpp | 4 +- src/core/numerics/pusher/boris.hpp | 2 +- src/core/utilities/cellmap.hpp | 2 +- src/initializer/CMakeLists.txt | 3 +- src/phare/CMakeLists.txt | 1 + src/python3/CMakeLists.txt | 3 ++ src/simulator/CMakeLists.txt | 2 +- 14 files changed, 78 insertions(+), 10 deletions(-) create mode 100755 res/cmake_pgo_go.sh diff --git a/res/cmake/def.cmake b/res/cmake/def.cmake index 911d21737..0af9d3702 100644 --- a/res/cmake/def.cmake +++ b/res/cmake/def.cmake @@ -8,9 +8,26 @@ else() # !Clang set (PHARE_FLAGS ${PHARE_FLAGS} --param=min-pagesize=0 ) endif() # clang +set (PHARE_LINK_FLAGS ) +set (PHARE_BASE_LIBS ) + +if(PGO_GEN) + if(PGO_USE) + message(FATAL_ERROR "cannot generate and use pgo at the same time.") + endif() + set (PHARE_LINK_FLAGS ${PHARE_LINK_FLAGS} -fprofile-generate ) + set (PHARE_FLAGS ${PHARE_FLAGS} -fprofile-generate ) +endif() + +if(PGO_USE) + set (PHARE_LINK_FLAGS ${PHARE_LINK_FLAGS} -fprofile-use ) + set (PHARE_FLAGS ${PHARE_FLAGS} -fprofile-use ) +endif() + + set (PHARE_WERROR_FLAGS ${PHARE_FLAGS} ${PHARE_WERROR_FLAGS}) set (PHARE_PYTHONPATH "${CMAKE_BINARY_DIR}:${CMAKE_SOURCE_DIR}/pyphare") -set (PHARE_BASE_LIBS ) + # now we see if we are running with configurator if (phare_configurator) diff --git a/res/cmake/options.cmake b/res/cmake/options.cmake index a335b90d7..ddf1b3b34 100644 --- a/res/cmake/options.cmake +++ b/res/cmake/options.cmake @@ -70,6 +70,12 @@ option(lowResourceTests "Disable heavy tests for CI (2d/3d/etc" OFF) option(testDuringBuild "Runs C++ unit tests after they are built" OFF) +# -DPGO_GEN=OFF profile guided optimization generate +option(PGO_GEN "profile guided optimization generate" OFF) +# -DPGO_USE=OFF +option(PGO_USE "profile guided optimization use" OFF) + + # Controlling the activation of tests if (NOT DEFINED PHARE_EXEC_LEVEL_MIN) set(PHARE_EXEC_LEVEL_MIN 1) diff --git a/res/cmake_pgo_go.sh b/res/cmake_pgo_go.sh new file mode 100755 index 000000000..7d8e9b2bd --- /dev/null +++ b/res/cmake_pgo_go.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +# usage: +# build PHARE with profile guilded optimizations + +set -ex +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +cd $SCRIPT_DIR && cd .. && CWD=$PWD # move to project root + +[ ! -f "$CWD/CMakeLists.txt" ] && echo "script expected to be run from project root" && exit 1 +[ ! -d "$CWD/subprojects/cppdict/include" ] && git submodule update --init + +export OPYTHONPATH=${PYTHONPATH} +export PYTHONPATH=${PWD}:${PWD}/build:${PWD}/pyphare:${OPYTHONPATH} + +THREADS=${THREADS:-"10"} +BUILD_DIR=${BUILD_DIR:-"$CWD/build"} +SAMRAI=${SAMRAI:-""} # "" = from system or as subproject if not found in system +[[ -n "${SAMRAI}" ]] && SAMRAI=-DSAMRAI_ROOT="${SAMRAI}" + +CMAKE_CXX_FLAGS="-DNDEBUG -g0 -O3 -march=native -mtune=native" +CMAKE_CONFIG=" -Dphare_configurator=ON -DCMAKE_BUILD_TYPE=Release" + +export CC=${CC:-"gcc"} +export CXX=${CXX:-"g++"} +set -xe + +mkdir -p ${BUILD_DIR} +( + cd ${BUILD_DIR} + + cmake $CWD ${SAMRAI} ${CMAKE_CONFIG} -G Ninja -DCMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS}" -DPGO_GEN=ON; + ninja -v -j${THREADS} cpp cpp_etc dictator + python3 tests/functional/harris/harris_2d_2.py + + cmake $CWD ${SAMRAI} ${CMAKE_CONFIG} -G Ninja -DCMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS}" -DPGO_GEN=OFF -DPGO_USE=ON; + ninja -v -j${THREADS} cpp cpp_etc dictator + python3 tests/functional/harris/harris_2d_2.py # should be faster than without any PGO +) diff --git a/src/amr/CMakeLists.txt b/src/amr/CMakeLists.txt index aa0522025..0e00a6361 100644 --- a/src/amr/CMakeLists.txt +++ b/src/amr/CMakeLists.txt @@ -91,4 +91,5 @@ target_link_libraries(${PROJECT_NAME} PUBLIC SAMRAI_tbox SAMRAI_xfer ) +set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY LINK_FLAGS " ${PHARE_LINK_FLAGS}") diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index a35966cfb..fc4784a38 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -65,5 +65,5 @@ target_link_libraries(${PROJECT_NAME} PRIVATE phare_initializer ${MPI_C_LIBRARI set_property(TARGET ${PROJECT_NAME} PROPERTY INTERPROCEDURAL_OPTIMIZATION ${PHARE_INTERPROCEDURAL_OPTIMIZATION}) target_include_directories(${PROJECT_NAME} PUBLIC ${MPI_C_INCLUDE_DIRS} $) - +set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY LINK_FLAGS " ${PHARE_LINK_FLAGS}") diff --git a/src/core/data/particles/particle.hpp b/src/core/data/particles/particle.hpp index badab19ab..0457865c2 100644 --- a/src/core/data/particles/particle.hpp +++ b/src/core/data/particles/particle.hpp @@ -54,8 +54,8 @@ struct Particle Particle() = default; - double weight; - double charge; + double weight = 0; + double charge = 0; std::array iCell = ConstArray(); std::array delta = ConstArray(); diff --git a/src/core/numerics/ion_updater/ion_updater.hpp b/src/core/numerics/ion_updater/ion_updater.hpp index 9a9579225..c4ed55abb 100644 --- a/src/core/numerics/ion_updater/ion_updater.hpp +++ b/src/core/numerics/ion_updater/ion_updater.hpp @@ -185,6 +185,7 @@ void IonUpdater::updateAndDepositDomain_(Ions& ion if (copyInDomain) { + domain.reserve(domain.size() + enteredInDomain.size()); std::copy(enteredInDomain.begin(), enteredInDomain.end(), std::back_inserter(domain)); } diff --git a/src/core/numerics/ohm/ohm.hpp b/src/core/numerics/ohm/ohm.hpp index 80ad56705..e26618177 100644 --- a/src/core/numerics/ohm/ohm.hpp +++ b/src/core/numerics/ohm/ohm.hpp @@ -334,8 +334,8 @@ class Ohm : public LayoutHolder template auto hyperresistive_(VecField const& J, MeshIndex index) const - { - return -nu_ * layout_->laplacian(J(component), index); // TODO : issue 3391 + { // TODO : https://github.com/PHAREHUB/PHARE/issues/3 + return -nu_ * layout_->laplacian(J(component), index); } }; diff --git a/src/core/numerics/pusher/boris.hpp b/src/core/numerics/pusher/boris.hpp index 593516f39..3a6e64ee0 100644 --- a/src/core/numerics/pusher/boris.hpp +++ b/src/core/numerics/pusher/boris.hpp @@ -112,7 +112,7 @@ class BorisPusher /** see Pusher::move() documentation*/ - void setMeshAndTimeStep(std::array ms, double ts) override + void setMeshAndTimeStep(std::array ms, double const ts) override { std::transform(std::begin(ms), std::end(ms), std::begin(halfDtOverDl_), [ts](double& x) { return 0.5 * ts / x; }); diff --git a/src/core/utilities/cellmap.hpp b/src/core/utilities/cellmap.hpp index 5fccb6629..d07df568f 100644 --- a/src/core/utilities/cellmap.hpp +++ b/src/core/utilities/cellmap.hpp @@ -391,7 +391,7 @@ inline void CellMap::empty() template template inline void CellMap::update(Array& items, std::size_t itemIndex, - CellIndex const& oldCell, CellExtractor extract) + CellIndex const& oldCell, CellExtractor /*extract*/) { // we want to check first if the particle is in the map // already. if is, needs to remove it before inserting it again diff --git a/src/initializer/CMakeLists.txt b/src/initializer/CMakeLists.txt index 9e4a334f6..815ce8809 100644 --- a/src/initializer/CMakeLists.txt +++ b/src/initializer/CMakeLists.txt @@ -16,7 +16,7 @@ set(PYBIND11_CPP_STANDARD -std=c++17) add_library(${PROJECT_NAME} SHARED ${SOURCE_CPP} ${SOURCE_INC}) target_compile_options(${PROJECT_NAME} PRIVATE ${PHARE_WERROR_FLAGS}) set_property(TARGET ${PROJECT_NAME} PROPERTY INTERPROCEDURAL_OPTIMIZATION ${PHARE_INTERPROCEDURAL_OPTIMIZATION}) - +set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY LINK_FLAGS " ${PHARE_LINK_FLAGS}") target_include_directories(${PROJECT_NAME} PUBLIC $) @@ -30,3 +30,4 @@ set_target_properties(dictator PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/pybindlibs" ) +set_property(TARGET dictator APPEND_STRING PROPERTY LINK_FLAGS " ${PHARE_LINK_FLAGS}") diff --git a/src/phare/CMakeLists.txt b/src/phare/CMakeLists.txt index 7cf083027..a794b0015 100644 --- a/src/phare/CMakeLists.txt +++ b/src/phare/CMakeLists.txt @@ -16,5 +16,6 @@ target_link_libraries(phare-exe PUBLIC phare_simulator pybind11::embed ) +set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY LINK_FLAGS " ${PHARE_LINK_FLAGS}") diff --git a/src/python3/CMakeLists.txt b/src/python3/CMakeLists.txt index d78a2d59d..4e6fb717c 100644 --- a/src/python3/CMakeLists.txt +++ b/src/python3/CMakeLists.txt @@ -11,6 +11,7 @@ set_target_properties(cpp ) # this is on by default "pybind11_add_module" but can interfere with coverage so we disable it if coverage is enabled set_property(TARGET cpp PROPERTY INTERPROCEDURAL_OPTIMIZATION ${PHARE_INTERPROCEDURAL_OPTIMIZATION}) +set_property(TARGET cpp APPEND_STRING PROPERTY LINK_FLAGS " ${PHARE_LINK_FLAGS}") if (CMAKE_BUILD_TYPE STREQUAL "Debug") pybind11_add_module(cpp_dbg cpp_simulator.cpp) @@ -21,6 +22,7 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug") LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/pybindlibs" ) set_property(TARGET cpp_dbg PROPERTY INTERPROCEDURAL_OPTIMIZATION ${PHARE_INTERPROCEDURAL_OPTIMIZATION}) + set_property(TARGET cpp_dbg APPEND_STRING PROPERTY LINK_FLAGS " ${PHARE_LINK_FLAGS}") endif (CMAKE_BUILD_TYPE STREQUAL "Debug") @@ -33,3 +35,4 @@ set_target_properties(cpp_etc ) # this is on by default "pybind11_add_module" but can interfere with coverage so we disable it if coverage is enabled set_property(TARGET cpp_etc PROPERTY INTERPROCEDURAL_OPTIMIZATION ${PHARE_INTERPROCEDURAL_OPTIMIZATION}) +set_property(TARGET cpp_etc APPEND_STRING PROPERTY LINK_FLAGS " ${PHARE_LINK_FLAGS}") diff --git a/src/simulator/CMakeLists.txt b/src/simulator/CMakeLists.txt index 4b0fcb75d..500863dd6 100644 --- a/src/simulator/CMakeLists.txt +++ b/src/simulator/CMakeLists.txt @@ -20,4 +20,4 @@ target_link_libraries(${PROJECT_NAME} PUBLIC phare_amr # for mpicc phare_diagnostic ) - +set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY LINK_FLAGS " ${PHARE_LINK_FLAGS}")