[codex] Precompute vector rotation on spherical grids#5670
Conversation
giordano
left a comment
There was a problem hiding this comment.
I thought we might speed things up if we compute the sines and cosines once and save them as part of the properties of the grid
This sounds good in principle, but it introduces a new separate kernel launch. Do you have benchmarks to share? I'm worried that on GPU launching the kernel may limit the performance gains.
| @allowscalar metric[i, j] = metric[Nx+i, j] | ||
| end | ||
| # fill east halos | ||
| for i in Nx⁺+1:Nx⁺+Hx | ||
| metric[i, j] = metric[i-Nx, j] | ||
| @allowscalar metric[i, j] = metric[i-Nx, j] |
There was a problem hiding this comment.
Why is this necessary now?
|
I am also a bit worried of the extra memory (especially parameter memory) and complication we introduce by storing variables that we bring around and need to be adapted to gpu when it is not needed (basically all our kernels use the grid 😅). It is totally worth it if the savings are large! |
|
Would another design add another function |
While digging into #5665 I realised that the rotation_angle includes a lot of sin and cos function calls that are run repeatedly over kernels. I thought we might speed things up if we compute the sines and cosines once and save them as part of the properties of the grid. I'm wondering if this would have impact on the NumericalEarth coupler which calls these functions repeatedly...
What changed
This refactor moves vector-rotation geometry onto
OrthogonalSphericalShellGridby precomputing and storing center-locatedcosθandsinθvalues on the grid.rotation_angle,intrinsic_vector, andextrinsic_vectorthen read the cached geometry instead of reconstructing the local rotation stencil on every call.The change also wires the cached rotation fields through the main orthogonal spherical grid construction paths and updates the focused vector-rotation test to recompute the cached fields when it manually mutates grid geometry.
Why
rotation_angle(i, j, grid)is geometric data rather than transient operator state. Caching it on the grid makes the design cleaner and reduces repeated stencil work in hot vector-rotation paths.Impact
This is intended as a standalone geometry/operator refactor.
It is not presented as the fix for issue #5665. That issue appears to originate in Tripolar seam geometry generation itself; this branch only changes how rotation is consumed once the geometry exists.
Validation
I verified that
using Oceananigansloads successfully on this branch.I also ran
julia --project test/test_vector_rotation_operators.jland confirmed that the focused rotation-angle portion passes. I did not wait for a clean end-to-end completion of the full file before opening this draft PR.