Skip to content
Open
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
15 changes: 15 additions & 0 deletions docs/src/lts.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,21 @@ Two mitigations apply on LTS:
Reductions that include dimension 1 (`dims=(1,3)`, or a full reduction) keep a contiguous
innermost axis and use the normal kernel.

### IGC's load/store combining is disabled

The LTS IGC miscompiles kernels that update a 2- or 4-byte aggregate in a loop, such as a
`ComplexF16`, `Complex{Int16}` or `Complex{Int8}` accumulator: every work-item except the
first of each group gets a wrong value, again without an error. Julia 1.13 generates code
that triggers it (Julia 1.10 doesn't), and any kernel can be affected, including sparse
`sum(A; dims)` with `ComplexF16` elements. The defect is in IGC's LdStCombine pass and was
fixed in IGC 2.26.

On LTS, oneAPI.jl turns that pass off by setting `IGC_EnableLdStCombine=0` before the first
kernel is compiled, and passes the same setting in each module's build options so that
kernels miscompiled earlier aren't reused from the driver's on-disk compiler cache. Setting
`IGC_EnableLdStCombine` yourself takes precedence. Disabling the pass costs little: at most
a few percent in the kernels we measured.

### Frees are synchronized against in-flight work

NEO LTS advertises `ZE_extension_memory_free_policies` but does not honor its
Expand Down
1 change: 1 addition & 0 deletions lib/level-zero/module.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ mutable struct ZeModule
device::ZeDevice

function ZeModule(ctx::ZeContext, dev::ZeDevice, image; build_flags="", log::Bool=true)
build_flags = join(filter(!isempty, [module_build_flags[], build_flags]), ' ')
log_ref = if log
log_ref = Ref{ze_module_build_log_handle_t}()
else
Expand Down
31 changes: 29 additions & 2 deletions lib/level-zero/oneL0.jl
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,9 @@ const parameter_validation = Ref{Bool}()

# Master switch for the Intel LTS-stack workarounds (driver/IGC quirks on the Aurora
# LTS NEO 25.18 stack): the SPIR-V translator codegen path, strided-reduction
# materialization, and command-queue drain-before-free. All such code paths are gated
# on `LTS[]`, so with it disabled the package behaves like the upstream rolling stack.
# materialization, command-queue drain-before-free, and disabling IGC's LdStCombine. All
# such code paths are gated on `LTS[]`, so with it disabled the package behaves like the
# upstream rolling stack.
# Default OFF (rolling stack), matching upstream: an LTS deployment opts in with
# `ONEAPI_LTS=1`. On Aurora that variable is set in the environment, and the GitHub
# Actions self-hosted (Aurora) runner sets it in ci.yml; the rolling-stack buildkite
Expand All @@ -165,6 +166,31 @@ function parse_env_bool(name::AbstractString, default::Bool)
return default
end

# The LTS IGC (2.11) miscompiles kernels that update a 2- or 4-byte aggregate (`ComplexF16`,
# `Complex{Int8}`, ...) in a loop, returning wrong values for all but the first work-item:
# its LdStCombine pass packs the fields of such values into one 32-bit lane, and copies of
# those packed fields were emitted as if they weren't. Fixed in IGC 2.26
# (intel/intel-graphics-compiler@15614f2), so the rolling stack isn't affected.
#
# IGC reads its settings once per process, at its first compilation, which may be of
# another library's module, so the environment variable has to be set before any module is
# built. The same setting is passed with every module too: NEO's on-disk compiler cache
# doesn't key on the environment, only on the build flags, and would otherwise keep serving
# kernels that were miscompiled before the workaround applied. If another library already
# compiled through IGC in this process before oneAPI.jl initialized, the setting comes too
# late. Turning the pass off costs little in our kernels.
const module_build_flags = Ref("")
function disable_broken_ldst_combine()
if LTS[] && !haskey(ENV, "IGC_EnableLdStCombine")
ENV["IGC_EnableLdStCombine"] = "0"
end
# derived from the environment every time, so that neither a package image nor a
# re-initialization carries it over
module_build_flags[] = get(ENV, "IGC_EnableLdStCombine", nothing) == "0" ?
"-igc_opts 'EnableLdStCombine=0'" : ""
return
end

function __init__()
# precompilation processes only initialize the driver when a workload asks for it (see
# `oneAPI.can_precompile`)
Expand Down Expand Up @@ -242,6 +268,7 @@ function initialize(; quiet::Bool=false)
return
end

disable_broken_ldst_combine()
validation_layer[] = parse(Bool, get(ENV, "ZE_ENABLE_VALIDATION_LAYER", "false"))
parameter_validation[] = parse(Bool, get(ENV, "ZE_ENABLE_PARAMETER_VALIDATION", "false"))
SCRATCH_HEDGE[] = parse_env_bool("ONEAPI_SCRATCH_HEDGE", true)
Expand Down
24 changes: 24 additions & 0 deletions test/execution.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1661,6 +1661,30 @@ end
end
end

@testset "accumulating a small aggregate in a loop" begin
# Julia 1.13 doesn't scalarize the accumulator, and the LTS IGC then mixed up the lanes
# of 2- and 4-byte ones; see `oneL0.disable_broken_ldst_combine`. Only the first
# work-item of a group came out right, so this needs several per group.
function accumulate_slices!(out, vals)
i = get_global_id()
a = 3i - 2
v = @inbounds vals[a]
for k in (a + 1):(a + 2)
v += @inbounds vals[k]
end
@inbounds out[i] = v
return
end
types = Any[Complex{Int8}, Complex{Int16}, ComplexF32]
float16_supported && push!(types, ComplexF16)
@testset "$T" for T in types
vals = rand(T, 3 * 32)
out = oneArray{T}(undef, 32)
@oneapi items=32 accumulate_slices!(out, oneArray(vals))
@test Array(out) ≈ [sum(@view vals[(3i - 2):3i]) for i in 1:32]
end
end

@testset "device-side reinterpret to a stronger alignment" begin
function kernel(y, a, offset)
ptr = reinterpret(Core.LLVMPtr{Int32,AS.CrossWorkgroup}, pointer(a)) + offset
Expand Down
Loading