Manuscript Offprint
arXiv:2610.25476CusADi2: Latency-Optimized Batch Computation of Robot Kinematics, Jacobians, and Hessians on the GPU
John Viljoen , Lasse Peters , Masayoshi Tomizuka , and Negar Mehr

UR5e
Franka FR3
I2RT YAM
Unitree Go2
Shadow Hand
Unitree G1
degrees of freedom
Fig. 1. CusADi2 evaluates batches of dynamical-system functions, such as robot kinematics, Jacobians, and Hessians, on the GPU with low latency. Here, we show the latency of batched forward kinematics (B = 256 rollouts of 8 time steps) for all 67 robots in the MuJoCo Menagerie, sorted by degrees of freedom, with common platforms labeled. CusADi2 is fastest on all but two low-DOF robots and evaluates common platforms in under 40 s.
Abstract—Trajectory optimization methods, from sampling-based zero-order to gradient-based first- and second-order approaches, require many evaluations of dynamical system functions, i.e., functions derived from a robot's dynamical model, such as forward kinematics and their Jacobians and Hessians. These evaluations are largely independent, e.g., across sampled trajectories or time steps, and can thus be evaluated in parallel as a batch. When used to make decisions online, these methods require low latency, i.e., each batch must complete in as little wall-clock time as possible. Existing frameworks utilize modern GPU hardware primarily to parallelize across batch instances, thereby optimizing throughput but not latency. We present CusADi2, a software library that reduces the batch evaluation latency by additionally parallelizing computation within each batch instance. We benchmark forward kinematics, Jacobians, and Hessians for all 67 robots in the MuJoCo Menagerie, including arms, hands, quadrupeds, humanoids, and biomechanical models, against MuJoCo XLA, MuJoCo Warp, frax, CusADi, and CasADi. CusADi2 achieves lower latency than all baselines at batch sizes of 64 to 4096, while matching them at larger batch sizes. We also demonstrate the performance advantage of CusADi2 in a sampling-based control application. All code is open-source at: https://github.com/johnviljoen/cusadi2.
I. INTRODUCTION
Modern robotics algorithms often make decisions by repeatedly evaluating dynamical system functions, i.e., functions derived from a robot's dynamical model, such as forward kinematics and their Jacobians and Hessians [1, 2]. In some cases, this dependence on a model is explicit. For example, model-based online planning techniques, whether zero-order (sampling-based) [3, 4] or first- and second-order (gradient-based) [5], all repeatedly evaluate a model to predict the effect of their actions on the environment [1]. In other cases, the dependence on a model may be implicit. For example, model-free techniques such as Reinforcement Learning (RL) usually rely on a simulator to generate sufficient training data [2]. Approaches that evaluate the model offline, such as RL, require high throughput. Therefore, modern GPU tools [6, 7, 8, 9] have been optimized for this criterion. However, techniques that evaluate the model online require a different criterion, namely low latency, which remains a secondary concern for these tools. Sampling-based methods evaluate batches of hundreds of rollouts for every control action, and gradient-based methods evaluate Jacobians and Hessians along the trajectory at every iteration. In both cases, the latency of these evaluations directly limits the achievable control rate. These online methods thus directly benefit from low-latency evaluation of dynamical system functions.
In this paper, we fill this gap by introducing CusADi2, a software library for low-latency batched evaluation of dynamical system functions on the GPU. To be broadly applicable in online planning, CusADi2 supports not only forward kinematics but also Jacobians and Hessians. It exploits the structure of each function's computational graph to parallelize its evaluation. Two further optimizations reuse one schedule across trajectory stages and group same-type operations, which GPUs execute more efficiently. It thus achieves lower latency than prior methods such as MuJoCo.
J. Viljoen, L. Peters, M. Tomizuka, and N. Mehr are with the Department of Mechanical Engineering, University of California, Berkeley, CA, USA. {john_viljoen, lasse.peters, tomizuka, negar}@berkeley.edu
This work has been submitted to the IEEE for possible publication. Copyright may be transferred without notice, after which this version may no longer be accessible.
Warp [7], MuJoCo XLA [6], and CusADi [9]. For 256 forward kinematics evaluations, existing GPU frameworks need at least 100 s on nearly every MuJoCo Menagerie [10] robot, whereas CusADi2 needs under 40 s on common platforms (Figure 1). Across all 67 robots, from dexterous hands to humanoids, this advantage is largest for batches of 64 to 4096, with no throughput loss beyond. Finally, we demonstrate a 50 Hz safe sampling-based planner for a Franka Panda arm, with a Higher-Order Control Barrier Function (HOCBF) [11] safety filter per sampled trajectory.
Batched GPU Simulation. Modern batched GPU simulators [6, 7, 8, 9, 12, 13, 14] parallelize simulation across thousands of independent instances to generate data at high throughput. These tools were originally designed for RL, where more environment interactions directly accelerate training [2]. However, batched simulation is increasingly used beyond RL, often targeting online deployment [3, 15]. Such online applications require low-latency batched evaluation, which is of secondary importance to existing GPU simulators but the primary focus of this paper.
Latency. Reducing the latency of a batched evaluation requires accelerating each instance, not only parallelizing across instances. Existing frameworks take one of two approaches to this per-instance parallelism. Some frameworks [6, 12, 14] rely on the OpenXLA compiler [16] from the JAX ecosystem [17], whose heuristics are designed for machine learning workloads dominated by large tensor operations, rather than fine-grained scalar operations that make up dynamical system functions. Hence, they accelerate each instance only to a small degree. Other frameworks [7, 8, 13, 15] instead require the user to supply a function that is already parallelized per instance, leaving this burden to the practitioner. In this paper, we introduce a method that automatically parallelizes per-instance computations.
Sparsity. A further limitation of existing batched evaluation frameworks is that they treat the highly sparse Jacobians and Hessians as dense. [18] addresses this with sparse automatic differentiation, but is designed for Jacobians and is inefficient for Hessians. Other works [9, 19, 20] use symbolic differentiation to obtain sparse Jacobians and Hessians, but either their compilation time grows prohibitively with expression size, or they apply no latency reduction techniques [9]. Our method inherits the fast sparse symbolic differentiation pipeline of CasADi [21] and combines it with latency reduction techniques.
III. PROBLEM STATEMENT
In this paper, we study the problem of evaluating a dynamical-system function (e.g., robot dynamics and their derivatives) at a batch of many input points in parallel on a GPU in minimal time. This problem arises naturally in sampling-based MPC [3, 4], which requires many rollouts over sampled action sequences, and in gradient-based MPC [5], where multiple initial guesses can help identify favorable local minima. To formalize the problem, we first explain why the latency of a batch evaluation hinges on how fast a single batch instance is evaluated. We then represent the function as a directed acyclic graph (DAG) of atomic operations, abstract the GPU as a set of parallel compute units, and cast minimum-time evaluation of a single instance as the problem of scheduling the DAG's vertices onto these units. Finally, we return to the batch and state when the resulting schedule is also optimal for the whole batch.
Parallelization Across Batches and Batch Instances. A batch consists of B evaluations of the same function at different input points, e.g., one per sampled rollout in sampling-based MPC. We refer to each of these evaluations as a batch instance. Since instances are independent of one another, they can be evaluated concurrently on the GPU. A naive parallelization strategy would exploit exactly this parallelism across instances. However, the batch computation is complete only once its slowest instance finishes, and parallelizing across instances does not reduce this per-instance latency. Instead, we focus on parallelization within each instance, which builds on the fact that many of its operations are independent of one another (see the example below). For the remainder of this section, we therefore ask how to evaluate a single batch instance on a GPU as fast as possible, and return to the per-batch latency once this problem is formalized.
A Minimal Example. Before formalizing the problem, we use a minimal example to illustrate how the evaluation of a dynamical-system function can be parallelized. The key observation is that such functions are not monolithic, but instead decompose into a sequence of “atomic” operations, i.e., low-level operations that cannot be further subdivided. For example, the function
decomposes into the atomic operations , , and . Given the structure of , some atomic operations are independent of others. The operations and each depend only on the inputs, whereas the sum depends on the results of both. Given at least two compute units, i.e., two or more processing cores of a simplified GPU, we can therefore compute in only two steps: first, compute and concurrently, then sum them to get the final result. Our goal is to systematically identify such opportunities for parallelization in general dynamical-system functions, including those arising from complex robots. In fact, in Section V, we benchmark our method on the entire MuJoCo Menagerie [10], which includes dynamical-system functions with up to 429,773 operations.
From Function to DAG. To formalize minimum-time evaluation of dynamical-system functions, we represent these composite functions as directed acyclic graphs (DAGs):
In the above DAG , denotes the vertex set, which is partitioned into three pairwise disjoint sets, : input vertices hold the arguments supplied to the function, computational vertices perform atomic operations, and output vertices expose the results. Each non-input vertex is labeled by a function . For computational vertices , is an atomic operation. Output vertices merely pass through a single value, i.e., and is the identity; thus, only computational vertices incur work. For instance, the DAG of in (1), shown in Figure 3, has input vertices , computational vertices with , , and , and a single output vertex that passes through the value of vertex 3. The function
returns the tuple of vertices whose values are input to . For example, for the DAG associated with Equation (1), we have since the sum (computational vertex 3) takes the results of (computational vertex 1) and (computational vertex 2) as its first and second arguments. Finally, the edge set connects each vertex to the vertices it takes as arguments:
e.g., vertex 3 in our example has incoming edges from vertices 1 and 2. We require the graph to be acyclic.
From DAG to Function. Next, we show that the DAG fully specifies the function it was built from, so that evaluating the function amounts to evaluating the DAG's vertices in a valid order. Given inputs , the values of all other vertices are defined recursively by
In our example DAG for Equation (1), , , and , so the output recovers . Thus, the DAG represents the function
For a given function , we denote its associated DAG by , such that . Henceforth, we use DAG evaluation and dynamical-system function evaluation interchangeably.
Obtaining the DAG. In practice, we do not construct ourselves but obtain it from CasADi [21], which represents f as a symbolic expression graph that it evaluates one vertex at a time. Since CasADi also differentiates symbolically, the Jacobian and Hessian of f are themselves CasADi functions with their own DAGs; hence, our method applies to derivatives (Jacobians and Hessians) without modification.
GPU Abstraction. For this problem statement, we abstract the GPU as a collection of N identical compute units. At each time step, every compute unit independently evaluates one atomic operation associated with a computational vertex, and we assume each operation takes one unit of time. Although our formulation abstracts away hardware details, our method and implementation explicitly account for these effects; see Section IV-C.
Scheduling a DAG Evaluation. Our goal is to determine the order in which vertices are evaluated. To this end, we first observe that the number of time steps any reasonable evaluation requires is bounded by , since even the worst-case schedule (evaluating one vertex at a time) finishes within steps. With this observation in place, we introduce the notion of a schedule , which assigns each of the computational vertices a “time step” in at which it will be evaluated. That is, the -th entry, , in the tuple is the time at which the computation of vertex is scheduled. However, we cannot assign these time steps arbitrarily, since a feasible schedule must satisfy two constraints: the topological order, which requires each parent to be evaluated before its children, and hardware saturation, which limits the number of operations scheduled at any time step to the available compute units. Since a schedule depends only on the DAG and on , not on the input values, it is computed once at compile time, i.e., as a one-time offline cost, and then reused for every evaluation.
Width and Depth of a Schedule. Two quantities characterize a schedule : width and depth. Its width at time step ,
is the number of vertices scheduled at time step t, i.e., the number of compute units that S occupies at that step, where denotes the indicator function. Its depth,
is the time step at which the last vertex is evaluated, i.e., the latency of an evaluation that follows S. In these terms, hardware saturation requires at every time step, and a faster schedule is one of smaller depth.
The Sequential Schedule. Tools such as CasADi do not natively identify opportunities for parallel scheduling. Instead, they evaluate vertices sequentially, one at a time in topological order. We denote this order by the sequential schedule , which assigns each computational vertex a unique time step such that every vertex appears after its parents, i.e., for all and , the computational vertices whose values consumes. Since it evaluates one vertex at a time, the sequential schedule has width one at every time step and depth .
Scheduling the Example Function. Consider our minimal example from Equation (1) and assume that we have two
Examples include the grouping of compute units into warps and thread blocks, the resulting preference for executing the same operation on neighboring units, and data-transfer costs.
Input vertices are available from the start and output vertices incur no computation, so neither needs to be scheduled.
(A) , sequential
(B) , two compute units

