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

Remove global allowscalar from testing suite attempt 2 #4039

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
4a44943
remove allowscalar
simone-silvestri Jan 12, 2025
437b86f
Update runtests.jl
simone-silvestri Jan 12, 2025
c059413
start adding the allowscalars
simone-silvestri Jan 12, 2025
7168b96
comment
simone-silvestri Jan 12, 2025
d8ee394
more allowscalars
simone-silvestri Jan 12, 2025
56b3b3f
Merge branch 'main' into ss/remove-allowscalar-from-tests
simone-silvestri Jan 13, 2025
62be01a
some scalar ops
navidcy Jan 14, 2025
c37dd14
Merge branch 'main' into ss/remove-allowscalar-from-tests
navidcy Jan 14, 2025
56f8a13
homogenize CUDA.@allowscalar before @test
navidcy Jan 14, 2025
af39cc1
Merge branch 'ss/remove-allowscalar-from-tests' of github.com:CliMA/O…
navidcy Jan 14, 2025
e18488c
few more allowscalars
navidcy Jan 14, 2025
e19f168
remove stray empty line
navidcy Jan 14, 2025
6e262a5
Merge branch 'main' into ss/remove-allowscalar-from-tests
navidcy Jan 14, 2025
50e856e
few more allowscalars
navidcy Jan 14, 2025
1fe5fb6
CUDA.@allowscalar at Base.getindex(f::Field, inds...)
navidcy Jan 15, 2025
1cf16e9
Merge branch 'main' into ss/remove-allowscalar-from-tests
navidcy Jan 15, 2025
29952d8
Update field.jl
navidcy Jan 15, 2025
891fc52
Merge branch 'main' into ss/remove-allowscalar-from-tests
navidcy Jan 19, 2025
9fc97db
remove GPUArrays pin
navidcy Jan 19, 2025
c64a806
Merge branch 'ss/remove-allowscalar-from-tests' of github.com:CliMA/O…
navidcy Jan 19, 2025
6e36c9e
Merge branch 'main' into ss/remove-allowscalar-from-tests
navidcy Jan 22, 2025
6f277a3
Merge branch 'main' into ss/remove-allowscalar-from-tests
simone-silvestri Jan 23, 2025
d612f0c
Update pipeline.yml
navidcy Jan 24, 2025
956cf00
Merge branch 'main' into ss/remove-allowscalar-from-tests
navidcy Jan 24, 2025
062028b
Merge branch 'main' into ss/remove-allowscalar-from-tests
simone-silvestri Jan 24, 2025
05e05ae
Pin GPUArrays version
simone-silvestri Jan 24, 2025
eb3bbb5
fetch for function fields
simone-silvestri Jan 24, 2025
bb1a3a6
Merge branch 'main' into ss/remove-allowscalar-from-tests
simone-silvestri Mar 11, 2025
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
5 changes: 4 additions & 1 deletion src/OutputWriters/fetch_output.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using CUDA

using Oceananigans.Fields: AbstractField, compute_at!, ZeroField
using Oceananigans.Fields: AbstractField, compute_at!, ZeroField, FunctionField
using Oceananigans.Models.LagrangianParticleTracking: LagrangianParticles

# TODO: figure out how to support this
Expand All @@ -19,6 +19,9 @@ function fetch_output(field::AbstractField, model)
return parent(field)
end

# Make sure a function field is evaluated on the CPU
fetch_output(field::FunctionField, model) = on_architecture(CPU(), field)

function fetch_output(lagrangian_particles::LagrangianParticles, model)
particle_properties = lagrangian_particles.properties
names = propertynames(particle_properties)
Expand Down
5 changes: 0 additions & 5 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ end
##### Run tests
#####

CUDA.allowscalar() do

@testset "Oceananigans" begin

if test_file != :none
Expand Down Expand Up @@ -246,6 +244,3 @@ CUDA.allowscalar() do
include("test_convergence.jl")
end
end

end #CUDA.allowscalar()

1 change: 0 additions & 1 deletion test/test_abstract_operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -366,4 +366,3 @@ for arch in archs
end
end
end

