Repository navigation
Separate the per-cell element routines from the op structs - #72
Merged
Merged
Conversation
_linear_element! and _nonlinear_element! write the Me/Ke/Fe or Je/re buffers and read the element state they are passed, instead of the LinearOp/NonlinearOp fields, so the CPU driver and a future device kernel (with per-worker views into 3D arrays) call the same contraction code. _kernel! keeps its signature and forwards the op's buffers; residual-only assembly passes Je = nothing. No behaviour change. Agent-Harness: Claude Code 2.1.318 Agent-Model: claude-opus-5-5 Agent-Session: f7b46bdf-7cc3-44dd-b8a4-9205616ff6ac Agent-Review: unreviewed Co-authored-by: Claude Code <agent@noreply.juliahub.com>
Gathering _linear_element! and _nonlinear_element! over every cell, with plain arrays and with views into 3D per-worker buffers, reproduces assemble_linear and assemble_nonlinear exactly for the coeffs and f paths, and the calls on views are allocation-free (AllocCheck and @allocated). Agent-Harness: Claude Code 2.1.318 Agent-Model: claude-opus-5-5 Agent-Session: f7b46bdf-7cc3-44dd-b8a4-9205616ff6ac Agent-Review: unreviewed Co-authored-by: Claude Code <agent@noreply.juliahub.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
This is phase 0 of GPU support: a CPU-only refactor that merges on its own, with no Ferrite dependency. GPU assembly will run the per-cell arithmetic inside a KernelAbstractions kernel, with each worker's element buffers as views into 3D device arrays. For the CPU driver and the device kernel to share the ~150 lines of contraction code, the element routine must not read or write
LinearOp/NonlinearOpfields.Change
_linear_element!(Me, Ke, Fe, k, Val(E), vals, xs, ranges, p, t)(for bothLinearBlockandKernelSpec) and_nonlinear_element!(Je, re, u_elem, k, Val(E), vals, xs, ranges, p, t)take the element buffers and element state as arguments. These can be arrays or views.Je = nothingassembles the residual only._kernel!is now a one-line adapter that passes the op's existing buffers. Volume and facet terms both go through it, so the driver,_start_cell!/_finish_cell!and the op structs are unchanged.Tests
test/Assembly/element.jluses two coupled fields with cross-diffusion and a nonlinear reaction, on both thecoeffs(LinearBlock) path and thefpath.assemble_linearandassemble_nonlinearexactly (==). This holds with one worker and with three workers using views intozeros(ne, ne, nw)slabs, for both the Jacobian and the residual-only path.@allocated == 0.Performance
benchmarks/assembly_cost.jlcases, 100×100 P1, BenchmarkTools medians of fresh single-process runs alternating master and branch.Allocations per pass are identical: 129, 268 and 180. Fresh-process noise on this machine is about ±7%. The generated code of the hot nonlinear routine matches master's apart from where three buffer loads happen: same calls, no boxing or dynamic dispatch, and
Je === nothingfolds away. Marking the element routines@inlinemade no measurable difference (median 3.081 ms), so this PR does not add it.This PR merges cleanly with #71 (element-type-generic operators), which also touches
src/assembly.jl.🤖 Posted by an AI agent · harness: Claude Code 2.1.318 · model: claude-opus-5-5
Review: unreviewed
Session: f7b46bdf-7cc3-44dd-b8a4-9205616ff6ac