Skip to content

Commit 24534c4

Browse files
imreddyTejaclaude
andcommitted
Fix unit_column.jl GPU failures
The reference values in the "Replacements for removed operators and boundary conditions" testset are built with scalar indexing, so extract the data they are built from (and the results they are compared against) on the CPU. Also apply the biased operators to `ᶠlg.J` rather than to `ᶠlg`: the GPU compiles the never-taken `NullBoundaryCondition` branch of the stencil, which multiplies by `NaN` and so cannot handle a `LocalGeometry` element type. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xn8GWgn2mufFccq5MMKPCS
1 parent f40ca5e commit 24534c4

1 file changed

Lines changed: 24 additions & 18 deletions

File tree

test/Operators/finitedifference/unit_column.jl

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -368,13 +368,17 @@ end
368368
wᶜ = Geometry.WVector.(1 .+ sin.(Fields.coordinate_field(cs).z))
369369
wᶠ = Geometry.WVector.(1 .+ sin.(Fields.coordinate_field(fs).z))
370370

371+
# the reference values below are built with scalar indexing, so the data
372+
# they are built from has to be moved to the CPU first
373+
cpu_parent(field) = Array(parent(field))
374+
371375
# the quantities that the removed stencils were written in terms of
372-
tᶜ = parent(θᶜ)[:]
373-
tᶠ = parent(θᶠ)[:]
374-
w³ᶜ = parent(Geometry.contravariant3.(wᶜ, ᶜlg))[:]
375-
w³ᶠ = parent(Geometry.contravariant3.(wᶠ, ᶠlg))[:]
376-
Jᶜ = parent(ᶜlg.J)[:]
377-
Jᶠ = parent(ᶠlg.J)[:]
376+
tᶜ = cpu_parent(θᶜ)[:]
377+
tᶠ = cpu_parent(θᶠ)[:]
378+
w³ᶜ = cpu_parent(Geometry.contravariant3.(wᶜ, ᶜlg))[:]
379+
w³ᶠ = cpu_parent(Geometry.contravariant3.(wᶠ, ᶠlg))[:]
380+
Jᶜ = cpu_parent(ᶜlg.J)[:]
381+
Jᶠ = cpu_parent(ᶠlg.J)[:]
378382
θ₀ = FT(0.5) # boundary value
379383
interpf2c = Operators.InterpolateF2C()
380384

@@ -395,7 +399,7 @@ end
395399
Geometry.Covariant3Vector.(2 .* (θ₀ .- θ_top)),
396400
),
397401
)
398-
@test parent(gradc2f.(θᶜ))[:] ref
402+
@test cpu_parent(gradc2f.(θᶜ))[:] ref
399403
end
400404

401405
@testset "DivergenceC2F, SetValue(0)" begin
@@ -407,24 +411,26 @@ end
407411
]
408412
# `LeftBiasedF2C(x)[i] = x[i-half]`, so its first level is the bottom
409413
# face; `RightBiasedF2C(x)[i] = x[i+half]`, so its last level is the top.
410-
lg_bot_face = Fields.level(Operators.LeftBiasedF2C().(ᶠlg), 1)
411-
lg_top_face = Fields.level(Operators.RightBiasedF2C().(ᶠlg), n)
414+
# These are applied to `J` rather than to the local geometry itself, so
415+
# that the stencil only ever operates on scalars.
416+
J_bot_face = Fields.level(Operators.LeftBiasedF2C().(ᶠlg.J), 1)
417+
J_top_face = Fields.level(Operators.RightBiasedF2C().(ᶠlg.J), n)
412418
set_bcs = Operators.SetBoundaryOperator(
413419
bottom = Operators.SetValue(
414420
Geometry.Jcontravariant3.(
415421
Fields.level(wᶜ, 1),
416422
Fields.level(ᶜlg, 1),
417-
) .* (2 .* inv.(lg_bot_face.J)),
423+
) .* (2 .* inv.(J_bot_face)),
418424
),
419425
top = Operators.SetValue(
420426
Geometry.Jcontravariant3.(
421427
Fields.level(wᶜ, n),
422428
Fields.level(ᶜlg, n),
423-
) .* (-2 .* inv.(lg_top_face.J)),
429+
) .* (-2 .* inv.(J_top_face)),
424430
),
425431
)
426432
divc2f = Operators.DivergenceC2F()
427-
@test parent(@. set_bcs(divc2f(wᶜ)))[:] ref
433+
@test cpu_parent(@. set_bcs(divc2f(wᶜ)))[:] ref
428434
end
429435

430436
@testset "UpwindBiasedProductC2F, SetValue" begin
@@ -437,8 +443,8 @@ end
437443
Operators.upwind_biased_product(w³ᶠ[i], tᶜ[i - 1], tᶜ[i])
438444
for i in 1:(n + 1)
439445
]
440-
v_bot = parent(Geometry.contravariant3.(wᶠ, ᶠlg))[1]
441-
v_top = parent(Geometry.contravariant3.(wᶠ, ᶠlg))[n + 1]
446+
v_bot = w³ᶠ[1]
447+
v_top = w³ᶠ[n + 1]
442448
set_bcs = Operators.SetBoundaryOperator(
443449
bottom = Operators.SetValue(
444450
Geometry.Contravariant3Vector(
@@ -452,7 +458,7 @@ end
452458
),
453459
)
454460
upwind = Operators.UpwindBiasedProductC2F()
455-
@test parent(@. set_bcs(upwind(wᶠ, θᶜ)))[:] ref
461+
@test cpu_parent(@. set_bcs(upwind(wᶠ, θᶜ)))[:] ref
456462
end
457463

458464
@testset "AdvectionC2C, SetValue" begin
@@ -474,7 +480,7 @@ end
474480
new = @. interpf2c(
475481
Geometry.dot(Geometry.Contravariant3Vector(wᶠ), gradc2f(θᶜ)),
476482
)
477-
@test parent(new)[:] ref
483+
@test cpu_parent(new)[:] ref
478484
end
479485

480486
@testset "AdvectionF2F" begin
@@ -486,7 +492,7 @@ end
486492
Geometry.Contravariant3Vector(wᶠ),
487493
interpc2f(gradf2c(θᶠ)),
488494
)
489-
@test parent(new)[2:n] ref
495+
@test cpu_parent(new)[2:n] ref
490496
end
491497

492498
@testset "FluxCorrectionC2C, Extrapolate" begin
@@ -512,6 +518,6 @@ end
512518
)
513519
# `GradientF2C` returns a `Covariant3Vector`, whose component is the
514520
# difference of the fluxes across the cell
515-
@test parent(gradf2c.(flux))[:] ref
521+
@test cpu_parent(gradf2c.(flux))[:] ref
516522
end
517523
end

0 commit comments

Comments
 (0)