Fig. 3. Example schedules for Equation (1). (A): the sequential schedule. (B): a parallel schedule on two compute units that saves one time step.
compute units. A sequential schedule is shown in Figure 3A: with vertices ordered (sin, cos, +), , i.e., first , then , and finally . Its width is one at every time step and its depth is three. A more efficient schedule, , evaluates and concurrently, then sums their results, as shown in Figure 3B. Its width is two at the first time step and one at the second, so it uses both compute units, and its depth is two, i.e., it saves one time step relative to the sequential schedule. This raises the question: what is the fastest way to evaluate an arbitrary DAG using at most N compute units?
The Per-Instance Minimum-Time Scheduling Problem. Given our DAG and schedule abstractions, we formulate the search for a minimum-time schedule , one that evaluates the DAG as quickly as possible using N compute units, as the following optimization problem:
That is, we seek the schedule of minimum depth among all schedules that satisfy the topological order and saturation requirements discussed above.
Remark: From One Instance to the Batch Schedule. A solution of (3) is a minimum-time schedule for a single instance. Since all instances perform the same operations independently of one another, we can construct a schedule for the entire batch by evaluating multiple instances with this same schedule in parallel. How many instances fit on the GPU at once depends on the maximum width of the instance schedule, , i.e., the largest number of compute units the per-instance schedule uses at any time step. If all instance schedules fit on the GPU at once ( ), the entire batch is evaluated in a single round and its latency equals that of a single instance, and it is easy to verify that is then also the minimum-time schedule for the batch. If instead not all instance schedules fit on the GPU at once ( ), the batch must be evaluated in multiple rounds, one after another, and the batch latency is that of a single instance times the number of rounds. When more than one round is needed, per-instance optimality does not necessarily translate to per-batch optimality. Despite this theoretical limitation, minimizing per-instance latency leads to significant reductions in batch latency in practice, as we shall see in Section V.
IV. METHOD
Finding a per-instance minimum-time schedule for (3) is NP-hard in general [22]. However, when the saturation constraint is not binding (i.e., when we have enough compute units to evaluate each vertex as soon as its parents are evaluated), a closed-form solution of (3) is known [23]. Fortunately, in many robotics applications the saturation constraint is rarely binding, even on a consumer-grade GPU (RTX 4080). For example, across all 67 robots of the MuJoCo Menagerie, forward kinematics and Jacobians never saturate, while Hessians saturate for only 4 robots (6.0%). Our method therefore handles two cases: without saturation (Section IV-A), we solve (3) optimally; with saturation (Section IV-B), we use a heuristic that reliably finds a feasible, though potentially suboptimal, schedule. After discussing each regime, we describe additional method details that leverage the DAG structure and GPU hardware for efficient execution (Section IV-C).
A. Unsaturated Regime
The Level Schedule. In the unsaturated regime, we utilize the level schedule , whose entry for each computational vertex is defined recursively as
where the maximum over an empty set is defined to be 0, so a vertex whose arguments are all inputs (and which thus has no computational parents) is assigned step 1. Intuitively, Equation (4) schedules every vertex as early as possible, i.e., one step after its latest parent, while respecting the topological order of the DAG. For our example, , i.e., the efficient schedule in Figure 3B is a level schedule for the DAG of Figure 3A. Algorithm 1 computes this schedule in a single pass over the vertices of D in topological order, which ensures that every parent is scheduled before its children.
On the Optimality of the Level Schedule. Recall from Section III that of a schedule is the number of vertices scheduled at time step and its depth depth( ) is the last time step at which a vertex is scheduled. Intuitively, the wider the schedule, the shallower it becomes, which reduces evaluation latency. This relationship between width and depth presages the optimality result of [23] for the unsaturated
A narrower but deeper per-instance schedule may fit more instances into one round and thereby finish the batch sooner, and the best batch schedule may even differ across instances. Solving this batch-level problem is harder still and beyond the scope of this paper.
Obtaining a topological order is trivial: the sequential schedule provided by CasADi already is one.
Algorithm 1 Level schedule construction.
1: function LEVELSCHEDULE(D) 2: 3: for do 4: 5: for all do already scheduled 6: if then must run after p 7: 8: return
regime. Specifically, [23] proves that, if the width of the level schedule never exceeds the number of compute units, i.e., , the level schedule is feasible and optimal for (3).
Remark: Depth vs. Computation Time. Equating minimal depth with minimal computation time rests on two assumptions: (1) all operations take equal time, and (2) a GPU can execute heterogeneous operations in parallel. Neither holds exactly. First, operations differ in cost, so the duration of a time step is set by its slowest operation. Second, GPUs support heterogeneous parallel execution only to a limited extent. We do not model heterogeneous operation costs and leave this to future work, but we address the limitations of GPU heterogeneity in Section IV-C. Moreover, our experiments in Section V validate the practical effectiveness of our method despite these simplifying assumptions.
B. Saturated Regime
The saturated regime is reached when the maximum width of the level schedule exceeds the number of compute units. In this regime, finding an optimal schedule is NP-hard [22]. Windowed Level Schedule. To address this, we construct a feasible, though potentially suboptimal, schedule by windowing the level schedule. We cut the sequential schedule into consecutive windows of K vertices each: the first K vertices form window 1, the next K form window 2, and so on. Recalling that is the time step of vertex w in the sequential schedule, window b thus contains the vertices
We then build a level schedule within each window and evaluate the windows one after another, each starting only once the previous one has finished. Formally, the windowed level schedule is given by
topological order
window locality
(6)
A modern NVIDIA GPU can execute different operations on different warps, but all threads within a warp must execute the same instruction (SIMD).
Algorithm 2 Windowed level schedule construction.
1: function WINDOWEDLEVELSCHEDULE(D, K) 2: 3: deepest time step assigned so far 4: for do 5: window b 6: earlier windows count as inputs 7: for all do 8: start after all earlier windows 9: 10: return
where, as in Equation (4), we define the maximum over an empty set to be 0. Here, the first term enforces the topological order, as in (4); the second places w after every vertex of all earlier windows. Since each window contains K vertices, choosing guarantees that satisfies the saturation constraint of (3) and is therefore feasible. Algorithm 2 computes the windowed level schedule of Equation (6) by running Algorithm 1 on each window in turn. Specifically, it applies Algorithm 1 to the sub-DAG induced by window , in which vertices of earlier windows become inputs, denoted by . This is valid because all earlier windows have finished when a window starts; the window's level schedule is then shifted by the deepest time step d assigned so far.
Choosing the Window Size. The window size interpolates between two extreme scheduling strategies. With , we obtain a single window, and it is easy to verify that Equation (6) reduces to the level schedule, i.e., . With , every window is a single vertex and Equation (6) reduces to the sequential schedule, i.e., . Since scheduling happens once at compile time, we can afford to search for a good offline. In practice, we identify a suitable window size by running Algorithm 2 for candidate window sizes and keeping the first window size that produces a schedule whose maximum width does not exceed the number of available compute units . In the unsaturated regime, this search returns and the windowed level schedule reduces to the optimal level schedule. In the saturated regime, it yields a feasible, though potentially suboptimal, schedule.
C. Additional Considerations for Efficient Execution
Although the scheduling strategy outlined above is already effective, we make two further improvements that take into account the DAG structure and the GPU hardware.
Staging. Many functions in online decision making, such as MPC, are stage-structured: they apply the same function h (e.g., the dynamics and their derivatives) independently at each of the H stages of a trajectory. The DAG of such a function therefore consists of H disconnected copies of the DAG of h, i.e., it is simply a wider DAG. CusADi2 detects this repeated structure and schedules the DAG of the per-stage function h only once; all H stages then reuse this schedule, so the scheduling work does not grow with the number of stages.
Vertex Ordering. Our scheduling approach models a GPU as a collection of compute units, each of which can evaluate any atomic operation independently. On modern NVIDIA GPUs, however, compute units are grouped into so-called warps of 32 units that must all execute the same operation simultaneously (i.e., in “lockstep”). Consequently, if the units of a warp require k distinct operations, the warp executes these operations sequentially, and each unit discards the results of the operations it does not need. Thus, a warp with k distinct operations requires k passes instead of one, an effect known as warp divergence. To mitigate warp divergence, we sort the vertices within each level by operation type. For example, consider a level with 32 sin(·) and 32 cos(·) vertices that are assigned to two warps. If the operations alternate (sin, cos, sin, cos, …), each warp contains both operations and thus requires two passes. Sorting the vertices by operation instead assigns all sin(·) vertices to the first warp and all cos(·) vertices to the second, so that each warp completes in a single pass and the evaluation time of this level is halved. This reordering is valid because, by construction, the vertices within a level are mutually independent and can therefore be evaluated in any order.
V. FUNCTION-LEVEL BENCHMARKS
Online decision-making algorithms such as sampling-based and gradient-based MPC spend a large amount of their computation time evaluating the dynamical system and its derivatives, so the latency of these evaluations bounds how fast the overall algorithm can run. We therefore first study these evaluations in isolation, decoupled from any particular downstream algorithm. This lets us attribute latency differences directly to the evaluation backend, and lets us test on a much broader set of robots than any single application would allow. We design these experiments to answer two questions:
Q1 How does the latency of CusADi2 compare to existing GPU and CPU frameworks across batch sizes? (Section V-A)
Q2 Which dynamical system functions benefit most from level parallelism, and why? (Section V-B)
Benchmark Setup. We evaluate forward kinematics, Jacobians, and Hessians for all 67 robots in the MuJoCo Menagerie [10], which yields 201 functions with up to 429,773 operations. Each batch instance evaluates the function along a rollout of 8 time steps, and we test batch sizes B from 1 to 16384 at fp32 precision.
Baselines. We compare against four GPU frameworks: MuJoCo XLA [6], MuJoCo Warp [7], CusADi [9], and frax [14]. The CPU framework we test against is CasADi's C code generation [21]. We report the CPU baseline both as compute alone (CPU idealized) and with GPU → CPU → GPU data transfer overhead that a practitioner would face if this were integrated into a GPU pipeline (CPU + transfer). All tests are run on a single machine with an AMD Ryzen 5800X3D CPU with 32 GB RAM and an RTX 4080 GPU with 16 GB VRAM. All CPU tests run 16 parallel instances on all 16 threads of our CPU. All tests are repeated 5 times, and the mean is used in all analyses.
A. How Does CusADi2 Latency Compare to Baselines?
Protocol. To answer Q1, we test the forward kinematics, Jacobians, and Hessians of every robot in the MuJoCo Menagerie across all baselines. We evaluate these functions across batch sizes and measure the wall-clock time from reading the inputs to writing the outputs. We plot this result in Figure 4A.
Largest Batch Results. At the largest batch size ( ), the batch dimension alone provides enough parallelism to saturate the GPU, so all GPU frameworks outperform the CPU baselines on forward kinematics. Consequently, the additional parallelism exposed by the level schedule matters less, and the speedup of CusADi2 over the other GPU frameworks is small, e.g., to roughly over MuJoCo XLA and MuJoCo Warp for forward kinematics. Nevertheless, CusADi2 remains faster than every baseline at this batch size and still shows a distinct advantage for Jacobians and Hessians.
Intermediate Batch Results. The advantage of CusADi2 is most pronounced in the intermediate batch regime ( ), which covers the batch sizes common in online decision making, such as the number of sampled trajectories in sampling-based MPC [24]. Here, the median speedup over CusADi peaks at at roughly , , and for forward kinematics, Jacobians, and Hessians, respectively, and CusADi2 remains several times faster than MuJoCo XLA, MuJoCo Warp, and frax throughout this regime. The reason is that frameworks which parallelize only across the batch leave most of the GPU idle until the batch is large, whereas the level schedule additionally exposes the parallelism within each function and thus saturates the GPU at much smaller batch sizes. Consequently, CusADi2 overtakes even the idealized CPU baseline at , whereas for forward kinematics the other GPU frameworks do so only around (MuJoCo XLA, MuJoCo Warp, frax) or beyond (CusADi), and for Jacobians and Hessians several of them never beat the CPU baselines at all within the tested range. In practice, this means an online algorithm benefits from utilizing CusADi2 for dynamical system function evaluations starting at around 64 samples.
Small Batch Results. At small batch sizes ( ), the idealized CPU baseline outperforms CusADi2. Individual GPU cores are considerably slower than CPU cores, so GPUs excel only through massive parallelism. Here, however, the CPU already runs at most one instance per thread, while most GPU cores sit idle. Once transfer is included, CusADi2 matches or outperforms the CPU baseline at
In principle, warp divergence could be eliminated entirely via warp specialization, but at the cost of lower GPU utilization and a more complex schedule assembly.
(A)
forward kinematics
Jacobians
Hessians

