Track outstanding GPU work per allocation for host-accessible arrays
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 45/100
Hướng nghiên cứu
Start by tracing oneArray's DataRef and the unsafe_convert methods for ZePtr and Ptr, along with scalar indexing and host↔shared unsafe_copyto! paths. Compare the ownership and synchronization behavior described for CUDA.jl, then add tests for broadcast followed by scalar indexing and for a kernel launched from another task and read from the parent. Done means host access synchronizes only dirty buffers on their owning stream, including cross-task and user-queue work.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Arrays backed by SharedBuffer or HostBuffer can be accessed directly from the CPU, so every host access has to wait for outstanding GPU work on the buffer first. #649 fixes the most visible symptom (sum/maximum returning 0) by unconditionally synchronizing the current task's stream in scalar getindex/setindex!. That is correct for the single-task case, but has a few problems:
- Cost. Every element access now does a
device()andglobal_streamtask-local lookup plus azeCommandListHostSynchronize(and a queue sync if oneMKL was used). A CPU loop over a shared array, which is the main reason to make these arrays host-indexable, turns into a driver call per element. - Other tasks. Only the calling task's stream is synchronized. Work on the buffer submitted from another task, or to a user-created queue, is not waited for.
- Other host accesses. Taking a CPU pointer through
unsafe_convert(Ptr{T}, x)(unsafe_wrap(Array, a), passingato a CPUccall, ...) doesn't synchronize at all. The host↔sharedunsafe_copyto!methods each synchronize explicitly to compensate.
How CUDA.jl does it
CUDA.jl wraps every allocation in a Managed object (CUDACore/src/memory.jl) that records the stream that last used it and whether that use has been synchronized:
- Converting the array to a device pointer (
convert(CuPtr, ::Managed), i.e. every kernel launch or copy) callstake_ownership!, which records the current stream and setsdirty = true. Switching to a different stream first syncs the previous owner. - Converting to a host pointer (
convert(Ptr, ::Managed)) callsmaybe_synchronize, which syncs the owning stream only if the allocation is dirty, and then clears the flag.
Scalar indexing goes through pointer(x, I; type=HostMemory), so it needs no explicit synchronization: the first access after GPU work syncs, later ones cost a lock and a Bool check. Because the owning stream is synchronized rather than the caller's, cross-task use works as well. (There's also a captured flag that forces synchronization for memory used during stream capture, which has no oneAPI equivalent yet.)
What oneAPI.jl would need
oneArray.data is a DataRef around the raw oneL0 buffer, so there's no place to keep this state. Roughly:
- Wrap buffers in a small mutable object holding the owning
oneStreamand adirtyflag (plus a lock), at least for host-accessible buffers. - Set ownership and
dirtyinunsafe_convert(::Type{ZePtr{T}}, ::oneArray), synchronizing the previous owner when the stream changes. - Call
maybe_synchronizeinunsafe_convert(::Type{Ptr{T}}, ::oneArray), and drop the explicit synchronization from scalar indexing and from the host↔sharedunsafe_copyto!methods.
Tests should cover broadcast followed by scalar indexing (not just reductions) and a kernel launched from another task and read from the parent.
Possibly related: #458.
- Ngôn ngữ chính
- Julia
- Star
- 217
- Fork
- 37
- Merge trung bình
- 1 ngày 7 giờ
- Pull request đã merge (30 ngày)
- 45
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/oneAPI.jl
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 74/100
Maintainer thường phản hồi trong vòng 1 ngày
-
libraries upstream
Độ khó 4/5 1-2 ngày Mức phù hợp với người mới 22/100
JuliaGPU/oneAPI.jl#703 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 62/100
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/oneAPI.jl#663 · 1 reaction ·
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 48/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của JuliaGPU/oneAPI.jl
Issue tương tự
-
OptimizationCUTEst jobs fail: gfortran not installed on the runnerCó thể đã có người làm @ChrisRackauckas-Claude đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
SciML/SciMLBenchmarks.jl#1946 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
JuliaSmoothOptimizers/NCL.jl#101 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 69/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
WaterLily-jl/WaterLily.jl#367 ·
Maintainer thường phản hồi trong vòng 1 ngày