oneAPI.jl, the Julia package for programming Intel GPUs, has had many releases since version 1.5, the last one covered on this blog. Launching kernels and uploading small arrays in a loop is now hundreds of times faster, the first operations of a session need much less compilation, errors thrown in kernels are reported, and a profiler works right in the REPL.

If you are upgrading from 1.x: oneAPI.jl now requires Julia 1.10 or later, and KernelAbstractions 0.10 if you use that package. Since version 2.0, the optional dimension argument of intrinsics like get_global_id counts from 1, so get_global_id(0) becomes get_global_id(1), or just get_global_id(). Kernels written for GPUArrays’ gpu_call interface, which GPUArrays 11 removed, need to be ported to KernelAbstractions.jl. The release notes list the other changes.

Less overhead #

oneAPI.jl 1.5 created and submitted a new command list for every operation, and submitting got slower as more work was queued. oneAPI.jl now reuses one command list per task and submits kernel launches in batches, allocates small arrays from larger blocks, and no longer waits for the GPU when freeing memory. For each row below, the operation was run 1000 times on 1024-element Float32 arrays, followed by one synchronize(); the table shows the total time divided by 1000:

oneAPI.jl 1.5oneAPI.jl 2.11
launch a kernel1093 µs3.0 µs
broadcast y = x .* 2f0 .+ 1f0527 µs5.4 µs
allocate and free (unsafe_free!) an array33 µs0.42 µs
copyto! from an Array1288 µs1.8 µs

An operation that waits for its result gains less, because it still pays for a round trip to the GPU. A broadcast followed by synchronize() took 215 µs with oneAPI.jl 1.5 and now takes 93 µs, against 5.4 µs per broadcast when synchronizing once after 1000:

julia> using oneAPI, BenchmarkTools

julia> x = oneArray(rand(Float32, 1024));

julia> @btime begin
           y = $x .* 2f0 .+ 1f0
           synchronize()
       end
  93.099 μs (32 allocations: 1.70 KiB)

Since version 2.10, reductions, scans, sorting and findall use the implementations in GPUArrays.jl that all of Julia’s GPU back-ends share. oneAPI.jl 1.5 had no GPU version of findall, cumsum and sort: they fell back to indexing element by element from the CPU, which is slow, and an error outside the REPL. The table shows times in milliseconds, including synchronization, for a Float32 vector x of 10⁷ elements and a 1000×10000 matrix A:

oneAPI.jl 1.5oneAPI.jl 2.11
sum(x)1.510.37
sum(A; dims=1)1.040.34
x[x .> 0.5f0]1.811.31
findall(>(0.5f0), x)error1.49
cumsum(x)error0.80
sort(x)error5.78

Faster first use #

On Julia 1.13, oneAPI.jl’s TTFX has dropped below 2 seconds. If a GPU is available when oneAPI.jl is precompiled, precompilation now allocates arrays, launches kernels and runs common operations, and the compiled code is cached for later sessions.

1.5, Julia 1.102.11, Julia 1.102.11, Julia 1.13
using oneAPI0.67 s1.21 s1.48 s
a = oneArray(rand(Float32, 1024))0.75 s0.11 s0.11 s
then a .* 2f0 .+ 1f09.47 s6.00 s0.21 s
then sum(a)0.82 s1.37 s0.03 s
then allocate an output and launch a new kernel0.11 s0.35 s0.15 s

On Julia 1.10 and 1.11, precompilation can’t compile kernels, so the gain there is small.

Errors in kernels #

Since version 2.10, a kernel that throws an exception, for example on an out-of-bounds access, raises a KernelException when you synchronize:

julia> using oneAPI

julia> function kernel(a)
           a[get_global_id() + 1] = 1
           return
       end
kernel (generic function with 1 method)

julia> a = oneArray{Int}(undef, 1);

julia> @oneapi kernel(a); synchronize()
ERROR: KernelException: A BoundsError was thrown by work-item 1×1×1
       in work-group 1×1×1: Out-of-bounds array access
For more details, run Julia with `-g2`, or launch the kernel with `debug_level=2`.

A built-in profiler #

oneAPI.@profile shows the calls a piece of code makes to Level Zero, the driver API that oneAPI.jl is built on, and the kernels and copies that run on the GPU as a result. Kernels that oneMKL launches show up too, like the sgemm below. This is the output of the second run, after compilation:

julia> using oneAPI

julia> a = oneArray(rand(Float32, 2048, 2048));

julia> b = similar(a);

julia> oneAPI.@profile begin
           c = a * a
           b .= c .+ 1f0
       end
Profiled over 8.67 ms.

Host-side activity: 49 Level Zero API calls taking 4.66 ms (53.72% of wall-clock)
...

Device-side activity: GPU was busy for 3.98 ms (45.91% of wall-clock)
┌──────────┬────────────┬───────┬───────────────────────────────┐
│ Time (%) │ Total time │ Calls │ Name                          |
├──────────┼────────────┼───────┼───────────────────────────────┤
│   43.19% │    3.75 ms │     1 │ sgemm_nocopy_nn_32x32_8x4     |
│    2.72% │  235.94 µs │     1 │ broadcast(...)                |
└──────────┴────────────┴───────┴───────────────────────────────┘

The matrix product takes almost all of the GPU’s time. In the host-side table, left out here, 4.03 ms of the host time went to six zeCommandQueueSynchronize calls, which wait for the GPU. With trace=true, the profiler lists the individual events in chronological order instead of these tables. The built-in profiler only works on x86_64 Linux. For more detail, run Julia under an external profiler such as VTune or unitrace with collection initially paused, and wrap the code of interest in oneAPI.@profile external=true to collect only that region.

FFTs and linear algebra #

Since version 2.3, oneMKL’s FFTs are available through the AbstractFFTs.jl interface. For example, a 2D FFT of a 4096×4096 matrix:

julia> using oneAPI, AbstractFFTs, BenchmarkTools

julia> x = oneArray(rand(ComplexF32, 4096, 4096));

julia> p = plan_fft(x);

julia> @btime ($p * $x; synchronize())
  12.349 ms (54 allocations: 2.86 KiB)

On this machine’s CPU, FFTW computes the same FFT in 24.5 ms with 16 threads and a FFTW.MEASURE plan.

Since version 2.11, dense oneMKL calls such as mul! return without waiting for the GPU, so a loop of 500 products of 32×32 Float32 matrices now takes 12.5 µs per product instead of 72 µs. cholesky and lu also work on dense oneArrays now, as does eigen for real symmetric and Hermitian matrices.

Other changes #

If something doesn’t work for you, please file an issue on GitHub.