Skip to content

Commit

Permalink
[profile] Initial profiling setup with Tracy
Browse files Browse the repository at this point in the history
  • Loading branch information
jslee02 committed Mar 25, 2024
1 parent 383140b commit c90799a
Show file tree
Hide file tree
Showing 17 changed files with 286 additions and 59 deletions.
17 changes: 16 additions & 1 deletion .github/workflows/ci_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,22 @@ jobs:
- uses: johnwason/vcpkg-action@v6
with:
# TODO: Add ode and coin-or-ipopt
pkgs: assimp eigen3 fcl fmt spdlog bullet3 freeglut glfw3 nlopt opengl osg pagmo2 tinyxml2 urdfdom
pkgs: >
assimp
eigen3
fcl
fmt
spdlog
bullet3
freeglut
glfw3
nlopt
opengl
osg
pagmo2
tinyxml2
tracy
urdfdom
triplet: x64-windows
revision: "2024.02.14"
github-binarycache: true
Expand Down
20 changes: 19 additions & 1 deletion .github/workflows/publish_dartpy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,25 @@ jobs:
if: ${{ matrix.os == 'windows-latest' && (matrix.release_only == false || github.ref == 'refs/heads/main') }}
uses: johnwason/vcpkg-action@v6
with:
pkgs: assimp ccd eigen3 fcl fmt spdlog bullet3 coin-or-ipopt freeglut glfw3 imgui nlopt ode opengl osg pagmo2 tinyxml2 urdfdom
pkgs: >
assimp
ccd
eigen3
fcl
fmt
spdlog
bullet3
coin-or-ipopt
freeglut
glfw3
imgui
nlopt
ode
opengl
osg
pagmo2
tinyxml2
urdfdom
triplet: x64-windows
revision: "2024.02.14"
github-binarycache: true
Expand Down
1 change: 1 addition & 0 deletions Brewfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Build dependencies
brew 'cmake'
brew 'pkg-config'
brew 'tracy'

brew 'assimp'
brew 'bullet'
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ dart_option(DART_ENABLE_SIMD
"Build DART with all SIMD instructions on the current local machine" OFF)
dart_option(DART_BUILD_GUI_OSG "Build osgDart library" ON)
dart_option(DART_BUILD_DARTPY "Build dartpy" ON)
dart_option(DART_BUILD_PROFILE "Build DART with profiling options" OFF)
dart_option(DART_CODECOV "Turn on codecov support" OFF)
dart_option(DART_FAST_DEBUG "Add -O1 option for DEBUG mode build" OFF)
# GCC and Clang add ANSI-formatted colors when they detect the output medium is a
Expand Down
16 changes: 16 additions & 0 deletions cmake/DARTFindDependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,22 @@ endif()
# Optional dependencies
#=======================

if(DART_BUILD_PROFILE)
include(FetchContent)
FetchContent_Declare(tracy
GIT_REPOSITORY https://github.com/wolfpld/tracy.git
GIT_TAG v0.10
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
)
FetchContent_MakeAvailable(tracy)
if(MSVC)
target_compile_options(external_lib_target PRIVATE /W0)
else()
target_compile_options(TracyClient PRIVATE -w)
endif()
endif()

find_package(Python3 COMPONENTS Interpreter Development)

option(DART_SKIP_spdlog "If ON, do not use spdlog even if it is found." OFF)
Expand Down
4 changes: 4 additions & 0 deletions dart/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ if(DART_CODECOV)
target_link_libraries(dart PUBLIC coverage_config)
endif()

if(DART_BUILD_PROFILE)
target_link_libraries(dart PUBLIC TracyClient)
endif()

install(FILES dart.hpp DESTINATION include/dart/ COMPONENT headers)

dart_format_add(${dart_core_headers} ${dart_core_sources})
59 changes: 59 additions & 0 deletions dart/common/Profile.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (c) 2011-2024, The DART development contributors
* All rights reserved.
*
* The list of contributors can be found at:
* https://github.com/dartsim/dart/blob/main/LICENSE
*
* This file is provided under the following "BSD-style" License:
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

#pragma once

#include <dart/config.hpp>

#if DART_BUILD_PROFILE
#include <tracy/Tracy.hpp>
#endif

#if DART_BUILD_PROFILE

#define DART_PROFILE_FRAME FrameMark
#define DART_PROFILE_SCOPED ZoneScoped
#define DART_PROFILE_SCOPED_N(name) ZoneScopedN(name)

#else // no-op

#define DART_PROFILE_FRAME
#define DART_PROFILE_SCOPED
#define DART_PROFILE_SCOPED_N(name)

#endif

namespace dart::common {

//

} // namespace dart::common
2 changes: 2 additions & 0 deletions dart/config.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,5 @@
#cmakedefine BT_USE_DOUBLE_PRECISION

#cmakedefine01 DART_USE_SYSTEM_IMGUI

#cmakedefine01 DART_BUILD_PROFILE
107 changes: 60 additions & 47 deletions dart/constraint/BoxedLcpConstraintSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#endif

#include "dart/common/Console.hpp"
#include "dart/common/Profile.hpp"
#include "dart/constraint/ConstraintBase.hpp"
#include "dart/constraint/DantzigBoxedLcpSolver.hpp"
#include "dart/constraint/PgsBoxedLcpSolver.hpp"
Expand Down Expand Up @@ -140,6 +141,8 @@ ConstBoxedLcpSolverPtr BoxedLcpConstraintSolver::getSecondaryBoxedLcpSolver()
//==============================================================================
void BoxedLcpConstraintSolver::solveConstrainedGroup(ConstrainedGroup& group)
{
DART_PROFILE_SCOPED;

// Build LCP terms by aggregating them from constraints
const std::size_t numConstraints = group.getNumConstraints();
const std::size_t n = group.getTotalDimension();
Expand Down Expand Up @@ -171,54 +174,60 @@ void BoxedLcpConstraintSolver::solveConstrainedGroup(ConstrainedGroup& group)
}

// For each constraint
ConstraintInfo constInfo;
constInfo.invTimeStep = 1.0 / mTimeStep;
for (std::size_t i = 0; i < numConstraints; ++i) {
const ConstraintBasePtr& constraint = group.getConstraint(i);

constInfo.x = mX.data() + mOffset[i];
constInfo.lo = mLo.data() + mOffset[i];
constInfo.hi = mHi.data() + mOffset[i];
constInfo.b = mB.data() + mOffset[i];
constInfo.findex = mFIndex.data() + mOffset[i];
constInfo.w = mW.data() + mOffset[i];

// Fill vectors: lo, hi, b, w
constraint->getInformation(&constInfo);

// Fill a matrix by impulse tests: A
constraint->excite();
for (std::size_t j = 0; j < constraint->getDimension(); ++j) {
// Adjust findex for global index
if (mFIndex[mOffset[i] + j] >= 0)
mFIndex[mOffset[i] + j] += mOffset[i];

// Apply impulse for mipulse test
constraint->applyUnitImpulse(j);

// Fill upper triangle blocks of A matrix
int index = nSkip * (mOffset[i] + j) + mOffset[i];
constraint->getVelocityChange(mA.data() + index, true);
for (std::size_t k = i + 1; k < numConstraints; ++k) {
index = nSkip * (mOffset[i] + j) + mOffset[k];
group.getConstraint(k)->getVelocityChange(mA.data() + index, false);
}
{
DART_PROFILE_SCOPED_N("Construct LCP");
ConstraintInfo constInfo;
constInfo.invTimeStep = 1.0 / mTimeStep;
for (std::size_t i = 0; i < numConstraints; ++i) {
const ConstraintBasePtr& constraint = group.getConstraint(i);

constInfo.x = mX.data() + mOffset[i];
constInfo.lo = mLo.data() + mOffset[i];
constInfo.hi = mHi.data() + mOffset[i];
constInfo.b = mB.data() + mOffset[i];
constInfo.findex = mFIndex.data() + mOffset[i];
constInfo.w = mW.data() + mOffset[i];

// Fill vectors: lo, hi, b, w
constraint->getInformation(&constInfo);

// Fill a matrix by impulse tests: A
constraint->excite();
for (std::size_t j = 0; j < constraint->getDimension(); ++j) {
// Adjust findex for global index
if (mFIndex[mOffset[i] + j] >= 0)
mFIndex[mOffset[i] + j] += mOffset[i];

// Apply impulse for mipulse test
constraint->applyUnitImpulse(j);

// Fill upper triangle blocks of A matrix
int index = nSkip * (mOffset[i] + j) + mOffset[i];
constraint->getVelocityChange(mA.data() + index, true);
for (std::size_t k = i + 1; k < numConstraints; ++k) {
index = nSkip * (mOffset[i] + j) + mOffset[k];
group.getConstraint(k)->getVelocityChange(mA.data() + index, false);
}

// Filling symmetric part of A matrix
for (std::size_t k = 0; k < i; ++k) {
const int indexI = mOffset[i] + j;
for (std::size_t l = 0; l < group.getConstraint(k)->getDimension();
++l) {
const int indexJ = mOffset[k] + l;
mA(indexI, indexJ) = mA(indexJ, indexI);
// Filling symmetric part of A matrix
for (std::size_t k = 0; k < i; ++k) {
const int indexI = mOffset[i] + j;
for (std::size_t l = 0; l < group.getConstraint(k)->getDimension();
++l) {
const int indexJ = mOffset[k] + l;
mA(indexI, indexJ) = mA(indexJ, indexI);
}
}
}
}

assert(isSymmetric(
n, mA.data(), mOffset[i], mOffset[i] + constraint->getDimension() - 1));
assert(isSymmetric(
n,
mA.data(),
mOffset[i],
mOffset[i] + constraint->getDimension() - 1));

constraint->unexcite();
constraint->unexcite();
}
}

assert(isSymmetric(n, mA.data()));
Expand Down Expand Up @@ -259,6 +268,7 @@ void BoxedLcpConstraintSolver::solveConstrainedGroup(ConstrainedGroup& group)
success = false;

if (!success && mSecondaryBoxedLcpSolver) {
DART_PROFILE_SCOPED_N("Secondary LCP");
mSecondaryBoxedLcpSolver->solve(
n,
mABackup.data(),
Expand Down Expand Up @@ -287,10 +297,13 @@ void BoxedLcpConstraintSolver::solveConstrainedGroup(ConstrainedGroup& group)
// std::cout << std::endl;

// Apply constraint impulses
for (std::size_t i = 0; i < numConstraints; ++i) {
const ConstraintBasePtr& constraint = group.getConstraint(i);
constraint->applyImpulse(mX.data() + mOffset[i]);
constraint->excite();
{
DART_PROFILE_SCOPED_N("Apply constraint impulses");
for (std::size_t i = 0; i < numConstraints; ++i) {
const ConstraintBasePtr& constraint = group.getConstraint(i);
constraint->applyImpulse(mX.data() + mOffset[i]);
constraint->excite();
}
}
}

Expand Down
13 changes: 12 additions & 1 deletion dart/constraint/ConstraintSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "dart/collision/fcl/FCLCollisionDetector.hpp"
#include "dart/common/Console.hpp"
#include "dart/common/Macros.hpp"
#include "dart/common/Profile.hpp"
#include "dart/constraint/ConstrainedGroup.hpp"
#include "dart/constraint/ContactConstraint.hpp"
#include "dart/constraint/ContactSurface.hpp"
Expand Down Expand Up @@ -361,6 +362,8 @@ LCPSolver* ConstraintSolver::getLCPSolver() const
//==============================================================================
void ConstraintSolver::solve()
{
DART_PROFILE_SCOPED_N("ConstraintSolver::solve");

for (auto& skeleton : mSkeletons) {
skeleton->clearConstraintImpulses();
DART_SUPPRESS_DEPRECATED_BEGIN
Expand Down Expand Up @@ -454,6 +457,8 @@ bool ConstraintSolver::checkAndAddConstraint(
//==============================================================================
void ConstraintSolver::updateConstraints()
{
DART_PROFILE_SCOPED;

// Clear previous active constraint list
mActiveConstraints.clear();

Expand Down Expand Up @@ -635,6 +640,8 @@ void ConstraintSolver::updateConstraints()
//==============================================================================
void ConstraintSolver::buildConstrainedGroups()
{
DART_PROFILE_SCOPED;

// Clear constrained groups
mConstrainedGroups.clear();

Expand Down Expand Up @@ -687,8 +694,12 @@ void ConstraintSolver::buildConstrainedGroups()
//==============================================================================
void ConstraintSolver::solveConstrainedGroups()
{
for (auto& constraintGroup : mConstrainedGroups)
DART_PROFILE_SCOPED;

for (auto& constraintGroup : mConstrainedGroups) {
DART_PROFILE_SCOPED;
solveConstrainedGroup(constraintGroup);
}
}

//==============================================================================
Expand Down
2 changes: 2 additions & 0 deletions dart/constraint/DantzigBoxedLcpSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include "dart/constraint/DantzigBoxedLcpSolver.hpp"

#include "dart/common/Profile.hpp"
#include "dart/external/odelcpsolver/lcp.h"

namespace dart {
Expand Down Expand Up @@ -62,6 +63,7 @@ bool DantzigBoxedLcpSolver::solve(
int* findex,
bool earlyTermination)
{
DART_PROFILE_SCOPED;
return external::ode::dSolveLCP(
n, A, x, b, nullptr, 0, lo, hi, findex, earlyTermination);
}
Expand Down
2 changes: 2 additions & 0 deletions dart/constraint/PGSLCPSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#endif

#include "dart/common/Console.hpp"
#include "dart/common/Profile.hpp"
#include "dart/constraint/ConstrainedGroup.hpp"
#include "dart/constraint/ConstraintBase.hpp"
#include "dart/external/odelcpsolver/lcp.h"
Expand All @@ -55,6 +56,7 @@ PGSLCPSolver::~PGSLCPSolver() {}
//==============================================================================
void PGSLCPSolver::solve(ConstrainedGroup* _group)
{
DART_PROFILE_SCOPED;
// If there is no constraint, then just return true.
std::size_t numConstraints = _group->getNumConstraints();
if (numConstraints == 0)
Expand Down
Loading

0 comments on commit c90799a

Please sign in to comment.