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
2 changes: 1 addition & 1 deletion cmake/deps.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protoc_mac_universal;https://github.com/protocolbuffers/protobuf/releases/downlo
psimd;https://github.com/Maratyszcza/psimd/archive/072586a71b55b7f8c584153d223e95687148a900.zip;1f5454b01f06f9656b77e4a5e2e31d7422487013
pthreadpool;https://github.com/google/pthreadpool/archive/dcc9f28589066af0dbd4555579281230abbf74dd.zip;533a77943203ef15ca608bcd9dbe2c94da7451d2
pybind11;https://github.com/pybind/pybind11/archive/refs/tags/v3.0.2.zip;a064e663b4d7a337ac291d1bef7337ef4e60a1ae
pytorch_cpuinfo;https://github.com/pytorch/cpuinfo/archive/4628dc060ce4e82345dc166bbac875609db4ff69.zip;e58d4b47c16a982111c897e669ae4f1821a393d7
pytorch_cpuinfo;https://github.com/pytorch/cpuinfo/archive/66ee79c038d70dad9f08705b2c9b3e58f6d8f512.zip;6e2be17c110e4f4184b059303c722b3c5bd080a6
re2;https://github.com/google/re2/archive/refs/tags/2024-07-02.zip;646e1728269cde7fcef990bf4a8e87b047882e88
safeint;https://github.com/dcleblanc/SafeInt/archive/refs/tags/3.0.28.zip;23f252040ff6cb9f1fd18575b32fa8fb5928daac
tensorboard;https://github.com/tensorflow/tensorboard/archive/373eb09e4c5d2b3cc2493f0949dc4be6b6a45e81.zip;67b833913605a4f3f499894ab11528a702c2b381
Expand Down
78 changes: 44 additions & 34 deletions cmake/external/onnxruntime_external_deps.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -363,42 +363,52 @@ if (CPUINFO_SUPPORTED)
set(CPUINFO_BUILD_UNIT_TESTS OFF CACHE INTERNAL "")
set(CPUINFO_BUILD_MOCK_TESTS OFF CACHE INTERNAL "")
set(CPUINFO_BUILD_BENCHMARKS OFF CACHE INTERNAL "")
if (onnxruntime_target_platform STREQUAL "ARM64EC" OR onnxruntime_target_platform STREQUAL "ARM64")
message(STATUS "Applying patches for Windows ARM64/ARM64EC in cpuinfo")
onnxruntime_fetchcontent_declare(
pytorch_cpuinfo
URL ${DEP_URL_pytorch_cpuinfo}
URL_HASH SHA1=${DEP_SHA1_pytorch_cpuinfo}
EXCLUDE_FROM_ALL
PATCH_COMMAND
${Patch_EXECUTABLE} -p1 < ${PROJECT_SOURCE_DIR}/patches/cpuinfo/patch_cpuinfo_h_for_arm64ec.patch &&
# https://github.com/pytorch/cpuinfo/pull/324
${Patch_EXECUTABLE} -p1 < ${PROJECT_SOURCE_DIR}/patches/cpuinfo/patch_vcpkg_arm64ec_support.patch
FIND_PACKAGE_ARGS NAMES cpuinfo
)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
message(STATUS "Applying sysfs fallback patch for cpuinfo on Linux")
onnxruntime_fetchcontent_declare(
pytorch_cpuinfo
URL ${DEP_URL_pytorch_cpuinfo}
URL_HASH SHA1=${DEP_SHA1_pytorch_cpuinfo}
EXCLUDE_FROM_ALL
PATCH_COMMAND
# https://github.com/microsoft/onnxruntime/issues/10038
${Patch_EXECUTABLE} -p1 < ${PROJECT_SOURCE_DIR}/patches/cpuinfo/fix_missing_sysfs_fallback.patch
FIND_PACKAGE_ARGS NAMES cpuinfo
)
if(onnxruntime_USE_VCPKG AND NOT APPLE)
find_package(cpuinfo CONFIG REQUIRED)
else()
onnxruntime_fetchcontent_declare(
pytorch_cpuinfo
URL ${DEP_URL_pytorch_cpuinfo}
URL_HASH SHA1=${DEP_SHA1_pytorch_cpuinfo}
EXCLUDE_FROM_ALL
FIND_PACKAGE_ARGS NAMES cpuinfo
)
if (onnxruntime_target_platform STREQUAL "ARM64EC" OR onnxruntime_target_platform STREQUAL "ARM64")
message(STATUS "Applying patches for Windows ARM64/ARM64EC in cpuinfo")
onnxruntime_fetchcontent_declare(
pytorch_cpuinfo
URL ${DEP_URL_pytorch_cpuinfo}
URL_HASH SHA1=${DEP_SHA1_pytorch_cpuinfo}
EXCLUDE_FROM_ALL
PATCH_COMMAND
${Patch_EXECUTABLE} -p1 < ${PROJECT_SOURCE_DIR}/patches/cpuinfo/patch_cpuinfo_h_for_arm64ec.patch &&
# https://github.com/pytorch/cpuinfo/pull/324
${Patch_EXECUTABLE} -p1 < ${PROJECT_SOURCE_DIR}/patches/cpuinfo/patch_vcpkg_arm64ec_support.patch &&
# https://github.com/pytorch/cpuinfo/pull/400
${Patch_EXECUTABLE} --binary --ignore-whitespace -p1 <
${PROJECT_SOURCE_DIR}/patches/cpuinfo/enable_deinit_refcounting.patch
)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
message(STATUS "Applying sysfs fallback patch for cpuinfo on Linux")
onnxruntime_fetchcontent_declare(
pytorch_cpuinfo
URL ${DEP_URL_pytorch_cpuinfo}
URL_HASH SHA1=${DEP_SHA1_pytorch_cpuinfo}
EXCLUDE_FROM_ALL
PATCH_COMMAND
# https://github.com/microsoft/onnxruntime/issues/10038
${Patch_EXECUTABLE} -p1 < ${PROJECT_SOURCE_DIR}/patches/cpuinfo/fix_missing_sysfs_fallback.patch &&
# https://github.com/pytorch/cpuinfo/pull/400
${Patch_EXECUTABLE} --binary --ignore-whitespace -p1 <
${PROJECT_SOURCE_DIR}/patches/cpuinfo/enable_deinit_refcounting.patch
)
else()
onnxruntime_fetchcontent_declare(
pytorch_cpuinfo
URL ${DEP_URL_pytorch_cpuinfo}
URL_HASH SHA1=${DEP_SHA1_pytorch_cpuinfo}
EXCLUDE_FROM_ALL
PATCH_COMMAND
# https://github.com/pytorch/cpuinfo/pull/400
${Patch_EXECUTABLE} --binary --ignore-whitespace -p1 <
${PROJECT_SOURCE_DIR}/patches/cpuinfo/enable_deinit_refcounting.patch
)
endif()
onnxruntime_fetchcontent_makeavailable(pytorch_cpuinfo)
endif()
set(ONNXRUNTIME_CPUINFO_PROJ pytorch_cpuinfo)
onnxruntime_fetchcontent_makeavailable(${ONNXRUNTIME_CPUINFO_PROJ})
if(TARGET cpuinfo::cpuinfo AND NOT TARGET cpuinfo)
message(STATUS "Aliasing cpuinfo::cpuinfo to cpuinfo")
add_library(cpuinfo ALIAS cpuinfo::cpuinfo)
Expand Down
4 changes: 2 additions & 2 deletions cmake/external/xnnpack.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ endif()


