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
13 changes: 12 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ endif()
list(APPEND CMAKE_PREFIX_PATH /opt/rocm /opt/rocm/llvm $ENV{ROCM_PATH} $ENV{HIP_PATH})
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

cmake_policy(SET CMP0091 NEW)

project(migraphx LANGUAGES C CXX)
include(CTest)

Expand All @@ -58,6 +60,16 @@ detect_package_backend()
find_package(ROCmCMakeBuildTools REQUIRED)
find_package(Threads REQUIRED)

include(CMakeDependentOption)

cmake_dependent_option(MIGRAPHX_MSVC_STATIC_RUNTIME "" OFF "WIN32" OFF)

if(NOT MIGRAPHX_MSVC_STATIC_RUNTIME)
set(MIGRAPHX_MSVC_RUNTIME_SUFFIX "DLL")
endif()

set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>${MIGRAPHX_MSVC_RUNTIME_SUFFIX}")
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 should be a cached variable.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Collaborator Author

@apwojcik apwojcik May 12, 2026

Choose a reason for hiding this comment

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

For command-line usage, the PR defines the MIGRAPHX_MSVC_STATIC_RUNTIME cached variable instead. Similar to other 3rd-party projects (i.e., protobuf_MSVC_STATIC_RUNTIME, ONNX_MSVC_STATIC_RUNTIME, ABSL_MSVC_STATIC_RUNTIME, etc.) that control the value of the CMAKE_MSVC_RUNTIME_LIBRARY variable accordingly.

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.

The CMAKE_MSVC_RUNTIME_LIBRARY variable is a CMake variable and not a cache variable. Please see its documentation and usage example here: https://cmake.org/cmake/help/latest/variable/CMAKE_MSVC_RUNTIME_LIBRARY.html

Thats not the way cmake variables work. Its a cached variable when the user sets from the command-line or in the toolchain or superproject.

Please see how it is being used, for example, by protobuf, abseil-cpp, boost, and more

Ok so abseil and protobuf dont set it correctly. Its completely broken when users set CMAKE_MSVC_RUNTIME_LIBRARY either in the toolchain or from the command-line.

Boost does set it correctly and we can follow what they did. Instead of a cache variable, we need to check if(NOT CMAKE_MSVC_RUNTIME_LIBRARY) before setting this flag.

For command-line usage, the PR defines the MIGRAPHX_MSVC_STATIC_RUNTIME cached variable instead.

Users should be able to use standard cmake variables instead of trying to figure out the custom flags for each project. Especially for something like this where it needs to be the same across all projects.

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.

Suggested change
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>${MIGRAPHX_MSVC_RUNTIME_SUFFIX}")
if(NOT CMAKE_MSVC_RUNTIME_LIBRARY)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>${MIGRAPHX_MSVC_RUNTIME_SUFFIX}")
endif()


if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
option(MIGRAPHX_USE_BINSKIM_COMPLIANT_COMPILE_FLAGS "Prepare MIGraphX for BinSkim Binary Analyzer" OFF)
option(MIGRAPHX_USE_SPECTRE_MITIGATED_LIBRARIES "Use Spectre-mitigated libraries" OFF)
Expand Down Expand Up @@ -94,7 +106,6 @@ endif()

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

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

