Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not interweave transform #587

Merged
merged 27 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
366ea11
Do not interweave transform
milankl Oct 11, 2024
42f7e9c
propagate nlayers argument from inputs
milankl Oct 11, 2024
628f529
Do not store recursion factors
milankl Oct 11, 2024
c3a340d
SpectralTransform.Grid now keyword argument
milankl Oct 11, 2024
41eec88
introduce scratch memory for FFT output because strides don't match
milankl Oct 11, 2024
394da96
Legendre shortcut generalised
milankl Oct 14, 2024
56a82e5
with fused_oddeven_dot
milankl Oct 14, 2024
823b66f
Fourier/Legendre into functions, smaller scratch output for FFTW
milankl Oct 15, 2024
e8c01fd
first version of a fused matvec
milankl Oct 15, 2024
41433a3
Batched Legendre transform
milankl Oct 15, 2024
4c47e15
docstrings added
milankl Oct 15, 2024
1b80380
move even +- odd into kernel
milankl Oct 15, 2024
b057f66
ismatching with nlayers check
milankl Oct 15, 2024
873f6d0
grid to spectral versions v0
milankl Oct 15, 2024
b5d04c2
SpectralTransform constructors overhauled
milankl Oct 16, 2024
9b8363f
Forward _legendre!
milankl Oct 16, 2024
57539cf
Legendre transforms nlayers flexible
milankl Oct 16, 2024
e14aca9
variables renamed to match harmonics meaning of odd/even
milankl Oct 16, 2024
bd27856
function barrier for fourier_batched, fourier_serial
milankl Oct 16, 2024
594fc8d
tests adapted
milankl Oct 16, 2024
58d7e77
size(::LTA, ::Integer)
milankl Oct 18, 2024
6633ccc
fix FFTW alignment problem
milankl Oct 21, 2024
21831d2
Merge branch 'main' into mk/transform
milankl Oct 21, 2024
5a9bac7
speedy transforms docs, recompute legendre removed
milankl Oct 21, 2024
876900e
Merge branch 'mk/transform' of https://github.com/SpeedyWeather/Speed…
milankl Oct 21, 2024
628c860
improve boundscheck error messages
milankl Oct 21, 2024
db4b46c
boundschecks fixed
milankl Oct 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

