Skip to content

static compile prototype [AI generated]#4791

Draft
kahmed10 wants to merge 3 commits intodevelopfrom
static_compile
Draft

static compile prototype [AI generated]#4791
kahmed10 wants to merge 3 commits intodevelopfrom
static_compile

Conversation

@kahmed10
Copy link
Copy Markdown
Collaborator

@kahmed10 kahmed10 commented Apr 15, 2026

Motivation

POC for migraphx driver to compile migraphx statically

Technical Details

to configure, do cmake -DBUILD_SHARED_LIBS=Off ..

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.

Comment thread src/driver/CMakeLists.txt
$<TARGET_FILE:migraphx_ref>
$<TARGET_FILE:migraphx_onnx>
$<TARGET_FILE:migraphx_tf>
-Wl,--no-whole-archive
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why are we needing this? It should work by just linking migraphx_all_targets migraphx_onnx migraphx_tf

Comment thread cmake/Embed.cmake Outdated
generate_embed_source(${EMBED_NAME} ${EMBED_DIR} "${PARSE_RELATIVE}" SYMBOLS ${SYMBOLS} FILES ${PARSE_UNPARSED_ARGUMENTS})
set(INTERNAL_EMBED_LIB embed_lib_${EMBED_NAME})
if(EMBED_USE STREQUAL "LD")
if(EMBED_USE STREQUAL "LD" OR EMBED_USE STREQUAL "CArrays")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

CArrays should not create a static library. It should be an object library so it can be linked into the static library.

Comment thread src/targets/gpu/CMakeLists.txt Outdated
if(BUILD_SHARED_LIBS)
target_link_options(migraphx_gpu PRIVATE "-Wl,--exclude-libs,ALL")
else()
target_compile_options(migraphx_gpu PRIVATE -fvisibility=hidden)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This doesnt make sense. Why are we doing this>

Comment thread CMakeLists.txt Outdated
MIGRAPHX_ONNX_STATIC_DEFINE
MIGRAPHX_TF_STATIC_DEFINE
MIGRAPHX_STATIC_TARGETS
)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why are there so many defines? Also the defines should be added using target_compile_definitions.

Comment thread cmake/Embed.cmake
elseif(EMBED_USE STREQUAL "LD" OR EMBED_USE STREQUAL "CArrays")
target_link_libraries(${EMBED_NAME} INTERFACE ${INTERNAL_EMBED_LIB})
else()
target_sources(${EMBED_NAME} INTERFACE $<TARGET_OBJECTS:${INTERNAL_EMBED_LIB}>)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Dont remove the object library path.

Comment thread src/targets/gpu/CMakeLists.txt Outdated

if(NOT BUILD_SHARED_LIBS)
install(TARGETS embed_lib_migraphx_kernels EXPORT migraphx-targets ARCHIVE DESTINATION lib)
install(TARGETS migraphx_kernels EXPORT migraphx-targets)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Embed libraries should not be installed. They should be added to the static library.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 17, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #4791   +/-   ##
========================================
  Coverage    92.49%   92.49%           
========================================
  Files          583      583           
  Lines        29561    29562    +1     
========================================
+ Hits         27342    27343    +1     
  Misses        2219     2219           
Files with missing lines Coverage Δ
src/register_target.cpp 93.94% <ø> (ø)

... and 19 files with indirect coverage changes

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

Comment thread src/driver/CMakeLists.txt
# Static archives only pull in objects that resolve undefined symbols.
# MIGRAPHX_REGISTER_OP/MIGRAPHX_REGISTER_TARGET use static initializers
# in translation units with no other referenced symbols, so the linker
# drops them without --whole-archive.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ideally, the consumers should not do this. Instead this needs to be added to the INTERFACE. Let me test something out to see if it works.

Comment thread src/onnx/CMakeLists.txt
)

if(NOT BUILD_SHARED_LIBS)
install(TARGETS onnx-proto EXPORT migraphx-targets ARCHIVE DESTINATION lib)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We can make this an object library instead of trying to install this extra lib.

Comment thread src/register_target.cpp
// Load the library without the so_major_version in the name.
store_target_lib(dynamic_loader(target_name));
}
#endif
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I dont think this is needed. Claude is just overthinking this.


if(NOT BUILD_SHARED_LIBS)
set(_SAVED_EMBED_USE ${EMBED_USE})
set(EMBED_USE CArrays)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Remove all this. CArrays is already set when BUILD_SHARED_LIBS=Off.

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