62 changes: 34 additions & 28 deletions test/test_distributed_models.jl
Original file line number Diff line number Diff line change
Expand Up @@ -340,14 +340,16 @@ function test_triply_periodic_halo_communication_with_411_ranks(halo, child_arch
fill!(field, arch.local_rank)
fill_halo_regions!(field)

@test all(east_halo(field, include_corners=false) .== arch.connectivity.east)
@test all(west_halo(field, include_corners=false) .== arch.connectivity.west)

@test all(interior(field) .== arch.local_rank)
@test all(north_halo(field, include_corners=false) .== arch.local_rank)
@test all(south_halo(field, include_corners=false) .== arch.local_rank)
@test all(top_halo(field, include_corners=false) .== arch.local_rank)
@test all(bottom_halo(field, include_corners=false) .== arch.local_rank)
CUDA.@allowscalar begin
@test all(east_halo(field, include_corners=false) .== arch.connectivity.east)
@test all(west_halo(field, include_corners=false) .== arch.connectivity.west)

@test all(interior(field) .== arch.local_rank)
@test all(north_halo(field, include_corners=false) .== arch.local_rank)
@test all(south_halo(field, include_corners=false) .== arch.local_rank)
@test all(top_halo(field, include_corners=false) .== arch.local_rank)
@test all(bottom_halo(field, include_corners=false) .== arch.local_rank)
end # CUDA.@allowscalar
end

return nothing
Expand All @@ -362,14 +364,16 @@ function test_triply_periodic_halo_communication_with_141_ranks(halo, child_arch
fill!(field, arch.local_rank)
fill_halo_regions!(field)

@test all(north_halo(field, include_corners=false) .== arch.connectivity.north)
@test all(south_halo(field, include_corners=false) .== arch.connectivity.south)
CUDA.@allowscalar begin
@test all(north_halo(field, include_corners=false) .== arch.connectivity.north)
@test all(south_halo(field, include_corners=false) .== arch.connectivity.south)

@test all(interior(field) .== arch.local_rank)
@test all(east_halo(field, include_corners=false) .== arch.local_rank)
@test all(west_halo(field, include_corners=false) .== arch.local_rank)
@test all(top_halo(field, include_corners=false) .== arch.local_rank)
@test all(bottom_halo(field, include_corners=false) .== arch.local_rank)
@test all(interior(field) .== arch.local_rank)
@test all(east_halo(field, include_corners=false) .== arch.local_rank)
@test all(west_halo(field, include_corners=false) .== arch.local_rank)
@test all(top_halo(field, include_corners=false) .== arch.local_rank)
@test all(bottom_halo(field, include_corners=false) .== arch.local_rank)
end # CUDA.@allowscalar
end

return nothing
Expand All @@ -384,19 +388,21 @@ function test_triply_periodic_halo_communication_with_221_ranks(halo, child_arch
fill!(field, arch.local_rank)
fill_halo_regions!(field)

@test all(interior(field) .== arch.local_rank)

@test all(east_halo(field, include_corners=false) .== arch.connectivity.east)
@test all(west_halo(field, include_corners=false) .== arch.connectivity.west)
@test all(north_halo(field, include_corners=false) .== arch.connectivity.north)
@test all(south_halo(field, include_corners=false) .== arch.connectivity.south)

@test all(top_halo(field, include_corners=false) .== arch.local_rank)
@test all(bottom_halo(field, include_corners=false) .== arch.local_rank)
@test all(southwest_halo(field) .== arch.connectivity.southwest)
@test all(southeast_halo(field) .== arch.connectivity.southeast)
@test all(northwest_halo(field) .== arch.connectivity.northwest)
@test all(northeast_halo(field) .== arch.connectivity.northeast)
CUDA.@allowscalar begin
@test all(interior(field) .== arch.local_rank)

@test all(east_halo(field, include_corners=false) .== arch.connectivity.east)
@test all(west_halo(field, include_corners=false) .== arch.connectivity.west)
@test all(north_halo(field, include_corners=false) .== arch.connectivity.north)
@test all(south_halo(field, include_corners=false) .== arch.connectivity.south)

@test all(top_halo(field, include_corners=false) .== arch.local_rank)
@test all(bottom_halo(field, include_corners=false) .== arch.local_rank)
@test all(southwest_halo(field) .== arch.connectivity.southwest)
@test all(southeast_halo(field) .== arch.connectivity.southeast)
@test all(northwest_halo(field) .== arch.connectivity.northwest)
@test all(northeast_halo(field) .== arch.connectivity.northeast)
end # CUDA.@allowscalar
end

return nothing
Expand Down
13 changes: 11 additions & 2 deletions test/test_grids.jl
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ function test_regular_rectilinear_xnode_ynode_znode_and_spacings(arch, FT)
for (grid_type, grid) in zip(grids_types, grids)
@info " Testing grid utils on $grid_type grid...."

CUDA.@allowscalar begin

@test xnode(2, grid, Center()) ≈ FT(π/2)
@test ynode(2, grid, Center()) ≈ FT(π/2)
@test znode(2, grid, Center()) ≈ FT(π/2)
Expand Down Expand Up @@ -235,6 +237,8 @@ function test_regular_rectilinear_xnode_ynode_znode_and_spacings(arch, FT)
@test Δx(1, 1, 1, grid, Face(), Center(), Center()) ≈ FT(π/N)
@test Δy(1, 1, 1, grid, Center(), Face(), Center()) ≈ FT(π/N)
@test Δz(1, 1, 1, grid, Center(), Center(), Face()) ≈ FT(π/N)

end # CUDA.@allowscalar
end

return nothing
Expand Down Expand Up @@ -349,7 +353,7 @@ function test_grid_equality(arch)
grid2 = RectilinearGrid(arch, topology=topo, size=(Nx, Ny, Nz), x=(0, 1), y=(-1, 1), z=0:Nz)
grid3 = RectilinearGrid(arch, topology=topo, size=(Nx, Ny, Nz), x=(0, 1), y=(-1, 1), z=0:Nz)

return grid1==grid1 && grid2 == grid3 && grid1 !== grid3
return grid1 == grid1 && grid2 == grid3 && grid1 !== grid3
end

function test_grid_equality_over_architectures()
Expand Down Expand Up @@ -708,7 +712,7 @@ function test_lat_lon_precomputed_metrics(FT, arch)
longitude = (lonreg, lonstr, lonregB, lonstrB)
zcoord = (zreg, zstr)

CUDA.allowscalar() do
CUDA.@allowscalar begin

# grid with pre computed metrics vs metrics computed on the fly
for lat in latitude
Expand Down Expand Up @@ -982,6 +986,9 @@ end

for arch in archs
for FT in float_types

CUDA.@allowscalar begin

ccc = (Center(), Center(), Center())
grid = RectilinearGrid(arch, FT, size=4, z=(-1, 0), topology=(Flat, Flat, Bounded))
x = xnodes(grid, ccc...)
Expand Down Expand Up @@ -1030,6 +1037,8 @@ end
gpu_grid = on_architecture(GPU(), grid)
@test gpu_grid == grid
end

end # CUDA.@allowscalar
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions test/test_hydrostatic_free_surface_immersed_boundaries.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ using Oceananigans.TurbulenceClosures
set!(model, u = 1, b = (x, y, z) -> 4z)

# Inside the bump
@test b[4, 4, 2] == 0
@test u[4, 4, 2] == 0
CUDA.@allowscalar @test b[4, 4, 2] == 0
CUDA.@allowscalar @test u[4, 4, 2] == 0

simulation = Simulation(model, Δt = 1e-3, stop_iteration=2)

run!(simulation)

# Inside the bump
@test b[4, 4, 2] == 0
@test u[4, 4, 2] == 0
CUDA.@allowscalar @test b[4, 4, 2] == 0
CUDA.@allowscalar @test u[4, 4, 2] == 0
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/test_implicit_free_surface_solver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function set_simple_divergent_velocity!(model)

# pick a surface cell at the middle of the domain
i, j, k = Int(floor(grid.Nx / 2)) + 1, Int(floor(grid.Ny / 2)) + 1, grid.Nz
inactive_cell(i, j, k, grid) && error("The nudged cell at ($i, $j, $k) is inactive.")
CUDA.@allowscalar inactive_cell(i, j, k, grid) && error("The nudged cell at ($i, $j, $k) is inactive.")

Δy = CUDA.@allowscalar Δyᶜᶠᶜ(i, j, k, grid)
Δz = CUDA.@allowscalar Δzᶜᶠᶜ(i, j, k, grid)
Expand Down
2 changes: 0 additions & 2 deletions test/test_jld2_output_writer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,6 @@ for arch in archs
filename = "sliced_func_fields_jld2_test",
overwrite_existing = true)



u₀ = CUDA.@allowscalar model.velocities.u[3, 3, 3]
v₀ = CUDA.@allowscalar model.velocities.v[3, 3, 3]
w₀ = CUDA.@allowscalar model.velocities.w[3, 3, 3]
Expand Down
2 changes: 1 addition & 1 deletion test/test_shallow_water_models.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function test_shallow_water_diffusion_cosine(grid, formulation, fieldname, ξ)
analytical_solution = Field(location(field), grid)
analytical_solution .= diffusing_cosine.(ξ, model.clock.time, ν, m)

return isapprox(field, analytical_solution, atol=1e-6, rtol=1e-6)
return CUDA.@allowscalar isapprox(field, analytical_solution, atol=1e-6, rtol=1e-6)
end

@testset "Shallow Water Models" begin
Expand Down
6 changes: 3 additions & 3 deletions test/test_simulations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function wall_time_step_wizard_tests(arch)
CFL = 0.45
u₀ = 7
Δt = 2.5
model.velocities.u[1, 1, 1] = u₀
CUDA.@allowscalar model.velocities.u[1, 1, 1] = u₀

wizard = TimeStepWizard(cfl=CFL, max_change=Inf, min_change=0)
Δt = new_time_step(Δt, wizard, model)
Expand All @@ -35,7 +35,7 @@ function wall_time_step_wizard_tests(arch)
Δt = new_time_step(Δt, wizard, model)
@test Δt ≈ 1.99

model.velocities.u[1, 1, 1] = u₀/100
CUDA.@allowscalar model.velocities.u[1, 1, 1] = u₀/100

wizard = TimeStepWizard(cfl=CFL, max_change=1.1, min_change=0)
Δt = new_time_step(1.0, wizard, model)
Expand Down Expand Up @@ -223,7 +223,7 @@ function run_nan_checker_test(arch; erroring)
grid = RectilinearGrid(arch, size=(4, 2, 1), extent=(1, 1, 1))
model = NonhydrostaticModel(grid=grid)
simulation = Simulation(model, Δt=1, stop_iteration=2)
model.velocities.u[1, 1, 1] = NaN
CUDA.@allowscalar model.velocities.u[1, 1, 1] = NaN
erroring && erroring_NaNChecker!(simulation)

if erroring
Expand Down
10 changes: 5 additions & 5 deletions test/test_turbulence_closures.jl
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ function run_catke_tke_substepping_tests(arch, closure)
time_step!(model, 1)

# Check that eⁿ⁺¹ == Δt * Gⁿ.e with Δt = 1 (euler step)
@test model.tracers.e ≈ model.timestepper.G⁻.e
CUDA.@allowscalar @test model.tracers.e ≈ model.timestepper.G⁻.e

eⁿ = deepcopy(model.tracers.e)
G⁻⁻ = deepcopy(model.timestepper.G⁻.e)
Expand All @@ -199,8 +199,8 @@ function run_catke_tke_substepping_tests(arch, closure)

eⁿ⁺¹ = compute!(Field(eⁿ + C₁ * G⁻ - C₂ * G⁻⁻))

# Check that eⁿ⁺¹ == eⁿ + Δt * (C₁ Gⁿ.e - C₂ G⁻.e)
@test model.tracers.e ≈ eⁿ⁺¹
# Check that eⁿ⁺¹ == eⁿ + Δt * (C₁ Gⁿ.e - C₂ G⁻.e)
CUDA.@allowscalar @test model.tracers.e ≈ eⁿ⁺¹

return model
end
Expand Down Expand Up @@ -320,8 +320,8 @@ end
ν = viscosity(model.closure, model.diffusivity_fields)
@test viscosity(model) == viscosity(model.closure, model.diffusivity_fields)
ν_dx_u = ν * ∂x(u)
@test ν_dx_u[1, 1, 1] == 0
@test κ_dx_c[1, 1, 1] == 0
CUDA.@allowscalar @test ν_dx_u[1, 1, 1] == 0
CUDA.@allowscalar @test κ_dx_c[1, 1, 1] == 0
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/test_vertical_vorticity_field.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ using Oceananigans.Models.HydrostaticFreeSurfaceModels: VerticalVorticityField,

compute!(ζ)

@test all(isfinite.(ζ.data))
CUDA.@allowscalar @test all(isfinite.(ζ.data))
end
end
end