Remove legacy factorI/solveLD and clean up benchmarks/tests

Deletes mj_factorI_legacy and mj_solveLD_legacy from the engine and headers.
Updates factorI, solveLD, and inertia benchmarks to remove legacy targets
and only benchmark CSR.
Rewrites engine_core_smooth_test to verify CSR solver against mj_mulM
instead of legacy solver.

PiperOrigin-RevId: 942507341
Change-Id: I4281decb7018cfa3e46cb446efd5fe1179f6ae1f
This commit is contained in:
Yuval Tassa
2026-07-04 08:33:56 -07:00
committed by Copybara-Service
parent 10d6c01dce
commit 7c6f519879
6 changed files with 49 additions and 375 deletions
+7 -28
View File
@@ -30,7 +30,7 @@ static const int kNumBenchmarkSteps = 50;
// ----------------------------- benchmark ------------------------------------
static void BM_factorI(benchmark::State& state, bool legacy, bool coil) {
static void BM_factorI(benchmark::State& state, bool coil) {
static mjModel* m;
if (coil) {
m = LoadModelFromPath("plugin/elasticity/coil.xml");
@@ -46,21 +46,14 @@ static void BM_factorI(benchmark::State& state, bool legacy, bool coil) {
// M: mass matrix in CSR format
mjtNum* M = mj_stackAllocNum(d, m->nC);
mju_gather(M, d->qM, m->mapM2M, m->nC);
// LDlegacy: legacy LD matrix (size nM)
mjtNum* LDlegacy = mj_stackAllocNum(d, m->nM);
mju_copy(M, d->M, m->nC);
// benchmark
while (state.KeepRunningBatch(kNumBenchmarkSteps)) {
for (int i=0; i < kNumBenchmarkSteps; i++) {
if (legacy) {
mj_factorI_legacy(m, d, d->qM, LDlegacy, d->qLDiagInv);
} else {
mju_copy(d->qLD, M, m->nC);
mj_factorI(d->qLD, d->qLDiagInv, m->nv,
m->M_rownnz, m->M_rowadr, m->M_colind, nullptr);
}
mju_copy(d->qLD, M, m->nC);
mj_factorI(d->qLD, d->qLDiagInv, m->nv,
m->M_rownnz, m->M_rowadr, m->M_colind, nullptr);
}
}
@@ -71,31 +64,17 @@ static void BM_factorI(benchmark::State& state, bool legacy, bool coil) {
state.SetItemsProcessed(state.iterations());
}
void ABSL_ATTRIBUTE_NO_TAIL_CALL
BM_factorI_COIL_LEGACY(benchmark::State& state) {
MujocoErrorTestGuard guard;
BM_factorI(state, /*legacy=*/true, /*coil=*/true);
}
BENCHMARK(BM_factorI_COIL_LEGACY);
void ABSL_ATTRIBUTE_NO_TAIL_CALL
BM_factorI_COIL_CSR(benchmark::State& state) {
MujocoErrorTestGuard guard;
BM_factorI(state, /*legacy=*/false, /*coil=*/true);
BM_factorI(state, /*coil=*/true);
}
BENCHMARK(BM_factorI_COIL_CSR);
void ABSL_ATTRIBUTE_NO_TAIL_CALL
BM_factorI_H100_LEGACY(benchmark::State& state) {
MujocoErrorTestGuard guard;
BM_factorI(state, /*legacy=*/true, /*coil=*/false);
}
BENCHMARK(BM_factorI_H100_LEGACY);
void ABSL_ATTRIBUTE_NO_TAIL_CALL
BM_factorI_H100_CSR(benchmark::State& state) {
MujocoErrorTestGuard guard;
BM_factorI(state, /*legacy=*/false, /*coil=*/false);
BM_factorI(state, /*coil=*/false);
}
BENCHMARK(BM_factorI_H100_CSR);
+8 -30
View File
@@ -31,12 +31,7 @@ static const int kNumBenchmarkSteps = 50;
// ----------------------------- benchmark ------------------------------------
enum class SolveType {
kLegacy = 0,
kCsr,
};
static void BM_solve(benchmark::State& state, SolveType type) {
static void BM_solve(benchmark::State& state) {
static mjModel* m;
m = LoadModelFromPath("../test/benchmark/testdata/inertia.xml");
@@ -48,10 +43,7 @@ static void BM_solve(benchmark::State& state, SolveType type) {
// M: mass matrix in CSR format
mjtNum* M = mj_stackAllocNum(d, m->nC);
mju_gather(M, d->qM, m->mapM2M, m->nC);
// LDlegacy: legacy LD matrix (size nM)
mjtNum* LDlegacy = mj_stackAllocNum(d, m->nM);
mju_copy(M, d->M, m->nC);
// arbitrary input vector
mjtNum *res = mj_stackAllocNum(d, m->nv);
@@ -64,19 +56,11 @@ static void BM_solve(benchmark::State& state, SolveType type) {
while (state.KeepRunningBatch(kNumBenchmarkSteps)) {
for (int i=0; i < kNumBenchmarkSteps; i++) {
mju_copy(res, vec, m->nv);
switch (type) {
case SolveType::kLegacy:
mj_factorI_legacy(m, d, d->qM, LDlegacy, d->qLDiagInv);
mj_solveLD_legacy(m, res, 1, LDlegacy, d->qLDiagInv);
mj_solveM(m, d, res, vec, 1);
break;
case SolveType::kCsr:
mju_copy(d->qLD, M, m->nC);
mj_factorI(d->qLD, d->qLDiagInv, m->nv,
m->M_rownnz, m->M_rowadr, m->M_colind, nullptr);
mj_solveLD(res, d->qLD, d->qLDiagInv, m->nv, 1,
m->M_rownnz, m->M_rowadr, m->M_colind, nullptr);
}
mju_copy(d->qLD, M, m->nC);
mj_factorI(d->qLD, d->qLDiagInv, m->nv,
m->M_rownnz, m->M_rowadr, m->M_colind, nullptr);
mj_solveLD(res, d->qLD, d->qLDiagInv, m->nv, 1,
m->M_rownnz, m->M_rowadr, m->M_colind, nullptr);
}
}
@@ -87,15 +71,9 @@ static void BM_solve(benchmark::State& state, SolveType type) {
state.SetItemsProcessed(state.iterations());
}
void ABSL_ATTRIBUTE_NO_TAIL_CALL BM_solve_LEGACY(benchmark::State& state) {
MujocoErrorTestGuard guard;
BM_solve(state, SolveType::kLegacy);
}
BENCHMARK(BM_solve_LEGACY);
void ABSL_ATTRIBUTE_NO_TAIL_CALL BM_solve_CSR(benchmark::State& state) {
MujocoErrorTestGuard guard;
BM_solve(state, SolveType::kCsr);
BM_solve(state);
}
BENCHMARK(BM_solve_CSR);
+5 -26
View File
@@ -30,7 +30,7 @@ static const int kNumBenchmarkSteps = 50;
// ----------------------------- benchmark ------------------------------------
static void BM_solveLD(benchmark::State& state, bool featherstone, bool coil) {
static void BM_solveLD(benchmark::State& state, bool coil) {
static mjModel* m;
if (coil) {
m = LoadModelFromPath("plugin/elasticity/coil.xml");
@@ -51,21 +51,12 @@ static void BM_solveLD(benchmark::State& state, bool featherstone, bool coil) {
vec[i] = 0.2 + 0.3*i;
}
// scatter into legacy matrix
mjtNum* LDlegacy = mj_stackAllocNum(d, m->nM);
mju_zero(LDlegacy, m->nM);
mju_scatter(LDlegacy, d->qLD, m->mapM2M, m->nC);
// benchmark
while (state.KeepRunningBatch(kNumBenchmarkSteps)) {
for (int i=0; i < kNumBenchmarkSteps; i++) {
mju_copy(res, vec, m->nv);
if (featherstone) {
mj_solveLD_legacy(m, res, 1, LDlegacy, d->qLDiagInv);
} else {
mj_solveLD(res, d->qLD, d->qLDiagInv, m->nv, 1,
m->M_rownnz, m->M_rowadr, m->M_colind, nullptr);
}
mj_solveLD(res, d->qLD, d->qLDiagInv, m->nv, 1,
m->M_rownnz, m->M_rowadr, m->M_colind, nullptr);
}
}
@@ -76,27 +67,15 @@ static void BM_solveLD(benchmark::State& state, bool featherstone, bool coil) {
state.SetItemsProcessed(state.iterations());
}
void ABSL_ATTRIBUTE_NO_TAIL_CALL BM_solveLD_COIL_FS(benchmark::State& state) {
MujocoErrorTestGuard guard;
BM_solveLD(state, /*featherstone=*/true, /*coil=*/true);
}
BENCHMARK(BM_solveLD_COIL_FS);
void ABSL_ATTRIBUTE_NO_TAIL_CALL BM_solveLD_COIL_CSR(benchmark::State& state) {
MujocoErrorTestGuard guard;
BM_solveLD(state, /*featherstone=*/false, /*coil=*/true);
BM_solveLD(state, /*coil=*/true);
}
BENCHMARK(BM_solveLD_COIL_CSR);
void ABSL_ATTRIBUTE_NO_TAIL_CALL BM_solveLD_H100_FS(benchmark::State& state) {
MujocoErrorTestGuard guard;
BM_solveLD(state, /*featherstone=*/true, /*coil=*/false);
}
BENCHMARK(BM_solveLD_H100_FS);
void ABSL_ATTRIBUTE_NO_TAIL_CALL BM_solveLD_H100_CSR(benchmark::State& state) {
MujocoErrorTestGuard guard;
BM_solveLD(state, /*featherstone=*/false, /*coil=*/false);
BM_solveLD(state, /*coil=*/false);
}
BENCHMARK(BM_solveLD_H100_CSR);