Skip to content

Commit

Permalink
Inference problem on the CPU (#4032)
Browse files Browse the repository at this point in the history
* fix the problem

* bugfix
  • Loading branch information
simone-silvestri authored Jan 8, 2025
1 parent 0345a2c commit 19baa39
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ function compute_hydrostatic_momentum_tendencies!(model, velocities, kernel_para
u_immersed_bc = immersed_boundary_condition(velocities.u)
v_immersed_bc = immersed_boundary_condition(velocities.v)

u_forcing = model.forcing.u
v_forcing = model.forcing.v

start_momentum_kernel_args = (model.advection.momentum,
model.coriolis,
model.closure)
Expand All @@ -139,17 +142,17 @@ function compute_hydrostatic_momentum_tendencies!(model, velocities, kernel_para
model.auxiliary_fields,
model.clock)

u_kernel_args = tuple(start_momentum_kernel_args..., u_immersed_bc, end_momentum_kernel_args...)
v_kernel_args = tuple(start_momentum_kernel_args..., v_immersed_bc, end_momentum_kernel_args...)
u_kernel_args = tuple(start_momentum_kernel_args..., u_immersed_bc, end_momentum_kernel_args..., u_forcing)
v_kernel_args = tuple(start_momentum_kernel_args..., v_immersed_bc, end_momentum_kernel_args..., v_forcing)

launch!(arch, grid, kernel_parameters,
compute_hydrostatic_free_surface_Gu!, model.timestepper.Gⁿ.u, grid,
active_cells_map, u_kernel_args, model.forcing.u;
active_cells_map, u_kernel_args;
active_cells_map)

launch!(arch, grid, kernel_parameters,
compute_hydrostatic_free_surface_Gv!, model.timestepper.Gⁿ.v, grid,
active_cells_map, v_kernel_args, model.forcing.v;
active_cells_map, v_kernel_args;
active_cells_map)

return nothing
Expand Down Expand Up @@ -179,27 +182,27 @@ end
#####

""" Calculate the right-hand-side of the u-velocity equation. """
@kernel function compute_hydrostatic_free_surface_Gu!(Gu, grid, ::Nothing, args, forcing)
@kernel function compute_hydrostatic_free_surface_Gu!(Gu, grid, ::Nothing, args)
i, j, k = @index(Global, NTuple)
@inbounds Gu[i, j, k] = hydrostatic_free_surface_u_velocity_tendency(i, j, k, grid, args..., forcing)
@inbounds Gu[i, j, k] = hydrostatic_free_surface_u_velocity_tendency(i, j, k, grid, args...)
end

@kernel function compute_hydrostatic_free_surface_Gu!(Gu, grid, active_cells_map, args, forcing)
@kernel function compute_hydrostatic_free_surface_Gu!(Gu, grid, active_cells_map, args)
idx = @index(Global, Linear)
i, j, k = active_linear_index_to_tuple(idx, active_cells_map)
@inbounds Gu[i, j, k] = hydrostatic_free_surface_u_velocity_tendency(i, j, k, grid, args..., forcing)
@inbounds Gu[i, j, k] = hydrostatic_free_surface_u_velocity_tendency(i, j, k, grid, args...)
end

""" Calculate the right-hand-side of the v-velocity equation. """
@kernel function compute_hydrostatic_free_surface_Gv!(Gv, grid, ::Nothing, args, forcing)
@kernel function compute_hydrostatic_free_surface_Gv!(Gv, grid, ::Nothing, args)
i, j, k = @index(Global, NTuple)
@inbounds Gv[i, j, k] = hydrostatic_free_surface_v_velocity_tendency(i, j, k, grid, args..., forcing)
@inbounds Gv[i, j, k] = hydrostatic_free_surface_v_velocity_tendency(i, j, k, grid, args...)
end

@kernel function compute_hydrostatic_free_surface_Gv!(Gv, grid, active_cells_map, args, forcing)
@kernel function compute_hydrostatic_free_surface_Gv!(Gv, grid, active_cells_map, args)
idx = @index(Global, Linear)
i, j, k = active_linear_index_to_tuple(idx, active_cells_map)
@inbounds Gv[i, j, k] = hydrostatic_free_surface_v_velocity_tendency(i, j, k, grid, args..., forcing)
@inbounds Gv[i, j, k] = hydrostatic_free_surface_v_velocity_tendency(i, j, k, grid, args...)
end

#####
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ implicitly during time-stepping.
diffusivities,
hydrostatic_pressure_anomaly,
auxiliary_fields,
clock,
clock,
forcing)

model_fields = merge(hydrostatic_fields(velocities, free_surface, tracers), auxiliary_fields)
Expand All @@ -49,7 +49,7 @@ implicitly during time-stepping.
- ∂xᶠᶜᶜ(i, j, k, grid, hydrostatic_pressure_anomaly)
- ∂ⱼ_τ₁ⱼ(i, j, k, grid, closure, diffusivities, clock, model_fields, buoyancy)
- immersed_∂ⱼ_τ₁ⱼ(i, j, k, grid, velocities, u_immersed_bc, closure, diffusivities, clock, model_fields)
+ forcing(i, j, k, grid, clock, hydrostatic_prognostic_fields(velocities, free_surface, tracers)))
+ forcing(i, j, k, grid, clock, model_fields))
end

"""
Expand Down Expand Up @@ -82,7 +82,7 @@ implicitly during time-stepping.

model_fields = merge(hydrostatic_fields(velocities, free_surface, tracers), auxiliary_fields)

return ( - U_dot_∇v(i, j, k, grid, advection, velocities)
return ( - U_dot_∇v(i, j, k, grid, advection, velocities)
- explicit_barotropic_pressure_y_gradient(i, j, k, grid, free_surface)
- y_f_cross_U(i, j, k, grid, coriolis, velocities)
- ∂yᶜᶠᶜ(i, j, k, grid, hydrostatic_pressure_anomaly)
Expand Down

0 comments on commit 19baa39

Please sign in to comment.