Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ Three documents define the work. Read them in this order before touching code:
mechanically.
* New dependencies need a one-line justification in the Report. Never `dev`
unregistered or local checkouts into the project (the package requires
KernelAbstractions 0.10 and GPUArrays 12, hence CUDA.jl >= 6.5, AMDGPU.jl
>= 2.10, Metal.jl >= 1.11 and oneAPI.jl >= 2.10; the test allocation budgets
carry a per-launch allowance for the 0.10 CPU backend -- see
KernelAbstractions 0.10 (>= 0.10.3) and GPUArrays 12, hence CUDA.jl >= 6.5,
AMDGPU.jl >= 2.10, Metal.jl >= 1.11 and oneAPI.jl >= 2.10; KA >= 0.10.3
launches allocation-free on the CPU backend, so the test allocation budgets
carry no per-launch allowance outside coverage runs -- see
`ka_cpu_alloc_budget` and #145).
* The repository is `github.com/exanauts/SparseDirectSolver.jl` (remote
`origin`, branch `main`). Commit at the end of the task with a message
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Adapt = "4"
Atomix = "1"
CUDACore = "6.5"
CliqueTrees = "1"
KernelAbstractions = "0.10"
KernelAbstractions = "0.10.3"
Krylov = "0.10"
LinearAlgebra = "1.13"
MadNLP = "0.11"
Expand Down
2 changes: 1 addition & 1 deletion test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ oneAPI = "8f75cd03-7ff8-4ecb-9b8f-daf728133b1b"
Adapt = "4"
Aqua = "0.8"
DelimitedFiles = "1"
KernelAbstractions = "0.10"
KernelAbstractions = "0.10.3"
Krylov = "0.10"
LinearAlgebra = "1.13"
ParallelTestRunner = "2"
Expand Down
18 changes: 18 additions & 0 deletions test/test_helpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,24 @@ end
end
end

# A trivial kernel: the per-launch allocation of the KA CPU backend itself (#145).
@kernel function ka_launch_probe_kernel!(y)
i = @index(Global, Linear)
@inbounds y[i] = i
end

# The CPU allocation budgets (`ka_cpu_alloc_budget`) grant nothing per launch: a KA
# release that allocates per launch again would fail the numeric and solve budgets
# all over the suite, so this guard names the cause (#145).
TEST_CPU && @testset "KA CPU backend launches allocation-free" begin
y = zeros(Int, 256)
launch!() = (ka_launch_probe_kernel!(CPU(), 64)(y; ndrange = length(y)); KernelAbstractions.synchronize(CPU()))
launch!(); launch!(); launch!() # compile and warm up
bytes = @allocated launch!()
@test y == 1:256
@test bytes <= (Base.JLOptions().code_coverage != 0 ? 64 : 0)
end

@testset "tolerances and residuals" begin
@test tol(Float32) == sqrt(eps(Float32))
@test tol(ComplexF64) == sqrt(eps(Float64))
Expand Down
29 changes: 16 additions & 13 deletions test/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -268,22 +268,25 @@ growth_tol(::Type{T}, Nr) where {T} = panel_tol(T) * max(one(real(T)), real(T)(f

Bytes the KernelAbstractions CPU backend itself may allocate for `launches`
kernel launches whose `@localmem` buffers total `localmem_bytes`, on top of
the 1024 B allowed to an allocation-free phase (PLAN §3.9). Measured (T09
review round 1): 0 without coverage (the local runs, Julia ≥ 1.13 is required);
with `--code-coverage` (CI's `julia-runtest`) the `@localmem` `MArray`s are
heap-allocated, hence `localmem_bytes` plus 64 B of header per launch. The
KernelAbstractions 0.10 CPU backend heap-allocates on every launch (~230 B
measured; 0.9 was allocation-free), hence 320 B per launch. (Julia ≤ 1.11
also boxed the arguments of every launch behind KA's `__run` inference
the 1024 B allowed to an allocation-free phase (PLAN §3.9). Without coverage
that is 0: a warmed launch on the KernelAbstractions ≥ 0.10.3 CPU backend
allocates nothing (measured for #145 with a trivial and a `@localmem` kernel:
KA 0.10.3 with and without `--code-coverage=all`, KA 0.10.4 with 1 and 4
threads; `test_helpers` guards it). With `--code-coverage` (CI's
`julia-runtest`) the `@localmem` `MArray`s may be heap-allocated (T09 review
round 1), hence `localmem_bytes` plus 64 B of header per launch. KA 0.10.0–0.10.2
heap-allocated on every launch (96 B measured with a trivial kernel, ~230 B in
PR #133), which a 320 B/launch allowance covered; that allowance hid real
allocations of the numeric phase (~62 KB of headroom, 195 launches, for one
`factorize!` of `random_spd(500, 0.01)`, which itself allocates 512 B), so
it went with the `[compat] KernelAbstractions = "0.10.3"` bound (#145). (Julia
≤ 1.11 also boxed the arguments of every launch behind KA's `__run` inference
barrier; that allowance went with the Julia 1.10 support.)
"""
function ka_cpu_alloc_budget(launches::Integer, localmem_bytes::Integer)
b = 1024
# KernelAbstractions 0.10's CPU backend heap-allocates per launch (~230 B measured
# with a trivial precompiled kernel; the new backend's task machinery). 320 B of
# per-launch headroom keeps the budgets meaningful -- they still scale with the
# phase's launch count -- until the upstream allocation is fixed.
b += 320 * launches
# no per-launch term: KA >= 0.10.3 (the compat bound) launches allocation-free on the
# CPU backend (#145); only coverage instrumentation may heap-allocate `@localmem`
Base.JLOptions().code_coverage != 0 && (b += localmem_bytes + 64 * launches)
return b
end
Expand Down Expand Up @@ -548,7 +551,7 @@ assembly launches and, per chunk (`ldlt_c_chunk_end`) and batch member, one
columns, the finish kernel and one contribution-block pack per front; plus the
`max |aᵢⱼ|` and statistics reductions. `lu = true` budgets `factorize_lu!`
instead: every launch group is one fused launch, plus the two Schur assembly
launches. `@localmem` (heap-allocated only under `--code-coverage` on KA 0.9):
launches. `@localmem` (heap-allocated only under `--code-coverage`):
the largest regime-A kernel (48 KiB) per subtree launch and per launch group,
blocked groups included as before, plus the two reductions (T15).
"""
Expand Down
Loading