Repository navigation
Assemble the linear operators on a KernelAbstractions device - #73
Merged
Merged
Conversation
…embly 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>
…mbly 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>
…embly 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>
Device assembly is chosen on the discretization like every other option (design D1): backend = nothing keeps the host path unchanged, the keywords are validated at construction and never forwarded to the problem, and the core holds only stubs whose error says what to load. discretize refuses the features device assembly does not cover yet before assembling anything. 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>
FiniteElementMethodKAExt builds a DeviceAssemblyContext from the host AssemblyContext (DofHandler adapted with the host numbering, per-field CellValues and CellCaches distributed to workers, element buffers as slabs of 3D device arrays) and scatters each SubDofHandler with one launch per color, or one atomic launch, calling the host driver's element routine. The device matrices share the host pattern, so only the values are copied back into the Float64 operators; Dirichlet rows are then replaced on the host as before. The AMDGPU extension maps ROCBackend to ROCSparseMatrixCSC; GenericSparseArrays serves backends without a sparse library (JLArrays). The GPU environments take Ferrite from the PR #1496 branch. 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>
Agent-Harness: Claude Code 2.1.319 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>
xtalax-droid
marked this pull request as ready for review
November 6, 2026 16:38
Agent-Harness: Claude Code 2.1.319 Agent-Model: claude-sonnet-5-5 Agent-Session: 43e03fde-3384-4386-bae9-03e81f19ba7c 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.
Targets the long-lived feature branch
gpu/ka. Nothing here merges to master until a Ferrite release contains Ferrite-FEM/Ferrite.jl#1496.Builds on #70 (device kernel preparation, merged into
gpu/ka) and on #69, #71 and #72 (merged to master, and merged intogpu/ka). The diff shows only the device-assembly layer.What
FEMDiscretization(Ω, t; backend, precision, assembly)assembles the mass matrixM, the stiffness matrixKand the constant loadFon a KernelAbstractions backend.discretize(andNonlinearProblem) then returns the same hostDAEProblemwithFloat64SparseMatrixCSCoperators, so the solve paths are untouched. The defaultbackend = nothingis today's host path.Core: the
backend,precision(Float32/Float64, defaultFloat64) andassembly(:colored, the deterministic default, or:atomic) keywords. They are validated at construction and never forwarded to the problem. The core holds only stubs, whose error says what to load when the extension is missing.precisionwithoutbackendis an error.FiniteElementMethodKAExt: a
DeviceAssemblyContextbuilt from the hostAssemblyContext:CellValuesandCellCaches distributed to workers;Each SubDofHandler is scattered with one
@kernellaunch per color, or one atomic launch. The kernel calls the same element routine as the host driver (_linear_element!from Separate the per-cell element routines from the op structs #72), with kernels prepared bydevice_kernelfrom Add KernelAbstractions extension: device kernel preparation #70 and taken from the host functions, so there is no second codegen pass. The device matrices share the host sparsity pattern, so only their values are copied back. Dirichlet rows are replaced on the host as before. The extension also checks that Ferrite'sFerriteKAExtis loaded.FiniteElementMethodAMDGPUExt: maps
ROCBackendtoROCSparseMatrixCSC.FiniteElementMethodGenericSparseArraysExt: maps other GPU backends, such as JLArrays, to
GenericSparseMatrixCSC.Not supported on the device yet, each raising an
ArgumentErrorthat names it: facet terms (Neumann and Robin conditions), nonlinear terms, sources that depend on time, SUPG, anddirichlet = :eliminate.Documentation says "assembly runs on the device" and makes no speedup claim. Support status: KA.CPU and JLArrays are tested in CI, AMDGPU is tested on a Radeon 8060S (gfx1151), and CUDA, oneAPI and Metal are untested.
Tests
test/GPU/assembly.jl, throughdiscretizeon KA.CPU and JLArrays, covers three problems:Each runs with constant and time-dependent Dirichlet data, in Float32 and Float64, with colored and atomic assembly. Two checks per run:
sol(t, x...)equals the host solution.It also checks that colored assembly is deterministic, and that a steady problem solves.
test/GPU/extension.jlchecks that both extensions load, the keyword validation, the error for a Ferrite without GPU support, and the out-of-scope errors.test/Frontend/backend.jlchecks the error text when the extension is absent.Results: GPU group 557/557, QA 21/21, Perf 28/28, Assembly 136/136, Frontend 778/778. The docs build cleanly.
CI: since
gpu/kadcb0e17 the PR workflows (Tests, Downgrade, Benchmarks) run for every base branch, so this PR now gets the full test matrix. Local evidence before that: GPU group 557/557 at head 2aee507 (after merginggpu/ka, which contains current master), and QA, Perf, Assembly and Frontend as listed above.AMDGPU (by hand, Radeon 8060S gfx1151, ROCm/HIP 7.2, AMDGPU.jl 2.8.0, KA 0.9.45, Julia 1.12.1, Ferrite
do/gpu-cia8db9b1a): 59/59 kernel tests and 131/131 device-assembly tests. Largest relative errors against the host Float64 assembly:Timing (report only, no claim)
3D P1 hexahedron heat problem on Radeon 8060S, run alone. Device columns are Float32 and include the copy back to the host. The host column is the existing serial Float64 path; there is no Float32 host path to compare with. Best of 5 runs.
M and K are assembled once per problem, so this does not change end-to-end solve time materially.
Known limitations
distribute_to_workers,start_assemble(...; atomic), the deviceCellCache, and the assembler's adapt rules.Merge gate
The package keeps
Ferrite = "1.7".test/GPUandtest/GPU/vendor/amdgputake Ferrite fromdo/gpu-cithrough[sources].🤖 Posted by an AI agent · harness: Claude Code 2.1.318 · model: claude-opus-5-5
Review: unreviewed
Session: f7b46bdf-7cc3-44dd-b8a4-9205616ff6ac