`lower_throw!` treats any function whose name contains `jl_error` etc. as a throw (kernel becomes a trap / segfault)
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 75/100
Hướng nghiên cứu
Bắt đầu với lower_throw! trong src/irgen.jl, khoảng dòng 180–198, và các helper kiểm thử PTX được nêu trong issue. Kiểm tra cách so khớp tên hàm xử lý khai báo so với các hàm có thân, sau đó thêm một kiểm thử hồi quy dùng reproducer handle_jl_error đã được báo cáo. Công việc hoàn tất khi lời gọi hàm thông thường và store vẫn còn trong LLVM được tạo ra, trong khi các hàm throw thực sự vẫn được hạ thành báo cáo ngoại lệ và trap.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
lower_throw! picks the throw functions with a substring match on the name:
https://github.com/JuliaGPU/GPUCompiler.jl/blob/6c73a0ec7d0ac2a931e215f4954ce2373e72187e/src/irgen.jl#L180-L198
so a normal Julia function whose name contains jl_error, jl_throw, jl_bounds_error etc. is treated as a throw too: its calls get erased and replaced by an exception report + trap. on PTX the kernel just becomes a trap, and on Metal it segfaults during compilation.
i came across this while going through lower_throw! with claude, not by hitting it in real code, so it's a corner case. the Metal crash made it seem worth fixing though.
repro on PTX (no GPU needed, uses the test helpers; run from a GPUCompiler checkout with julia --project):
using GPUCompiler, LLVM
include("test/helpers/runtime.jl"); include("test/helpers/ptx.jl")
@noinline handle_ok(x::Int) = x > 0 ? x + 1 : x - 1
@noinline handle_jl_error(x::Int) = x > 0 ? x + 1 : x - 1 # same body, only the name differs
k_ok(p::Ptr{Int}, x::Int) = (unsafe_store!(p, handle_ok(x)); nothing)
k_bad(p::Ptr{Int}, x::Int) = (unsafe_store!(p, handle_jl_error(x)); nothing)
PTX.code_llvm(stdout, k_ok, Tuple{Ptr{Int},Int}; dump_module=true)
PTX.code_llvm(stdout, k_bad, Tuple{Ptr{Int},Int}; dump_module=true)
k_ok keeps the call and the store:
%0 = call fastcc i64 @julia_handle_ok_1536(i64 signext %"x::Int64")
store i64 %0, ptr %"p::Ptr", align 1
ret void
k_bad only has the trap left:
call fastcc void @gpu_report_exception()
call fastcc void @gpu_signal_exception()
call void @llvm.trap()
unreachable
on Metal (1.12.0) the same thing crashes Julia:
using Metal
@noinline handle_ok(x::Int) = x > 0 ? x + 1 : x - 1
@noinline handle_jl_error(x::Int) = x > 0 ? x + 1 : x - 1
k_ok(a, x) = (a[1] = handle_ok(x); nothing)
k_bad(a, x) = (a[1] = handle_jl_error(x); nothing)
a = Metal.zeros(Int, 1)
@metal k_ok(a, 5); Array(a)[1] # 6
@metal k_bad(a, 5) # signal 11
the segfault is in llvm::Value::getContext while cloning a StoreInst. probably because the call is erased without replacing its uses, so the store ends up pointing at a deleted value.
the real throw functions are always declarations, so skipping functions that have a body (isdeclaration(f) || continue) fixes it and keeps the name matching as is. i'll open a PR with that and a test.
versions
Julia Version 1.13.3
Commit 67ac47b9cd8 (2026-10-25 15:28 UTC)
Platform Info:
OS: macOS (arm64-apple-darwin27.0.0)
CPU: 10 × Apple M5
LLVM: libLLVM-20.1.8 (ORCJIT, apple-m1)
GPUCompiler v2.22.2 (main, 6c73a0e)
LLVM.jl v10.4.3
Metal.jl v1.12.0 (crashes with the registered GPUCompiler v2.22.2 and v2.22.0)
- Ngôn ngữ chính
- Julia
- Star
- 191
- Fork
- 73
- Merge trung bình
- 17 giờ 5 phút
- Pull request đã merge (30 ngày)
- 43
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
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của JuliaGPU/GPUCompiler.jl
-
spirv
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
JuliaGPU/GPUCompiler.jl#1008 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
SPIR-V runtime library fails to build on 32-bit hosts: `unbox_int64` returns voidCó thể đã có người làm @maleadt đã nhận 18 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
JuliaGPU/GPUCompiler.jl#1085 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
JuliaGPU/GPUCompiler.jl#1074 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
JuliaGPU/GPUCompiler.jl#1060 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
JuliaGPU/GPUCompiler.jl#1050 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của JuliaGPU/GPUCompiler.jl
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
MagneticResonanceImaging/MRIReco.jl#366 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
`AdamW` gives `NaN` for zero-gradient entries of `Float16` parameters (epsilon underflows to 0)Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/100
FluxML/Optimisers.jl#253 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
JuliaGraphs/GraphNeuralNetworks.jl#736 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Maintainer thường phản hồi trong vòng 1 ngày
-
`poissonians` is not public, unlike `brownians` and `jumps`Có thể đã có người làm @isaacsas đã nhận hôm nay. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 86/100
SciML/ModelingToolkit.jl#5389 ·
Maintainer thường phản hồi trong vòng 2 ngày