(B)
B = 64
B = 256

mean width
mean width
forward kinematics ▲ frame Hessians
frame Jacobians
Fig. 4. We compare the latency of CusADi2 against each baseline across the MuJoCo Menagerie. (A): we plot the speedup of CusADi2 over each baseline as a function of batch size. Speedup is the ratio of the two backends' wall-clock latencies, each averaged over 5 runs. Each faded dot is one robot, the solid line is the median across robots, and the shaded band spans the 25th to 75th percentile. (B): we show the speedup of CusADi2 over CusADi for every robot at two batch sizes. Each robot is placed by the mean width and maximum depth of its DAG and colored by its speedup.
on average. This is the relevant comparison whenever the surrounding pipeline already runs on the GPU (e.g., sampling, cost evaluation, or a learned policy), since falling back to the CPU at small batch sizes incurs exactly this transfer. The idealized CPU baseline is therefore preferable only for purely CPU-based pipelines at small batch sizes, where existing code generation such as CasADi already suffices.
Key Takeaways. CusADi2 achieves the lowest latency of all frameworks in the intermediate batch regime ( ) while remaining competitive at both extremes: at small batch sizes, it matches the CPU baseline once GPU transfer is accounted for, and at large batch sizes, it remains faster than existing GPU frameworks.
B. Which Robots Benefit the Most?
Although Figure 4A captures the general trends, it does not tell a practitioner whether CusADi2 suits the particular robot they wish to simulate (Q2).
Per-Robot Latency Across Degrees of Freedom. Figure 1 reports the absolute latency across the MuJoCo Menagerie at B = 256, a regime common in online decision making [24]. CusADi2 achieves the lowest latency for all robots except two with very few degrees of freedom, where the idealized CPU baseline is marginally faster. For common platforms such as the UR5e, Franka FR3, Unitree Go2, and Unitree G1, CusADi2 evaluates a full batch in under 40 s, roughly 2–5× faster than the fastest baseline. Moreover, the latency of CusADi2 grows only mildly with the degrees of freedom, whereas that of CusADi, which follows the sequential schedule and only parallelizes across the batch dimension, grows by more than an order of magnitude. However, degrees of freedom alone do not determine latency. For example, CusADi2 evaluates the 92-DOF IIT SoftFoot more than twice as fast as the 85-DOF MS Human 700 model. This counterintuitive relationship between degrees of freedom and latency motivates our next analysis.
Speedup by DAG Shape. To understand which robots benefit most from CusADi2, Figure 4B reports its speedup over CusADi at two batch sizes, . Each marker corresponds to the DAG of one dynamics function (forward kinematics, Jacobian, or Hessian) of one Menagerie robot, placed according to its depth and mean width and colored by speedup. Since CusADi evaluates the sequential schedule directly, this comparison isolates the effect of our level schedule. The speedup grows primarily with mean width, which measures the parallelism available to the level schedule. Depth, in contrast, has little effect on the speedup and instead determines the absolute latency.
Key Takeaways. The benefit of CusADi2 grows with the parallelism a function exposes at each level, not with its size: robots whose kinematic trees branch into many independent chains, such as multi-legged robots, humanoids, and dexterous hands, gain the most, whereas long serial chains gain the least.
VI. DOWNSTREAM APPLICATION
Having characterized latency in isolation, we now ask:
Q3 How well do CusADi2's gains transfer to a downstream robotics task?
To answer Q3, we adopt a task from [14] where a Franka arm reaches successive end-effector waypoints while respecting joint limits and avoiding singularities, self-collisions, the floor, and a spherical obstacle between waypoints.
Controller. We solve this task with the predictive-sampling planner of MuJoCo MPC [3], a sampling-based MPC method, applied to the Franka dynamics with an HOCBF safety filter [11] on its input. The planner thus optimizes directly over the safety-filtered dynamics and only proposes trajectories that are safe under the model. Safety-filtering the candidate rollouts of sampling-based controllers is an active area of research [25, 26], which makes it a relevant application for CusADi2. Each control step runs three planner iterations with B samples, each a cubic spline of joint targets with seven control points over a 0.7 s horizon.
A GPU-only workflow has the additional benefit of leaving the CPU free for other tasks during rollouts.
For example, a snake-like robot (a single long kinematic chain) yields a deep, narrow DAG with little opportunity for parallelism, whereas a spider-like robot (eight short, independent legs) yields a shallow, wide DAG with ample parallelism.
CusADi2 CusADi CPU idealized
MuJoCo XLA frax CPU + transfer

