You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix eager FD kernel bugs and replace op-specific isa checks with dispatch
Bug fixes (each reproduced on GPU before the fix):
- ext/cuda/operators_finite_difference.jl: read `mask.N[1]` under
`CUDA.@allowscalar`. It is a one-element device array, so the masked eager
path threw "Scalar indexing is disallowed" on its first call. Matches the
three existing read sites in data_layouts_threadblock.jl.
- src/Operators/finitedifference.jl: restore
`boundary_width(::DivergenceF2C, ::Extrapolate) = 1`. Without it the boundary
centers fall in the interior window, so `op_matrix_first_row`/`_last_row` for
`Extrapolate` were unreachable and the condition was silently ignored --
`divf2c_extrapolate(u)` returned the plain interior stencil at the boundary.
`test_op_matrix(DivergenceF2C, Extrapolate, ...)` could not catch this because
both the matrix and operator paths degraded identically.
- ext/cuda/operators_fd_eager.jl: size the dynamic shared memory from the
actual projected operand type (`cached_operand_type`) instead of the
`AbstractTensor ? sizeof(eltype)*9 : sizeof` heuristic. `project_row2_for_mul`
projects tensor leaves nested inside a `BandMatrixRow`, which the heuristic
did not see: a `QuaddiagonalMatrixRow{Covariant1Vector{Float64}}` was budgeted
32 bytes and written as 96, crashing the kernel with ERROR_ILLEGAL_ADDRESS.
The new version mirrors `project_row2_for_mul`'s type logic, so it cannot
drift from what the kernel writes.
- .buildkite/pipeline.yml: drop the stray `soft_fail: true` from the
`agents:` block of unit_matrix_field_broadcasting_gpu_non_scalar_3. It is a
step attribute, not an agent tag; there it became an agent-tag query that
would leave the step unscheduled. The correct one three lines above stays.
Op-specific `isa` checks in generic machinery, now handled by dispatch:
- `should_call_left_boundary`/`should_call_right_boundary` no longer special-case
`SetBoundaryOperator` + `NullBoundaryCondition`. Instead
`boundary_width(::SetBoundaryOperator, ...)` returns 0 by default and 1 for the
four value-fixing conditions, matching the idiom already used for
GradientF2C/DivergenceF2C. This also fixes what the guard could not reach:
`left_interior_window_idx`/`right_interior_window_idx` bypass
`should_call_*`, so one-sided SetBoundaryOperators were needlessly widening
the boundary window by a level. `should_call_right_boundary` now also uses the
`boundary_condition` local it already binds.
- The `op_matrix.op isa Union{GradientF2C, DivergenceF2C} && bc isa SetValue`
branch inside the generic `FDOperatorMatrix` `stencil_*_boundary` methods
becomes a more specific method on `FDOperatorMatrix{<:InputFixingFDOperator}`.
- The `op isa SetBoundaryOperator` early return in the generic
`OneArgFDOperator` StencilBroadcasted constructor becomes its own constructor
method; the gradient/divergence adjoint ternaries become
`adjoint_matrix_arg`/`adjoint_matrix_result`. The generic constructor now has
no `isa` checks.
- Drop `split_bcs = op isa WeightedInterpolateC2F` from the `TwoArgFDOperator`
constructor. Every other two-argument operator's conditions are linear, so
`output_bcs` is already empty and `op_with_matrix_bcs` already returns the op
unchanged; the flag was both a hardcoded op name and redundant.
`detect_ambiguities` is empty for both Operators and MatrixFields. Verified on
CPU and GPU: MatrixFields/operator_matrices.jl (CPU 275+41, GPU 207+25),
finitedifference/unit_column.jl (25 each), and
matrix_fields_broadcasting/test_non_scalar_2.jl (GPU 2) all pass.
test_non_scalar_3.jl remains red, but with a pre-existing InvalidIRError over
`AutoBroadcaster` row entries that reproduces with these changes stashed, so its
soft_fail is left in place.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BLMKMmk7JezBvagh3AybPQ
0 commit comments