Skip to content

Commit

Permalink
Merge pull request #191 from jorisv/topic/tracy-wrapper
Browse files Browse the repository at this point in the history
Use tracy.cmake to easily set/remove tracy dependency
  • Loading branch information
ManifoldFR authored Sep 11, 2024
2 parents f110f9b + abaa3e9 commit 7d750a8
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 46 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Use placement-new for `Workspace` and `Results` in solvers (FDDP and ProxDDP)
- Deprecate typedef for `std::vector<T, Eigen::aligned_allocator<T>>`
- Deprecate function template `allocate_shared_eigen_aligned<T>`
- Use custom macro defined in `aligator/tracy.hpp` to call Tracy ([#191](https://github.com/Simple-Robotics/aligator/pull/191))

### Fixed

Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ compute_project_args(PROJECT_ARGS LANGUAGES CXX)
project(${PROJECT_NAME} ${PROJECT_ARGS})
set(CMAKE_VERBOSE_MAKEFILE OFF)

include(${JRL_CMAKE_MODULES}/tracy.cmake)
include(${JRL_CMAKE_MODULES}/boost.cmake)
include(${JRL_CMAKE_MODULES}/ide.cmake)
include(${JRL_CMAKE_MODULES}/python.cmake)
Expand Down
2 changes: 1 addition & 1 deletion cmake
Submodule cmake updated 2 files
+107 −0 tracy.cmake
+33 −0 tracy.hh.cmake
6 changes: 3 additions & 3 deletions gar/include/aligator/gar/block-tridiagonal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "aligator/gar/blk-matrix.hpp"
#include "aligator/eigen-macros.hpp"
#include <tracy/Tracy.hpp>
#include "aligator/tracy.hpp"

namespace aligator {
namespace gar {
Expand Down Expand Up @@ -81,7 +81,7 @@ bool symmetricBlockTridiagSolve(std::vector<MatrixType> &subdiagonal,
const std::vector<MatrixType> &superdiagonal,
BlkMatrix<RhsType, -1, 1> &rhs,
std::vector<DecType> &facs) {
ZoneScoped;
ALIGATOR_TRACY_ZONE_SCOPED;
ALIGATOR_NOMALLOC_SCOPED;

if (subdiagonal.size() != superdiagonal.size() ||
Expand Down Expand Up @@ -183,7 +183,7 @@ bool symmetricBlockTridiagSolveDownLooking(
std::vector<MatrixType> &subdiagonal, std::vector<MatrixType> &diagonal,
std::vector<MatrixType> &superdiagonal, BlkMatrix<RhsType, -1, 1> &rhs,
std::vector<DecType> &facs) {
ZoneScoped;
ALIGATOR_TRACY_ZONE_SCOPED;
ALIGATOR_NOMALLOC_SCOPED;

if (subdiagonal.size() != superdiagonal.size() ||
Expand Down
3 changes: 2 additions & 1 deletion gar/include/aligator/gar/dense-riccati.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "dense-riccati.hpp"
#include "lqr-problem.hpp"
#include "aligator/tracy.hpp"

namespace aligator::gar {

Expand Down Expand Up @@ -44,7 +45,7 @@ template <typename Scalar> void RiccatiSolverDense<Scalar>::initialize() {
template <typename Scalar>
bool RiccatiSolverDense<Scalar>::backward(const Scalar mudyn,
const Scalar mueq) {
ZoneScoped;
ALIGATOR_TRACY_ZONE_SCOPED;
const auto &stages = problem_->stages;

const uint N = (uint)problem_->horizon();
Expand Down
3 changes: 2 additions & 1 deletion gar/include/aligator/gar/parallel-solver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "aligator/gar/fwd.hpp"
#include "aligator/gar/riccati-base.hpp"
#include "aligator/gar/riccati-impl.hpp"
#include "aligator/tracy.hpp"

namespace aligator {
namespace gar {
Expand Down Expand Up @@ -40,7 +41,7 @@ class ParallelRiccatiSolver : public RiccatiSolverBase<_Scalar> {
void allocateLeg(uint start, uint end, bool last_leg);

static void setupKnot(KnotType &knot, const Scalar mudyn) {
ZoneScoped;
ALIGATOR_TRACY_ZONE_SCOPED;
ALIGATOR_NOMALLOC_SCOPED;
knot.Gx = knot.A.transpose();
knot.Gu = knot.B.transpose();
Expand Down
15 changes: 8 additions & 7 deletions gar/include/aligator/gar/parallel-solver.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "aligator/gar/block-tridiagonal.hpp"
#include "aligator/gar/work.hpp"
#include "aligator/gar/lqr-problem.hpp"
#include "aligator/tracy.hpp"

#include "aligator/threads.hpp"

Expand All @@ -16,7 +17,7 @@ template <typename Scalar>
ParallelRiccatiSolver<Scalar>::ParallelRiccatiSolver(
LQRProblemTpl<Scalar> &problem, const uint num_threads)
: Base(), numThreads(num_threads), problem_(&problem) {
ZoneScoped;
ALIGATOR_TRACY_ZONE_SCOPED;

uint N = (uint)problem.horizon();
for (uint i = 0; i < num_threads; i++) {
Expand All @@ -40,7 +41,7 @@ ParallelRiccatiSolver<Scalar>::ParallelRiccatiSolver(
template <typename Scalar>
void ParallelRiccatiSolver<Scalar>::allocateLeg(uint start, uint end,
bool last_leg) {
ZoneScoped;
ALIGATOR_TRACY_ZONE_SCOPED;
for (uint t = start; t < end; t++) {
KnotType &knot = problem_->stages[t];
if (!last_leg)
Expand All @@ -52,7 +53,7 @@ void ParallelRiccatiSolver<Scalar>::allocateLeg(uint start, uint end,
template <typename Scalar>
void ParallelRiccatiSolver<Scalar>::assembleCondensedSystem(
const Scalar mudyn) {
ZoneScoped;
ALIGATOR_TRACY_ZONE_SCOPED;
std::vector<MatrixXs> &subdiagonal = condensedKktSystem.subdiagonal;
std::vector<MatrixXs> &diagonal = condensedKktSystem.diagonal;
std::vector<MatrixXs> &superdiagonal = condensedKktSystem.superdiagonal;
Expand Down Expand Up @@ -102,7 +103,7 @@ bool ParallelRiccatiSolver<Scalar>::backward(const Scalar mudyn,
const Scalar mueq) {

ALIGATOR_NOMALLOC_SCOPED;
ZoneScopedN("parallel_backward");
ALIGATOR_TRACY_ZONE_SCOPED_N("parallel_backward");
auto N = static_cast<uint>(problem_->horizon());
for (uint i = 0; i < numThreads - 1; i++) {
uint end = get_work(N, i, numThreads).end;
Expand All @@ -116,7 +117,7 @@ bool ParallelRiccatiSolver<Scalar>::backward(const Scalar mudyn,
#ifdef __linux__
char *thrdname = new char[16];
snprintf(thrdname, 16, "thread%d[c%d]", int(i), sched_getcpu());
tracy::SetThreadName(thrdname);
ALIGATOR_TRACY_SET_THREAD_NAME(thrdname);
#endif
auto [beg, end] = get_work(N, i, numThreads);
boost::span<const KnotType> stview =
Expand Down Expand Up @@ -164,7 +165,7 @@ bool ParallelRiccatiSolver<Scalar>::forward(
VectorOfVectors &xs, VectorOfVectors &us, VectorOfVectors &vs,
VectorOfVectors &lbdas, const std::optional<ConstVectorRef> &) const {
ALIGATOR_NOMALLOC_SCOPED;
ZoneScopedN("parallel_forward");
ALIGATOR_TRACY_ZONE_SCOPED_N("parallel_forward");
uint N = (uint)problem_->horizon();
for (uint i = 0; i < numThreads; i++) {
uint i0 = get_work(N, i, numThreads).beg;
Expand Down Expand Up @@ -198,7 +199,7 @@ bool ParallelRiccatiSolver<Scalar>::forward(
template <typename Scalar>
void ParallelRiccatiSolver<Scalar>::initializeTridiagSystem(
const std::vector<long> &dims) {
ZoneScoped;
ALIGATOR_TRACY_ZONE_SCOPED;
std::vector<MatrixXs> subdiagonal;
std::vector<MatrixXs> diagonal;
std::vector<MatrixXs> superdiagonal;
Expand Down
10 changes: 5 additions & 5 deletions gar/include/aligator/gar/proximal-riccati.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "./proximal-riccati.hpp"
#include "./lqr-problem.hpp"

#include <tracy/Tracy.hpp>
#include "aligator/tracy.hpp"

namespace aligator::gar {

Expand All @@ -13,7 +13,7 @@ ProximalRiccatiSolver<Scalar>::ProximalRiccatiSolver(
: Base(), kkt0(problem.stages[0].nx, problem.nc0(), problem.ntheta()),
thGrad(problem.ntheta()), thHess(problem.ntheta(), problem.ntheta()),
problem_(&problem) {
ZoneScoped;
ALIGATOR_TRACY_ZONE_SCOPED;
auto N = uint(problem_->horizon());
auto &knots = problem_->stages;
datas.reserve(N + 1);
Expand All @@ -30,7 +30,7 @@ template <typename Scalar>
bool ProximalRiccatiSolver<Scalar>::backward(const Scalar mudyn,
const Scalar mueq) {
ALIGATOR_NOMALLOC_SCOPED;
ZoneNamed(Zone1, true);
ALIGATOR_TRACY_ZONE_NAMED(Zone1, true);
bool ret = Impl::backwardImpl(problem_->stages, mudyn, mueq, datas);

StageFactor<Scalar> &d0 = datas[0];
Expand All @@ -39,7 +39,7 @@ bool ProximalRiccatiSolver<Scalar>::backward(const Scalar mudyn,
vinit.vx = vinit.pvec;
// initial stage
{
ZoneNamedN(Zone2, "factor_initial", true);
ALIGATOR_TRACY_ZONE_NAMED_N(Zone2, "factor_initial", true);
kkt0.mat(0, 0) = vinit.Vxx;
kkt0.mat(1, 0) = problem_->G0;
kkt0.mat(0, 1) = problem_->G0.transpose();
Expand All @@ -65,7 +65,7 @@ bool ProximalRiccatiSolver<Scalar>::forward(
std::vector<VectorXs> &xs, std::vector<VectorXs> &us,
std::vector<VectorXs> &vs, std::vector<VectorXs> &lbdas,
const std::optional<ConstVectorRef> &theta_) const {
ZoneScoped;
ALIGATOR_TRACY_ZONE_SCOPED;

// solve initial stage
Impl::computeInitial(xs[0], lbdas[0], kkt0, theta_);
Expand Down
14 changes: 7 additions & 7 deletions gar/include/aligator/gar/riccati-impl.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
#include "./riccati-impl.hpp"
#include "./lqr-problem.hpp"

#include <tracy/Tracy.hpp>
#include "aligator/tracy.hpp"

namespace aligator {
namespace gar {
template <typename Scalar>
bool ProximalRiccatiKernel<Scalar>::backwardImpl(
boost::span<const KnotType> stages, const Scalar mudyn, const Scalar mueq,
boost::span<StageFactorType> datas) {
ZoneScoped;
ALIGATOR_TRACY_ZONE_SCOPED;
// terminal node
if (datas.size() == 0)
return true;
Expand All @@ -38,7 +38,7 @@ template <typename Scalar>
void ProximalRiccatiKernel<Scalar>::terminalSolve(const KnotType &model,
const Scalar mueq,
StageFactorType &d) {
ZoneScoped;
ALIGATOR_TRACY_ZONE_SCOPED;
value_t &vc = d.vm;
// fill cost-to-go matrix
VectorRef kff = d.ff.blockSegment(0);
Expand Down Expand Up @@ -101,7 +101,7 @@ template <typename Scalar>
void ProximalRiccatiKernel<Scalar>::computeInitial(
VectorRef x0, VectorRef lbd0, const kkt0_t &kkt0,
const std::optional<ConstVectorRef> &theta_) {
ZoneScoped;
ALIGATOR_TRACY_ZONE_SCOPED;
assert(kkt0.chol.info() == Eigen::Success);
x0 = kkt0.ff.blockSegment(0);
lbd0 = kkt0.ff.blockSegment(1);
Expand All @@ -117,7 +117,7 @@ void ProximalRiccatiKernel<Scalar>::stageKernelSolve(const KnotType &model,
value_t &vn,
const Scalar mudyn,
const Scalar mueq) {
ZoneScoped;
ALIGATOR_TRACY_ZONE_SCOPED;
// step 1. compute decomposition of the E matrix
d.Efact.compute(model.E);
d.EinvP.setIdentity();
Expand Down Expand Up @@ -204,7 +204,7 @@ void ProximalRiccatiKernel<Scalar>::stageKernelSolve(const KnotType &model,
RowMatrixRef Lth = d.fth.blockRow(2);
RowMatrixRef Yth = d.fth.blockRow(3);
if (model.nth > 0) {
ZoneScopedN("stage_solve_parameter");
ALIGATOR_TRACY_ZONE_SCOPED_N("stage_solve_parameter");

// store Pxttilde = -Einv * Pxt
// this is like ptilde
Expand Down Expand Up @@ -255,7 +255,7 @@ bool ProximalRiccatiKernel<Scalar>::forwardImpl(
boost::span<const StageFactorType> datas, boost::span<VectorXs> xs,
boost::span<VectorXs> us, boost::span<VectorXs> vs,
boost::span<VectorXs> lbdas, const std::optional<ConstVectorRef> &theta_) {
ZoneScoped;
ALIGATOR_TRACY_ZONE_SCOPED;

uint N = (uint)(datas.size() - 1);
for (uint t = 0; t <= N; t++) {
Expand Down
3 changes: 2 additions & 1 deletion include/aligator/core/lagrangian.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "aligator/core/traj-opt-problem.hpp"
#include "aligator/core/cost-abstract.hpp"
#include "aligator/gar/blk-matrix.hpp"
#include "aligator/tracy.hpp"

namespace aligator {

Expand All @@ -24,7 +25,7 @@ template <typename Scalar> struct LagrangianDerivatives {
using StageData = StageDataTpl<Scalar>;
const std::size_t nsteps = problem.numSteps();

ZoneScopedN("LagrangianDerivatives::compute");
ALIGATOR_TRACY_ZONE_SCOPED_N("LagrangianDerivatives::compute");
ALIGATOR_NOMALLOC_SCOPED;

math::setZero(Lxs);
Expand Down
8 changes: 4 additions & 4 deletions include/aligator/core/traj-opt-problem.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "aligator/core/traj-opt-problem.hpp"
#include "aligator/utils/mpc-util.hpp"
#include "tracy/Tracy.hpp"
#include "aligator/tracy.hpp"

#include <fmt/format.h>

Expand Down Expand Up @@ -57,7 +57,7 @@ template <typename Scalar>
Scalar TrajOptProblemTpl<Scalar>::evaluate(
const std::vector<VectorXs> &xs, const std::vector<VectorXs> &us,
Data &prob_data, ALIGATOR_MAYBE_UNUSED std::size_t num_threads) const {
ZoneScopedN("TrajOptProblem::evaluate");
ALIGATOR_TRACY_ZONE_SCOPED_N("TrajOptProblem::evaluate");
const std::size_t nsteps = numSteps();
if (xs.size() != nsteps + 1)
ALIGATOR_RUNTIME_ERROR(fmt::format(
Expand Down Expand Up @@ -93,7 +93,7 @@ void TrajOptProblemTpl<Scalar>::computeDerivatives(
const std::vector<VectorXs> &xs, const std::vector<VectorXs> &us,
Data &prob_data, ALIGATOR_MAYBE_UNUSED std::size_t num_threads,
bool compute_second_order) const {
ZoneScopedN("TrajOptProblem::computeDerivatives");
ALIGATOR_TRACY_ZONE_SCOPED_N("TrajOptProblem::computeDerivatives");
const std::size_t nsteps = numSteps();
if (xs.size() != nsteps + 1)
ALIGATOR_RUNTIME_ERROR(fmt::format(
Expand Down Expand Up @@ -170,7 +170,7 @@ template <typename Scalar>
Scalar TrajOptProblemTpl<Scalar>::computeTrajectoryCost(
const Data &problem_data) const {
ALIGATOR_NOMALLOC_SCOPED;
ZoneScoped;
ALIGATOR_TRACY_ZONE_SCOPED;
Scalar traj_cost = 0.;

const std::size_t nsteps = numSteps();
Expand Down
5 changes: 3 additions & 2 deletions include/aligator/solvers/proxddp/merit-function.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "merit-function.hpp"
#include "workspace.hpp"
#include "aligator/core/lagrangian.hpp"
#include "aligator/tracy.hpp"

namespace aligator {

Expand Down Expand Up @@ -31,7 +32,7 @@ Scalar PDALFunction<Scalar>::evaluate(const Scalar mu,
const std::vector<VectorXs> &lams,
const std::vector<VectorXs> &vs,
Workspace &workspace) {
ZoneScoped;
ALIGATOR_TRACY_ZONE_SCOPED;
TrajOptData &prob_data = workspace.problem_data;
Scalar penalty_value = 0.;
const std::vector<VectorXs> &lams_plus = workspace.lams_plus;
Expand Down Expand Up @@ -62,7 +63,7 @@ Scalar PDALFunction<Scalar>::directionalDerivative(
const Scalar mu, const TrajOptProblem &problem,
const std::vector<VectorXs> &lams, const std::vector<VectorXs> &vs,
Workspace &workspace) {
ZoneScoped;
ALIGATOR_TRACY_ZONE_SCOPED;
TrajOptData &prob_data = workspace.problem_data;
const std::size_t nsteps = workspace.nsteps;

Expand Down
Loading

0 comments on commit 7d750a8

Please sign in to comment.