onnxruntime_fetchcontent_declare(googlexnnpack URL ${DEP_URL_googlexnnpack} URL_HASH SHA1=${DEP_SHA1_googlexnnpack}
PATCH_COMMAND ${Patch_EXECUTABLE} --binary --ignore-whitespace -p1 < ${PROJECT_SOURCE_DIR}/patches/xnnpack/AddEmscriptenAndIosSupport.patch
PATCH_COMMAND ${Patch_EXECUTABLE} --binary --ignore-whitespace -p1 < ${PROJECT_SOURCE_DIR}/patches/xnnpack/AddEmscriptenAndIosSupport.patch &&
${Patch_EXECUTABLE} --ignore-whitespace -p1 < ${PROJECT_SOURCE_DIR}/patches/xnnpack/release_cpuinfo_after_hardware_config.patch
EXCLUDE_FROM_ALL
FIND_PACKAGE_ARGS NAMES xnnpack
)
onnxruntime_fetchcontent_makeavailable(googlexnnpack)
set(XNNPACK_DIR ${googlexnnpack_SOURCE_DIR})
Expand Down
69 changes: 69 additions & 0 deletions cmake/onnxruntime_unittests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1986,6 +1986,43 @@ endif()
set_target_properties(ep_weight_sharing_ctx_gen PROPERTIES FOLDER "ONNXRuntimeTest")
endif()

