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
{{ message }}
Repository navigation
test(ad): GPU/packed-field AD parity for the exchange rules #43
ext/MatrixFreeOperatorsEnzymeCoreExt.jl registers rules on _exchange_storage!/_bc_storage!, which are layout-agnostic: they take raw storage plus a BlockLayout tag, so PackedBlockField goes through the same rules as BlockField. That is the mechanism DESIGN.md §6 calls mandatory for @kernel-authored leaves — the packed GPU exchange must never be differentiated through, and now it structurally cannot be.
None of that is tested on a GPU. Specifically:
No AD test uses a packed field at all, on any backend. src/packedfield.jl:17-18 still designates BlockField as "the reference layout for AD".
test/device.jl / test/device_gpu.jl never differentiate, so MFO_TEST_GPU=true adds no AD coverage.
The device exchange path (_run_exchange!(::PackedBlockField, ...) in src/transfer_kernels.jl:194-198) dispatches to batched kernels below the rule seam only when the backend is a real GPU. On CPU it falls back to _run_exchange_host!, which is what the current tests exercise — so the rule is verified against the fallback, not against the kernels.
What to add
CPU-side first — the quick, self-contained first deliverable. It needs no hardware and can land as its own PR ahead of steps 2-3: a packed-field AD test asserting the gradient matches the declared adjoint and that the rules fire (ENZ_EXT.rule_hits() counters increase across the call), mirroring test/enzyme_rules.jl.
Under MFO_TEST_GPU, the same against CUDA arrays — the real question being whether the rule's reverse body (_exchange_storage_adjoint!, which stays on host descriptor loops on all backends by design, see transfer_kernels.jl:16-23) composes correctly with a forward pass that ran as batched kernels.
Decide and document whether GPU reverse mode is supported or explicitly refused. Right now it is neither — it is untested.
—
🤖 Claude fixed a line number that had wandered off. claude-opus-5-5[1m] (high) · claude-code 2.1.285 · unreviewed
Activity