Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Wrong results for overflowing Int16 arithmetic in a reduction kernel

Chiusa
#670 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@maleadt ci sta già lavorando.

Dal 8/10/2026.

  • #674 di @maleadt — aperta

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
julia
Ambito
backend

Direzione di ricerca

The report points to AcceleratedKernels’ generic mapreducedim! kernel for sources without strides and the reductions/mapreducedim! test in GPUArrays 12. Start by reproducing the failing Complex{Int16} abs2 reduction and comparing the generic kernel’s generated code with the handwritten oneAPI kernels described here. Done means identifying and fixing the cause of the incorrect results, with a regression test covering overflowing values.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

On an Iris Xe (i7-1165G7), a reduction of abs2 over Complex{Int16} values gives wrong results when abs2 overflows Int16, in AcceleratedKernels' generic mapreducedim! kernel (the one used for sources without strides). Julia's IR is correct (wrapping mul i16/add i16 feeding llvm.smax.i16), so this looks like a miscompile further down, in the SPIR-V translation or IGC.

GPUArrays 12's testsuite hit it (reductions/mapreducedim!, Base.mapreducedim!(abs2, max, R, adjoint(A)) with Complex{Int16}). GPUArrays 12.0.1 keeps those values small.

using oneAPI
function check(label, gen, f)
    bad = 0
    for _ in 1:50
        A = gen()
        R0 = zeros(Int16, 1, 3)
        mk = A -> view(permutedims(A), [1, 2, 3, 4], :)   # not strided: AK's generic kernel
        c = Base.mapreducedim!(f, max, copy(R0), mk(A))
        g = Array(Base.mapreducedim!(f, max, oneArray(R0), mk(oneArray(A))))
        c == g || (bad += 1)
    end
    println(rpad(label, 30), bad, "/50")
end
function main()
    small = () -> complex.(rand(Int16(-100):Int16(100), 3, 4), rand(Int16(-100):Int16(100), 3, 4))
    full = () -> rand(Complex{Int16}, 3, 4)
    check("small abs2", small, abs2)
    check("full abs2", full, abs2)
    check("full re*re", full, x -> real(x) * real(x))
    check("full re*re+im*im", full, x -> real(x) * real(x) + imag(x) * imag(x))
    check("full re*im", full, x -> real(x) * imag(x))
end
main()
small abs2                    0/50
full abs2                     50/50
full re*re                    0/50
full re*re+im*im              49/50
full re*im                    0/50

The kernel's loop body, from @device_code_llvm:

  %.unpack = load i16, ptr addrspace(1) %16, align 2
  %.unpack73 = load i16, ptr addrspace(1) %.elt72, align 2
  %17 = mul i16 %.unpack, %.unpack
  %18 = mul i16 %.unpack73, %.unpack73
  %19 = add i16 %18, %17
  %20 = call i16 @llvm.smax.i16(i16 %19, i16 %value_phi24)

Hand-written @oneapi kernels with the same arithmetic (max over abs2 of Complex{Int16} loaded from a 2D array, with the seed passed as an argument or as a constant) compute the right result, so I couldn't reduce it below AK's kernel yet.

oneAPI 2.9.2 and the GPUArrays 12 port (#665), AcceleratedKernels 0.5.1, Julia 1.12.7 and 1.13.

Lingua principale
Julia
Stelle
217
Fork
37
Merge medio
1g 7h
PR unite (30g)
33

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di JuliaGPU/oneAPI.jl

Tutte le issue di JuliaGPU/oneAPI.jl

Issue simili

Altre issue su Julia

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.