if (CPUINFO_SUPPORTED AND NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
set(onnxruntime_cpuinfo_test_library cpuinfo)
get_target_property(onnxruntime_cpuinfo_aliased_target cpuinfo ALIASED_TARGET)
if(onnxruntime_cpuinfo_aliased_target)
set(onnxruntime_cpuinfo_test_library ${onnxruntime_cpuinfo_aliased_target})
endif()
get_target_property(onnxruntime_cpuinfo_library_type ${onnxruntime_cpuinfo_test_library} TYPE)
if(onnxruntime_cpuinfo_library_type STREQUAL "STATIC_LIBRARY")
onnxruntime_add_executable(
onnxruntime_cpuinfo_refcount_test
${ONNXRUNTIME_SHARED_LIB_TEST_SRC_DIR}/cpuinfo_refcount_test.cc)
target_compile_definitions(
onnxruntime_cpuinfo_refcount_test
PRIVATE ORT_CPUINFO_TEST_HAS_INTERNAL_STATE)
if(onnxruntime_USE_XNNPACK)
target_compile_definitions(
onnxruntime_cpuinfo_refcount_test
PRIVATE ORT_CPUINFO_TEST_USE_XNNPACK)
if(onnxruntime_USE_VCPKG)
target_include_directories(onnxruntime_cpuinfo_refcount_test PRIVATE ${XNNPACK_HDR})
else()
target_include_directories(onnxruntime_cpuinfo_refcount_test PRIVATE ${XNNPACK_INCLUDE_DIR})
endif()
target_link_libraries(
onnxruntime_cpuinfo_refcount_test
PRIVATE ${onnxruntime_EXTERNAL_LIBRARIES_XNNPACK})
endif()
target_link_libraries(onnxruntime_cpuinfo_refcount_test PRIVATE cpuinfo Threads::Threads)
add_test(
NAME onnxruntime_cpuinfo_refcount_test
COMMAND onnxruntime_cpuinfo_refcount_test)
set_target_properties(
onnxruntime_cpuinfo_refcount_test
PROPERTIES FOLDER "ONNXRuntimeTest")
endif()
endif()

# shared lib
if (onnxruntime_BUILD_SHARED_LIB)
if(WIN32)
Expand All @@ -1994,6 +2031,38 @@ endif()
add_test(NAME onnxruntime_shared_lib_dlopen_test COMMAND onnxruntime_shared_lib_dlopen_test WORKING_DIRECTORY $<TARGET_FILE_DIR:onnxruntime_shared_lib_dlopen_test>)
set_target_properties(onnxruntime_shared_lib_dlopen_test PROPERTIES FOLDER "ONNXRuntimeTest")

if(onnxruntime_cpuinfo_library_type STREQUAL "STATIC_LIBRARY")
onnxruntime_add_shared_library(
onnxruntime_cpuinfo_dlopen_test_library
${ONNXRUNTIME_SHARED_LIB_TEST_SRC_DIR}/cpuinfo_dlopen_test_library.cc
${ONNXRUNTIME_SHARED_LIB_TEST_SRC_DIR}/cpuinfo_dlopen_test_library.def)
target_include_directories(
onnxruntime_cpuinfo_dlopen_test_library
PRIVATE ${ONNXRUNTIME_ROOT})
target_link_libraries(
onnxruntime_cpuinfo_dlopen_test_library
PRIVATE onnxruntime_common cpuinfo)

onnxruntime_add_executable(
onnxruntime_shared_lib_cpuinfo_dlopen_test
${ONNXRUNTIME_SHARED_LIB_TEST_SRC_DIR}/cpuinfo_dlopen_test.cc)
add_dependencies(
onnxruntime_shared_lib_cpuinfo_dlopen_test
onnxruntime_cpuinfo_dlopen_test_library)
target_compile_definitions(
onnxruntime_shared_lib_cpuinfo_dlopen_test
PRIVATE
ORT_CPUINFO_DLOPEN_TEST_LIBRARY=L"$<TARGET_FILE_NAME:onnxruntime_cpuinfo_dlopen_test_library>")
add_test(
NAME onnxruntime_shared_lib_cpuinfo_dlopen_test
COMMAND onnxruntime_shared_lib_cpuinfo_dlopen_test
WORKING_DIRECTORY $<TARGET_FILE_DIR:onnxruntime_cpuinfo_dlopen_test_library>)
set_target_properties(
onnxruntime_cpuinfo_dlopen_test_library
onnxruntime_shared_lib_cpuinfo_dlopen_test
PROPERTIES FOLDER "ONNXRuntimeTest")
endif()

if (MSVC)
# set VS debugger working directory to the test program's directory
set_target_properties(onnxruntime_shared_lib_dlopen_test PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY $<TARGET_FILE_DIR:onnxruntime_shared_lib_dlopen_test>)
Expand Down
3 changes: 3 additions & 0 deletions cmake/patches/.gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
*.patch text eol=lf

# cpuinfo contains both LF and CRLF source files, so this patch must preserve both.
cpuinfo/enable_deinit_refcounting.patch -text
Loading
Loading