Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ option(IPC_TOOLKIT_WITH_ABSEIL "Use Abseil's hash functions"
option(IPC_TOOLKIT_WITH_FILIB "Use filib for interval arithmetic" ON)
option(IPC_TOOLKIT_WITH_INEXACT_CCD "Use the original inexact CCD method of IPC" OFF)
option(IPC_TOOLKIT_WITH_PROFILER "Enable performance profiler" OFF)
option(IPC_TOOLKIT_WITH_TRACY "Enable Tracy frame profiler" OFF)

# Advanced options
option(IPC_TOOLKIT_WITH_CODE_COVERAGE "Enable coverage reporting" OFF)
Expand Down Expand Up @@ -250,6 +251,12 @@ if(IPC_TOOLKIT_WITH_PROFILER)
target_link_libraries(ipc_toolkit PUBLIC nlohmann_json::nlohmann_json)
endif()

# Tracy profiler
if(IPC_TOOLKIT_WITH_TRACY)
include(tracy)
target_link_libraries(ipc_toolkit PUBLIC Tracy::TracyClient)
endif()

# Extra warnings (link last for highest priority)
include(ipc_toolkit_warnings)
target_link_libraries(ipc_toolkit PRIVATE ipc::toolkit::warnings)
Expand Down
17 changes: 17 additions & 0 deletions cmake/recipes/tracy.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Tracy (https://github.com/wolfpld/tracy)
# License: BSD-3-Clause
if(TARGET Tracy::TracyClient)
return()
endif()

message(STATUS "Third-party: creating target 'Tracy::TracyClient'")

include(CPM)
CPMAddPackage(
URI "gh:wolfpld/tracy@0.13.1"
OPTIONS
"TRACY_ENABLE ${IPC_TOOLKIT_WITH_TRACY}"
"TRACY_ON_DEMAND ON"
)

set_target_properties(TracyClient PROPERTIES FOLDER "ThirdParty")
3 changes: 3 additions & 0 deletions docs/source/_static/graphviz/dependencies.dot
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,7 @@ digraph "IPC Toolkit Dependencies" {
// ipc_toolkit -> nlohmann_json
"node14" [label = "nlohmann_json\n(nlohmann_json::nlohmann_json)";shape = box;style = "rounded,filled";fillcolor = "#FFE6CC";color = "#DAA52D";];
"node5" -> "node14" [color = "#8FB976";];
// ipc_toolkit -> tracy
"node16" [label = "TracyClient\n(Tracy::TracyClient)";shape = box;style = "rounded,filled";fillcolor = "#D5E8D4";color = "#8FB976";];
"node5" -> "node16" [color = "#8FB976";];
}
233 changes: 123 additions & 110 deletions docs/source/_static/graphviz/dependencies.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions docs/source/about/dependencies.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ Additionally, IPC Toolkit may optionally use the following libraries:
- `github.com/nlohmann/json <https://github.com/nlohmann/json>`_
- |:white_large_square:|
- ``IPC_TOOLKIT_WITH_PROFILER``
* - Tracy
- Frame profiler
- BSD-3-Clause
- `github.com/wolfpld/tracy <https://github.com/wolfpld/tracy>`_
- |:white_large_square:|
- ``IPC_TOOLKIT_WITH_TRACY``
* - rational-cpp
- Rational arithmetic used for exact intersection checks (requires `GMP <https://gmplib.org>`_ to be installed at a system level)
- MIT
Expand Down
1 change: 1 addition & 0 deletions src/ipc/config.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#cmakedefine IPC_TOOLKIT_WITH_ABSEIL
#cmakedefine IPC_TOOLKIT_WITH_FILIB
#cmakedefine IPC_TOOLKIT_WITH_PROFILER
#cmakedefine IPC_TOOLKIT_WITH_TRACY
// #define IPC_TOOLKIT_DEBUG_AUTODIFF

namespace ipc {
Expand Down
22 changes: 11 additions & 11 deletions src/ipc/potentials/potential.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ double Potential<TCollisions>::operator()(
Eigen::ConstRef<Eigen::MatrixXd> X) const
{
assert(X.rows() == mesh.num_vertices());
IPC_TOOLKIT_PROFILE_BLOCK(this->name() + "::operator()");
IPC_TOOLKIT_PROFILE_BLOCK("Potential<T>::operator()");

return tbb::parallel_reduce(
tbb::blocked_range<size_t>(size_t(0), collisions.size()), 0.0,
Expand All @@ -63,7 +63,7 @@ Eigen::VectorXd Potential<TCollisions>::gradient(
Eigen::ConstRef<Eigen::MatrixXd> X) const
{
assert(X.rows() == mesh.num_vertices());
IPC_TOOLKIT_PROFILE_BLOCK(this->name() + "::gradient()");
IPC_TOOLKIT_PROFILE_BLOCK("Potential<T>::gradient()");

if (collisions.empty()) {
return Eigen::VectorXd::Zero(X.size());
Expand All @@ -74,7 +74,7 @@ Eigen::VectorXd Potential<TCollisions>::gradient(
tbb::combinable<Eigen::VectorXd> grad(Eigen::VectorXd::Zero(X.size()));

{
IPC_TOOLKIT_PROFILE_BLOCK("compute local gradients");
IPC_TOOLKIT_PROFILE_BLOCK("Compute Local Gradients");
tbb::parallel_for(size_t(0), collisions.size(), [&](size_t i) {
const TCollision& collision = collisions[i];

Expand All @@ -88,7 +88,7 @@ Eigen::VectorXd Potential<TCollisions>::gradient(
}

{
IPC_TOOLKIT_PROFILE_BLOCK("combine local gradients");
IPC_TOOLKIT_PROFILE_BLOCK("Combine Local Gradients");
return grad.combine([](const Eigen::VectorXd& a,
const Eigen::VectorXd& b) { return a + b; });
}
Expand All @@ -102,7 +102,7 @@ Eigen::SparseMatrix<double> Potential<TCollisions>::hessian(
const PSDProjectionMethod project_hessian_to_psd) const
{
assert(X.rows() == mesh.num_vertices());
IPC_TOOLKIT_PROFILE_BLOCK(this->name() + "::hessian()");
IPC_TOOLKIT_PROFILE_BLOCK("Potential<T>::hessian()");

if (collisions.empty()) {
return Eigen::SparseMatrix<double>(X.size(), X.size());
Expand All @@ -129,15 +129,15 @@ Eigen::SparseMatrix<double> Potential<TCollisions>::hessian(

MatrixMaxNd local_hess;
{
IPC_TOOLKIT_PROFILE_BLOCK("compute local hessian");
IPC_TOOLKIT_PROFILE_BLOCK("Compute Local Hessian");
local_hess = this->hessian(
collision, collision.dof(X, edges, faces),
project_hessian_to_psd);
}

{
IPC_TOOLKIT_PROFILE_BLOCK(
"map local hessian to global triplets");
"Map Local Hessian to Global Triplets");
local_hessian_to_global_triplets(
local_hess, collision.vertex_ids(edges, faces), dim,
*(hess_triplets.cache), mesh.num_vertices());
Expand All @@ -152,7 +152,7 @@ Eigen::SparseMatrix<double> Potential<TCollisions>::hessian(
// storage

{
IPC_TOOLKIT_PROFILE_BLOCK("prune local storages");
IPC_TOOLKIT_PROFILE_BLOCK("Prune Local Storages");
tbb::parallel_for_each(
storage.begin(), storage.end(),
[](const auto& local_storage) { local_storage.cache->prune(); });
Expand Down Expand Up @@ -188,13 +188,13 @@ Eigen::SparseMatrix<double> Potential<TCollisions>::hessian(

// Allocate triplets
{
IPC_TOOLKIT_PROFILE_BLOCK("allocate triplets");
IPC_TOOLKIT_PROFILE_BLOCK("Allocate Triplets");
triplets.resize(triplet_count);
}

// Parallel copy into triplets
{
IPC_TOOLKIT_PROFILE_BLOCK("parallel copy into triplets");
IPC_TOOLKIT_PROFILE_BLOCK("Parallel Copy into Triplets");
tbb::parallel_for(size_t(0), storage.size(), [&](size_t i) {
const SparseMatrixCache& cache =
dynamic_cast<const SparseMatrixCache&>(
Expand All @@ -214,7 +214,7 @@ Eigen::SparseMatrix<double> Potential<TCollisions>::hessian(

// Sort and assemble
{
IPC_TOOLKIT_PROFILE_BLOCK("assemble hessian from triplets");
IPC_TOOLKIT_PROFILE_BLOCK("Assemble Hessian from Triplets");
hess.setFromTriplets(triplets.begin(), triplets.end());
}

Expand Down
15 changes: 13 additions & 2 deletions src/ipc/utils/profiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

#include <ipc/config.hpp>

#ifdef IPC_TOOLKIT_WITH_TRACY
#include <tracy/Tracy.hpp>
#else
// Empty macro to avoid compilation errors when Tracy is not enabled.
#define ZoneScopedN(name) ((void)0)
#endif

#include <string>

#ifdef IPC_TOOLKIT_WITH_PROFILER

// clang-format off
Expand All @@ -22,7 +31,8 @@

#define IPC_TOOLKIT_PROFILE_BLOCK(...) \
ipc::ProfilePoint IPC_TOOLKIT_PROFILE_BLOCK_CONCAT( \
__ipc_profile_point_, __COUNTER__)(__VA_ARGS__)
__ipc_profile_point_, __COUNTER__)(__VA_ARGS__); \
ZoneScopedN(__VA_ARGS__)
Comment on lines 32 to +35

namespace ipc {

Expand Down Expand Up @@ -132,6 +142,7 @@ template <class Timer = ChronoTimer> class ProfilePoint {

#else

#define IPC_TOOLKIT_PROFILE_BLOCK(...)
// Custom profiler disabled: Tracy zone only.
#define IPC_TOOLKIT_PROFILE_BLOCK(...) ZoneScopedN(__VA_ARGS__)

#endif
Loading