-
Notifications
You must be signed in to change notification settings - Fork 26
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
adapt functions for diagnostic_variables.jl #129
Conversation
src/SpeedyWeather.jl
Outdated
import KernelAbstractions | ||
using KernelAbstractions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, use import PkgName: PkgName, A, B, C
instead of using
. Otherwise we may get conflicts when packages export functions with the same name as we want to define. Keeps our name space smaller.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The branch is WIP and we'll probably end up using almost all functions KernelAbstractions exports. While working on it, I would just keep the using
statement and then in the end when merging into main change it to import
the functions that we actually use
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry yeah, do as you like! We can also convert this PR to draft if it's not meant to be merged anytime soon
Project.toml
Outdated
Enzyme = "7da242da-08ed-463a-9acd-ee780be4f1d9" | ||
FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341" | ||
FastGaussQuadrature = "442a2c76-b920-505d-bb47-c5924d526838" | ||
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819" | ||
KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c" | ||
KernelGradients = "e5faadeb-7f6c-408e-9747-a7a26e81c66a" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy for Enzyme
and KernelGradients
to be added, but can you also directly add some compatible versions to [compat]?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we let CompatHelper
handle this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but in my experience it takes a while for CompatHelper to create a PR for this stuff. So I've been adding things manually when I include a new package and then CompatHelper suggested new versions if they become available. Maybe you are right and it's not needed, I just ended up with a lot of package downgrades when CUAKernels 0.4 was available but our compat was still "0.3"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah okay, that makes sense, especially with a WIP branch that will be around longer
test/kernelabstractions.jl
Outdated
@@ -1,8 +1,12 @@ | |||
using KernelAbstractions | |||
using KernelAbstractions | |||
import Parameters: @with_kw, @unpack |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we have Parameters as dependency in our tests (package dependency and test dependency aren't the same, as you may want to test against another package but the code doesn't actually depend on it). This may work in your local environment, but this may fail at CI. Note in general (since Julia v1.7) can also unpack like this
(;lmax,mmax) = m.spectral_transform
or always rename locally if you don't feel lazy
maximum_degree_l = m.spectral_transform.lmax
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can just use the first style so,
(;lmax,mmax) = m.spectral_transform
I'd say, We can add this later the kernelabstractions_adtest
branch
…tests Adapt functions for diagnostic_variables.jl
I've just resolved the conflicts that arose because I changed all gridded fields from
DiagnosticVariables(G::Geometry{NF},S::SpectralTransform{NF}) where NF = zeros(DiagnosticVariables,G,S) Both
function clip_negatives!(A::AbstractArray{T}) where T
@inbounds for i in eachindex(A)
A[i] = max(A[i],zero(T))
end
end Otherwise I don't think there's a need to write |
@milankl why do you want this to merge directly into main? I would rather not do this until the |
@@ -202,13 +243,17 @@ function Base.zeros(::Type{DiagnosticVariablesLayer}, | |||
return DiagnosticVariablesLayer(tendencies,grid_variables,dynamics_variables,npoints) | |||
end | |||
|
|||
# GPU methods for DiagnosticVariablesLayer | |||
function Adapt.adapt_structure(to, dvl::DiagnosticVariablesLayer) | |||
DiagnosticVariablesLayer(dvl.tendencies, dvl.grid_variables, dvl.dynamics_variables, dvl.npoints) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, the calls to adapt
are missing for tendencies
, grid_variables
and dynamics_variables
# GPU methods for DiagnosticVariables | ||
function Adapt.adapt_structure(to, dv::DiagnosticVariables{NF}) where NF | ||
DiagnosticVariables(Adapt.adapt(to, dv.layers), | ||
dv.surface, dv.nlev, dv.npoints) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
surface
needs to be converted as well adapt
test/kernelabstractions.jl
Outdated
@@ -1,8 +1,12 @@ | |||
using KernelAbstractions | |||
using KernelAbstractions | |||
import Parameters: @with_kw, @unpack |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can just use the first style so,
(;lmax,mmax) = m.spectral_transform
I'd say, We can add this later the kernelabstractions_adtest
branch
Sorry my bad! Misunderstood what was supposed to go into which branch and just incorrectly merged two PRs that pointed into different branches. I'll let you merge anything kernelabstractions-related from now on! Sorry 😬 |
Ok to sort this out, I guess I would just close this PR and @katharinamaetschke does the corrections as another PR into the And for the next PRs, everything as planned also as PRs that point to the |
The last commit addresses the compat issues, the unpacking in the tests and @katharinamaetschke it is best when you sync your fork on the |
I'll close this PR now. @katharinamaetschke please do another PR for the corrections into the |
Yes, I willl, I am very sorry for taking so long! |
@maximilian-gelbrecht Adapt functions for the structs in diagnostic_variables.jl in the way they were also implemented in the lower_triangular_matrices.jl file. I haven't tested them yet, but wanted to know if this is basically the right way to do it.