Repository navigation
Add KernelAbstractions extension: device kernel preparation - #70
Merged
Merged
Conversation
FiniteElementMethodKAExt (triggers KernelAbstractions, Adapt, GPUArrays, GPUArraysCore) prepares an emitted kernel Expr for a device: Float64 and Rational literals are retyped to the working precision, NaNMath.pow becomes a FEM-owned nanpow, library ccalls such as NaNMath.lgamma are refused, and the function is built in FEM's RuntimeGeneratedFunctions cache with drop_expr so it is isbits. Core gains only the device_kernel stub, which names the packages to load when the extension is absent. 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>
Kernels of real PDESystems go through the device pass and a KernelAbstractions kernel on KA.CPU() and JLArrays, and must match the host Float64 kernels (Float32 within 1e-6). test/GPU/vendor/amdgpu runs the same files on ROCBackend by hand, including a Dict-allocating registered function whose compile failure must name it. 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.
Targets the long-lived feature branch
gpu/ka. It merges to master only after a Ferrite release contains Ferrite-FEM/Ferrite.jl#1496.This is the first layer of GPU support: preparing FEM's generated kernels so they can run inside a KernelAbstractions kernel. There is no device assembly yet; that comes in a later PR.
What changes
FiniteElementMethodKAExt. There is no version bump and no other compat change.Exprfromemit_kernels(...; expression = Val(true))and prepares it for precisionT:T. The kernel's own time argument, which is namedT, is never touched.NaNMath.powis rewritten to an FEM-ownednanpow, a copy of the NaNMath 1.1.5 pure-Julia body. It gives NaN for a negative base with a non-integer exponent instead of throwing. Integer powers throughBase.literal_poware left as they are.NaNMath.lgamma, eight verified ccall-backed SpecialFunctions names, closures and ccalls are refused with anArgumentErrorwhen the kernel is prepared.RuntimeGeneratedFunction(FEM, FEM, ex), the cache Symbolics uses, and thendrop_expr. The result is asserted to be isbits.foreign_calleesandlaunch_checkedturn a compile failure in a user-registered function into an error that names the function.device_kernel(ex, T). Without the extension it says which packages to load.Tests
New opt-in group
GPU(in_all = false) on Julia 1 only, with its owntest/GPU/Project.tomlthat develops FEM through[sources].The kernels come from real PDESystems: heat with a parameter and a Neumann facet kernel, SUPG with
CellCoeffs, nonlinearfandtangent,NaNMath.powwith constant and symbolic exponents, time-dependent Dirichlet data, and a registered function.devicepass.jl(host, 169 tests):NaNMath.pow.LinearBlockof prepared kernels; aKernelSpecis not.nanpowmatches NaNMath, while^throws aDomainErroron the host.lgamma, closures and ccalls are refused.backends.jl(113 tests): every kernel inside a@kernelonKernelAbstractions.CPU()and on JLArrays matches the host Float64 kernel, in Float32 and Float64. A small check shows thatGenericSparseMatrixCSCwith JLArray storage works.The repository requires an end-to-end test for every code path. For this layer that test is: real
PDESystem, then the emitted kernels, then the device pass, then a KernelAbstractions kernel whose result equals the host kernel. End-to-end tests throughdiscretizearrive with device assembly.JLArrays and KA.CPU test host discipline only, as
test/GPU/README.mdexplains. A kernel that would not compile for a GPU passes on both.Other groups: GPU 169/169 and 113/113, QA 21/21, Kernels 346/346. Runic 1.13 is clean on every touched file.
AMDGPU (by hand:
test/GPU/vendor/amdgpu)Tested on Radeon 8060S (gfx1151). Julia 1.12.1, AMDGPU.jl 2.8.0, KernelAbstractions 0.9.45, HIP 7.2.53211. The memory pool is capped at a 6 GiB soft and 8 GiB hard limit.
Dictfails withArgumentError: a generated kernel failed to compile for ROCBackend; it calls the user functions Main.badf, which must be GPU-compilable (no allocation, Dict, String or ccall). Original error: InvalidIRError: ...CUDA, oneAPI and Metal are untested.
Known limitations
test/GPU/common/cases.jlcopies the start ofFEM._lowerand calls internals, so it can drift if_lowerchanges. End-to-end tests throughdiscretizewill remove that risk. Its DirichletExprs copy the body ofemit_dirichlet, which Add expression keyword to emit_dirichlet #69 replaces with anexpressionkeyword.launch_checkedattributes any first-launch error to the listed user functions; the original error is kept in the message.Int. The device driver converts values when it stores them.🤖 Posted by an AI agent · harness: Claude Code 2.1.318 · model: claude-opus-5-5
Review: unreviewed
Session: f7b46bdf-7cc3-44dd-b8a4-9205616ff6ac