---
title: 'GRaM-X: Dynamical-Spacetime GRMHD on GPUs'
url: https://www.emergentmind.com/topics/gram-x
type: topic
---

# GRaM-X: Dynamical-Spacetime GRMHD on GPUs

GRaM-X, expanded as **General Relativistic accelerated Magnetohydrodynamics on AMReX**, is a GPU-accelerated dynamical-spacetime general relativistic magnetohydrodynamics (GRMHD) code developed within the Einstein Toolkit to target GPU-based exascale systems. It extends the Einstein Toolkit GRMHD capability by combining dynamical spacetime evolution, 3D adaptive mesh refinement (AMR) on GPUs via CarpetX and AMReX, the Z4c formalism for general relativity, and the Valencia formulation for GRMHD. The code supports both analytic and tabulated equations of state, implements TVD and WENO reconstruction together with the HLLE Riemann solver, and is validated on standard static- and dynamical-spacetime benchmarks. The reported weak-scaling result is approximately \(40\%-50\%\) efficiency on 2304 Summit nodes, corresponding to 13824 NVIDIA V100 GPUs, relative to single-node performance [2210.17509].

## 1. Definition and position within the Einstein Toolkit

GRaM-X is presented as a new GPU-accelerated dynamical-spacetime GRMHD code for the Einstein Toolkit. Its stated purpose is to enable dynamical-spacetime GRMHD simulations on GPU-based exascale systems, a setting motivated by applications such as compact-object mergers, magnetized neutron stars, and core-collapse supernovae. Within the Einstein Toolkit software stack, it is built as a Cactus-based capability layered on the new CarpetX driver, which itself leverages AMReX as the underlying AMR framework [2210.17509].

The code is described as a complete redesign of GRHydro for GPU-era computing rather than as an incremental port of earlier CPU-centric infrastructure. The distinction emphasized in the literature is not that GRaM-X is the first GPU GRMHD code in general, but that it combines **dynamical spacetime**, **GRMHD**, **3D AMR**, and **Einstein Toolkit integration** in a GPU-oriented implementation. This places it at the intersection of numerical relativity, relativistic astrophysics, and exascale heterogeneous computing [2210.17509].

In architectural terms, the relevant layers are Cactus as the multiphysics framework, CarpetX as the AMR and driver layer, and AMReX as the low-level block-structured AMR and heterogeneous runtime substrate. That organization makes GRaM-X part of the broader Einstein Toolkit ecosystem rather than a standalone monolithic code. A plausible implication is that its design prioritizes interoperability with existing Einstein Toolkit components alongside accelerator performance.

## 2. Software architecture, AMR model, and heterogeneous execution

GRaM-X uses block-structured Berger–Oliger AMR through CarpetX. A coarse rectangular mesh is overlaid by rectangular refined grids organized into refinement levels with factor-of-two spacing ratios, and proper nesting is required so that level \(L+1\) lies entirely within level \(L\). Refined grids carry ghost zones, which are filled either by copying from neighboring blocks or MPI ranks or by prolongation from the next coarser level; restriction updates coarse data where fine grids overlay coarse regions [2210.17509].

A notable implementation choice is the mixed centering of fields. Vertex-centered variables are used for spacetime geometry, while conserved fluid quantities are cell-centered. This is coupled to higher-order generic templated stencils in CarpetX for inter-mesh transport, so that both vertex-centered geometry and cell-centered conservative data are handled consistently across AMR boundaries. For hydrodynamics, face-centered fluxes are synchronized conservatively across blocks and coarse-fine interfaces. Because the code currently uses a global time step across all AMR levels, refluxing is unnecessary [2210.17509].

The parallelization strategy is explicitly three-level: OpenMP shared-memory parallelism on CPUs, GPU kernel parallelism through AMReX accelerator facilities, and MPI across nodes. AMReX GPU kernel launches are used via lambda functions, and the software stack is stated to support CUDA, HIP/ROC, and DPC++/SYCL as applicable. On CPUs, CarpetX and GRaM-X use OpenMP and NSIMD for vectorization. The design goal on GPUs is that all data remain resident in accelerator memory except during I/O, with even simple reductions performed on device because device-host transfers are too expensive [2210.17509].

The mesh is decomposed into rectangular blocks, which are the units of scheduling and distribution. A representative block size given in the implementation discussion is \(8\times 8\times 8\) cells. On CPUs, tiles are chosen with cache behavior in mind; for example, \(1000\times 4\times 4\) is cited as a typical efficient OpenMP tile shape. A central exascale-oriented design decision is the absence, at this stage, of time subcycling: all refinement levels use the same time step. The stated rationale is that this simplifies synchronization and improves parallel scalability because all levels can evolve simultaneously rather than serializing level advances [2210.17509].

## 3. Physical formulation: Z4c spacetime evolution and Valencia GRMHD

GRaM-X evolves both spacetime and magnetized relativistic fluid. For spacetime, it uses the Z4c formalism for Einstein’s equations, together with \(1+\log\) foliation for the lapse and a \(\Gamma\)-driver condition for the shift. The parameters reported for the gauge and damping system are
\[
\kappa_1 = 0.02, \qquad \kappa_2 = 0.0, \qquad \mu_L=\frac{2}{\alpha}, \qquad \mu_S=1, \qquad \eta=2.
\]
Although Z4c introduces additional dynamical fields, other Einstein Toolkit thorns interface through the standard ADM variables \(\gamma_{ij}\), \(K_{ij}\), \(\alpha\), \(\beta^i\), \(A=\partial_t\alpha\), and \(B^i=\partial_t\beta^i\) [2210.17509].

For the matter sector, GRaM-X adopts the Valencia formulation of ideal GRMHD. The governing conservation laws are written as
\[
\nabla_{\mu} J^\mu = 0,\qquad \nabla_{\mu} T^{\mu\nu}=0,\qquad \nabla_\nu {^{*}F^{\mu\nu}} = 0,
\]
with ideal MHD imposed through
\[
E_\nu = u_\mu F^{\mu\nu} = 0.
\]
The stress-energy tensor is decomposed into hydrodynamic and electromagnetic parts, and the total system is expressed in flux-conservative form. The primitive variables are
\[
\mathbf{P} = [\rho, v^i, \epsilon, B^i],
\]
while the conserved variables are
\[
\mathbf{U} = [D, S_j, \tau, \mathcal{B}^k],
\]
with
\[
D = \sqrt{\gamma}\,\rho W,
\]
\[
S_j = \sqrt{\gamma}\left(\rho h^* W^2 v_j - \alpha b^0 b_j\right),
\]
\[
\tau = \sqrt{\gamma}\left(\rho h^* W^2 - P^* - (\alpha b^0)^2 \right) - D,
\]
\[
\mathcal{B}^k = \sqrt{\gamma} B^k.
\]
Here \(W=(1-v^i v_i)^{-1/2}\), and \(v^i=u^i/W+\beta^i/\alpha\) [2210.17509].

A distinctive numerical consequence of the mixed centering strategy is that \(T^{\mu\nu}\) is stored at vertices whereas fluid variables are cell-centered cell averages. To construct \(T^{\mu\nu}\), fluid variables must therefore be interpolated from cell centers to vertices using fourth-order symmetric 3D interpolation. This interpolation step is not an incidental detail; it materially affects the accuracy of the coupled spacetime-matter evolution, particularly in dynamical-spacetime tests [2210.17509].

## 4. Numerical methods, equations of state, and magnetic-field treatment

GRaM-X uses the Method of Lines for all evolved fields. A typical right-hand-side evaluation proceeds by recovering primitive variables from conserved variables, reconstructing primitive states to faces, solving Riemann problems, and then forming flux divergences and source terms. The primary conservative-to-primitive inversion is a 3D Newton–Raphson method solving for \((W, z=\rho h W^2, T)\). A Newman–Hamlin method serves as a fallback, and if both fail, bisection in temperature is used as a guaranteed-convergence but expensive final fallback. The rationale given for preferring the 3D Newton–Raphson method is that Newman’s method requires about 20 times more equation-of-state calls, which is particularly costly for tabulated EOS [2210.17509].

The reconstruction options implemented are TVD with limiter choices including minmod, and WENO5. TVD is described as second-order accurate in smooth monotonic regions and first order near shocks or extrema, whereas WENO is fifth-order accurate in smooth monotonic flows and intended for production simulations. The Riemann solver implemented in the reported version is HLLE. Time integration uses RK4 in all validation problems except benchmark setup A, for which RK2 is employed [2210.17509].

GRaM-X supports both analytic and tabulated equations of state. The analytic options explicitly mentioned are the polytropic EOS,
\[
P = K \rho^\gamma,
\]
and the ideal-gas or \(\Gamma\)-law EOS,
\[
P = (\Gamma - 1)\rho \epsilon.
\]
For realistic nuclear matter, the tabulated EOS support includes tables containing 19 fluid variables such as pressure \(P\), specific enthalpy \(h\), and speed of sound \(c_s\) as functions of \((\rho,T,Y_e)\). These tables are loaded into unified memory so that both CPU and GPU can access them [2210.17509].

The treatment of the magnetic divergence constraint is problem dependent in the published study. The 1D shock-tube tests are run without constrained transport, while the 2D cylindrical explosion, 2D magnetic rotor, and 3D TOV star tests use constrained transport to preserve the divergence-free magnetic-field condition. The paper notes the advantages of placing the magnetic vector potential \(A^i\) at edges for maintaining \(\nabla\cdot\mathbf{B}=0\) exactly up to floating-point precision, but it does not give a full formal description of the constrained-transport algorithm used in GRaM-X [2210.17509].

## 5. Verification, benchmark problems, and measured performance

The published validation suite spans static spacetime, special-relativistic MHD, and full dynamical-spacetime evolution. On static backgrounds, GRaM-X is tested with the five standard Balsara shock tubes, a 2D cylindrical explosion, and a 2D magnetic rotor. On dynamical spacetimes, the principal benchmark is the oscillation of a 3D magnetized TOV star [2210.17509].

| Test class | Configuration | Reported outcome |
|---|---|---|
| 1D MHD shock tubes | Balsara 1–5 | Very good agreement with analytic solutions |
| 2D cylindrical explosion | Flat spacetime, constrained transport | Very good agreement with GRHydro and Komissarov |
| 2D magnetic rotor | Flat spacetime, constrained transport | Matches prior published rotor solutions very well |
| 3D TOV star oscillations | Dynamical spacetime, Z4c | Convergence of central density and good mode-frequency agreement |

In the Balsara shock tubes, the domain is \(x\in[-0.5,0.5]\) with 1600 points and \(\Delta x=1/1600\), using RK4, CFL \(0.8\), TVD reconstruction with minmod, HLLE, and von Neumann boundaries. The code is reported to reproduce the elementary-wave structure accurately, including the more challenging features of the relativistic cases. The Balsara 3 test is identified as the most difficult, and the reported undershoot with TVD at \(\Delta x=1/1600\) improves substantially when WENO is used [2210.17509].

The 2D cylindrical explosion is evolved on \([-6,6]^2\) with a \(200\times 200\times 8\) grid, \(\Gamma=4/3\), a uniform field \(B^i=(0.1,0,0)\), constrained transport, TVD plus minmod, HLLE, RK4, and CFL \(0.25\), up to \(t=4\). The paper reports very good agreement with GRHydro and Komissarov, and attributes minor discrepancies to different centering conventions. The 2D magnetic rotor, on \([-0.5,0.5]^2\) with a \(400\times 400\times 8\) grid and an initial maximum edge velocity \(v_{\max}=0.995\), is likewise reported to match published reference solutions very well [2210.17509].

The 3D TOV-star test is the key dynamical-spacetime validation. The equilibrium star is constructed from the Tolman–Oppenheimer–Volkoff solution with \(K=100\), \(\Gamma=2\), and central density \(1.28\times 10^{-3}M_\odot\), yielding \(M=1.4M_\odot\) and \(R=8.125M_\odot\). A poloidal magnetic field is initialized through a vector potential, and four AMR resolutions are used with finest spacings \(1M_\odot\), \(0.5M_\odot\), \(0.25M_\odot\), and \(0.125M_\odot\). The reported convergence order of the central density is approximately \(2\), and the Fourier spectrum agrees well with perturbation theory for the \(F\), \(H1\), and \(H2\) modes, while \(H3\) is slightly shifted at the highest tested resolution [2210.17509].

Performance measurements are reported primarily on OLCF’s Summit. Single-GPU throughput on Summit V100 hardware reaches \(0.44\times 10^8\) to \(0.47\times 10^8\) zone-cycles/s for static-spacetime setup A, \(0.24\times 10^8\) to \(0.26\times 10^8\) zone-cycles/s for static-spacetime setup B with tabulated EOS and RK4, and \(0.062\times 10^8\) zone-cycles/s for dynamical-spacetime setup C. The headline weak-scaling result is approximately \(40\%-50\%\) efficiency on 2304 nodes, i.e. 13824 NVIDIA V100 GPUs, relative to one node. For setup C, the reported efficiency remains roughly flat from 36 nodes to 2304 nodes, which the paper interprets as stable large-scale scaling once inter-node communication becomes dominant. The principal bottleneck identified is ghost-zone communication bandwidth rather than latency [2210.17509].

## 6. Later extensions, comparison points, and documented limitations

A later paper extends GRaM-X from ideal GRMHD to **full resistive GRMHD** in dynamical spacetime. The resistive module evolves the full resistive GRMHD equations using Z4c, treats stiff source terms with a second-order IMEX-SSP2 \((2,2,2)\) scheme, employs a one-dimensional conservative-to-primitive recovery, and uses HLLE with TVD and WENO reconstruction. Its validation suite includes 1D shock tubes, current sheets, Alfvén waves, 2D cylindrical explosions, and 3D TOV stars. The stated scientific motivation is that ideal GRMHD neglects resistive effects needed for magnetic reconnection, dissipation, magnetospheric dynamics, and transitions between high-conductivity interior plasma and low-conductivity or electrovacuum exterior regions [2510.18968].

Within the same Einstein Toolkit, CarpetX, and AMReX design space, AsterX is presented as a closely related GPU-accelerated GRMHD code for dynamical spacetimes. It also uses Valencia GRMHD and Z4c, but is distinguished by a staggered vector-potential magnetic-field treatment, generalized Lorenz gauge, and subcycling in time. Its reported weak-scaling efficiency is about \(67\%-77\%\) on 4096 Frontier nodes compared to 8-node performance, and the paper explicitly positions AsterX as operating in a similar algorithmic and performance regime to GRaM-X [2406.11669]. This suggests that GRaM-X has become part of a broader family of Einstein Toolkit–native exascale GRMHD codes rather than an isolated development.

The documented limitations of the 2022 GRaM-X release are specific. No AMR performance benchmarks are included in that paper; all reported scaling measurements are unigrid. Time subcycling is not yet implemented. The spacetime solver is not yet fully GPU-optimized and exhibits register spills. HLLE is the only Riemann solver presently implemented in that version, with Roe and Marquina identified as future additions. The mixed centering of hydro and spacetime variables makes \(T_{\mu\nu}\) approximate and increases numerical error in coupled evolutions such as TOV oscillations. The paper also does not mention neutrino transport in the current version, although testing and implementation of an M1 moment-based neutrino transport scheme is explicitly reported as future work [2210.17509].

In that sense, GRaM-X is best understood as an exascale-oriented Einstein Toolkit GRMHD capability whose defining features are GPU execution, dynamical spacetime, 3D AMR compatibility through CarpetX and AMReX, and support for both analytic and tabulated EOS. Its later resistive extension broadens the mathematical model from ideal to resistive GRMHD, while related CarpetX-based codes such as AsterX provide an external comparison point for formulation choices, AMR strategy, and large-scale scaling behavior [2510.18968].

Source: https://www.emergentmind.com/topics/gram-x