Always-inliner cost grows with call depth: a large body is re-cloned at every single-call wrapper level

Đang mở
#9,075 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

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
Công nghệ
cpp, python
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

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của microsoft/DirectXShaderCompiler

Tất cả issue của microsoft/DirectXShaderCompiler

Issue tương tự

Thêm issue về C++

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.