Always-inliner cost grows with call depth: a large body is re-cloned at every single-call wrapper level
メンテナーはふだん 2 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 12/100
- issue の種類
- 機能追加
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 領域
- compilers, performance
調査の方向性
The ask is an algorithmic change to the always-inliner in LLVM's inlining pass as used by DXC, so start by finding where DXC drives the inliner and where CloneAndPruneIntoFromInst/fixupLineNumbers/alias-scope metadata costs come from in the LLVM sources vendored in this repo. Build dxc, generate d0.hlsl/d4.hlsl/d8.hlsl with the provided gen_hlsl.py, and compare -ftime-report for Inliner for always_inline functions across depths to establish the baseline. Done means the single-call-site case stops re-cloning the body at each wrapper level and the depth-4/depth-8 inliner times approach the depth-0 time without changing emitted DXIL.
索引モデルが issue の本文から書いたものです。
説明
Summary
Inliner for always_inline functions dominates compile time for large compute shaders (49-75% of passes;
-ftime-report). -ftime-trace shows the cost is CloneAndPruneIntoFromInst + fixupLineNumbers + alias-scope
metadata for each inlining of an already-large function. Because inlining is bottom-up, a body under N
single-call wrappers is cloned N+1 times. Generated HLSL (Tint, Slang) commonly has 2-4 such levels (kernel
function -> entry _inner shim -> entry).
Measurements (dxcompiler 1.9.2609 from Chrome, -T cs_6_6 /O3 /Gis /Zpr -HV 2018)
Synthetic (generated as Slang -> WGSL -> Tint HLSL in our measurement; the same DXIL in every case): depth 0: 5.6-6.0 s; depth 4: 9.2-9.6 s;
depth 8: 11.5-12.6 s. The body inlined into the entry by hand: 4.2-5.0 s.
Production kernel (1 MB HLSL, 247 KB DXIL): 15.2 s of passes, 7.5 s inliner. Three full-body clones at
0.73-0.82 s each in CloneAndPrune plus ~0.7 s each in metadata/line fixups. Hand-flattening two levels: 15.6 ->
12.3 s.
Ask
Inline a function with a single call site by moving its body, not cloning it (the callee is deleted
afterwards anyway). Or process single-caller chains top-down, so the large body is copied once.
Repro
The script below writes plain HLSL with the same structure (a 1200-block body under DEPTH single-call wrappers):
python gen_hlsl.py 0 d0.hlsl & python gen_hlsl.py 4 d4.hlsl & python gen_hlsl.py 8 d8.hlsl
dxc -T cs_6_6 -E main /O3 /Gis /Zpr -HV 2018 -ftime-report d8.hlsl
Compare the Inliner for always_inline functions time across depths.
gen_hlsl.py
import sys
# gen_hlsl.py DEPTH OUT.hlsl: a large compute body under DEPTH single-call wrapper functions.
depth, out = int(sys.argv[1]), sys.argv[2]
s = ["RWStructuredBuffer<float4> buf : register(u0);",
"float4 h(float4 a, float4 b, uint k) { if ((k & 3u) == 0u) return a * b + 0.5; return a.yzwx - b * 0.25; }",
"float4 body(uint t) {", " float4 a = buf[t]; float4 b = buf[t + 1u];"]
for i in range(1200):
s.append(f" if (a.x > {i * 0.001:.3f}) {{ a = h(a, b, {i}u + t); b = h(b, a, t ^ {i}u); }} else {{ b = h(a, b, t + {i}u); }}")
s += [" return a + b;", "}"]
prev = "body"
for d in range(depth):
s.append(f"float4 w{d}(uint t) {{ return {prev}(t) * 1.0001; }}")
prev = f"w{d}"
s.append(f"[numthreads(64, 1, 1)] void main(uint3 id : SV_DispatchThreadID) {{ buf[id.x] = {prev}(id.x); }}")
open(out, "w").write("\n".join(s) + "\n")
- 主要言語
- C++
- スター
- 3.7k
- フォーク
- 926
- 平均マージ
- 3日 22時間
- マージ済み PR(30日)
- 45
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
microsoft/DirectXShaderCompiler のほかの issue
-
bug needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
microsoft/DirectXShaderCompiler#9173 ·
メンテナーはふだん 2 日以内に返信
-
bug needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
microsoft/DirectXShaderCompiler#9155 · コメント 4 件 ·
メンテナーはふだん 2 日以内に返信
-
bug needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
microsoft/DirectXShaderCompiler#9135 ·
メンテナーはふだん 2 日以内に返信
-
DXC emits DW_LANG_C_plus_plus instead of DW_LANG_HLSL for HLSL対応中かも @rj123-nv が 18 日前に担当しました。 オープンbug needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
microsoft/DirectXShaderCompiler#9087 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
microsoft/DirectXShaderCompiler#9086 ·
メンテナーはふだん 2 日以内に返信
microsoft/DirectXShaderCompiler の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
feature:config kind:docs os:windows toolchain:cmake triaged
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
arch-based bug niri
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
noctalia-dev/noctalia#5552 ·
メンテナーはふだん 1 日以内に返信