Option to link MIGraphX to MVSC Runtime Library statically or dynamically#4839
Option to link MIGraphX to MVSC Runtime Library statically or dynamically#4839apwojcik wants to merge 24 commits into
Conversation
|
I think you are doing something wrong. The dependencies in requirements.txt build with rbuild using clang-cl, and it doesnt need |
I dont think we even use the |
We use clang to compile, and the change is for the clang compiler (not clang-cl). With clang-cl, the MIGraphX compiles with no warnings. We will perform additional testing on binaries built with clang-cl and consider switching the compiler. |
Either way this change should go into protobuf. MIGraphX shouldn't be monkey patching it. |
| set_target_properties(${target} PROPERTIES | ||
| MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>${__suffix}") | ||
| unset(__suffix) | ||
| endfunction() No newline at end of file |
There was a problem hiding this comment.
Are you trying to build migraphx with clang-cl as well?
I dont think we need to do this in here. These seem like toochain variables and can be set with -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded$<$<CONFIG:Debug>:Debug>DLL -DCMAKE_CXX_FLAGS_DEBUG=/D _DEBUG /D _ITERATOR_DEBUG_LEVEL=2
There was a problem hiding this comment.
Are you trying to build migraphx with clang-cl as well?
I dont think we need to do this in here. These seem like toochain variables and can be set with
-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded$<$<CONFIG:Debug>:Debug>DLL -DCMAKE_CXX_FLAGS_DEBUG=/D _DEBUG /D _ITERATOR_DEBUG_LEVEL=2
Yes, we switch the compiler to clang-cl. After upgrading to protobuf v30, we need to set that information manually. Otherwise, there are mismatches between the runtime libraries used by MIGraphX and the protobuf-generated libraries. For some reason, the new protoc is not propagating the runtime library and setting _DEBUG and the iterator level correctly.
We do not use a toolchain file for the compiler. As I mentioned in the updated description, we need to switch the entire MIGraphX to the statically linked MSVC runtime soon. We want to change the runtime library linking with a single CMake option. We don't want to set it globally, only for the targets that require it. The function does what we require.
There was a problem hiding this comment.
For some reason, the new protoc is not propagating the runtime library
It should propagate the runtime library fine. I set something like this in the toolchain: -Dprotobuf_MSVC_STATIC_RUNTIME=Off -DABSL_MSVC_STATIC_RUNTIME=Off -DCMAKE_POLICY_DEFAULT_CMP0091=NEW -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDLL. I dont know if all those flags are needed but I was able to build and run the tests for onnx and tf on windows with thos defined in the toolchain.
and setting _DEBUG and the iterator level correctly.
Are you saying the protoc doesnt have these flags set? That seems like a toolchain mismatch, but maybe protobuf edits the CMAKE_CXX_FLAGS(thats the reason for CMP0091).
We do not use a toolchain file for the compiler.
If you are using cget(or rbuild) you are using a toolchain file. And you can set flags in it with cget init -Dprotobuf_MSVC_STATIC_RUNTIME=Off -DABSL_MSVC_STATIC_RUNTIME=Off -DCMAKE_POLICY_DEFAULT_CMP0091=NEW -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDLL.(I do see cget being used on the windows CI). You can also set those in rbuild session with global_defines.
We want to change the runtime library linking with a single CMake option.
Yes thats what the CMAKE_MSVC_RUNTIME_LIBRARY option does in cmake. We should use the standard options provided by cmake.
We don't want to set it globally
Why? Wont that cause issues with some targets built with different runtimes? Everything should be built with the same runtime.
There was a problem hiding this comment.
I used the wrong depend folder for testing. When I switched to the correct one, I no longer needed the recent changes I had made. I reverted them. Thanks for noticing!
| file(GLOB TESTS CONFIGURE_DEPENDS *.cpp) | ||
| list(REMOVE_ITEM TESTS ${CMAKE_CURRENT_SOURCE_DIR}/register_target.cpp) | ||
| if(NOT MIGRAPHX_USE_MIOPEN) | ||
| list(REMOVE_ITEM TESTS ${CMAKE_CURRENT_SOURCE_DIR}/sqlite.cpp) |
There was a problem hiding this comment.
This will remove the sqlite tests on the linux runners. They should not be removed.
| set(MIGRAPHX_MSVC_RUNTIME_SUFFIX "DLL") | ||
| endif() | ||
|
|
||
| set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>${MIGRAPHX_MSVC_RUNTIME_SUFFIX}") |
There was a problem hiding this comment.
This should be a cached variable.
There was a problem hiding this comment.
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
Please see how it is being used, for example, by protobuf, abseil-cpp, boost, and more: https://github.com/protocolbuffers/protobuf/blob/c616b4becd58b9e85bbb3488d38be0d31ab5447f/CMakeLists.txt#L207
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
| 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() |
The content of the PR changed from the original submission. Now the PR only adds an option to MIGraphX to enable linking to the MSVC Runtime Library either statically or dynamically. I left the original description below.
Original description: