Skip to content

Commit

Permalink
Clean up profile event names
Browse files Browse the repository at this point in the history
Summary: Remove redundant prefixes from the profile event names (e.g., `Solver: ` and `Skeleton: `) for a cleaner view in profilers. This information can be extracted by examining the parent scope or viewing details (by hovering over the event, as in the Tracy case).

Reviewed By: EscapeZero

Differential Revision: D68533619

fbshipit-source-id: 39e9f7d25cd2291bc905645ddba32b0a7d07743c
  • Loading branch information
jeongseok-meta authored and facebook-github-bot committed Jan 23, 2025
1 parent 436daed commit a67e3f1
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 22 deletions.
2 changes: 1 addition & 1 deletion momentum/character_solver/gauss_newton_solver_qr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void GaussNewtonSolverQRT<T>::doIteration() {
const auto parameterTransform = sf->getParameterTransform();

{
MT_PROFILE_EVENT("Skeleton: JtJR - update state");
MT_PROFILE_EVENT("JtJR - update state");
skeletonState_->set(parameterTransform->apply(this->parameters_), *skeleton);
}

Expand Down
10 changes: 5 additions & 5 deletions momentum/character_solver/skeleton_solver_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ double SkeletonSolverFunctionT<T>::getJacobian(

// update the state according to the transformed parameters
{
MT_PROFILE_EVENT("Skeleton: set state");
MT_PROFILE_EVENT("Set state");
state_->set(parameterTransform_->apply(parameters), *skeleton_);
}

Expand All @@ -141,7 +141,7 @@ double SkeletonSolverFunctionT<T>::getJacobian(
// add values to the jacobian
size_t position = 0;

MT_PROFILE_EVENT("Skeleton: collect all jacobians");
MT_PROFILE_EVENT("Collect all jacobians");

for (size_t i = 0; i < errorFunctions_.size(); i++) {
int rows = 0;
Expand Down Expand Up @@ -171,7 +171,7 @@ double SkeletonSolverFunctionT<T>::getJtJR(

// update the state according to the transformed parameters
{
MT_PROFILE_EVENT("Skeleton: JtJR - update state");
MT_PROFILE_EVENT("JtJR - update state");
state_->set(parameterTransform_->apply(parameters), *skeleton_);
}

Expand All @@ -193,7 +193,7 @@ double SkeletonSolverFunctionT<T>::getJtJR(
}

{
MT_PROFILE_EVENT("Skeleton: JtJR - set to Zero");
MT_PROFILE_EVENT("JtJR - set to Zero");

tJacobian_.topRows(jacobianSize).setZero();
tResidual_.head(jacobianSize).setZero();
Expand Down Expand Up @@ -222,7 +222,7 @@ double SkeletonSolverFunctionT<T>::getJtJR(

// Update JtJ
if (rows > 0) {
MT_PROFILE_EVENT("Skeleton: partial JtJ JtR");
MT_PROFILE_EVENT("Partial JtJ JtR");

// ! In truth, on the the "this->actualParameters_" leftmost block will be used
// We take advantage of this here and skip the other computations
Expand Down
2 changes: 1 addition & 1 deletion momentum/character_solver/trust_region_qr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void TrustRegionQRT<T>::doIteration() {
const auto parameterTransform = sf->getParameterTransform();

{
MT_PROFILE_EVENT("Skeleton: JtJR - update state");
MT_PROFILE_EVENT("JtJR - update state");
skeletonState_.set(parameterTransform->apply(this->parameters_), *skeleton);
}

Expand Down
33 changes: 18 additions & 15 deletions momentum/solver/gauss_newton_solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,12 @@ void GaussNewtonSolverT<T>::doIteration() {

template <typename T>
void GaussNewtonSolverT<T>::doIterationDense() {
MT_PROFILE_FUNCTION();

Eigen::VectorX<T> delta;
if (useBlockJtJ_) {
// get JtJ and JtR pre-computed
MT_PROFILE_EVENT("Solver: Get JtJ and JtR");
MT_PROFILE_EVENT("Get JtJ and JtR");
this->error_ = this->solverFunction_->getJtJR(this->parameters_, hessianApprox_, JtR_);
} else {
// Get the jacobian and compute JtJ and JtR here
Expand All @@ -90,7 +92,7 @@ void GaussNewtonSolverT<T>::doIterationDense() {
// calculate the step direction according to the gauss newton update
delta.setZero(this->numParameters_);
{
MT_PROFILE_EVENT("Solver: Dense gauss newton step");
MT_PROFILE_EVENT("Dense gauss newton step");

// delta = (Jt*J)^-1*Jt*r ...
// - add some regularization to make sure the system is never unstable and explodes in weird
Expand All @@ -104,7 +106,7 @@ void GaussNewtonSolverT<T>::doIterationDense() {
updateParameters(delta);

{
MT_PROFILE_EVENT("Solver: Store history");
MT_PROFILE_EVENT("Store history");
if (this->storeHistory) {
auto& jtjHist = this->iterationHistory_["jtj"];
if (jtjHist.rows() !=
Expand All @@ -123,30 +125,31 @@ void GaussNewtonSolverT<T>::doIterationDense() {

template <typename T>
void GaussNewtonSolverT<T>::doIterationSparse() {
MT_PROFILE_FUNCTION();

Eigen::VectorX<T> delta;
MT_PROFILE_EVENT("Solver: sparse gauss newton step");

if (!directSparseJtJ_) // make a dense matrix and sparsify later
{
if (useBlockJtJ_) {
// get JtJ and JtR pre-computed
{
MT_PROFILE_EVENT("Solver: Get sparse JtJ and JtR");
MT_PROFILE_EVENT("Get sparse JtJ and JtR");
this->error_ = this->solverFunction_->getJtJR(this->parameters_, hessianApprox_, JtR_);
}

{
MT_PROFILE_EVENT("Solver: Get sparse JtJ and JtR");
MT_PROFILE_EVENT("Get sparse JtJ and JtR");
// sparsify the system
JtJ_ = hessianApprox_.sparseView();
}
} else {
MT_PROFILE_EVENT("Solver: Sparse gauss newton step");
MT_PROFILE_EVENT("Sparse gauss newton step");

// get the jacobian and residual
size_t size = 0;
{
MT_PROFILE_EVENT("Solver: get Jacobian");
MT_PROFILE_EVENT("get Jacobian");
this->error_ =
this->solverFunction_->getJacobian(this->parameters_, jacobian_, residual_, size);
}
Expand All @@ -160,7 +163,7 @@ void GaussNewtonSolverT<T>::doIterationSparse() {
}
} else // directly sparse JtJ
{
MT_PROFILE_EVENT("Solver: Get sparse JtJ and JtR");
MT_PROFILE_EVENT("Get sparse JtJ and JtR");
this->error_ = this->solverFunction_->getJtJR_Sparse(this->parameters_, JtJ_, JtR_);
}

Expand All @@ -172,28 +175,28 @@ void GaussNewtonSolverT<T>::doIterationSparse() {

// Symbolic decomposition, only needed if the params pattern changed
if (this->newParameterPattern_) {
MT_PROFILE_EVENT("Solver: Sparse analyze");
MT_PROFILE_EVENT("Sparse analyze");
lltSolver_.analyzePattern(JtJ_);
this->newParameterPattern_ = !directSparseJtJ_; // works fine for sparse matrix with explicit 0s
}

// Numerical update with the new coefficients
{
MT_PROFILE_EVENT("Solver: Sparse factorization");
MT_PROFILE_EVENT("Sparse factorization");
lltSolver_.factorize(JtJ_);
}

// Solve, compute the gauss-newton step
{
MT_PROFILE_EVENT("Solver: Sparse solve");
MT_PROFILE_EVENT("Sparse solve");
delta.setZero(this->numParameters_);
delta.head(this->actualParameters_) = lltSolver_.solve(JtR_);
}

updateParameters(delta);

{
MT_PROFILE_EVENT("Solver: Store history");
MT_PROFILE_EVENT("Store history");
if (this->storeHistory) {
this->iterationHistory_["solver_err"].setZero(1, 1);
if (lltSolver_.info() != Eigen::Success) {
Expand All @@ -209,12 +212,12 @@ void GaussNewtonSolverT<T>::doIterationSparse() {
template <typename T>
void GaussNewtonSolverT<T>::updateParameters(Eigen::VectorX<T>& delta) {
if (!doLineSearch_) {
MT_PROFILE_EVENT("Solver: Update params");
MT_PROFILE_EVENT("Update params");
this->solverFunction_->updateParameters(this->parameters_, delta);
return;
}

MT_PROFILE_EVENT("Solver: Line search");
MT_PROFILE_EVENT("Line search");

static constexpr T kC1 = 1e-3;
static constexpr T kTau = 0.5;
Expand Down

0 comments on commit a67e3f1

Please sign in to comment.