Skip to content

Enable static build of migraphx#4817

Open
pfultz2 wants to merge 9 commits intodevelopfrom
static-lib
Open

Enable static build of migraphx#4817
pfultz2 wants to merge 9 commits intodevelopfrom
static-lib

Conversation

@pfultz2
Copy link
Copy Markdown
Collaborator

@pfultz2 pfultz2 commented Apr 23, 2026

Motivation

Technical Details

Changelog Category

Add a CHANGELOG.md entry for any option other than Not Applicable

    • Added: New functionality.
    • Changed: Changes to existing functionality.
    • Removed: Functionality or support that has been removed. (Compared to a previous release)
    • Optimized: Component performance that has been optimized or improved.
    • Resolved Issues: Known issues from a previous version that have been resolved.
    • Not Applicable: This PR is not to be included in the changelog.

Copilot AI review requested due to automatic review settings April 23, 2026 20:44
@pfultz2 pfultz2 requested a review from causten as a code owner April 23, 2026 20:44
@causten causten requested a review from kahmed10 April 23, 2026 20:46
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

This PR aims to make MIGraphX buildable/usable as a fully static build by adjusting how internal libraries are linked and embedded so that required static initialization and generated sources aren’t dropped by the linker.

Changes:

  • Introduces an enable_static_init() CMake helper to force whole-archive linking semantics for static libraries on major platforms.
  • Switches TF/ONNX protobuf helper libs from STATIC to OBJECT and adjusts how they’re consumed by migraphx_tf/migraphx_onnx.
  • Updates embedding/installation behavior for GPU kernels and enables static-init handling across several component libraries.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
CMakeLists.txt Adds global PIC, defines enable_static_init() for static whole-archive semantics.
src/CMakeLists.txt Applies enable_static_init(migraphx) to preserve static init when building migraphx as static.
src/targets/cpu/CMakeLists.txt Applies enable_static_init(migraphx_cpu) for static builds.
src/targets/gpu/CMakeLists.txt Applies enable_static_init(migraphx_gpu) and updates install target list (now includes migraphx_kernels).
src/onnx/CMakeLists.txt Converts onnx-proto to an OBJECT library; adjusts linking and applies static-init handling for migraphx_onnx.
src/tf/CMakeLists.txt Converts tf-proto to an OBJECT library; adjusts linking and applies static-init handling for migraphx_tf.
cmake/Embed.cmake Adds an extra warning-suppression flag and changes embed include dirs to build-interface-only.

Comment thread CMakeLists.txt Outdated
set(MIGRAPHX_SO_VERSION ${MIGRAPHX_SO_MAJOR_VERSION}.0)

option( BUILD_SHARED_LIBS "Build as a shared library" ON )
option(BUILD_SHARED_LIBS "Build as a shared library" ON )
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

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

BUILD_SHARED_LIBS is declared twice in the top-level CMakeLists (once near the top and again here). Having duplicate option(BUILD_SHARED_LIBS ...) definitions can lead to confusing/help-text mismatches and makes it unclear which one is authoritative; consider keeping a single option() definition and removing the duplicate.

Suggested change
option(BUILD_SHARED_LIBS "Build as a shared library" ON )

Copilot uses AI. Check for mistakes.
Comment thread cmake/Embed.cmake Outdated
endif()
target_include_directories(${INTERNAL_EMBED_LIB} PRIVATE "${EMBED_DIR}/include")
target_compile_options(${INTERNAL_EMBED_LIB} PRIVATE -Wno-reserved-identifier -Wno-extern-initializer -Wno-missing-variable-declarations)
target_compile_options(${INTERNAL_EMBED_LIB} PRIVATE -Wno-reserved-identifier -Wno-extern-initializer -Wno-missing-variable-declarations -Wno-c++11-narrowing)
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

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

-Wno-c++11-narrowing is added unconditionally. This warning flag is compiler-specific (typically Clang) and can produce “unrecognized option” warnings or failures on other toolchains; consider guarding it with a compiler/flag check (e.g., check_cxx_compiler_flag) or applying it only for Clang.

Suggested change
target_compile_options(${INTERNAL_EMBED_LIB} PRIVATE -Wno-reserved-identifier -Wno-extern-initializer -Wno-missing-variable-declarations -Wno-c++11-narrowing)
target_compile_options(${INTERNAL_EMBED_LIB} PRIVATE
-Wno-reserved-identifier
-Wno-extern-initializer
-Wno-missing-variable-declarations
$<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CXX_COMPILER_ID:Clang>>:-Wno-c++11-narrowing>
)

Copilot uses AI. Check for mistakes.
Comment thread src/targets/gpu/CMakeLists.txt Outdated
rocm_install_targets(
PRIVATE
TARGETS migraphx_gpu migraphx_device compile_for_gpu
TARGETS migraphx_gpu migraphx_device compile_for_gpu migraphx_kernels
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

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

migraphx_kernels is an embed-generated INTERFACE target that references build-tree generated sources/headers and an internal target (embed_lib_migraphx_kernels). Adding it to rocm_install_targets() is likely to produce an unusable installed target (or export/install errors) unless the generated headers and the internal embed library are also installed/exported. Consider either removing migraphx_kernels from the install set or making it an installable library (and installing its generated headers).

Suggested change
TARGETS migraphx_gpu migraphx_device compile_for_gpu migraphx_kernels
TARGETS migraphx_gpu migraphx_device compile_for_gpu

Copilot uses AI. Check for mistakes.
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4817      +/-   ##
===========================================
- Coverage    92.49%   92.46%   -0.03%     
===========================================
  Files          583      583              
  Lines        29562    29564       +2     
===========================================
- Hits         27343    27336       -7     
- Misses        2219     2228       +9     

see 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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