Skip to content

Max 1550: oneMKL potrf! costs ~3.4 µs per column, small oneMKL calls 17–30 µs, queued launches slower than synced ones #766

Done

Description

@michel2323

We profiled the multifrontal Cholesky of SparseDirectSolver.jl on Aurora. It makes thousands of small dense calls per factorization. Three costs show up in standalone reproducers (the scripts are below, no SparseDirectSolver.jl needed). The biggest is that oneMKL potrf! costs about 3.4 µs per column, whatever the matrix size.

Environment: one tile of an Intel Data Center GPU Max 1550 (ZE_FLAT_DEVICE_HIERARCHY=FLAT, ZE_AFFINITY_MASK=0), Aurora LTS driver (Level Zero v1.3.33578, ONEAPI_LTS=1), oneAPI.jl 2.10.0, GPUCompiler 2.22.1, KernelAbstractions 0.10.7, Julia 1.13.3. All numbers are Float64 medians or means of back-to-back calls with one synchronize at the end, unless noted.

1. oneMKL.potrf! costs about 3.4 µs per column

n potrf! per call of which onemklDpotrf GFLOP/s
16 104 µs 90 µs 0.01
32 151 µs 139 µs 0.07
64 265 µs 256 µs 0.33
128 484 µs 472 µs 1.4
256 880 µs 870 µs 6.4
512 1.77 ms 1.75 ms 25
1024 3.27 ms 110
1600 5.13 ms 266

From n = 16 to n = 512 the time grows linearly with n, not with n³: about 90 µs plus 3.4 µs per column. A multifrontal factorization calls potrf! once per front, and most fronts are small. On a 674k-row KKT system (fronts mostly n ≈ 150–200), oneMKL's potrf runs at 1–4 GFLOP/s.

The Julia wrapper isn't the problem. The scratchpad size query takes 0.6 µs, and allocating and freeing the scratchpad (1 element for every n here) takes 0.6 µs. Nearly all the time is in the oneMKL call (onemklDpotrf, timed with a preallocated scratchpad). That looks like a sequential per-column (or per-panel) launch chain inside oneMKL's GPU potrf. It may belong upstream, but I'm filing it here first: you'll know whether there's a better entry point, such as potrf_batch with a group of 1, or a different scratchpad or queue setup.

2. Back-to-back kernel launches are slower than launch + synchronize (LTS stack)

default ONEAPI_SYNC_EACH_SUBMISSION=1
trivial @oneapi kernel, 2000 launches, one synchronize 24.6 µs per launch 6.7 µs
same, synchronize after every launch 7.7 µs 9.9 µs

Queueing launches without waiting costs 3× more per launch than waiting after each one. That's the opposite of what you'd expect, and it penalizes exactly the code that avoids host syncs. This may be related to #756 (that one was measured on an Arc A770, and doesn't show the inversion).

3. Small level-3 BLAS calls cost 17–30 µs each

m (all square m × m) gemm! syrk! trsm!
32 17.3 µs 19.0 µs 22.5 µs
64 17.6 µs 18.8 µs 29.4 µs
256 22.4 µs 22.6 µs 64.7 µs

That's 2–4× a trivial kernel plus synchronize (7.7 µs). These numbers are the same with and without ONEAPI_SYNC_EACH_SUBMISSION. Each generated wrapper in deps/src/onemkl.cpp ends with wait_and_throw(), and the *_batch wrappers also wait before the call. So every oneMKL call is a host round trip, and a sequence of small calls can't overlap. A non-blocking variant (returning the event, or skipping the wait when the caller synchronizes later) would help code that issues many small calls on one in-order queue.

Side note: a single-workgroup kernel and Int64 % / ÷

Our fallback dense Cholesky runs as one 128-lane workgroup. It reaches 0.2–0.5 GFLOP/s, so it's slow regardless and that part is our problem. Still, in the trailing update, indexing q -> (q % r, q ÷ r) with Int64 costs 1.44× the Int32 version (n = 512: 224 ms vs 156 ms; n = 1600: 6.66 s vs 4.59 s). That's presumably the emulated 64-bit integer division. It's worth knowing for any kernel that linearizes a 2-D loop with Int indices. It's included in the second script below in case it's useful as a compiler test case.

