Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Wrong results for overflowing Int16 arithmetic in a reduction kernel

Đang mở
#670 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@maleadt đang làm issue này rồi.

Từ ngày 8/10/2026.

  • #674 của @maleadt — đang mở

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
45/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
julia
Lĩnh vực
backend

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Julia
Star
217
Fork
37
Merge trung bình
18 giờ 12 phút
Pull request đã merge (30 ngày)
26

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của JuliaGPU/oneAPI.jl

Tất cả issue của JuliaGPU/oneAPI.jl

Issue tương tự

Thêm issue về Julia

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.