# Strip symbols for release
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# THE SOFTWARE.
#####################################################################################
abseil/abseil-cpp@20250512.0 -DABSL_ENABLE_INSTALL=ON -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DABSL_MSVC_STATIC_RUNTIME=Off
google/protobuf@v30.0 -DCMAKE_POSITION_INDEPENDENT_CODE=On -Dprotobuf_BUILD_TESTS=Off -Dprotobuf_MSVC_STATIC_RUNTIME=Off -DCMAKE_POLICY_VERSION_MINIMUM=3.5
google/protobuf@v30.0 -DCMAKE_POSITION_INDEPENDENT_CODE=On -Dprotobuf_BUILD_TESTS=Off -Dprotobuf_BUILD_SHARED_LIBS=Off -Dprotobuf_MSVC_STATIC_RUNTIME=Off -Dprotobuf_BUILD_LIBPROTOC=On -Dprotobuf_BUILD_PROTOC_BINARIES=On -Dprotobuf_BUILD_PROTOBUF_BINARIES=On -DCMAKE_POLICY_VERSION_MINIMUM=3.5
nlohmann/json@v3.8.0 -DCMAKE_POLICY_VERSION_MINIMUM=3.5
pybind/pybind11@3e9dfa2866941655c56877882565e7577de6fc7b --build
msgpack/msgpack-c@cpp-3.3.0 -DMSGPACK_BUILD_TESTS=Off -DMSGPACK_BUILD_EXAMPLES=Off -DCMAKE_POLICY_VERSION_MINIMUM=3.5
Expand Down
18 changes: 10 additions & 8 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ add_library(migraphx
rewrite_dot.cpp
simplify_qdq.cpp
split_reduce.cpp
sqlite.cpp
rewrite_gelu.cpp
rewrite_low_precision.cpp
rewrite_pooling.cpp
Expand All @@ -150,15 +149,16 @@ add_library(migraphx
verify_args.cpp
)

if(MIGRAPHX_USE_MIOPEN)
target_sources(migraphx PRIVATE sqlite.cpp)
endif()

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

if(WIN32)
# Due to compilation crashing, we need to use type-erased matchers on Windows.
target_compile_definitions(migraphx PUBLIC MIGRAPHX_USE_TYPE_ERASED_MATCHERS=1)
target_compile_options(migraphx PUBLIC "-mno-ms-bitfields")
# Due to BinSkim errors EnableControlFlowGuard
target_compile_options(migraphx PUBLIC "SHELL:-Xclang -cfguard")
endif()

configure_file(version.h.in include/migraphx/version.h)
Expand Down Expand Up @@ -349,7 +349,7 @@ endif()
target_link_libraries(migraphx PUBLIC Threads::Threads)

if(MIGRAPHX_USE_EIGEN)
find_package(Eigen3)
find_package(Eigen3 QUIET)
if(Eigen3_FOUND)
target_compile_definitions(migraphx PUBLIC MIGRAPHX_USE_EIGEN=1)
target_compile_definitions(migraphx PRIVATE EIGEN_MPL2_ONLY)
Expand Down Expand Up @@ -378,12 +378,14 @@ endif()
find_package(nlohmann_json 3.8.0 REQUIRED)
target_link_libraries(migraphx PRIVATE nlohmann_json::nlohmann_json)

find_package(SQLite3 REQUIRED)
target_link_libraries(migraphx PRIVATE SQLite::SQLite3)
if(MIGRAPHX_USE_MIOPEN)
find_package(SQLite3 REQUIRED)
target_link_libraries(migraphx PRIVATE SQLite::SQLite3)
endif()

# See: https://github.com/msgpack/msgpack-c/wiki/Q%26A#how-to-support-both-msgpack-c-c-version-5x-and-6x-
# Prefer 6.x (msgpack-cxx)
find_package(msgpack-cxx)
find_package(msgpack-cxx QUIET)
if(msgpack-cxx_FOUND)
message(STATUS "Found msgpack-cxx (>=6.x)")
else()
Expand Down
9 changes: 4 additions & 5 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 @@ -26,15 +26,14 @@ find_package(protobuf QUIET CONFIG)
if(protobuf_FOUND)
add_library(onnx-proto STATIC)
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)
target_include_directories(onnx-proto SYSTEM PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(onnx-proto PUBLIC protobuf::libprotobuf)
else()
find_package(Protobuf REQUIRED)
protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS onnx.proto)
add_library(onnx-proto STATIC ${PROTO_SRCS})
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 PUBLIC ${PROTOBUF_LIBRARY})
endif()

if(MSVC)
Expand Down
4 changes: 3 additions & 1 deletion src/targets/fpga/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 @@ -35,6 +35,8 @@ rocm_set_soversion(migraphx_fpga ${MIGRAPHX_SO_VERSION})
rocm_clang_tidy_check(migraphx_fpga)
target_link_libraries(migraphx_fpga migraphx)

migraphx_generate_export_header(migraphx_fpga)

rocm_install_targets(
PRIVATE
TARGETS migraphx_fpga
Expand Down
13 changes: 7 additions & 6 deletions src/targets/gpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,6 @@ if(NOT MIGRAPHX_USE_COMPOSABLEKERNEL)
${CMAKE_CURRENT_SOURCE_DIR}/jit/ck_gemm_softmax_gemm.cpp)
endif()

if(MIGRAPHX_USE_MIOPEN)
set(MIOPEN_SRCS abs.cpp)
endif()

add_library(migraphx_gpu
analyze_streams.cpp
allocation_model.cpp
Expand Down Expand Up @@ -184,7 +180,6 @@ add_library(migraphx_gpu
prefuse_ops.cpp
prepare_mlir.cpp
prepare_reduce.cpp
perfdb.cpp
pooling.cpp
problem_cache.cpp
rocblas.cpp
Expand All @@ -195,9 +190,15 @@ add_library(migraphx_gpu
topk.cpp
write_literals.cpp
${JIT_GPU_SRCS}
${MIOPEN_SRCS}
)

if(MIGRAPHX_USE_MIOPEN)
target_sources(migraphx_gpu
PRIVATE
abs.cpp
perfdb.cpp)
endif()

set_target_properties(migraphx_gpu PROPERTIES EXPORT_NAME gpu)
migraphx_generate_export_header(migraphx_gpu)

Expand Down
10 changes: 4 additions & 6 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 @@ -27,7 +27,7 @@ if(protobuf_FOUND)
add_library(tf-proto STATIC ${PROTO_SRCS})
protobuf_generate(
TARGET tf-proto
PROTOS
PROTOS
graph.proto
node_def.proto
attr_value.proto
Expand All @@ -39,9 +39,8 @@ if(protobuf_FOUND)
op_def.proto
versions.proto
)
target_include_directories(tf-proto SYSTEM PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${PROTOBUF_INCLUDE_DIR})
target_link_libraries(tf-proto PRIVATE ${PROTOBUF_LIBRARY})
target_link_libraries(tf-proto PRIVATE protobuf::libprotobuf)
target_include_directories(tf-proto SYSTEM PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(tf-proto PUBLIC protobuf::libprotobuf)
else()
find_package(Protobuf REQUIRED)
protobuf_generate_cpp(
Expand Down Expand Up @@ -86,4 +85,3 @@ rocm_install_targets(
PRIVATE
TARGETS migraphx_tf
)

Loading