Skip to content

Commit

Permalink
profile guided optimization release
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipDeegan committed Dec 9, 2023
1 parent 2e9c825 commit 7214ee5
Show file tree
Hide file tree
Showing 14 changed files with 78 additions and 10 deletions.
19 changes: 18 additions & 1 deletion res/cmake/def.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions res/cmake/options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
38 changes: 38 additions & 0 deletions res/cmake_pgo_go.sh
Original file line number Diff line number Diff line change
@@ -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
)
1 change: 1 addition & 0 deletions src/amr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}")

2 changes: 1 addition & 1 deletion src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../../subprojects>)

set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY LINK_FLAGS " ${PHARE_LINK_FLAGS}")

4 changes: 2 additions & 2 deletions src/core/data/particles/particle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ struct Particle

Particle() = default;

double weight;
double charge;
double weight = 0;
double charge = 0;

std::array<int, dim> iCell = ConstArray<int, dim>();
std::array<double, dim> delta = ConstArray<double, dim>();
Expand Down
1 change: 1 addition & 0 deletions src/core/numerics/ion_updater/ion_updater.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ void IonUpdater<Ions, Electromag, GridLayout>::updateAndDepositDomain_(Ions& ion

if (copyInDomain)
{
domain.reserve(domain.size() + enteredInDomain.size());
std::copy(enteredInDomain.begin(), enteredInDomain.end(),
std::back_inserter(domain));
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/numerics/ohm/ohm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,8 @@ class Ohm : public LayoutHolder<GridLayout>

template<auto component, typename VecField>
auto hyperresistive_(VecField const& J, MeshIndex<VecField::dimension> 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);
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/core/numerics/pusher/boris.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class BorisPusher


/** see Pusher::move() documentation*/
void setMeshAndTimeStep(std::array<double, dim> ms, double ts) override
void setMeshAndTimeStep(std::array<double, dim> ms, double const ts) override
{
std::transform(std::begin(ms), std::end(ms), std::begin(halfDtOverDl_),
[ts](double& x) { return 0.5 * ts / x; });
Expand Down
2 changes: 1 addition & 1 deletion src/core/utilities/cellmap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ inline void CellMap<dim, cell_index_t>::empty()
template<std::size_t dim, typename cell_index_t>
template<typename Array, typename CellIndex, typename CellExtractor>
inline void CellMap<dim, cell_index_t>::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
Expand Down
3 changes: 2 additions & 1 deletion src/initializer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../../subprojects>)
Expand All @@ -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}")
1 change: 1 addition & 0 deletions src/phare/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}")


3 changes: 3 additions & 0 deletions src/python3/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")


Expand All @@ -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}")
2 changes: 1 addition & 1 deletion src/simulator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}")

0 comments on commit 7214ee5

Please sign in to comment.