Fig. 5. Comparison of CusADi2 against all baselines on the safe predictive sampling task. (A): Speedup of CusADi2 over each baseline as a function of batch size on the safe predictive sampling task. (B): Absolute latency of one control step for all backends.
Baselines. We instantiate this controller with each method from Section V for evaluating the safety-filtered dynamics, i.e., the HOCBF filter together with the Franka dynamics. Since the HOCBF constraints require second-order derivatives of the forward kinematics, we exclude MuJoCo Warp, which does not support the computation of Hessians.
Results. Figure 5 reports latency, both relative and absolute, averaged across five runs of the safe predictive sampling task. The end-to-end results show similar performance trends to those of Section V: CusADi2 outperforms all GPU baselines at every batch size tested and is outperformed by both CPU baselines only at smaller batch sizes.
VII. Conclusion
We presented CusADi2, a software library that reduces the latency of batched dynamical system function evaluations on the GPU by parallelizing computation not only across but also within batch instances. Across the forward kinematics, Jacobians, and Hessians of all 67 robots in the MuJoCo Menagerie, CusADi2 is faster than the existing GPU frameworks we tested at every batch size, and it overtakes an idealized CPU baseline from about 64 batch instances onward. The gains are largest for robots whose kinematic trees branch into many independent chains, and they carry over to a safe sampling-based MPC controller. Our scheduling model currently assumes that all operations take equal time. Future work could reduce latency further by accounting for per-operation costs and by making the schedule more hardware-aware, e.g., via warp specialization [27].
REFERENCES
[1] M. J. Kochenderfer, T. A. Wheeler, and K. H. Wray, Algorithms for Decision Making. MIT Press, 2022.
[2] N. Rudin, D. Hoeller, P. Reist, and M. Hutter, “Learning to walk in minutes using massively parallel deep reinforcement learning,” in Conference on robot learning. PMLR, 2022, pp. 91–100.
[3] T. Howell, N. Gileadi, S. Tunyasuvunakool, K. Zakka, T. Erez, and Y. Tassa, “Predictive Sampling: Real-time Behaviour Synthesis with MuJoCo,” Dec. 2022. [Online]. Available: https://arxiv.org/abs/2212.00541
[4] G. Williams, A. Aldrich, and E. Theodorou, “Model predictive path integral control using covariance variable importance sampling,” arXiv preprint arXiv:1509.01149, 2015.
[5] E. F. Camacho and C. Bordons, Model Predictive Control, 2nd ed. Springer, 2007.
[6] D. T. Limited, “Mujoco xla (mjx),” https://mujoco.readthedocs.io/en/stable/mjx.html, 2024, accessed: 10/06/2026.
[7] Google DeepMind and NVIDIA, “MuJoCo Warp (MJWarp),” 2025. [Online]. Available: https://github.com/google-deepmind/mujoco_warp
[8] M. M. et al., “Isaac lab: A gpu-accelerated simulation framework for multi-modal robot learning,” arXiv preprint arXiv:2511.04831, 2025. [Online]. Available: https://arxiv.org/abs/2511.04831
[9] S. H. Jeon, S. Hong, H. J. Lee, C. Khazoom, and S. Kim, “Cusadi: A gpu parallelization framework for symbolic expressions and optimal control,” IEEE Robotics and Automation Letters, vol. 10, no. 2, pp. 899–906, 2025.
[10] K. Zakka, Y. Tassa, and MuJoCo Menagerie Contributors, "MuJoCo Menagerie: A collection of high-quality simulation models for MuJoCo," 2022. [Online]. Available: http://github.com/google-deepmind/mujoco_menagerie
[11] W. Xiao and C. Belta, “High-order control barrier functions,” IEEE Transactions on Automatic Control, vol. 67, no. 7, pp. 3655–3662, 2021.
[12] C. D. Freeman, E. Frey, A. Raichuk, S. Girgin, I. Mordatch, and O. Bachem, “Brax - a differentiable physics engine for large scale rigid body simulation,” 2021. [Online]. Available: http://github.com/google/brax
[13] B. Shacklett, L. G. Rosenzweig, Z. Xie, B. Sarkar, A. Szot, E. Wijmans, V. Koltun, D. Batra, and K. Fatahalian, “An extensible, data-oriented architecture for high-performance, many-world simulation,” ACM Trans. Graph., vol. 42, no. 4, 2023.
[14] D. Morton and M. Pavone, “frax: Fast robot kinematics and dynamics in jax,” arXiv preprint arXiv:2604.04310, 2026, iCRA 2026 Workshop on Frontiers of Optimization for Robotics.
[15] B. Vlahov, J. Gibson, M. Gandhi, and E. A. Theodorou, “Mppigeneric: A cuda library for stochastic trajectory optimization,” 2024. [Online]. Available: https://arxiv.org/abs/2409.07563
[16] A. Sabne, “Xla: Compiling machine learning for peak performance,” 2020.
[17] J. Bradbury, R. Frostig, P. Hawkins, M. J. Johnson, Y. Katariya, C. Leary, D. Maclaurin, G. Necula, A. Paszke, J. VanderPlas, S. Wanderman-Milne, and Q. Zhang, "JAX: composable transformations of Python+NumPy programs," 2018. [Online]. Available: http://github.com/jax-ml/jax
[18] A. Hill and G. Dalle, “asdex: Automatic sparse differentiation in jax.” [Online]. Available: https://github.com/adrhill/asdex
[19] J. Viljoen, J. Haffner, M. Tomizuka, and N. Mehr, “Scaling nonlinear optimization: Many problems one gpu,” arXiv preprint arXiv:2606.26341, 2026.
[20] H. Hose, S. H. Jeon, C. Khazoom, S. Kim, and S. Trimpe, “WarpMPC: Large-batch MPC on GPU via ADMM with unrolled factorization,” arXiv preprint arxiv:2607.11603, 2026.
[21] J. A. Andersson, J. Gillis, G. Horn, J. B. Rawlings, and M. Diehl, "CasADi: a software framework for nonlinear optimization and optimal control," Mathematical Programming Computation, vol. 11, no. 1, pp. 1–36, 2019.
[22] J. D. Ullman, “Np-complete scheduling problems,” Journal of Computer and System Sciences, vol. 10, no. 3, pp. 384–393, 1975.
[23] J. E. Kelley Jr and M. R. Walker, “Critical-path planning and scheduling,” in Papers presented at the December 1-3, 1959, eastern joint IRE-AIEE-ACM computer conference, 1959, pp. 160–173.
[24] M. Bhardwaj, B. Sundaralingam, A. Mousavian, N. D. Ratliff, D. Fox, F. Ramos, and B. Boots, “Storm: An integrated framework for fast joint-space model-predictive control for reactive manipulation,” in Conference on Robot Learning. PMLR, 2022, pp. 750–759.
[25] P. Rabiee and J. B. Hoagg, “Guaranteed-safe mppi through composite control barrier functions for efficient sampling in multi-constrained robotic systems,” in 2025 IEEE 64th Conference on Decision and Control (CDC). IEEE, 2025, pp. 5515–5520.
[26] A. Coker and L. Cui, “Exact-safe mppi: Safety-aware sampling with nonsmooth control barrier functions,” arXiv preprint arXiv:2610.07369, 2026.
[27] M. Bauer, H. Cook, and B. Khailany, “Cudadma: optimizing gpu memory bandwidth via warp specialization,” in Proceedings of 2011 international conference for high performance computing, networking, storage and analysis, 2011, pp. 1–11.