Skip to content

CPU allocation tests fail on loaded CI with KernelAbstractions >= 0.10.6: the backend yields after slow launches and @allocated charges other tasks #188

Closed

Description

@michel2323

Found while working on: T36 (PR #187), CI runs of 2026-11-09 (CPU-only, CUDA and Aurora legs)

What: KernelAbstractions 0.10.6 (2026-11-08) replaced the CPU backend's launch path: kernels run as PoCL host kernels on Julia's threads (JuliaGPU/KernelAbstractions.jl#906, #941, #956), and after any launch that took 50 µs or longer the backend calls yield() so other tasks can run (run_other_tasks() in src/pocl/compiler/execution.jl, threshold host_kernel_long_ticks). Julia's @allocated is process-wide, so whatever the other tasks of the process allocate during that yield is charged to the measured call. In a ParallelTestRunner worker those are the runner's communication tasks; on a loaded CI machine many solve launches exceed 50 µs, and the CPU allocation tests fail on every element type with 0.10.7 resolved:

test allocated budget
test/test_solve.jl:204, "no allocations (CPU)" (level-sweep sweep_solve!, laplacian2d(40, 40), 5 RHS) 3.3–4.3 MB 1–11 KB
test/test_api.jl:524, "MadNLP-like refactorization loop" on CPU() 1.5 MB 0.8 MB

The same code passed CI on 2026-11-05 with KernelAbstractions 0.10.4 (PR #187, a4bb8bb); the commits in between touched only tests. Locally with 0.10.7 on an idle machine test_solve passes (524/524), a run with 32 parallel workers passes (10488/10488), and a direct measurement gives 16 bytes per CPU launch, short or long, with 1 or 4 threads. A reproducer with an allocating task on the same thread shows the mechanism: a 1 µs launch adds nothing, a 29 ms launch adds exactly that task's 64 KiB ($SCRATCH/t36/ka/launch_alloc_bg.jl of session session_01MsLzHn17wzxqT2iMbuJyUh; script below). The solver itself does not allocate: the failure is in what the tests measure, not in what the kernels do.

using KernelAbstractions
@kernel function axpy_kernel!(y, a, @Const(x))
    i = @index(Global); @inbounds y[i] += a * x[i]
end
be = CPU(); running = Ref(true)
bg = @async while running[]; zeros(UInt8, 65536); yield(); end   # stands in for the test runner's tasks
for n in (1_000, 20_000_000)
    x = rand(n); y = rand(n); k = axpy_kernel!(be)
    for _ in 1:3; k(y, 2.0, x; ndrange = n); KernelAbstractions.synchronize(be); end
    a = @allocated (k(y, 2.0, x; ndrange = n); KernelAbstractions.synchronize(be))
    println("n = $n: $a bytes")       # KA 0.10.7, 1 thread: 16 bytes, then 65592 bytes
end
running[] = false

Why it is out of scope: T36 adds solve_alg = "algo1" and does not touch the level sweeps or the CPU backend; no task in TASKS.md owns the allocation-test methodology (ka_cpu_alloc_budget, solve_allocated, device_allocated, #145). It blocks every PR until resolved, so PR #187 caps the compat bound at KernelAbstractions = "0.10.3 - 0.10.5" in Project.toml and test/Project.toml (commit 7c2fb04). The owner prefers to resolve this in SparseDirectSolver.jl rather than upstream.

Suggested fix or plan change: keep the budgets as they are (an allowance for other tasks' allocations would be a guess) and change how the CPU allocation tests measure, then lift the cap. Options: (1) measure in a process without the runner's tasks, e.g. run the "no allocations" testsets in a child julia process (or a dedicated test file that ParallelTestRunner runs without its monitor tasks) and read the count back; (2) wrap the measured call so that no other task can run on the thread: pin the measurement to a thread of the :interactive pool, or temporarily hold the scheduler by running the call inside Base.@sync with other tasks blocked, which is fragile; (3) measure with Base.gc_num() per task if Julia gains a per-task counter. (1) is the robust one. Independently, note in AGENTS.md ("the test allocation budgets carry no per-launch allowance") that KernelAbstractions ≥ 0.10.6 yields after slow launches, so @allocated around a launch is only meaningful in a process whose other tasks do not allocate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    cifound-by-agent

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions