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

Abierto
#9,075 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 2 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
12/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
cpp, python

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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")
Lenguaje dominante
C++
Estrellas
3.7k
Forks
926
Merge medio
3 d 22 h
PR fusionados (30 d)
45

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de microsoft/DirectXShaderCompiler

Todos los issues de microsoft/DirectXShaderCompiler

Issues similares

Más issues de C++

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.