Commit Graph

84 Commits

Author SHA1 Message Date
Kyle Bayes b935d4153c Add new mju_threadpool API function, and delete old threading API.
PiperOrigin-RevId: 922838541
Change-Id: Id9f7e0fb298ffde61fcc49a802dc78971858ce51
2026-05-28 10:11:44 -07:00
Kyle Bayes a0c4c62654 Update thread_performance_test.cc.
PiperOrigin-RevId: 916025277
Change-Id: Icc000e5f81b79e0239359638d0eabc3e2ecd00e6
2026-05-15 08:47:48 -07:00
Yuval Tassa a8a5afc8dc Cache benchmark data in engine_util_sparse_benchmark_test
PiperOrigin-RevId: 902651349
Change-Id: I760e3f696b37699366c40c3c93a74e2b1b35678e
2026-04-20 08:29:56 -07:00
Yuval Tassa e6d77650f7 Refactor mju_combineSparse to eliminate temporary buffers.
Combine sparse vectors in-place by first counting total `nnz` and then working backwards from the end. This removes the need for temporary buffers in `mju_combineSparse` and its callers and speeds up the function by ~10%.

PiperOrigin-RevId: 902530210
Change-Id: I4f48c327103552ab968d3915399c6067367bec9f
2026-04-20 03:10:18 -07:00
Yuval Tassa a2d0e33c0f 2-3x speedup of sparse matrix squaring.
Split symbolic and numeric phases for sparse `M'*diag*M` computation. Microseconds per call for the monolithic vs the split approach for the 100_humanoids and 2humanoid100 models:

```
+-------+------+----------+------------+---------+
| Model | Arch | Col (µs) | Split (µs) | Speedup |
+-------+------+----------+------------+---------+
| 2H100 | x86  | 238.3    | 74.5       | 3.2x    |
+-------+------+----------+------------+---------+
|       | ARM  | 111.6    | 53.2       | 2.1x    |
+-------+------+----------+------------+---------+
| 100H  | x86  | 1325.3   | 656.2      | 2.0x    |
+-------+------+----------+------------+---------+
|       | ARM  | 594.8    | 306.6      | 1.9x    |
+-------+------+----------+------------+---------+
```

PiperOrigin-RevId: 900154308
Change-Id: Ia6e9b8e196e2ed37b723a0faf60e9731303a9619
2026-04-15 07:19:41 -07:00
Sam Haves a6a639003f Fix number of textures in BM_CompileManyTextures to 100.
PiperOrigin-RevId: 865475996
Change-Id: I63fd1e8b9aaff9536a9609d8f8390f8c9473785e
2026-02-04 10:35:20 -08:00
Sam Haves f0d5ed73b2 Restore cache capacity after BM_CompileManyTextures benchmark.
The BM_CompileManyTextures benchmark temporarily sets the MuJoCo cache capacity to 0. This change ensures that the original cache capacity is restored after the benchmark completes, preventing side effects on other tests.

PiperOrigin-RevId: 864332653
Change-Id: I5f756e30d4922d5e6f9b70d19ba9d0e31cde9259
2026-02-02 06:43:05 -08:00
Sam Haves 799f8a300e Add parsing benchmark simulating many textures.
PiperOrigin-RevId: 857883857
Change-Id: Ia428ff8aeba4fbaae67a6337d0856cd2b19af2e6
2026-01-18 11:17:45 -08:00
Yuval Tassa 849a650143 Refactor mju_cholUpdateSparse to use a dense accumulator, 1.5-2x function speedup.
PiperOrigin-RevId: 846754379
Change-Id: Ie599658db2907a26095072d97d07b99a693050dc
2025-12-19 08:57:45 -08:00
Yuval Tassa 45b0153067 Refactor sparse Cholesky factorization into symbolic and numeric phases.
The new symbolic function is a generalization of the function it replaces. In this CL it takes two unused temp arrays. The actual change in behavior happens in the followup.

New benchmark test output below ("L" is 2 humanoids and 100 free objects, "XL" is 100 humanoids). Note that `symbolic` is only ever called once per Newton iteration, while `numeric` is sometimes called multiple times (when the rank-1 update fails), hence timing them separately is valuable.

