Search arXiv⌕ Search

arXiv · 2610.26694

CuAD: Source-to-Source Automatic Differentiation of CUDA Kernels for Discrete Adjoints in Computational Fluid Dynamics

Abstract

Discrete adjoint methods give the sensitivities that aerodynamic design and data assimilation require, but they remain hard to obtain for flow solvers that run on graphics processors. This paper presents CuAD, a source-to-source automatic differentiation tool that reads CUDA kernels and writes their tangent and adjoint versions as ordinary CUDA source. Its reverse mode is organised around the GPU thread. It adopts the convention of CUDA kernels that inputs and outputs do not alias, recomputes intermediate values instead of storing them, differentiates pure accumulations without a tape and keeps any remaining tape in a fixed thread-local array. We evaluate CuAD on four kernels from simple flow models and on a two-dimensional Euler solver. All generated derivatives pass dot-product tests to round-off, and the adjoint kernels cost two to six times the primal kernels. On a Biot-Savart summation compiled by one compiler, the CuAD adjoint costs about four times the primal at every size, as does Enzyme when the source declares the absence of aliasing with __restrict__. On the unchanged source Enzyme caches the loop in the device heap and costs 9 to 240 times the primal, while the heap tape of Clad costs 60 to 4400 times the primal and fails beyond 8192 vortices. Exact Jacobians assembled from the generated tangents also matter for accuracy. In single precision, the adjoint gradient of a finite-difference Jacobian reaches errors of 45 to 75 per cent on a stiff Burgers problem and of $5\times10^{-4}$ to $4\times10^{-2}$ on a transonic airfoil, whereas the generated Jacobian keeps them below $5\times10^{-5}$ and $3\times10^{-6}$. The applications include the shape sensitivities of lift and drag of a transonic NACA 0012, for which the residual, the boundary conditions and the wall force are differentiated by CuAD and the adjoint agrees with the tangent to $10^{-13}$.

Explore related subjects

Keep this discovery

Explore connections, maps & timelines

BibTeXRIS

Seunghyun Joo. 2026-10-20. CuAD: Source-to-Source Automatic Differentiation of CUDA Kernels for Discrete Adjoints in Computational Fluid Dynamics. https://arxiv.org/abs/2610.26694

Cite the original work for its findings. Save a collection to share your selection of sources.

KEEP EXPLORING

Related papers

Connecting the Hydrodynamics of Polymeric Fluids and Active Nematics

We establish a correspondence between the continuum descriptions of polymer solutions and active nematics, two seemingly disparate but well-studied complex fluids. Through a mapping of the governing equations, we demonstrate that polymeric fluids can be interpreted as deformable, contractile, high-temperature active nematics, with an effective activity controlled by polymer extension. Using numerical simulations under Kolmogorov flow, we construct a phase diagram connecting the nematic and polymer limits, highlighting how their one- and two-dimensional instabilities depend on deformability. This encompasses both a flow-suppressed regime, in which active stresses oppose the imposed flow, and a transverse instability that generates secondary flows and leads towards elastic turbulence. The transverse instability is facilitated by spatial gradients in activity, which arise naturally in extensible polymers through variations in chain extension. We further show that the transition into the well-known traveling arrowhead structures in elastic turbulence is marked by the emergence of charge $\pm 1/2$ topological defects in the polymer director field, indicating emergent nematic ordering of stretched polymers. Our results establish a unified framework connecting polymer and active matter hydrodynamics, with implications for low-Reynolds-number turbulence, active polymer systems, and the mechanics of deformable living matter.

physics.flu-dyn↗

Edge turbulence controlled by topologically self-optimized fluxes in fusion devices

The magnetic field topology undergoes a drastic transition near the separatrix in magnetic confinement fusion devices, inducing topological chaos. This phenomenon is investigated across tokamaks, stellarators, and the RFX-mod reversed-field pinch. Within this boundary region, self-optimized fluxes of shear-generated magnetic and cross-helicity, together with the ensemble-averaged magnetic moment, are hypothesized to govern plasma stability, self-organization, and transport. By treating the averaged magnetic moment as an active scalar and using the Fokker-Planck equation to reconcile kinetic and fluid descriptions, this study couples its dynamics with a novel multichannel, self-optimized helicity cascade loop. The derived spectral laws for the floating potential and ion saturation current agree with measurements from numerous experiments. Distributed chaos theory quantifies the randomness of the observed states, revealing that a narrow layer at the separatrix suppresses strong core randomness, transforming it into distributed chaos in the scrape-off layer. A constrained variational principle for active control has also been considered. Tuning Lagrangian multipliers via helicity injection drives the system toward an attractor state that stabilizes the separatrix shear layer, suppresses edge-localized modes, and spreads the heat load, using magnetic reconnection as a nonlinear solver. This framework circumvents conventional diffusive limitations, providing an analytical foundation to model heat-load patterns and stochastic ripple loss in next-step devices.

physics.flu-dyn↗

Quantifying Injection-Driven Interphase Mass Transfer within Porous Media via Time-Elapsed X-ray micro-Computed Tomography

Understanding interphase mass transfer is essential for a variety of applications in porous media, from groundwater remediation to geologic energy storage. While X-ray micro-Computed Tomography (micro-CT) is a measurement technique that can provide critical in situ observations, quantifying transient mass transfer requires models and workflows capable of compensating for the spatial and temporal resolution constraints. Current literature presents three analytical frameworks for evaluating interphase mass transfer using time-lapsed sequences of X-ray micro-CT scans: the Slice-Averaged Concentration approach, the Non-Classified per-Cluster approach, and the Classified per-Cluster approach. We systematically evaluate the frameworks and results for each of the three approaches as applied to several sequences of time-lapsed scans, each observing hydrogen dissolution experiments at varying injection rates. Estimates of average mass transfer coefficients vary within an order of magnitude, increasing as injection rate decreases. However, approach estimates diverged when approximating more complex, pore-scale phenomena, such as aqueous solute concentration. Per-Cluster approaches preserve more information, enabling quantification of important localized physicochemical processes such as dissolution fingering and cluster remobilization. Given the lack of ground-truth benchmarks for mass-transfer kinetic data in the conditions of interest to fields such as geologic storage, additional research is still needed to understand how these approaches vary under different state and flow conditions. The utility of one approach over another is ultimately determined by the desired level of system detail, at the cost of the computational resources required to achieve it. Our results provide a framework for researchers to select analytical approaches based on the desired level of physical detail.

physics.flu-dyn↗