llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[MLIR][CSE] Repeated side-effect scans over overlapping intervals in SDXL CLIP

Open Michael-Chen-NJU opened this issue 2 weeks ago • 1 comments

Problem

While compiling a public SDXL CLIP MLIR input with IREE, CSE repeatedly scans overlapping intervals between equivalent reads.

In hasOtherSideEffectingOpInBetween, the existing cache reuses scan progress for the same fromOp, but does not share effect-query results across different starting operations. Queries with different starting operations can therefore repeatedly inspect overlapping intervals. One captured hotspot performs 2,590,482 intermediate-operation inspections for 695 queries, including repeated recursive effect checks on linalg.generic. Across these queries, the read effects use DefaultResource and have no associated Value.

Reproducer

clip-cse-reproducer.zip

The attachment contains the unchanged enclosing module captured immediately before a CSE invocation on util.func @encode_prompts$async. This intermediate IR requires IREE dialects:

"$IREE_BUILD/tools/iree-opt" clip-cse-fixed.mlir \
  '--pass-pipeline=builtin.module(cse)' -o result.mlir

IREE revision: 5332c68297a68fafd596277d7686f91009ebf1cb
Embedded LLVM: a7dcddcdd7fe0d6bed9f79e0090ac6438b05f794

Replay reproduces the hotspot's query sequence and inspection counts, although its module scope differs from the original function-pass scope. Input hashes and the full compilation command are in the attachment.

Measurements

A block-local interval-summary prototype avoids rescanning intervals proven free of conflicting writes or unknown effects, with the original scan as fallback. For the identified 695-query hotspot, the prototype eliminates the 2,590,482 original interval-scan inspections, while performing 10,658 summary-building classifications. Summary classifications count root operations, not all recursively visited operations.

Release/O3, assertions off, AMD EPYC 9J14. Command timings use uninstrumented binaries; inspection counts come from separate diagnostic runs. Replay results are from the fixed-IR recheck; full-compilation results reuse the earlier seven-pair experiment. Both variants use the same input and build configuration. Each comparison has one warmup per variant followed by seven serial AB/BA pairs. CSE pass timings use a separate seven-pair run with standard --mlir-timing. Medians; changes computed before rounding:

Measurement Baseline Prototype Change
Replay command, including parsing/output 0.6995 s 0.1953 s −72.08%
CSE pass, separate --mlir-timing runs 0.5448 s 0.0382 s −92.99%
Full CLIP compilation 18.055 s 17.839 s −1.20%
Full ResNet50 compilation 4.697 s 4.687 s −0.20%
Full Whisper tiny-en compilation 3.352 s 3.318 s −1.00%

The 72% replay-command reduction is clear; end-to-end improvement is much smaller. Control-workload differences are within noise and do not exclude small regressions.

Full CLIP peak RSS medians increase 358.2→378.8 MiB (+5.75%), not yet fully attributed. Outputs match, and ResNet50 numerical tests pass; CLIP lacks complete numerical reference validation. A standalone upstream-MLIR reduction is not yet available. The prototype demonstrates avoidable work on this input; it is included for discussion rather than proposed as an upstream-ready fix.

Michael-Chen-NJU avatar Nov 17 '26 10:11 Michael-Chen-NJU

@llvm/issue-subscribers-mlir

Author: 陈子昂 (Michael-Chen-NJU)

Problem

While compiling a public SDXL CLIP MLIR input with IREE, CSE repeatedly scans overlapping intervals between equivalent reads.

In hasOtherSideEffectingOpInBetween, the existing cache reuses scan progress for the same fromOp, but does not share effect-query results across different starting operations. Queries with different starting operations can therefore repeatedly inspect overlapping intervals. One captured hotspot performs 2,590,482 intermediate-operation inspections for 695 queries, including repeated recursive effect checks on linalg.generic. Across these queries, the read effects use DefaultResource and have no associated Value.

Reproducer

clip-cse-reproducer-minimal.zip

The attachment contains the unchanged enclosing module captured immediately before a CSE invocation on util.func @<!-- -->encode_prompts$async. This intermediate IR requires IREE dialects:

"$IREE_BUILD/tools/iree-opt" clip-cse-fixed.mlir \
  '--pass-pipeline=builtin.module(cse)' -o result.mlir

IREE revision: 5332c68297a68fafd596277d7686f91009ebf1cb
Embedded LLVM: a7dcddcdd7fe0d6bed9f79e0090ac6438b05f794

Replay reproduces the hotspot's query sequence and inspection counts, although its module scope differs from the original function-pass scope. Input hashes and the full compilation command are in the attachment.

Measurements

A block-local interval-summary prototype avoids rescanning intervals proven free of conflicting writes or unknown effects, with the original scan as fallback. For the identified 695-query hotspot, the prototype eliminates the 2,590,482 original interval-scan inspections, while performing 10,658 summary-building classifications. Summary classifications count root operations, not all recursively visited operations.

Release/O3, assertions off, AMD EPYC 9J14. Command timings use uninstrumented binaries; inspection counts come from separate diagnostic runs. Replay results are from the fixed-IR recheck; full-compilation results reuse the earlier seven-pair experiment. Both variants use the same input and build configuration. Each comparison has one warmup per variant followed by seven serial AB/BA pairs. CSE pass timings use a separate seven-pair run with standard --mlir-timing. Medians; changes computed before rounding:

Measurement Baseline Prototype Change
Replay command, including parsing/output 0.6995 s 0.1953 s −72.08%
CSE pass, separate --mlir-timing runs 0.5448 s 0.0382 s −92.99%
Full CLIP compilation 18.055 s 17.839 s −1.20%
Full ResNet50 compilation 4.697 s 4.687 s −0.20%
Full Whisper tiny-en compilation 3.352 s 3.318 s −1.00%

The 72% replay-command reduction is clear; end-to-end improvement is much smaller. Control-workload differences are within noise and do not exclude small regressions.

Full CLIP peak RSS medians increase 358.2→378.8 MiB (+5.75%), not yet fully attributed. Outputs match, and ResNet50 numerical tests pass; CLIP lacks complete numerical reference validation. A standalone upstream-MLIR reduction is not yet available. The prototype demonstrates avoidable work on this input; it is included for discussion rather than proposed as an upstream-ready fix.