```
Benchmark               Time(ns)        CPU(ns)     Iterations
--------------------------------------------------------------
BM_old_L_mean              84382          84703          19547  11.807k items/s
BM_symbolic_L_mean         16345          16381          88414  61.055k items/s
BM_numeric_L_mean          10986          10994         120000  90.999k items/s
BM_old_XL_mean           1241208        1244212           1200  803.924 items/s
BM_symbolic_XL_mean       130917         131042          12720  7.631k items/s
BM_numeric_XL_mean         77004          76767          21116  13.029k items/s
```

PiperOrigin-RevId: 846704054
Change-Id: Ib0c365724d63bf2b81606ca5353756a6496c3a26
2025-12-19 06:11:55 -08:00
Yuval Tassa 769f37b653 Implement sleeping in engine
PiperOrigin-RevId: 829361787
Change-Id: I6f64d8e25c4248cf32c18cd94d37ff5def78946e
2025-11-07 03:33:07 -08:00
Yuval Tassa ab9575d8a6 Refactor and speed up mj_crb and add a benchmark.
This is a no-op "prefactor" of `mj_crb` to reduce the number of lines changed in the upcoming sleeping CL. The main change here is that `mj_crb` now avoids accessing the model and data pointer repeatedly, but instead has the input and output pointers explicitly declared as local variables. A benchmark test found a healthy **14% perf bump** due to two changes:
- Adding `restrict` to `mju_mulInertVec`
- The function-local pointers.

Adding `restrict` to the local pointers had no effect. Note that `mj_crb` is not a particularly expensive function so these speed bumps are not significant per se, but rather indicative of possible future gains with these techniques.

```
Benchmark                Time(ns)        CPU(ns)     Iterations
---------------------------------------------------------------

ORGINAL BASELINE
BM_CRB_BASELINE_mean         4325           4348         993200  230.052k items/s

BASELINE + RESTRICT
BM_CRB_BASELINE_mean         4057           4090        1186150  244.573k items/s

LOCAL POINTERS + RESTRICT
BM_CRB_mean                  3772           3800        1001750  263.209k items/s
```

PiperOrigin-RevId: 815798225
Change-Id: Iffdf57b544e8e10562807c617f73ca4ccd1c614f
2025-10-06 10:54:01 -07:00
Kyle Bayes 91257896c0 Implement faster mju_isZeroByte.
PiperOrigin-RevId: 814148714
Change-Id: Iaf5ed9d3502eaaaee8d46a986f2db00811ae0707
2025-10-02 02:53:53 -07:00
Sam Haves c31f11824e Add hfields to cache_hits benchmark.
PiperOrigin-RevId: 812759213
Change-Id: I155c2db58811dd1efa56a6361fd39aac669b63e7
2025-09-29 06:22:24 -07:00
Sam Haves e3377ceca3 Add cache hit benchmark to parsing benchmarks.
PiperOrigin-RevId: 810495543
Change-Id: I8c10806a091f870266f2c1194b39159c1f3105e0
2025-09-23 10:40:12 -07:00
Yuval Tassa d71d42a374 Add private function mju_isZeroByte to check for byte-wise zero.
PiperOrigin-RevId: 810456282
Change-Id: I877d0f9225e7a783ed7ff12ce54f4ed0a7889793
2025-09-23 08:49:43 -07:00
Yuval Tassa 681f5767b2 Remove -Wno-extra-semi, add workaround for mjSORT confusing some IDEs
PiperOrigin-RevId: 808689636
Change-Id: Ia091fb597c171a33842e62690d06f32614fbe4eb
2025-09-18 12:28:09 -07:00
Yuval Tassa ec94bb49aa Make constraint island discovery on by default.
Also fix latent bug in mjData serialization.

PiperOrigin-RevId: 799505349
Change-Id: I299e7cc8133fa2ec0b339a7ff3d02543e06778b1
2025-08-26 04:27:24 -07:00
Yuval Tassa 2f28473bc1 Remove transposed Jacobian fields from mjData
No longer computed unconditionally, only ad-hoc where required.

PiperOrigin-RevId: 797753297
Change-Id: I2030fc342c98ff33575b0526dd72e2110c4fcb74
2025-08-21 07:21:24 -07:00
Yuval Tassa 977f94e9df Delete sparsity structures from mjData, use the ones in mjModel
PiperOrigin-RevId: 795067950
Change-Id: If4f52e40ac49f7c6986b33ef9c8b534199dfd21a
2025-08-14 09:13:02 -07:00
Yuval Tassa 365cac49f8 Add benchmarks for mjSORT macro.
PiperOrigin-RevId: 781555531
Change-Id: Ia33b5512fbf65b08931037859d8c6062b018d760
2025-07-10 09:00:46 -07:00
Alessio Quaglino 7edbdd0ad6 Remove the Shell plugin and integrate it into the engine.
PiperOrigin-RevId: 760688502
Change-Id: Ia70988d42b7edf571d7cb4a4f48f8fc50b51667d
2025-05-19 10:51:25 -07:00
Yuval Tassa 45fc15b844 Speed up sparse supernode detection by combining it with transposition.
PiperOrigin-RevId: 760673008
Change-Id: I6d66580e675fd86e5b974859383f93f87482ca16
2025-05-19 10:14:15 -07:00
Yuval Tassa ee8abdf854 Speed up mju_sqrMatTDSparse
PiperOrigin-RevId: 759593417
Change-Id: I0168e1f96333769d09d61e835560910d43aac608
2025-05-16 06:42:17 -07:00
Yuval Tassa d8bebdc675 Remove unnecessary diagnum argument in mj_solveLD and mj_factorI
PiperOrigin-RevId: 758669364
Change-Id: Icfefc4a7a1e7d28da373725358ccf9d5f589f689
2025-05-14 07:13:27 -07:00
Yuval Tassa dd28b887d4 Rename C sparse structure to M in mjdata, improve docstrings.
PiperOrigin-RevId: 758636638
Change-Id: If78acc423601d2911f514929b27f7b6d0af9ef58
2025-05-14 05:26:19 -07:00
Yuval Tassa 627fffdef9 Switch mjData.{qH,qLD} from full ("M") to reduced ("C") inertia matrix structure.
PiperOrigin-RevId: 758273074
Change-Id: If1a2e663ea70044694af985e0119afd6d58115ac
2025-05-13 10:20:32 -07:00
Yuval Tassa b53ed63b5f Use 2humanoid100.xml model in a benchmark test.
PiperOrigin-RevId: 757784271
Change-Id: I7da11ab85ba9f5e023cdbe3c77d31224f3444ca5
2025-05-12 08:59:14 -07:00
Yuval Tassa c2ac0d724e Add mju_gather and mju_scatter, private engine functions.
PiperOrigin-RevId: 750245294
Change-Id: I3a14ccdd55a324d3fe206e388fb2a513772f5f5e
2025-04-22 10:33:33 -07:00
Kyle Bayes 606f00f802 Remove contact pruning with box-box collisions in nativeccd and add benchmarks.
PiperOrigin-RevId: 744732382
Change-Id: I2e20b646c541ee99888f1e964302d1b4363b2dc4
2025-04-07 08:34:04 -07:00
Kyle Bayes 467a63d203 Add BoxBox to ccd benchmarks.
PiperOrigin-RevId: 738761460
Change-Id: If59d306748d64e9e30abe65daa746a4f8e9ec78c
2025-03-20 05:16:33 -07:00
Yuval Tassa 0f563ecf31 Switch mjData.{qH,qLD} from reduced ("C") to full ("M") inertia matrix structure. No performance impact of extra zeros because of existing "simple dof" skipping mechanism.
PiperOrigin-RevId: 733523931
Change-Id: Ic8d8a152dda5532331c239cb6b4ce7d8d09b7fff
2025-03-04 17:34:35 -08:00
Kyle Bayes ed16f2daf2 Set nativeccd as default.
PiperOrigin-RevId: 731343200
Change-Id: I315779017b676f3d118e0d38ee53a515272f50b8
2025-02-26 09:15:15 -08:00
Alessio Quaglino c52d1b3941 Remove the particle composite (replaced by replicate).
PiperOrigin-RevId: 730089997
Change-Id: If8d18fb56ae01241e76f84dbf7951e034026d829
2025-02-23 03:14:11 -08:00
Yuval Tassa b516edae1b Rename inertia factorization routines:
```
mj_factorI -> mj_factorI_legacy
mj_solveLD -> mj_solveLD_legacy
mj_factorIs -> mj_factorI
mj_solveLDs -> mj_solveLD
```

PiperOrigin-RevId: 728246367
Change-Id: I3bc7804cb96faac2ae5419ba9abfc3c1648ed4c6
2025-02-18 09:42:05 -08:00
Yuval Tassa fb07e0d1f7 Convert qLD to CSR format.
PiperOrigin-RevId: 728196818
Change-Id: I31bdf32e251293284426ed345019f27fd051a0e1
2025-02-18 07:14:45 -08:00
Yuval Tassa e39a5df06a mju_compressSparse(): add option to compress away small elements.
PiperOrigin-RevId: 726010576
Change-Id: Ib6458037a5cf9a9d82abb364b7dda7aab2f36807
2025-02-12 05:08:20 -08:00
Yuval Tassa 5ee0654830 Roll back recent change to mjData.qLD until some issues are resolved.
PiperOrigin-RevId: 724389161
Change-Id: I1b30ab0950ab5c5e611b1c6fc3bf3f42f964939c
2025-02-07 10:21:42 -08:00
Yuval Tassa c27d3758c2 Convert qLD to CSR format.
PiperOrigin-RevId: 723955038
Change-Id: I30c3dc7f59739e89ae5fff8841432bc74717ec1b
2025-02-06 08:59:35 -08:00
Yuval Tassa 00010f5848 Compute diagonal indices in mj_sqrMatTDSparse
PiperOrigin-RevId: 713714087
Change-Id: Icc8eae74e6e47ba1d12a6e9aa0d774ab006cfe38
2025-01-09 10:17:31 -08:00
Yuval Tassa 8a5f092081 Allow CSR back-substitution to handle multiple vectors.
PiperOrigin-RevId: 713229673
Change-Id: I7a5b43fe966cf9e482bd41e2eea6c30dd3ffa1d4
2025-01-08 03:32:16 -08:00
Yuval Tassa ac11e5faa6 Add CSR implementation of mj_factorI
PiperOrigin-RevId: 712498431
Change-Id: I13b52e53482ed97da8788875d4d95e2beb5ca7c1
2025-01-06 05:48:14 -08:00
Yuval Tassa 7eb8231fda Represent only the lower triangle in Newton solver's reduced dof-dof matrix.
PiperOrigin-RevId: 712488529
Change-Id: Iad91c72654376539791d7856765a0d0ac9088251
2025-01-06 04:58:55 -08:00
Yuval Tassa 4510c6d290 Further speedup to CSR back-substitution using dof_simplenum.
PiperOrigin-RevId: 711440268
Change-Id: I81cd9a6a8b8ec78d08cfbc34f60a9216ea753833
2025-01-02 09:04:51 -08:00
Yuval Tassa ea98c57921 Clean up engine_core_smooth_benchmark_test.
PiperOrigin-RevId: 709573203
Change-Id: I461f259c33d74b3eaf0b6fe58124fe09418c5303
2024-12-25 07:44:25 -08:00
Copybara-Service 526637f118 Merge pull request #2276 from traversaro:reducetestboilerplate
PiperOrigin-RevId: 707613522
Change-Id: Ic945c6b057b77f3462dbdb758139af12133f6a8f
2024-12-18 11:22:59 -08:00
Yuval Tassa 1c4c7b012c CSR implementation of mj_solveLD.
PiperOrigin-RevId: 704316200
Change-Id: Ibaff0284e40b3ebbe43bb489b6211ce739270e27
2024-12-09 09:34:17 -08:00
Silvio 756a8d716a Reduce cmake test boilerplate
All instances of mujoco_test in the code base were followed by
a call to  target_link_libraries(<testname> fixture gmock).

As anyhow mujoco_test already was calling target_link_libraries
to some predefined list of targets (mujoco and gtest_main),
this PR adds to the list of default linked targets also fixture
and gmock, to reduce the boilerplate.

Furthermore, to completly remove the need for calling
target_link_libraries after a call to mujoco_test, this PR also
add to the mujoco_test macro the ADDITIONAL_LINK_LIBRARIES
argument, that can be used if a given test needs to link some
additional targets beside the default ones.

To permit to use these new features also for mujoco benchmarks,
this PR adds a MAIN_TARGET parameter to mujoco_test, to select
if gtest_main or another target is used to provide the main
entry point to the test executable.
2024-12-07 17:14:20 +01:00
Yuval Tassa a4a6248a06 Move AsVector utility to fixture.h
PiperOrigin-RevId: 690577546
Change-Id: I2cebcffa1f2e3b0789f43e772e364c4762719ab3
2024-10-28 05:52:25 -07:00
Yuval Tassa 62ec802ec1 Tweaks to benchmarks.
- Modify parse_benchmark_test to not time the first instance of file loading.
- Improve readability of step_benchmark_test.

PiperOrigin-RevId: 680953562
Change-Id: I4569d1b946ecb49b6590ea313f0b598ffc897888
2024-10-01 04:08:40 -07:00