- De-interweave SpectralTransform [#587](https://github.com/SpeedyWeather/SpeedyWeather.jl/pull/587)
- Array-agnostic SpectralTransform [#583](https://github.com/SpeedyWeather/SpeedyWeather.jl/pull/583)
- Move CUDA dependency into extension [#586](https://github.com/SpeedyWeather/SpeedyWeather.jl/pull/586)
- Stop supporting Julia v1.9 [#585](https://github.com/SpeedyWeather/SpeedyWeather.jl/pull/585)
Expand Down
1 change: 0 additions & 1 deletion src/LowerTriangularMatrices/lower_triangular_array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ end

function Base.array_summary(io::IO, L::LowerTriangularMatrix{T}, inds::Tuple{Vararg{Base.OneTo}}) where T
mn = size(L; as=Matrix)
@info Base.dims2string(length.(inds))
print(io, Base.dims2string(length.(inds)), ", $(mn[1])x$(mn[2]) LowerTriangularMatrix{$T}")
end

Expand Down
3 changes: 1 addition & 2 deletions src/SpeedyTransforms/SpeedyTransforms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import Primes
using ..LowerTriangularMatrices
using ..RingGrids

const DEFAULT_GRID = FullGaussianGrid

# TRANSFORM
export SpectralTransform,
transform!,
Expand All @@ -42,6 +40,7 @@ export spectral_truncation,

include("aliasing.jl")
include("legendrepolarray.jl")
include("legendre_shortcuts.jl")
include("spectral_transform.jl")
include("spectral_gradients.jl")
include("spectral_truncation.jl")
Expand Down
49 changes: 49 additions & 0 deletions src/SpeedyTransforms/legendre_shortcuts.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""Legendre shortcut is the truncation of the loop over the order m of the spherical harmonics
in the Legendre transform. For reduced grids with as few as 4 longitudes around the poles
(HEALPix grids) or 20 (octahedral grids) the higher wavenumbers in large orders m do not
project (significantly) onto such few longitudes. For performance reasons the loop over m can
therefore but truncated early. A Legendre shortcut `<: AbstractLegendreShortcut`
is implemented as a functor that returns the 0-based maximum order m to retain per latitude ring,
i.e. to be used for m in 0:mmax_truncation.

New shortcuts can be added by defining `struct LegendreShortcutNew <: AbstractLegendreShortcut end`
and the functor method `LegendreShortcutNew(nlon::Integer, lat::Real) = ...`, with `nlon` the
number of longitude points on that ring, and `latd` its latitude in degrees (-90˚ to 90˚N).
Many implementations may not use the latitude `latd` but it is included for compatibility.
If unused set to default value to 0. Also define `short_name(::Type{<:LegendreShortcutNew}) = "new"`.

Implementions are `LegendreShortcutLinear`, `LegendreShortcutQuadratic`, `LegendreShortcutCubic`,
`LegendreShortcutLinQuadCosLat²` and `LegendreShortcutLinCubCoslat`."""
abstract type AbstractLegendreShortcut end
short_name(s::Type{<:AbstractLegendreShortcut}) = string(s)
short_name(s::AbstractLegendreShortcut) = short_name(typeof(s))

struct LegendreShortcutLinear <: AbstractLegendreShortcut end
"""$(TYPEDSIGNATURES)
Linear Legendre shortcut, truncates the Legendre loop over order m to nlon/2."""
LegendreShortcutLinear(nlon::Integer, latd::Real=0) = nlon÷2
short_name(::Type{<:LegendreShortcutLinear}) = "linear"

struct LegendreShortcutQuadratic <: AbstractLegendreShortcut end
"""$(TYPEDSIGNATURES)
Quadratic Legendre shortcut, truncates the Legendre loop over order m to nlon/3."""
LegendreShortcutQuadratic(nlon::Integer, latd::Real=0) = nlon÷3
short_name(::Type{<:LegendreShortcutQuadratic}) = "quadratic"

struct LegendreShortcutCubic <: AbstractLegendreShortcut end
"""$(TYPEDSIGNATURES)
Cubic Legendre shortcut, truncates the Legendre loop over order m to nlon/4."""
LegendreShortcutCubic(nlon::Integer, latd::Real=0) = nlon÷4
short_name(::Type{<:LegendreShortcutCubic}) = "cubic"

struct LegendreShortcutLinQuadCoslat² <: AbstractLegendreShortcut end
"""$(TYPEDSIGNATURES)
Linear-Quadratic Legendre shortcut, truncates the Legendre loop over order m to nlon/(2 + cosd(latd)^2)."""
LegendreShortcutLinQuadCoslat²(nlon::Integer, latd::Real) = floor(Int, nlon/(2 + cosd(latd)^2))
short_name(::Type{<:LegendreShortcutLinQuadCoslat²}) = "linquadcoslat²"

struct LegendreShortcutLinCubCoslat <: AbstractLegendreShortcut end
"""$(TYPEDSIGNATURES)
Linear-Cubic Legendre shortcut, truncates the Legendre loop over order m to nlon/(2 + 2cosd(latd))."""
LegendreShortcutLinCubCoslat(nlon::Integer, latd::Real) = floor(Int, nlon/(2 + 2cosd(latd)))
short_name(::Type{<:LegendreShortcutLinCubCoslat}) = "lincubcoslat"
13 changes: 7 additions & 6 deletions src/SpeedyTransforms/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ function prettymemory(b)
end

function Base.show(io::IO, S::SpectralTransform{NF, ArrayType}) where {NF, ArrayType}
(; lmax, mmax, Grid, nlat_half) = S
(; lmax, mmax, Grid, nlat_half, nlayers) = S

# add information about size of Legendre polynomials
s = S.recompute_legendre ? Base.summarysize(S.Λ) : Base.summarysize(S.Λs)
s_str = prettymemory(s)
# add information about size of Legendre polynomials and scratch memory
s_str = prettymemory(Base.summarysize(S.legendre_polynomials))
m_str = prettymemory(Base.summarysize(S.scratch_memory_north)*2 + Base.summarysize(S.scratch_memory_grid))

dealias = get_dealiasing(mmax, nlat_half)
truncations = ["<linear", "linear", "quadratic", "cubic", ">cubic"]
Expand All @@ -28,5 +28,6 @@ function Base.show(io::IO, S::SpectralTransform{NF, ArrayType}) where {NF, Array
println(io, "├ Spectral: T$mmax, $(lmax+1)x$(mmax+1) LowerTriangularMatrix{Complex{$NF}}")
println(io, "├ Grid: $(RingGrids.get_nlat(Grid, nlat_half))-ring $Grid{$NF}")
println(io, "├ Truncation: dealiasing = $dealiasing ($truncation)")
print(io, "└ Legendre: recompute polynomials $(S.recompute_legendre) ($s_str)")
end
println(io, "├ Legendre: Polynomials $s_str, shortcut: $(short_name(S.LegendreShortcut))")
print(io, "└ Memory: for $nlayers layers ($m_str)")
end
Loading
Loading