Skip to content

Adds the ability to build static archives in addition to shared objects #2179

Open
Micky774 wants to merge 5 commits intomainfrom
zain/archive
Open

Adds the ability to build static archives in addition to shared objects #2179
Micky774 wants to merge 5 commits intomainfrom
zain/archive

Conversation

@Micky774
Copy link
Copy Markdown
Contributor

@Micky774 Micky774 commented Mar 4, 2026

Motivation

TE currently relies on libmha_{b, f}wd.so to provide AITER symbols at runtime, however if other projects (e.g. pytorch) also build the AITER library, but of a different version, then loading the same symbols can create conflict. To avoid this, we at TE would like to be able to generate static archives as part of the build triggered through aiter/op_tests/cpp/mha/compile.py.

Technical Details

Gated by a new environment variable AITER_BUILD_STATIC, there is now a new rule inserted which will build libmha_*wd.a using AITER_AR_BIN (set to ar by default). Backwards compatibility is ensured by AITER_BUILD_STATIC being defaulted to 0.

Test Plan

Run aiter/op_tests/cpp/mha/compile.py and validate that the expected artifacts are produced.

Test Result

Submission Checklist

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds an opt-in build path to produce static archives for the MHA forward/backward test libraries to avoid runtime symbol conflicts when multiple AITER versions are present.

Changes:

  • Adds an ar tool variable to the generated Ninja config (overridable via AITER_AR_BIN).
  • When AITER_BUILD_STATIC=1 and the output is libmha_fwd.so / libmha_bwd.so, emits a corresponding libmha_*wd.a archive build rule and includes it in Ninja defaults.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread aiter/jit/utils/cpp_extension.py Outdated
Comment on lines +1740 to +1744
archive_rule = ["rule archive"]
archive_rule.append(
" command = rm -f $out && $ar rcs $out @$out.rsp\n rspfile = $out.rsp\n rspfile_content = $in"
)

Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

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

archive_rule is defined unconditionally here but then always either overwritten with the same contents in the emit_static_archive branch or replaced with [] in the else branch, so this initial definition is dead code. Consider defining archive_rule only inside the emit_static_archive branch (and otherwise leaving it empty) to avoid duplication and reduce confusion.

Suggested change
archive_rule = ["rule archive"]
archive_rule.append(
" command = rm -f $out && $ar rcs $out @$out.rsp\n rspfile = $out.rsp\n rspfile_content = $in"
)

Copilot uses AI. Check for mistakes.
ldflags = ([] if is_standalone else [SHARED_FLAG]) + extra_ldflags

ext = EXEC_EXT if is_standalone else LIB_EXT
library_target = f"{name}{ext}"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can we detect whether it's .a or .so based on the library target ext?

Comment thread aiter/jit/utils/cpp_extension.py Outdated
emit_static_archive = (
library_target is not None
and os.environ.get("AITER_BUILD_STATIC", "0") == "1"
and os.path.basename(library_target) in {"libmha_fwd.so", "libmha_bwd.so"}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Probably we can add some argument/option and pass the library_target down from compile.py in op_tests/cpp/mha as libmha_fwd/bwd.a instead of libmha_fwd/bwd.so?

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.

3 participants