Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make all fields of simulator.JaxSim static excluding SimulatorData #55

Merged
merged 1 commit into from
Oct 24, 2023

Conversation

diegoferigo
Copy link
Member

With @flferretti, we noticed the occurrence of trace leaks in a jitted context of a parallel simulation on GPUs. It turns out that the leak was caused by the following line:

dt_ns = jnp.array(self.step_size_ns * self.steps_per_run, dtype=jnp.uint64)

For some reason, jax detects a leak in this operation.

Converting JaxSim.step_size_ns to a static attribute was the most straightforward solution. The pay to price, this time, is losing the possibility to perform a parallel simulation whose models are integrated using different step sizes, that is regardless an edge case not so common. If needed, we can try to fix it in the future, what matters now is to simulate a large batch of models all together on hardware accelerators.

After this change, all attributes of JaxSim are marked as Static, with the exception of JaxSim.data that now contains the only mutable information — the real simulator state. It makes clear what can be changed during runtime —dynamically, w/o triggering recompilations— and what not.

Fixes trace leaks  when jitting vectorized simulations
@diegoferigo diegoferigo self-assigned this Oct 20, 2023
@diegoferigo diegoferigo changed the title Make all fields of simulator.JaxSim static, excluding SimulatorData Make all fields of simulator.JaxSim static excluding SimulatorData Oct 20, 2023
@diegoferigo diegoferigo merged commit 804d525 into new_api Oct 24, 2023
16 checks passed
@diegoferigo diegoferigo deleted the fix/jaxsim_static_fields branch October 24, 2023 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants