From 7b5ca4b0f4bc68661a48477ee46901800651a582 Mon Sep 17 00:00:00 2001 From: t Date: Thu, 5 Nov 2026 22:39:05 +0000 Subject: [PATCH 1/4] Add a cuDSS GPU solver for Maxwell frequency sweeps CuDSSSolver() is a solve_sweep solver that factorises the sweep operator on an NVIDIA GPU through the FiniteElementMethodCUDSSExt extension (using CUDA, CUDSS). The first frequency uploads A in CSR layout and runs analysis and factorisation; later frequencies gather the new values through a CSR permutation computed once on the host, copy only nzval to the device and refactorise. All port columns are solved in one call. The host-side CSR layout and value update are tested on the CPU in the Maxwell group; a new opt-in GPU group checks that the extension loads and infers (JET) and compares the GPU sweep with UMFPACK only when CUDA is functional. CUDSS compat is 0.8, 1 because ArrayInterface and LinearSolve cap CUDSS below 1 today. Agent-Harness: Claude Code 2.1.318 Agent-Model: claude-opus-5-5 Agent-Session: ee6a670e-e4ec-446c-b941-3ebb999c45c5 Agent-Review: unreviewed Co-authored-by: Claude Code --- Project.toml | 5 +++ docs/src/maxwell.md | 23 +++++++++++ ext/FiniteElementMethodCUDSSExt.jl | 40 +++++++++++++++++++ src/FiniteElementMethod.jl | 3 +- src/maxwell/cudss.jl | 63 ++++++++++++++++++++++++++++++ test/GPU/Project.toml | 20 ++++++++++ test/GPU/cudss.jl | 45 +++++++++++++++++++++ test/Maxwell/cudss.jl | 56 ++++++++++++++++++++++++++ test/Maxwell/ports.jl | 19 +-------- test/shared/wr90.jl | 22 +++++++++++ test/test_groups.toml | 7 ++++ 11 files changed, 284 insertions(+), 19 deletions(-) create mode 100644 ext/FiniteElementMethodCUDSSExt.jl create mode 100644 src/maxwell/cudss.jl create mode 100644 test/GPU/Project.toml create mode 100644 test/GPU/cudss.jl create mode 100644 test/Maxwell/cudss.jl create mode 100644 test/shared/wr90.jl diff --git a/Project.toml b/Project.toml index fc7c0189..0508d4d3 100644 --- a/Project.toml +++ b/Project.toml @@ -21,14 +21,19 @@ SymbolicUtils = "d1185830-fcd6-423d-90d6-eec64667417b" Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7" [weakdeps] +CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba" +CUDSS = "45b445bb-4962-46a0-9369-b4df9d0f772e" FerriteGmsh = "4f95f4f8-b27c-4ae5-9a39-ea55e634e36b" [extensions] +FiniteElementMethodCUDSSExt = ["CUDA", "CUDSS"] FiniteElementMethodFerriteGmshExt = "FerriteGmsh" [compat] ADTypes = "1.24" AllocCheck = "0.2" +CUDA = "6" +CUDSS = "0.8, 1" DiffEqBase = "7.21" DomainSets = "0.7, 0.8" Ferrite = "1.7" diff --git a/docs/src/maxwell.md b/docs/src/maxwell.md index b20c3ebb..2aa01505 100644 --- a/docs/src/maxwell.md +++ b/docs/src/maxwell.md @@ -55,6 +55,28 @@ sweep.S[2, 1, 5] # S21 at 10 GHz: |S21| ≈ 1, angle ≈ -93.3° are normalised to power waves through the TE10 wave impedance `ωμ0μr/β`. Below cutoff the propagation constant is `β = -iα`, the evanescent branch. +### Solving on an NVIDIA GPU + +`solver = CuDSSSolver()` moves the factorisation and solves of [`solve_sweep`](@ref) to an NVIDIA GPU through +[cuDSS](https://developer.nvidia.com/cudss); it needs `using CUDA, CUDSS` and a functional CUDA device. +Assembly stays on the CPU. The first frequency uploads the operator and runs the cuDSS analysis and +factorisation; later frequencies copy only the new nonzero values and refactorise, reusing the analysis, and +every port excitation is solved in one call. + +```julia +using CUDA, CUDSS +sweep = solve_sweep(model, 2π .* (8.0e9:0.5e9:12.0e9); solver = CuDSSSolver()) +``` + +The default is cuDSS's general LU (`structure = "G"`). `CuDSSSolver(; structure = "S")` uses its complex +symmetric LDLᵀ instead (the Maxwell operator is complex symmetric, not Hermitian), with about half the factor +storage; CUDSS.jl documents complex symmetric matrices from its version 1.0, so use it with CUDSS.jl 1. Both +CUDSS.jl 0.8 and 1 are accepted for the default. + +The CPU side of this solver (the CSR layout and the per-frequency value update) is tested in the Maxwell test +group, and the `GPU` group checks that the extension loads and infers. The comparison of the GPU sweep with +UMFPACK on a WR-90 guide runs only where `CUDA.functional()` holds, so only on a CUDA machine. + ```@docs MaxwellModel MaxwellMaterial @@ -72,6 +94,7 @@ FiniteElementMethod.WavePortData solve_sweep MaxwellSweep FiniteElementMethod.umfpack_solver +CuDSSSolver FiniteElementMethod.tangential_mass FiniteElementMethod.port_excitations FiniteElementMethod.s_parameters diff --git a/ext/FiniteElementMethodCUDSSExt.jl b/ext/FiniteElementMethodCUDSSExt.jl new file mode 100644 index 00000000..39d80f53 --- /dev/null +++ b/ext/FiniteElementMethodCUDSSExt.jl @@ -0,0 +1,40 @@ +module FiniteElementMethodCUDSSExt + +using FiniteElementMethod: CuDSSSolver, csr_layout, csr_values! +using CUDA: CuMatrix, CuVector, cuSPARSE +using CUDSS: CudssSolver, cudss, cudss_update +using SparseArrays: SparseMatrixCSC, nonzeros + +const CudssFloat = Union{Float32, Float64, ComplexF32, ComplexF64} + +# What a CuDSSSolver keeps between frequencies: the host CSR value buffer and its gather permutation, the +# device matrix (whose value array cuDSS reads in place) and the cuDSS analysis and factors. +struct CuDSSCache{T, S} + perm::Vector{Int} + vals::Vector{T} + dA::cuSPARSE.CuSparseMatrixCSR{T, Int32} + solver::S +end + +function (s::CuDSSSolver)(A::SparseMatrixCSC{T}, B::AbstractMatrix{T}, cache) where {T <: CudssFloat} + dB = CuMatrix{T}(B) + dX = similar(dB) + if cache === nothing + rowptr, colval, perm = csr_layout(A) + vals = nonzeros(A)[perm] + dA = cuSPARSE.CuSparseMatrixCSR{T, Int32}(CuVector(rowptr), CuVector(colval), CuVector(vals), size(A)) + solver = CudssSolver(dA, s.structure, 'F') + cudss("analysis", solver, dX, dB) + cudss("factorization", solver, dX, dB) + cache = CuDSSCache(perm, vals, dA, solver) + else + csr_values!(cache.vals, A, cache.perm) + copyto!(cache.dA.nzVal, cache.vals) + cudss_update(cache.solver, cache.dA) + cudss("refactorization", cache.solver, dX, dB) + end + cudss("solve", cache.solver, dX, dB; asynchronous = false) + return Array(dX), cache +end + +end # module diff --git a/src/FiniteElementMethod.jl b/src/FiniteElementMethod.jl index 9926afc6..003f084b 100644 --- a/src/FiniteElementMethod.jl +++ b/src/FiniteElementMethod.jl @@ -54,9 +54,10 @@ include("maxwell/ports.jl") include("maxwell/model.jl") include("maxwell/driven.jl") include("maxwell/sweep.jl") +include("maxwell/cudss.jl") export MaxwellMaterial, MaxwellModel, MaxwellTerm, maxwell_operator, maxwell_operator! export MaxwellSolution, driven_problem, solve_driven, field_values -export WavePort, MaxwellSweep, solve_sweep +export WavePort, MaxwellSweep, solve_sweep, CuDSSSolver include("precompile.jl") diff --git a/src/maxwell/cudss.jl b/src/maxwell/cudss.jl new file mode 100644 index 00000000..a8b0edbc --- /dev/null +++ b/src/maxwell/cudss.jl @@ -0,0 +1,63 @@ +# The cuDSS sparse direct solver of `solve_sweep`, implemented by the FiniteElementMethodCUDSSExt extension. The +# host-side pieces (the CSR layout of a CSC matrix and the per-frequency value gather) live here so that they are +# testable without a GPU. + +""" + CuDSSSolver(; structure = "G") + +A [`solve_sweep`](@ref) solver that factorises `A` on an NVIDIA GPU with cuDSS: `solve_sweep(model, omegas; +solver = CuDSSSolver())`. It needs `using CUDA, CUDSS` (the FiniteElementMethodCUDSSExt extension) and a +functional CUDA device. + +Assembly stays on the CPU. The first frequency uploads `A` in CSR layout and runs the cuDSS analysis +(reordering and symbolic factorisation) and the numerical factorisation; every later frequency copies only the +new nonzero values to the device and refactorises. All port excitations (the columns of `B`) are solved at once +on the device and returned to the host. + +`structure = "G"` (the default) is cuDSS's general LDU factorisation. `structure = "S"` is its symmetric LDLᵀ, +which for complex values treats `A` as complex symmetric (`transpose(A) == A`, true of the Maxwell operator); +it halves the factor storage but is documented for complex values only from CUDSS.jl 1.0 (cuDSS 1.0). +""" +struct CuDSSSolver + structure::String + function CuDSSSolver(; structure::AbstractString = "G") + structure in ("G", "S") || + throw(ArgumentError("CuDSSSolver structure must be \"G\" or \"S\", got \"$structure\"")) + return new(String(structure)) + end +end + +function (::CuDSSSolver)(A, B, cache) + loaded = Base.get_extension(@__MODULE__, :FiniteElementMethodCUDSSExt) !== nothing + msg = loaded ? + "CuDSSSolver solves a SparseMatrixCSC with Float32, Float64, ComplexF32 or ComplexF64 values and a dense right-hand side of the same element type; got $(typeof(A)) and $(typeof(B))" : + "CuDSSSolver needs the CUDA and CUDSS packages: run `using CUDA, CUDSS` first" + throw(ArgumentError(msg)) +end + +""" + csr_layout(A::SparseMatrixCSC) -> (rowptr, colval, perm) + +The compressed-sparse-row arrays of `A` with `Int32` indices (1-based, as cuSPARSE's `CuSparseMatrixCSR` stores +them) and the permutation with `A.nzval[perm]` the values in that row order. The pattern of the sweep operator +never changes, so `perm` is computed once and every later frequency only gathers its values. +""" +function csr_layout(A::SparseMatrixCSC) + nnz(A) < typemax(Int32) || + throw(ArgumentError("CuDSSSolver uses Int32 indices; the matrix has $(nnz(A)) stored entries")) + positions = SparseMatrixCSC(size(A)..., A.colptr, A.rowval, collect(1:nnz(A))) + byrow = copy(transpose(positions)) + return Int32.(byrow.colptr), Int32.(byrow.rowval), byrow.nzval +end + +""" + csr_values!(vals, A::SparseMatrixCSC, perm) + +Overwrite `vals` with the nonzero values of `A` in the row order of [`csr_layout`](@ref). +""" +function csr_values!(vals, A::SparseMatrixCSC, perm) + length(perm) == nnz(A) || + throw(DimensionMismatch("the sparsity pattern changed: $(nnz(A)) stored entries, $(length(perm)) expected")) + vals .= view(nonzeros(A), perm) + return vals +end diff --git a/test/GPU/Project.toml b/test/GPU/Project.toml new file mode 100644 index 00000000..ff510f81 --- /dev/null +++ b/test/GPU/Project.toml @@ -0,0 +1,20 @@ +[deps] +CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba" +CUDSS = "45b445bb-4962-46a0-9369-b4df9d0f772e" +Ferrite = "c061ca5d-56c9-439f-9c0e-210fe06d3992" +FiniteElementMethod = "e08948db-0ae8-498a-9b98-73fc7f237ce3" +JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b" +LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" +SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f" +SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[compat] +CUDA = "6" +CUDSS = "0.8, 1" +Ferrite = "1.7" +JET = "0.9, 0.10, 0.11, 0.12" +LinearAlgebra = "1.10" +SafeTestsets = "0.1" +SparseArrays = "1.10" +Test = "1" diff --git a/test/GPU/cudss.jl b/test/GPU/cudss.jl new file mode 100644 index 00000000..e1c387d3 --- /dev/null +++ b/test/GPU/cudss.jl @@ -0,0 +1,45 @@ +# The cuDSS sweep solver against UMFPACK on the WR-90 sweep. Without a functional CUDA device only the +# extension's loading and inference are checked. +using FiniteElementMethod, Ferrite, SparseArrays, LinearAlgebra, Test +using CUDA, CUDSS, JET + +include(joinpath(@__DIR__, "..", "shared", "wr90.jl")) + +const EXT = Base.get_extension(FiniteElementMethod, :FiniteElementMethodCUDSSExt) + +@testset "extension loads and infers" begin + @test EXT !== nothing + model = wr90(5.0, 20.0) + A = maxwell_operator(model, F10) + B = FiniteElementMethod.port_excitations(model, F10) + solver = CuDSSSolver() + @test_opt target_modules = (EXT,) solver(A, B, nothing) + @test_call target_modules = (EXT,) solver(A, B, nothing) + Cache = EXT.CuDSSCache{ComplexF64, CUDSS.CudssSolver{ComplexF64, Int32}} + @test only(Base.return_types(solver, (typeof(A), typeof(B), Nothing))) == Tuple{Matrix{ComplexF64}, Cache} + @test only(Base.return_types(solver, (typeof(A), typeof(B), Cache))) == Tuple{Matrix{ComplexF64}, Cache} + @test_throws "SparseMatrixCSC" solver(Matrix(A), B, nothing) # dense A is not for cuDSS +end + +# The complex symmetric LDLᵀ is documented from CUDSS.jl 1.0 on. +const STRUCTURES = pkgversion(CUDSS) >= v"1" ? ["G", "S"] : ["G"] + +if CUDA.functional() + @testset "cuDSS sweep equals UMFPACK ($structure)" for structure in STRUCTURES + model = wr90(3.0, 30.0) + ωs = 2π .* [9.0e9, 10.0e9, 11.0e9] + cpu = solve_sweep(model, ωs; fields = true) + calls = Ref(0) + cudss_solver = CuDSSSolver(; structure) + counting(A, B, cache) = (calls[] += 1; cudss_solver(A, B, cache)) + gpu = solve_sweep(model, ωs; fields = true, solver = counting) + @test calls[] == length(ωs) + @test gpu.S ≈ cpu.S rtol = 1.0e-8 + for k in eachindex(ωs) + @test gpu.fields[k] ≈ cpu.fields[k] rtol = 1.0e-8 + end + end +else + @info "CUDA is not functional here; the cuDSS solve against UMFPACK is skipped" + @test_skip "cuDSS sweep equals UMFPACK" +end diff --git a/test/Maxwell/cudss.jl b/test/Maxwell/cudss.jl new file mode 100644 index 00000000..838bce01 --- /dev/null +++ b/test/Maxwell/cudss.jl @@ -0,0 +1,56 @@ +# The device-independent pieces of the cuDSS sweep solver: the CSR layout of the sweep operator, the +# per-frequency value gather, and the error without the extension. The GPU solve itself is in test/GPU. +using FiniteElementMethod, Ferrite, SparseArrays, LinearAlgebra, Test +using FiniteElementMethod: csr_layout, csr_values! + +include(joinpath(@__DIR__, "..", "shared", "wr90.jl")) + +# The CSR arrays of `A` (rows of the transpose's columns), built independently of csr_layout. +function reference_csr(A) + rowptr = ones(Int, size(A, 1) + 1) + colval, vals = Int[], eltype(A)[] + for i in 1:size(A, 1) + for j in 1:size(A, 2) + if any(==(i), rowvals(A)[nzrange(A, j)]) + push!(colval, j) + push!(vals, A[i, j]) + end + end + rowptr[i + 1] = length(colval) + 1 + end + return rowptr, colval, vals +end + +@testset "CSR layout of a nonsymmetric matrix with stored zeros" begin + A = sparse([1, 3, 2, 1, 3, 2], [1, 1, 2, 3, 3, 3], ComplexF64[1 + 2im, 3, 0, 4im, 5, 6], 3, 3) + rowptr, colval, perm = csr_layout(A) + @test rowptr isa Vector{Int32} && colval isa Vector{Int32} + ref_rowptr, ref_colval, ref_vals = reference_csr(A) + @test rowptr == ref_rowptr && colval == ref_colval + @test nonzeros(A)[perm] == ref_vals + @test length(colval) == nnz(A) # the stored zero A[2, 2] stays in the pattern + vals = similar(nonzeros(A)) + A.nzval .*= 2im + @test csr_values!(vals, A, perm) == 2im .* ref_vals + @test_throws DimensionMismatch csr_values!(vals, sparse(A[1:2, 1:2]), perm) +end + +@testset "CSR layout of the WR-90 sweep operator" begin + model = wr90(5.0, 20.0) + A = maxwell_operator(model, F10) + Ferrite.apply!(A, model.ch) + rowptr, colval, perm = csr_layout(A) + csr = SparseMatrixCSC(size(A)..., Int.(rowptr), Int.(colval), nonzeros(A)[perm]) # CSC of transpose(A) + @test transpose(csr) == A + vals = similar(nonzeros(A)) + maxwell_operator!(A, model, 1.1 * F10) # a new frequency, the same pattern + Ferrite.apply!(A, model.ch) + @test transpose(SparseMatrixCSC(size(A)..., Int.(rowptr), Int.(colval), csr_values!(vals, A, perm))) == A +end + +@testset "CuDSSSolver without CUDA" begin + @test CuDSSSolver().structure == "G" + @test CuDSSSolver(; structure = "S").structure == "S" + @test_throws "must be \"G\" or \"S\"" CuDSSSolver(; structure = "H") + @test_throws "using CUDA, CUDSS" solve_sweep(wr90(5.0, 20.0), [F10]; solver = CuDSSSolver()) +end diff --git a/test/Maxwell/ports.jl b/test/Maxwell/ports.jl index 458f5e38..bf4ae63d 100644 --- a/test/Maxwell/ports.jl +++ b/test/Maxwell/ports.jl @@ -2,24 +2,7 @@ # against closed forms (exp(+iωt), ports at z = 0 and z = L, broad wall along x). using FiniteElementMethod, Ferrite, SparseArrays, LinearAlgebra, Test -const WR90_A, WR90_B = 22.86, 10.16 # mm -const F10 = 2π * 10.0e9 -const BETA10 = 158.2383 # rad/m, TE10 at 10 GHz -const K010 = F10 / FiniteElementMethod.C0 - -# A WR-90 section of length `len` mm with cells of about `h` mm; the bottom face z = 0 is a wave port, the top -# face a wave port too unless `top` names another termination. -function wr90(h, len; top = :port, kwargs...) - n = ceil.(Int, (WR90_A, WR90_B, len) ./ h) - grid = generate_grid(Tetrahedron, Tuple(n), Vec(0.0, 0.0, 0.0), Vec(WR90_A, WR90_B, float(len))) - walls = ["left", "right", "front", "back"] - ports = [WavePort("bottom"; a_direction = (1, 0, 0), kwargs...)] - top === :port && push!(ports, WavePort("top"; a_direction = (1, 0, 0), kwargs...)) - return MaxwellModel( - grid; pec = top === :pec ? [walls; "top"] : walls, absorbing = top === :abc ? ["top"] : String[], - ports, length_scale = 1.0e-3, - ) -end +include(joinpath(@__DIR__, "..", "shared", "wr90.jl")) phase_deg(z) = rad2deg(angle(z)) wrap_deg(x) = mod(x + 180, 360) - 180 diff --git a/test/shared/wr90.jl b/test/shared/wr90.jl new file mode 100644 index 00000000..150af2cc --- /dev/null +++ b/test/shared/wr90.jl @@ -0,0 +1,22 @@ +# The WR-90 waveguide model shared by the Maxwell and GPU groups (exp(+iωt), ports at z = 0 and z = L, +# broad wall along x). +using FiniteElementMethod, Ferrite + +const WR90_A, WR90_B = 22.86, 10.16 # mm +const F10 = 2π * 10.0e9 +const BETA10 = 158.2383 # rad/m, TE10 at 10 GHz +const K010 = F10 / FiniteElementMethod.C0 + +# A WR-90 section of length `len` mm with cells of about `h` mm; the bottom face z = 0 is a wave port, the top +# face a wave port too unless `top` names another termination. +function wr90(h, len; top = :port, kwargs...) + n = ceil.(Int, (WR90_A, WR90_B, len) ./ h) + grid = generate_grid(Tetrahedron, Tuple(n), Vec(0.0, 0.0, 0.0), Vec(WR90_A, WR90_B, float(len))) + walls = ["left", "right", "front", "back"] + ports = [WavePort("bottom"; a_direction = (1, 0, 0), kwargs...)] + top === :port && push!(ports, WavePort("top"; a_direction = (1, 0, 0), kwargs...)) + return MaxwellModel( + grid; pec = top === :pec ? [walls; "top"] : walls, absorbing = top === :abc ? ["top"] : String[], + ports, length_scale = 1.0e-3, + ) +end diff --git a/test/test_groups.toml b/test/test_groups.toml index f96b0ec8..1dff1c1d 100644 --- a/test/test_groups.toml +++ b/test/test_groups.toml @@ -51,3 +51,10 @@ versions = ["lts", "1", "pre"] [Maxwell] versions = ["lts", "1", "pre"] + +# The cuDSS sweep solver: a CUDA sub-env on a self-hosted GPU runner. Without a functional CUDA device it only +# checks that the extension loads and infers; the GPU solve is skipped. +[GPU] +in_all = false +versions = ["1"] +runner = ["self-hosted", "Linux", "X64", "gpu"] From b53a9489a9b0c36a46cd9c879202052f2a83fa8d Mon Sep 17 00:00:00 2001 From: t Date: Thu, 5 Nov 2026 22:48:11 +0000 Subject: [PATCH 2/4] Rename the cuDSS test group to MaxwellGPU and run it by hand Another expansion owns test/GPU. The group declares no self-hosted runner: it stays out of All and CI, and test/MaxwellGPU/README.md documents the manual run on a CUDA machine (GROUP=MaxwellGPU julia --project=. -e 'using Pkg; Pkg.test()'). Agent-Harness: Claude Code 2.1.318 Agent-Model: claude-opus-5-5 Agent-Session: ee6a670e-e4ec-446c-b941-3ebb999c45c5 Agent-Review: unreviewed Co-authored-by: Claude Code --- docs/src/maxwell.md | 5 +++-- test/{GPU => MaxwellGPU}/Project.toml | 0 test/MaxwellGPU/README.md | 14 ++++++++++++++ test/{GPU => MaxwellGPU}/cudss.jl | 0 test/shared/wr90.jl | 2 +- test/test_groups.toml | 7 +++---- 6 files changed, 21 insertions(+), 7 deletions(-) rename test/{GPU => MaxwellGPU}/Project.toml (100%) create mode 100644 test/MaxwellGPU/README.md rename test/{GPU => MaxwellGPU}/cudss.jl (100%) diff --git a/docs/src/maxwell.md b/docs/src/maxwell.md index f5ecf1ea..f324462a 100644 --- a/docs/src/maxwell.md +++ b/docs/src/maxwell.md @@ -74,8 +74,9 @@ storage; CUDSS.jl documents complex symmetric matrices from its version 1.0, so CUDSS.jl 0.8 and 1 are accepted for the default. The CPU side of this solver (the CSR layout and the per-frequency value update) is tested in the Maxwell test -group, and the `GPU` group checks that the extension loads and infers. The comparison of the GPU sweep with -UMFPACK on a WR-90 guide runs only where `CUDA.functional()` holds, so only on a CUDA machine. +group, and the `MaxwellGPU` group checks that the extension loads and infers. The comparison of the GPU sweep with +UMFPACK on a WR-90 guide runs only where `CUDA.functional()` holds; CI has no NVIDIA GPU, so run it by hand on a +CUDA machine with `GROUP=MaxwellGPU julia --project=. -e 'using Pkg; Pkg.test()'`. ```@docs MaxwellModel diff --git a/test/GPU/Project.toml b/test/MaxwellGPU/Project.toml similarity index 100% rename from test/GPU/Project.toml rename to test/MaxwellGPU/Project.toml diff --git a/test/MaxwellGPU/README.md b/test/MaxwellGPU/README.md new file mode 100644 index 00000000..e0a4a66a --- /dev/null +++ b/test/MaxwellGPU/README.md @@ -0,0 +1,14 @@ +# MaxwellGPU + +Tests of `CuDSSSolver`, the cuDSS GPU solver of `solve_sweep` (the `FiniteElementMethodCUDSSExt` extension). The +group has its own environment (CUDA, CUDSS, JET) and is not part of `All` or of CI, which has no NVIDIA GPU. + +Run it by hand on a machine with an NVIDIA GPU and a working CUDA driver, from the repository root: + +```sh +GROUP=MaxwellGPU julia --project=. -e 'using Pkg; Pkg.test()' +``` + +Without a functional CUDA device (`CUDA.functional() == false`) the group only checks that the extension loads +and infers (JET), and the WR-90 sweep against UMFPACK is reported as skipped (one `Broken` test). On a CUDA +machine that comparison runs for `structure = "G"`, and also for `"S"` with CUDSS.jl 1.x. diff --git a/test/GPU/cudss.jl b/test/MaxwellGPU/cudss.jl similarity index 100% rename from test/GPU/cudss.jl rename to test/MaxwellGPU/cudss.jl diff --git a/test/shared/wr90.jl b/test/shared/wr90.jl index 150af2cc..b51ccd53 100644 --- a/test/shared/wr90.jl +++ b/test/shared/wr90.jl @@ -1,4 +1,4 @@ -# The WR-90 waveguide model shared by the Maxwell and GPU groups (exp(+iωt), ports at z = 0 and z = L, +# The WR-90 waveguide model shared by the Maxwell and MaxwellGPU groups (exp(+iωt), ports at z = 0 and z = L, # broad wall along x). using FiniteElementMethod, Ferrite diff --git a/test/test_groups.toml b/test/test_groups.toml index 1dff1c1d..54f12fc2 100644 --- a/test/test_groups.toml +++ b/test/test_groups.toml @@ -52,9 +52,8 @@ versions = ["lts", "1", "pre"] [Maxwell] versions = ["lts", "1", "pre"] -# The cuDSS sweep solver: a CUDA sub-env on a self-hosted GPU runner. Without a functional CUDA device it only -# checks that the extension loads and infers; the GPU solve is skipped. -[GPU] +# The cuDSS sweep solver: a CUDA sub-env, run by hand on a CUDA machine (see test/MaxwellGPU/README.md). Without a +# functional CUDA device it only checks that the extension loads and infers; the GPU solve is skipped. +[MaxwellGPU] in_all = false versions = ["1"] -runner = ["self-hosted", "Linux", "X64", "gpu"] From ca9927dfbeb05120e4d4e3309ca71eee9a419367 Mon Sep 17 00:00:00 2001 From: t Date: Thu, 5 Nov 2026 23:59:20 +0000 Subject: [PATCH 3/4] Turn the csr_layout and csr_values! docstrings into comments Both are internal host-side helpers of the cuDSS solver, so Documenter's checkdocs = :all failed the docs build with :missing_docs because neither is in the manual. Internal helpers carry a plain comment instead. Agent-Harness: Claude Code 2.1.318 Agent-Model: claude-opus-5-5 Agent-Session: ee6a670e-e4ec-446c-b941-3ebb999c45c5 Agent-Review: unreviewed Co-authored-by: Claude Code --- src/maxwell/cudss.jl | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/maxwell/cudss.jl b/src/maxwell/cudss.jl index a8b0edbc..e559c540 100644 --- a/src/maxwell/cudss.jl +++ b/src/maxwell/cudss.jl @@ -35,13 +35,11 @@ function (::CuDSSSolver)(A, B, cache) throw(ArgumentError(msg)) end -""" - csr_layout(A::SparseMatrixCSC) -> (rowptr, colval, perm) - -The compressed-sparse-row arrays of `A` with `Int32` indices (1-based, as cuSPARSE's `CuSparseMatrixCSR` stores -them) and the permutation with `A.nzval[perm]` the values in that row order. The pattern of the sweep operator -never changes, so `perm` is computed once and every later frequency only gathers its values. -""" +# csr_layout(A::SparseMatrixCSC) -> (rowptr, colval, perm) +# +# The compressed-sparse-row arrays of `A` with `Int32` indices (1-based, as cuSPARSE's `CuSparseMatrixCSR` stores +# them) and the permutation with `A.nzval[perm]` the values in that row order. The pattern of the sweep operator +# never changes, so `perm` is computed once and every later frequency only gathers its values. function csr_layout(A::SparseMatrixCSC) nnz(A) < typemax(Int32) || throw(ArgumentError("CuDSSSolver uses Int32 indices; the matrix has $(nnz(A)) stored entries")) @@ -50,11 +48,9 @@ function csr_layout(A::SparseMatrixCSC) return Int32.(byrow.colptr), Int32.(byrow.rowval), byrow.nzval end -""" - csr_values!(vals, A::SparseMatrixCSC, perm) - -Overwrite `vals` with the nonzero values of `A` in the row order of [`csr_layout`](@ref). -""" +# csr_values!(vals, A::SparseMatrixCSC, perm) +# +# Overwrite `vals` with the nonzero values of `A` in the row order of `csr_layout`. function csr_values!(vals, A::SparseMatrixCSC, perm) length(perm) == nnz(A) || throw(DimensionMismatch("the sparsity pattern changed: $(nnz(A)) stored entries, $(length(perm)) expected")) From 26a2a3a7c4e50f94aae06a0206aa5e2799ef515a Mon Sep 17 00:00:00 2001 From: t Date: Wed, 11 Nov 2026 23:00:44 +0000 Subject: [PATCH 4/4] Document the cuDSS version that resolves CUDSS.jl 1.0 cannot be installed alongside DiffEqBase (ArrayInterface bounds), so the docs point to 0.8 and the general LU; the test gate already skips the symmetric structure there. Agent-Harness: Claude Code 2.1.322 Agent-Model: claude-sonnet-5-5 Agent-Session: 43e03fde-3384-4386-bae9-03e81f19ba7c Agent-Review: unreviewed Co-authored-by: Claude Code --- docs/src/maxwell.md | 5 +++-- test/MaxwellGPU/cudss.jl | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/src/maxwell.md b/docs/src/maxwell.md index f324462a..121a6ece 100644 --- a/docs/src/maxwell.md +++ b/docs/src/maxwell.md @@ -70,8 +70,9 @@ sweep = solve_sweep(model, 2π .* (8.0e9:0.5e9:12.0e9); solver = CuDSSSolver()) The default is cuDSS's general LU (`structure = "G"`). `CuDSSSolver(; structure = "S")` uses its complex symmetric LDLᵀ instead (the Maxwell operator is complex symmetric, not Hermitian), with about half the factor -storage; CUDSS.jl documents complex symmetric matrices from its version 1.0, so use it with CUDSS.jl 1. Both -CUDSS.jl 0.8 and 1 are accepted for the default. +storage; CUDSS.jl documents complex symmetric matrices only from its version 1.0. CUDSS.jl 1.0 currently cannot be +installed next to this package (its ArrayInterface bound conflicts with the one of DiffEqBase), so use CUDSS.jl 0.8 +with the default general LU until it resolves; the extension accepts both. The CPU side of this solver (the CSR layout and the per-frequency value update) is tested in the Maxwell test group, and the `MaxwellGPU` group checks that the extension loads and infers. The comparison of the GPU sweep with diff --git a/test/MaxwellGPU/cudss.jl b/test/MaxwellGPU/cudss.jl index e1c387d3..841eb26b 100644 --- a/test/MaxwellGPU/cudss.jl +++ b/test/MaxwellGPU/cudss.jl @@ -21,7 +21,8 @@ const EXT = Base.get_extension(FiniteElementMethod, :FiniteElementMethodCUDSSExt @test_throws "SparseMatrixCSC" solver(Matrix(A), B, nothing) # dense A is not for cuDSS end -# The complex symmetric LDLᵀ is documented from CUDSS.jl 1.0 on. +# The complex symmetric LDLᵀ is documented from CUDSS.jl 1.0 on; the supported resolvable version today is 0.8, +# where only the general LU runs, so the gate skips "S" there. const STRUCTURES = pkgversion(CUDSS) >= v"1" ? ["G", "S"] : ["G"] if CUDA.functional()