Skip to content

Commit

Permalink
Add ImpactX_UNITY_BUILD (#861)
Browse files Browse the repository at this point in the history
* Add `ImpactX_UNITY_BUILD`

Unity builds combine all `.cpp` files into a single one
(a single translation unit, TU). This is useful for
performance optimization, computer science experiments,
or differentiable programming.

* CI: Add a Unity Build

* Fix Ambiguous `diagnostics` namespace
  • Loading branch information
ax3l authored Feb 24, 2025
1 parent 23b543b commit 61b13e4
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ jobs:
-DCMAKE_VERBOSE_MAKEFILE=ON \
-DImpactX_FFT=ON \
-DImpactX_PYTHON=ON \
-DImpactX_UNITY_BUILD=ON \
-DMPIEXEC_POSTFLAGS="--use-hwthread-cpus"
cmake --build build -j 4
Expand Down
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ option(ImpactX_PYTHON_IPO
${_ImpactX_PYTHON_IPO_DEFAULT}
)

# Unity builds combine all .cpp files into a single one (a single translation
# unit, TU).
option(ImpactX_UNITY_BUILD "ImpactX library as unity build" OFF)

if(ImpactX_FFT)
set(ABLASTR_FFT ON CACHE STRING "FFT-based solvers" FORCE)
endif()
Expand Down Expand Up @@ -165,6 +169,16 @@ set_target_properties(lib PROPERTIES
WINDOWS_EXPORT_ALL_SYMBOLS ON
)

# Optional: build only a single TU
if(ImpactX_UNITY_BUILD)
set_target_properties(lib PROPERTIES
UNITY_BUILD ON
UNITY_BUILD_MODE BATCH
# Number must be more than the number of .cpp files in ImpactX
UNITY_BUILD_BATCH_SIZE 10000
)
endif()

# executable application
# note: we currently avoid a dependency on a core library
# for simpler usage, but could make this an option
Expand Down
3 changes: 3 additions & 0 deletions cmake/ImpactXFunctions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,9 @@ function(impactx_print_summary)
else()
set(LIB_TYPE "static")
endif()
if(ImpactX_UNITY_BUILD)
set(LIB_TYPE "${LIB_TYPE} (unity build)")
endif()
#message(" Testing: ${BUILD_TESTING}")
message(" Build options:")
message(" APP: ${ImpactX_APP}")
Expand Down
1 change: 1 addition & 0 deletions docs/source/install/cmake.rst
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ CMake Option Default & Values Des
============================= ============================================== ===========================================================
``BUILD_SHARED_LIBS`` ON/**OFF** Build shared libraries for dependencies
``ImpactX_CCACHE`` **ON**/OFF Search and use CCache to speed up rebuilds.
``ImpactX_UNITY_BUILD`` ON/**OFF** ImpactX library as unity build (single TU)
``ImpactX_ablastr_src`` *None* Path to ABLASTR source directory (preferred if set)
``ImpactX_ablastr_repo`` ``https://github.com/ECP-WarpX/WarpX.git`` Repository URI to pull and build ABLASTR from
``ImpactX_ablastr_branch`` *we set and maintain a compatible commit* Repository branch for ``ImpactX_ablastr_repo``
Expand Down
3 changes: 2 additions & 1 deletion src/initialization/InitElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,8 @@ namespace detail
pp_element.queryAddWithParser("cn", cn);
}

m_lattice.emplace_back(diagnostics::BeamMonitor(openpmd_name, openpmd_backend, openpmd_encoding, period_sample_intervals));
using impactx::elements::diagnostics::BeamMonitor;
m_lattice.emplace_back(BeamMonitor(openpmd_name, openpmd_backend, openpmd_encoding, period_sample_intervals));
} else if (element_type == "source")
{
std::string distribution, openpmd_path;
Expand Down

0 comments on commit 61b13e4

Please sign in to comment.