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 to on a transonic airfoil, whereas the generated Jacobian keeps them below and . 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 .
Create a lesson
Metadata
- Categories
- physics.flu-dyn, physics.comp-ph
- Comments
- v2: comparison with Enzyme and repeated timings, ablation of the accumulation analysis, 2-D Euler airfoil with adjoint shape sensitivities, single-precision study on a non-polynomial residual, CuAD v0.2.1. 25 pages, 10 figures, 10 tables. Code: https://github.com/SEUNGHYUN-JOO/CuAD
Related papers
Spontaneous Axis-Switching Swirling in Transonic Core-Annular Flow of Highly Differentiated Fluids
Shared title terminologyphysics.flu-dynWayne Strasser, Aleck Tilbrook, Daniel Wilson
Discrete adjoint method for the general synthetic iterative scheme for optimization of rarefied and continuum gas flows
Shared title terminologyphysics.flu-dynJianan Zeng, Ruifeng Yuan, Wei Su
An Implicit Discrete Adjoint Unified Gas-Kinetic Scheme for Sensitivity Analysis and Shape Optimization in Multiscale Gas Flows
Shared title terminologyphysics.flu-dynYuze Zhu, Hangkong Wu, Kun Xu
A Five-Dimensional Geometric Formulation of Geophysical Fluid Dynamics
Shared title terminologyphysics.flu-dynStéphane Gaudreault, Seth Taylor, Arad Nasiri et al.
Fluid memory beyond creeping flow: a history kernel for a sphere at finite Reynolds numbers
Shared title terminologyphysics.flu-dynM. D. Łasica, J. G. M. Kuerten, S. K. F. Stoter
Three-dimensional computational rheometry of viscoplastic fluids in vane-in-cup fixtures
Shared title terminologyphysics.flu-dynJames Malcolm, Clare McColgan, Emma Mullarkey et al.