Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Track outstanding GPU work per allocation for host-accessible arrays

オープン
#652 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
45/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
活発
技術スタック
julia
領域
hpc

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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() and global_stream task-local lookup plus a zeCommandListHostSynchronize (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), passing a to a CPU ccall, ...) doesn't synchronize at all. The host↔shared unsafe_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) calls take_ownership!, which records the current stream and sets dirty = true. Switching to a different stream first syncs the previous owner.
  • Converting to a host pointer (convert(Ptr, ::Managed)) calls maybe_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:

  1. Wrap buffers in a small mutable object holding the owning oneStream and a dirty flag (plus a lock), at least for host-accessible buffers.
  2. Set ownership and dirty in unsafe_convert(::Type{ZePtr{T}}, ::oneArray), synchronizing the previous owner when the stream changes.
  3. Call maybe_synchronize in unsafe_convert(::Type{Ptr{T}}, ::oneArray), and drop the explicit synchronization from scalar indexing and from the host↔shared unsafe_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.

主要言語
Julia
スター
217
フォーク
37
平均マージ
18時間 12分
マージ済み PR(30日)
26

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

JuliaGPU/oneAPI.jl のほかの issue

JuliaGPU/oneAPI.jl の issue をすべて見る

似ている issue

Julia の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。