Always-inliner cost grows with call depth: a large body is re-cloned at every single-call wrapper level
Maintainer thường phản hồi trong vòng 2 ngày
Chưa có ai nhận issue nà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
- 12/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Lĩnh vực
- compilers, performance
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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")
- Ngôn ngữ chính
- C++
- Star
- 3.7k
- Fork
- 926
- Merge trung bình
- 3 ngày 22 giờ
- Pull request đã merge (30 ngày)
- 45
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
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 microsoft/DirectXShaderCompiler
-
bug needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
microsoft/DirectXShaderCompiler#9173 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
bug needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
microsoft/DirectXShaderCompiler#9155 · 4 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
bug needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
microsoft/DirectXShaderCompiler#9135 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
DXC emits DW_LANG_C_plus_plus instead of DW_LANG_HLSL for HLSLCó thể đã có người làm @rj123-nv đã nhận 18 ngày trước. Đang mởbug needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
microsoft/DirectXShaderCompiler#9087 ·
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 75/100
microsoft/DirectXShaderCompiler#9086 ·
Maintainer thường phản hồi trong vòng 2 ngày
Tất cả issue của microsoft/DirectXShaderCompiler
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/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
-
feature:config kind:docs os:windows toolchain:cmake triaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
arch-based bug niri
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
noctalia-dev/noctalia#5552 ·
Maintainer thường phản hồi trong vòng 1 ngày