Reproducer for 1–3 (mwe2.jl)
using oneAPI, oneAPI.oneMKL, LinearAlgebra, Printf, Statistics
const M = oneAPI.oneMKL
println(oneAPI.device(), "  ONEAPI_SYNC_EACH_SUBMISSION=", get(ENV, "ONEAPI_SYNC_EACH_SUBMISSION", "unset"))
spd(n) = (B = rand(n, n); B * B' + n * I)

# per call, N calls back to back, one synchronize at the end
function percall(f, N)
    f(); oneAPI.synchronize()
    t = @elapsed (for _ in 1:N; f(); end; oneAPI.synchronize())
    return 1e6 * t / N
end
k0(a) = (@inbounds a[1] = 1.0; nothing)
z = oneArray(zeros(1))
@printf("trivial @oneapi kernel:            %6.1f µs per launch\n", percall(() -> @oneapi(k0(z)), 2000))
@printf("trivial @oneapi kernel + sync:     %6.1f µs per launch\n", percall(() -> (@oneapi(k0(z)); oneAPI.synchronize()), 2000))
for m in (32, 64, 256)
    A = oneArray(Matrix(LowerTriangular(spd(m)))); B = oneArray(rand(m, m)); C = oneArray(rand(m, m))
    @printf("m = %4d  gemm! %6.1f µs  syrk! %6.1f µs  trsm! %6.1f µs per call\n", m,
            percall(() -> oneMKL.gemm!('N', 'T', 1.0, B, B, 0.0, C), 500),
            percall(() -> oneMKL.syrk!('L', 'N', -1.0, B, 1.0, C), 500),
            percall(() -> oneMKL.trsm!('R', 'L', 'T', 'N', 1.0, A, B), 500))
end

# potrf!: whole call, and its parts (scratchpad size query, allocation, the oneMKL call itself)
for n in (16, 32, 64, 128, 256, 512)
    A0 = oneArray(spd(n)); A = similar(A0)
    q = M.sycl_queue(M.global_queue(oneAPI.context(A), oneAPI.device()))
    tfull = percall(() -> (copyto!(A, A0); oneMKL.potrf!('L', A)), 200)
    tq = percall(() -> M.onemklDpotrf_scratchpad_size(q, 'L', n, n), 200)
    sz = M.onemklDpotrf_scratchpad_size(q, 'L', n, n)
    talloc = percall(() -> oneAPI.unsafe_free!(oneVector{Float64}(undef, sz)), 200)
    scr = oneVector{Float64}(undef, sz)
    tcall = percall(() -> (copyto!(A, A0); M.onemklDpotrf(q, 'L', n, A, n, scr, sz)), 200)
    tcopy = percall(() -> copyto!(A, A0), 200)
    @printf("potrf! n = %4d  %7.1f µs  = size query %5.1f + alloc/free %5.1f + onemklDpotrf %6.1f µs (scratchpad %d, copyto! %4.1f µs)\n",
            n, tfull - tcopy, tq, talloc, tcall - tcopy, sz, tcopy)
end

Output (default, then ONEAPI_SYNC_EACH_SUBMISSION=1):

ZeDevice(GPU, vendor 0x8086, device 0x0bd6)  ONEAPI_SYNC_EACH_SUBMISSION=unset
trivial @oneapi kernel:              24.6 µs per launch
trivial @oneapi kernel + sync:        7.7 µs per launch
m =   32  gemm!   17.3 µs  syrk!   19.0 µs  trsm!   22.5 µs per call
m =   64  gemm!   17.6 µs  syrk!   18.8 µs  trsm!   29.4 µs per call
m =  256  gemm!   22.4 µs  syrk!   22.6 µs  trsm!   64.7 µs per call
potrf! n =   16    103.8 µs  = size query   0.6 + alloc/free   0.6 + onemklDpotrf   90.2 µs (scratchpad 1, copyto!  3.7 µs)
potrf! n =   32    150.6 µs  = size query   0.6 + alloc/free   0.7 + onemklDpotrf  139.3 µs (scratchpad 1, copyto!  3.3 µs)
potrf! n =   64    264.6 µs  = size query   0.6 + alloc/free   0.6 + onemklDpotrf  255.7 µs (scratchpad 1, copyto!  3.4 µs)
potrf! n =  128    483.8 µs  = size query   0.6 + alloc/free   0.6 + onemklDpotrf  471.9 µs (scratchpad 1, copyto!  3.3 µs)
potrf! n =  256    880.2 µs  = size query   0.6 + alloc/free   0.7 + onemklDpotrf  869.7 µs (scratchpad 1, copyto!  3.4 µs)
potrf! n =  512   1765.4 µs  = size query   0.6 + alloc/free   0.6 + onemklDpotrf 1754.2 µs (scratchpad 1, copyto!  4.3 µs)
ZeDevice(GPU, vendor 0x8086, device 0x0bd6)  ONEAPI_SYNC_EACH_SUBMISSION=1
trivial @oneapi kernel:               6.7 µs per launch
trivial @oneapi kernel + sync:        9.9 µs per launch
m =   32  gemm!   17.1 µs  syrk!   18.8 µs  trsm!   21.6 µs per call
m =   64  gemm!   17.5 µs  syrk!   18.7 µs  trsm!   29.4 µs per call
m =  256  gemm!   22.0 µs  syrk!   22.5 µs  trsm!   64.5 µs per call
potrf! n =   16    102.1 µs  = size query   0.6 + alloc/free   0.6 + onemklDpotrf   98.1 µs (scratchpad 1, copyto!  6.7 µs)
potrf! n =   32    148.5 µs  = size query   0.6 + alloc/free   0.5 + onemklDpotrf  144.8 µs (scratchpad 1, copyto!  7.0 µs)
potrf! n =   64    262.0 µs  = size query   0.6 + alloc/free   0.6 + onemklDpotrf  261.2 µs (scratchpad 1, copyto!  7.2 µs)
potrf! n =  128    493.5 µs  = size query   0.6 + alloc/free   0.6 + onemklDpotrf  486.2 µs (scratchpad 1, copyto!  7.3 µs)
potrf! n =  256    893.3 µs  = size query   0.6 + alloc/free   0.7 + onemklDpotrf  895.1 µs (scratchpad 1, copyto!  8.7 µs)
potrf! n =  512   1794.9 µs  = size query   0.6 + alloc/free   0.7 + onemklDpotrf 1789.6 µs (scratchpad 1, copyto!  8.7 µs)
Single-workgroup Cholesky, Int64 vs Int32 div/rem, and large potrf! (run with ONEAPI_SYNC_EACH_SUBMISSION=1)
using oneAPI, oneAPI.oneMKL, LinearAlgebra, Printf, Statistics
spd(n) = (B = rand(n, n); B * B' + n * I)
const GMF = isdefined(oneAPI, :GLOBAL_MEM_FENCE) ? oneAPI.GLOBAL_MEM_FENCE : oneAPI.SPIRVIntrinsics.GLOBAL_MEM_FENCE
med(f; n = 5) = (f(); median([(@elapsed begin f(); oneAPI.synchronize() end) for _ in 1:n]))

# unblocked Cholesky in one workgroup; trailing update indexed q -> (q % r, q ÷ r)
function chol1wg_divrem!(A, n::Ti) where {Ti}
    li = Ti(get_local_id()); WG = Ti(get_local_size())
    @inbounds for j in Ti(1):n
        li == 1 && (A[j, j] = sqrt(A[j, j]))
        barrier(GMF)
        ljj = A[j, j]
        for i in (j + li):WG:n
            A[i, j] /= ljj
        end
        barrier(GMF)
        r = n - j
        for q in (li - Ti(1)):WG:(r * r - Ti(1))
            i = j + Ti(1) + q % r
            k = j + Ti(1) + q ÷ r
            i >= k && (A[i, k] -= A[i, j] * A[k, j])
        end
        barrier(GMF)
    end
    return
end

for n in (512, 1024, 1600)
    A0 = spd(n); Lref = cholesky(Symmetric(A0, :L)).L
    for Ti in (Int64, Int32)
        A = oneArray(A0)
        t = med(() -> (copyto!(A, A0); @oneapi items = 128 groups = 1 chol1wg_divrem!(A, Ti(n))); n = 3)
        @printf("1-workgroup Cholesky n = %4d  %-6s %9.1f ms  err %.1e\n", n, Ti, 1e3t, norm(tril(Array(A)) - Lref) / norm(Lref))
    end
    A = oneArray(A0)
    t = med(() -> (copyto!(A, A0); oneMKL.potrf!('L', A)))
    @printf("oneMKL potrf!               n = %4d  %9.2f ms  %6.1f GFLOP/s\n", n, 1e3t, n^3 / 3 / t / 1e9)
end
1-workgroup Cholesky n =  512  Int64      223.7 ms  err 1.6e-15
1-workgroup Cholesky n =  512  Int32      155.9 ms  err 1.6e-15
oneMKL potrf!               n =  512       1.76 ms    25.4 GFLOP/s
1-workgroup Cholesky n = 1024  Int64     1756.6 ms  err 3.0e-15
1-workgroup Cholesky n = 1024  Int32     1214.9 ms  err 3.0e-15
oneMKL potrf!               n = 1024       3.27 ms   109.5 GFLOP/s
1-workgroup Cholesky n = 1600  Int64     6663.3 ms  err 4.2e-15
1-workgroup Cholesky n = 1600  Int32     4594.9 ms  err 4.2e-15
oneMKL potrf!               n = 1600       5.13 ms   265.9 GFLOP/s

Related: #756 (launch and synchronize latency on Arc), #755 (oneMKL potrf info column).

Found while benchmarking SparseDirectSolver.jl on Aurora, with the help of Claude Code.

Activity

  1. maleadt commented on Dec 2, 2026

    @maleadt
    Member

    Thanks for the numbers. The linear scaling of potrf! reproduces on an Arc A770, and also in plain SYCL/C++ calling oneapi::mkl::lapack::potrf directly, so it's in oneMKL rather than oneAPI.jl. Changing how we set up the queue we hand to oneMKL doesn't help either. Points 2 and 3 are on our side and will be tracked separately.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions