Closed tomchor closed 1 year ago
Here's a MWE:
using Oceananigans
using Oceanostics.FlowDiagnostics: TracerVarianceDissipationRate
grid = RectilinearGrid(GPU(), size=(4, 4, 4), extent=(1,1,1))
model = NonhydrostaticModel(; grid, closure=(VerticalScalarDiffusivity(ν=1), HorizontalScalarDiffusivity(ν=2)), tracers=:b)
χ = Field(TracerVarianceDissipationRate(model, :b))
compute!(χ)
Apparently the reason why this is failing is because you can't dynamically allocate an Array inside a GPU Kernel. So things like
diff_flux(i, j, k, grid, closure_tuple::Tuple, diffusivity_fields, args...) =
sum(diff_flux(i, j, k, grid, closure, diffusivities, args...) for (closure, diffusivities) in zip(closure_tuple, diffusivity_fields))
Have to replaced by stuff like
diff_flux(i, j, k, grid, closure_tuple::Tuple, diffusivity_fields, args...) =
diff_flux(i, j, k, grid, closure_tuple[1], diffusivity_fields[1], args...) +
diff_flux(i, j, k, grid, closure_tuple[2:end], diffusivity_fields[2:end], args...)
When calculating
TracerVarianceDissipationRate
on a GPU using a tuple closure I get:The issue seem to be coming from these lines: https://github.com/tomchor/Oceanostics.jl/blob/376c25e90397dfa3e13b305fed3bb16aa7dbed6a/src/FlowDiagnostics.jl#L353-L356
Although it's not clear to me why that's the case.
It's also a shame we don't have an available GPU for testing for this repo. It would have caught that.