methodinstance re-specializes on every lookup when the dispatch cache holds a widened method instance
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
The issue points to src/jlgen.jl where methodinstance calls specialize_method on every lookup. First read that file and the dispatch cache handling to understand how widened method instances are stored. Implement a cache for the specialized method instance keyed on the widened one, then verify with the benchmark snippet in the issue that lookup time drops to ~350 ns. Done when k_passes shows similar latency to k_typed.
索引モデルが issue の本文から書いたものです。
説明
When a kernel only passes a function argument on, Julia doesn't specialize on it, and the method instance in its dispatch cache has widened specTypes. methodinstance then calls specialize_method on every lookup to get the concrete one (src/jlgen.jl), which costs about 200 ns per launch:
using CUDACore
@noinline apply(f, x) = f(x)
function k_passes(f, a) # `f` only passed on: specialized as `Function`
i = threadIdx().x
@inbounds a[i] = apply(f, a[i])
return
end
function k_typed(f::F, a) where {F}
i = threadIdx().x
@inbounds a[i] = apply(f, a[i])
return
end
a = CuArray(zeros(Float32, 32))
for (name, k) in (("passes", k_passes), ("typed", k_typed))
@cuda launch=false k(sin, a)
lookup() = cufunction(k, Tuple{typeof(sin), typeof(cudaconvert(a))})
lookup()
t = minimum(begin t0 = time_ns(); for _ in 1:100_000; lookup(); end; (time_ns() - t0) / 100_000 end for _ in 1:10)
println(name, ": ", round(t), " ns")
end
passes: 555.0 ns
typed: 351.0 ns
(CUDACore 6.4.2, Julia 1.12.) AcceleratedKernels.jl hit this in nine reduction kernels and its merge sorts, where it was 2-6% of the time of a small reduction; it now spells out the argument types. Caching the specialized method instance, e.g. keyed on the widened one, would avoid it for everyone.
- 主要言語
- Julia
- スター
- 190
- フォーク
- 72
- 平均マージ
- 16時間 57分
- マージ済み PR(30日)
- 40
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
JuliaGPU/GPUCompiler.jl のほかの issue
-
spirv
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
JuliaGPU/GPUCompiler.jl#1008 ·
メンテナーはふだん 1 日以内に返信
-
SPIR-V runtime library fails to build on 32-bit hosts: `unbox_int64` returns void対応中かも @maleadt が 16 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
JuliaGPU/GPUCompiler.jl#1085 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
JuliaGPU/GPUCompiler.jl#1074 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
JuliaGPU/GPUCompiler.jl#1069 ·
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
JuliaGPU/GPUCompiler.jl#1050 ·
メンテナーはふだん 1 日以内に返信
JuliaGPU/GPUCompiler.jl の issue をすべて見る
似ている issue
-
documentation priority: high
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
epiforecasts/BVDOutbreakSize#1260 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
TuringLang/Turing.jl#2917 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
-
Validate UserDemand return_factor対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
メンテナーはふだん 2 日以内に返信