-
Notifications
You must be signed in to change notification settings - Fork 260
[xpupti] Fix Windows build support for xpupti tests and multi-config generators. #1394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
70f11d7
84e01ae
d6153db
0974fa5
5b9e230
7f903d1
dd7c407
7c64ebf
c4a9c4f
56b3fb0
dfc278b
f8e7705
183a0de
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,75 +6,119 @@ | |
|
|
||
| set(CMAKE_CXX_STANDARD 20) | ||
|
|
||
| set(LINK_LIBRARIES | ||
| gtest_main | ||
| # Do not link gtest into the shared library to avoid duplicate gtest globals | ||
| # (gtest is statically linked into the executable; the shared library resolves | ||
| # gtest symbols from the executable at runtime via --export-dynamic). | ||
| set(COMMON_LINK_LIBRARIES | ||
| kineto_base | ||
| kineto_api | ||
| $<BUILD_INTERFACE:fmt::fmt-header-only> | ||
| ${SYCL_LIBRARY} | ||
| ${PTI_LIBRARY} | ||
| ) | ||
|
|
||
| set(LINK_LIBRARIES gtest_main ${COMMON_LINK_LIBRARIES}) | ||
|
|
||
| add_executable(XpuptiScopeProfilerConfigTest XpuptiScopeProfilerConfigTest.cpp) | ||
| target_link_libraries(XpuptiScopeProfilerConfigTest PRIVATE ${LINK_LIBRARIES}) | ||
| gtest_discover_tests(XpuptiScopeProfilerConfigTest) | ||
|
|
||
| add_executable(XpuptiActivityHandlersTest XpuptiActivityHandlersTest.cpp) | ||
| target_link_libraries(XpuptiActivityHandlersTest PRIVATE ${LINK_LIBRARIES}) | ||
| gtest_add_tests(TARGET XpuptiActivityHandlersTest) | ||
| gtest_discover_tests(XpuptiActivityHandlersTest) | ||
|
|
||
| # Hardware-free test for the CPU->GPU flow-link allowlist. | ||
| add_executable(XpuptiFlowCorrelationTest XpuptiFlowCorrelationTest.cpp) | ||
| target_link_libraries(XpuptiFlowCorrelationTest PRIVATE ${LINK_LIBRARIES}) | ||
| gtest_discover_tests(XpuptiFlowCorrelationTest) | ||
|
|
||
| # These tests build a .so shared library and rely on --export-dynamic runtime | ||
| # symbol resolution (ELF/GNU linker), so they only build on Linux. | ||
| if(NOT WIN32) | ||
| include(ExternalProject) | ||
|
|
||
| function(make_test test_file) | ||
| get_filename_component(test_name "${test_file}" NAME_WE) | ||
| set(lib_name "${test_name}Lib") | ||
| add_library(${lib_name} SHARED XpuptiTestUtilities.cpp ${test_file}) | ||
|
|
||
| # Do not link gtest into the shared library to avoid duplicate gtest globals | ||
| # (gtest is statically linked into the executable; the shared library resolves | ||
| # gtest symbols from the executable at runtime via --export-dynamic). | ||
| set(LIB_LINK_LIBRARIES | ||
| kineto_base | ||
| kineto_api | ||
| $<BUILD_INTERFACE:fmt::fmt-header-only> | ||
| ${SYCL_LIBRARY} | ||
| ${PTI_LIBRARY} | ||
| ) | ||
| target_link_libraries(${lib_name} PRIVATE ${LIB_LINK_LIBRARIES}) | ||
| target_include_directories(${lib_name} PRIVATE | ||
| $<TARGET_PROPERTY:gtest,INTERFACE_INCLUDE_DIRECTORIES>) | ||
| include(ExternalProject) | ||
|
|
||
| function(make_sycl_test test_file) | ||
| get_filename_component(test_name "${test_file}" NAME_WE) | ||
| set(lib_name "${test_name}Lib") | ||
| add_library(${lib_name} SHARED XpuptiTestUtilities.cpp ${test_file}) | ||
|
|
||
| target_link_libraries(${lib_name} PRIVATE ${COMMON_LINK_LIBRARIES}) | ||
| target_include_directories(${lib_name} PRIVATE | ||
| $<TARGET_PROPERTY:gtest,INTERFACE_INCLUDE_DIRECTORIES>) | ||
|
|
||
| set_target_properties(${lib_name} PROPERTIES | ||
| POSITION_INDEPENDENT_CODE ON | ||
| WINDOWS_EXPORT_ALL_SYMBOLS ON | ||
| ) | ||
| # On Windows, DLLs must resolve all symbols at link time (unlike Linux .so). | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for my understanding: I see that the build is forced to progress despite the error with this flag enabled, but how does this end up producing a valid binary?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is caused by circular dependency. |
||
| # ComputeOnXpu is defined in the compute executable (ExternalProject) which | ||
| # links back to this DLL. /FORCE:UNRESOLVED allows the DLL to build with | ||
| # this symbol unresolved. The linker will still report LNK2019 as an error | ||
| # but /FORCE overrides it (followed by LNK4088 warning) — this is expected. | ||
| if(WIN32) | ||
| target_link_options(${lib_name} PRIVATE "LINKER:/FORCE:UNRESOLVED") | ||
| endif() | ||
|
|
||
| set(CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_BINARY_DIR}) | ||
| install(TARGETS ${lib_name} | ||
| LIBRARY DESTINATION lib | ||
| RUNTIME DESTINATION bin | ||
| ) | ||
|
|
||
| set_target_properties(${lib_name} PROPERTIES POSITION_INDEPENDENT_CODE ON) | ||
| set(_link_lib_search_dir ${CMAKE_CURRENT_BINARY_DIR}) | ||
|
|
||
| set(CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_BINARY_DIR}) | ||
| install(TARGETS ${lib_name} | ||
| LIBRARY DESTINATION lib | ||
| RUNTIME DESTINATION bin | ||
| # Build the common cmake args for the inner ExternalProject (single-config Ninja). | ||
| set(_ep_cmake_args | ||
| -DPROJECT_NAME=${test_name} | ||
| -DCMAKE_CXX_COMPILER=${SYCL_COMPILER} | ||
| -DCMAKE_PARENT_BINARY_DIR=${CMAKE_BINARY_DIR} | ||
| -DLINK_LIBRARY_NAME=${lib_name} | ||
| -DLINK_LIBRARY_DIR=${_link_lib_search_dir} | ||
| -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR} | ||
| ) | ||
| if(WIN32) | ||
| get_filename_component(_sycl_compiler_dir "${SYCL_COMPILER}" DIRECTORY) | ||
| get_filename_component(_sycl_root "${_sycl_compiler_dir}" DIRECTORY) | ||
| list(APPEND _ep_cmake_args | ||
| "-DCMAKE_EXE_LINKER_FLAGS=/Qoption,link,/LIBPATH:\"${_sycl_root}/lib\"" | ||
| ) | ||
| endif() | ||
|
|
||
| # - Multi-config (Visual Studio, Ninja Multi-Config): uses CONFIGURE_COMMAND | ||
| # with $<CONFIG> since CMAKE_ARGS doesn't support generator expressions. | ||
| # Ninja is forced as a single-config inner generator. | ||
| # - Single-config on Windows: forces Ninja for SYCL/ICX compatibility. | ||
| # - Single-config on Linux: forwards the outer generator (Ninja, Makefiles, etc.) | ||
| # via CMAKE_GENERATOR. | ||
| get_property(_is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) | ||
| if(_is_multi_config) | ||
| ExternalProject_Add(${test_name} | ||
| SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/compute | ||
| CMAKE_ARGS -DPROJECT_NAME=${test_name} | ||
| CMAKE_ARGS -DCMAKE_CXX_COMPILER=${SYCL_COMPILER} | ||
| CMAKE_ARGS -DCMAKE_PARENT_BINARY_DIR=${CMAKE_BINARY_DIR} | ||
| CMAKE_ARGS -DLINK_LIBRARY=${CMAKE_CURRENT_BINARY_DIR}/lib${lib_name}.so | ||
| CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR} | ||
| CONFIGURE_COMMAND ${CMAKE_COMMAND} | ||
| -G Ninja | ||
| -S <SOURCE_DIR> | ||
| -B <BINARY_DIR> | ||
| -DCMAKE_BUILD_TYPE=$<CONFIG> | ||
| ${_ep_cmake_args} | ||
| BUILD_ALWAYS TRUE | ||
| ) | ||
| else() | ||
| set(_selected_generator ${CMAKE_GENERATOR}) | ||
| if(WIN32) | ||
| set(_selected_generator Ninja) | ||
| endif() | ||
| ExternalProject_Add(${test_name} | ||
| SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/compute | ||
| CMAKE_GENERATOR ${_selected_generator} | ||
| CMAKE_ARGS | ||
| -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} | ||
| ${_ep_cmake_args} | ||
| BUILD_ALWAYS TRUE | ||
| ) | ||
| endif() | ||
|
|
||
| add_dependencies(${test_name} ${lib_name}) | ||
| add_dependencies(${test_name} gtest) | ||
| add_dependencies(${test_name} gtest_main) | ||
| endfunction() | ||
|
|
||
| add_dependencies(${test_name} ${lib_name}) | ||
| add_dependencies(${test_name} gtest) | ||
| add_dependencies(${test_name} gtest_main) | ||
| endfunction() | ||
| make_sycl_test(XpuptiProfilerTest.cpp) | ||
| make_sycl_test(XpuptiScopeProfilerTest.cpp) | ||
|
|
||
| make_test(XpuptiProfilerTest.cpp) | ||
| make_test(XpuptiScopeProfilerTest.cpp) | ||
| endif() | ||
Uh oh!
There was an error while loading. Please reload this page.