Skip to content

build: pre-build OOM-fragile MLIR objects - #29

Merged
zbeekman merged 1 commit into
mainfrom
build/oom-phase0
Oct 12, 2026
Merged

zbeekman merged 1 commit into
mainfrom
build/oom-phase0

Conversation

@zbeekman

Copy link
Copy Markdown
Member

Problem

Several MLIR dialect objects run out of memory in Phase 1 of the phased LLVM build, on CI (-j4) and locally (-j8). Each one costs a build-llvm.sh retry cycle at reduced parallelism. The LLVM 23 local build needed 9 recoveries in Phase 1.

The MLIR entries in the old -j2 regex did not help: Phase 1 had already built those objects before that phase ran.

Fix

  • Split Phase 1 into LLVM/Clang (LLVM_CLANG_TARGETS) and MLIR (MLIR_TARGETS) phases.
  • Between them, build mlir-headers at full parallelism, then the 13 known OOM-fragile MLIR objects at -j2.
  • The Flang -j2 phase now matches only Flang and FIR object directories.
  • Move the -j2 object selection into a shared build_oom_objects helper.
  • The single-pass build (PHASED_BUILD=false) builds the same targets as before.

Compatibility

--build-arg LLVM_VER still works. The version-specific logic is unchanged, and mlir-headers exists in LLVM 19, 22, and 23. The MLIR regex matches 13 objects on LLVM 22 and 23. The Flang regex matches 175 objects on LLVM 23 and 172 on LLVM 22. A pattern that matches nothing prints a warning and the build continues.

Testing

  • Local LLVM 23 build with salt-8cpu: Phase 2 built 13 MLIR objects and Phase 4 built 175 Flang objects at -j2, and the image exported.
  • The local build and CI both had a warm ccache, so they do not reproduce the cold-build OOM behavior. The memory benefit shows only on a cold build.

- MLIR dialect objects (LLVM, NVVM, ROCDL, SPIRV, Linalg, OpenACC,
  SparseTensor, RegisterAll) ran out of memory in Phase 1 on CI (-j4)
  and locally (-j8), costing a retry cycle each.
- The MLIR entries in the old -j2 regex never matched anything new:
  Phase 1 had already built them before that phase ran.
- Split Phase 1 into LLVM/Clang and MLIR phases. Between them, build
  `mlir-headers` at full parallelism, then the known OOM-fragile MLIR
  objects at -j2. Flang -j2 phase keeps only Flang/FIR dirs.
- Share the -j2 object selection in `build_oom_objects`.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The phase ordering and target selection are consistent with the stated behavior, with no unresolved correctness issues found.

0 open findings

What changed in this PR

Splits the phased LLVM build to pre-build memory-intensive MLIR and Flang objects at reduced parallelism.

Changes:

  • Separates LLVM/Clang and MLIR build phases.
  • Adds a shared helper for building OOM-fragile objects at -j2.
  • Preserves the existing single-pass target set.
File Description
Dockerfile Adds OOM-aware MLIR pre-building and refactors phased target selection.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@zbeekman zbeekman left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM although that is a beast of a regex. We may need to think of a cleaner way to handle that.

@zbeekman

Copy link
Copy Markdown
Member Author

I will try to test this again locally with a cold cache overnight tonight, but I'm not going to let that prevent merging.

@zbeekman
zbeekman merged commit 3f75411 into main Oct 12, 2026
9 checks passed
@zbeekman
zbeekman deleted the build/oom-phase0 branch October 12, 2026 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants