Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ endif()

# By default build shared libraries
option(BUILD_SHARED_LIBS "Create shared libraries" ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

option(MIGRAPHX_STRIP_SYMBOLS "Strip symbols in release mode" OFF)

Expand All @@ -97,8 +98,6 @@ rocm_setup_version(VERSION 2.16.0)
math(EXPR MIGRAPHX_SO_MAJOR_VERSION "(${PROJECT_VERSION_MAJOR} * 1000 * 1000) + (${PROJECT_VERSION_MINOR} * 1000) + ${PROJECT_VERSION_PATCH}")
set(MIGRAPHX_SO_VERSION ${MIGRAPHX_SO_MAJOR_VERSION}.0)

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

include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("--cuda-host-only -x hip" HAS_HIP)
if(HAS_HIP)
Expand Down Expand Up @@ -346,6 +345,23 @@ rocm_enable_cppcheck(
include(ROCMCreatePackage)
include(ROCMTest)

function(enable_static_init LIB)
get_target_property(_type ${LIB} TYPE)
if(_type STREQUAL "STATIC_LIBRARY")
if(APPLE)
target_link_options(${LIB} INTERFACE
"LINKER:-force_load,$<TARGET_FILE:${LIB}>")
elseif(MSVC)
target_link_options(${LIB} INTERFACE
"LINKER:/WHOLEARCHIVE:$<TARGET_FILE:${LIB}>")
else()
# GNU ld / LLD / gold
target_link_options(${LIB} INTERFACE
"LINKER:--push-state,--whole-archive,$<TARGET_FILE:${LIB}>,--pop-state")
endif()
endif()
endfunction()

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
Expand Down
29 changes: 20 additions & 9 deletions cmake/Embed.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,19 @@

include_guard(GLOBAL)

if(BUILD_SHARED_LIBS)
set(EMBED_USE_DEFAULT CArrays)
elseif(WIN32)
set(EMBED_USE_DEFAULT RC)
else()
set(EMBED_USE_DEFAULT LD)
endif()

if(WIN32)
set(EMBED_USE RC CACHE STRING "Use RC or CArrays to embed data files")
set(EMBED_USE ${EMBED_USE_DEFAULT} CACHE STRING "Use RC or CArrays to embed data files")
set_property(CACHE EMBED_USE PROPERTY STRINGS "RC;CArrays")
else()
if(BUILD_SHARED_LIBS)
set(EMBED_USE LD CACHE STRING "Use LD or CArrays to embed data files")
else()
set(EMBED_USE CArrays CACHE STRING "Use LD or CArrays to embed data files")
endif()
set(EMBED_USE ${EMBED_USE_DEFAULT} CACHE STRING "Use LD or CArrays to embed data files")
set_property(CACHE EMBED_USE PROPERTY STRINGS "LD;CArrays")
endif()

Expand Down Expand Up @@ -216,7 +220,7 @@ function(embed_file FILE BASE_DIRECTORY)
# wraps the hex string into multiple lines
embed_wrap_string(VARIABLE HEX_STRING AT_COLUMN 80)
# adds '0x' prefix and comma suffix before and after every byte respectively
string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1, " ARRAY_VALUES ${HEX_STRING})
string(REGEX REPLACE "([0-9a-f][0-9a-f])" "static_cast<char>(0x\\1), " ARRAY_VALUES ${HEX_STRING})
# removes trailing comma
string(REGEX REPLACE ", $" "" ARRAY_VALUES ${ARRAY_VALUES})
file(WRITE "${OUTPUT_FILE}" "
Expand Down Expand Up @@ -258,7 +262,14 @@ function(add_embed_library EMBED_NAME)
target_sources(${INTERNAL_EMBED_LIB} PRIVATE ${OUTPUT_FILES})
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)
# Disable extra warnings
foreach(COMPILER_WARNING -Wno-reserved-identifier -Wno-extern-initializer -Wno-missing-variable-declarations)
string(MAKE_C_IDENTIFIER "HAS_CXX_FLAG${COMPILER_WARNING}" HAS_COMPILER_WARNING)
check_cxx_compiler_flag(${COMPILER_WARNING} ${HAS_COMPILER_WARNING})
if(${HAS_COMPILER_WARNING})
target_compile_options(${INTERNAL_EMBED_LIB} PRIVATE ${COMPILER_WARNING})
endif()
endforeach()
set_target_properties(${INTERNAL_EMBED_LIB} PROPERTIES POSITION_INDEPENDENT_CODE On)
add_library(${EMBED_NAME} INTERFACE)
if(EMBED_USE STREQUAL "RC")
Expand All @@ -268,6 +279,6 @@ function(add_embed_library EMBED_NAME)
else()
target_sources(${EMBED_NAME} INTERFACE $<TARGET_OBJECTS:${INTERNAL_EMBED_LIB}>)
endif()
target_include_directories(${EMBED_NAME} INTERFACE "${EMBED_DIR}/include")
target_include_directories(${EMBED_NAME} INTERFACE "$<BUILD_INTERFACE:${EMBED_DIR}/include>")
endfunction()

2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ add_library(migraphx
verify_args.cpp
)

enable_static_init(migraphx)

file(GLOB BUILDER_SRCS CONFIGURE_DEPENDS op/builder/*.cpp)
target_sources(migraphx PRIVATE ${BUILDER_SRCS})

Expand Down
9 changes: 5 additions & 4 deletions src/onnx/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#####################################################################################
# The MIT License (MIT)
#
# Copyright (c) 2015-2025 Advanced Micro Devices, Inc. All rights reserved.
# Copyright (c) 2015-2026 Advanced Micro Devices, Inc. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand All @@ -24,15 +24,15 @@
find_package(protobuf QUIET CONFIG)

if(protobuf_FOUND)
add_library(onnx-proto STATIC)
add_library(onnx-proto OBJECT)
protobuf_generate(TARGET onnx-proto PROTOS onnx.proto)
target_include_directories(onnx-proto SYSTEM PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${PROTOBUF_INCLUDE_DIR})
target_link_libraries(onnx-proto PRIVATE ${PROTOBUF_LIBRARY})
target_link_libraries(onnx-proto PRIVATE protobuf::libprotobuf)
else()
find_package(Protobuf REQUIRED)
protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS onnx.proto)
add_library(onnx-proto STATIC ${PROTO_SRCS})
add_library(onnx-proto OBJECT ${PROTO_SRCS})
target_include_directories(onnx-proto SYSTEM PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${PROTOBUF_INCLUDE_DIR})
target_link_libraries(onnx-proto PRIVATE ${PROTOBUF_LIBRARY})
endif()
Expand All @@ -51,11 +51,12 @@ set_target_properties(migraphx_onnx PROPERTIES EXPORT_NAME onnx)
migraphx_generate_export_header(migraphx_onnx)
rocm_set_soversion(migraphx_onnx ${MIGRAPHX_SO_VERSION})
rocm_clang_tidy_check(migraphx_onnx)
target_link_libraries(migraphx_onnx PRIVATE onnx-proto)
target_link_libraries(migraphx_onnx PRIVATE $<BUILD_INTERFACE:onnx-proto>)
if(NOT WIN32)
target_link_libraries(migraphx_onnx PRIVATE "-Wl,--exclude-libs,ALL")
endif()
target_link_libraries(migraphx_onnx PUBLIC migraphx)
enable_static_init(migraphx_onnx)

rocm_install_targets(
PRIVATE
Expand Down
3 changes: 2 additions & 1 deletion src/targets/cpu/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#####################################################################################
# The MIT License (MIT)
#
# Copyright (c) 2015-2024 Advanced Micro Devices, Inc. All rights reserved.
# Copyright (c) 2015-2026 Advanced Micro Devices, Inc. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -53,6 +53,7 @@ add_library(migraphx_cpu
target.cpp
write_literals.cpp
)
enable_static_init(migraphx_cpu)
set_target_properties(migraphx_cpu PROPERTIES EXPORT_NAME cpu)
rocm_set_soversion(migraphx_cpu ${MIGRAPHX_SO_VERSION})

Expand Down
4 changes: 3 additions & 1 deletion src/targets/gpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ add_library(migraphx_gpu
${MIOPEN_SRCS}
)

enable_static_init(migraphx_gpu)

set_target_properties(migraphx_gpu PROPERTIES EXPORT_NAME gpu)
migraphx_generate_export_header(migraphx_gpu)

Expand Down Expand Up @@ -390,7 +392,7 @@ if(NOT MIGRAPHX_USE_MIOPEN AND NOT MIGRAPHX_USE_ROCBLAS)
else()
target_link_libraries(migraphx_gpu PRIVATE migraphx_device)
endif()
target_link_libraries(migraphx_gpu PRIVATE migraphx_kernels)
target_link_libraries(migraphx_gpu PRIVATE $<BUILD_INTERFACE:migraphx_kernels>)

# Link HSA runtime for chiplet query (Linux only)
if(NOT WIN32)
Expand Down
9 changes: 5 additions & 4 deletions src/tf/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#####################################################################################
# The MIT License (MIT)
#
# Copyright (c) 2015-2025 Advanced Micro Devices, Inc. All rights reserved.
# Copyright (c) 2015-2026 Advanced Micro Devices, Inc. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand All @@ -24,7 +24,7 @@
find_package(protobuf QUIET CONFIG)

if(protobuf_FOUND)
add_library(tf-proto STATIC ${PROTO_SRCS})
add_library(tf-proto OBJECT ${PROTO_SRCS})
protobuf_generate(
TARGET tf-proto
PROTOS
Expand Down Expand Up @@ -57,7 +57,7 @@ else()
op_def.proto
versions.proto
)
add_library(tf-proto STATIC ${PROTO_SRCS})
add_library(tf-proto OBJECT ${PROTO_SRCS})
target_include_directories(tf-proto SYSTEM PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${PROTOBUF_INCLUDE_DIR})
target_link_libraries(tf-proto PRIVATE ${PROTOBUF_LIBRARY})
endif()
Expand All @@ -76,11 +76,12 @@ target_include_directories(migraphx_tf PRIVATE include)
set_target_properties(migraphx_tf PROPERTIES EXPORT_NAME tf)
rocm_set_soversion(migraphx_tf ${MIGRAPHX_SO_VERSION})
rocm_clang_tidy_check(migraphx_tf)
target_link_libraries(migraphx_tf PRIVATE tf-proto)
target_link_libraries(migraphx_tf PRIVATE $<BUILD_INTERFACE:tf-proto>)
if(NOT WIN32)
target_link_libraries(migraphx_tf PRIVATE "-Wl,--exclude-libs,ALL")
endif()
target_link_libraries(migraphx_tf PUBLIC migraphx)
enable_static_init(migraphx_tf)

rocm_install_targets(
PRIVATE
Expand Down
Loading