diff --git a/cmake/deps.txt b/cmake/deps.txt index d8cd7713bfe65..666c32633d5a9 100644 --- a/cmake/deps.txt +++ b/cmake/deps.txt @@ -47,7 +47,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/403d652dca4c1046e8145950b1c0997a9f748b57.zip;30b2a07fe4bae8574f89176e56274cacdd6d135b +pytorch_cpuinfo;https://github.com/pytorch/cpuinfo/archive/4628dc060ce4e82345dc166bbac875609db4ff69.zip;e58d4b47c16a982111c897e669ae4f1821a393d7 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 diff --git a/cmake/external/onnxruntime_external_deps.cmake b/cmake/external/onnxruntime_external_deps.cmake index f523fefdd153a..a7813d42363e5 100644 --- a/cmake/external/onnxruntime_external_deps.cmake +++ b/cmake/external/onnxruntime_external_deps.cmake @@ -371,9 +371,7 @@ if (CPUINFO_SUPPORTED) 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/348 - ${Patch_EXECUTABLE} -p1 < ${PROJECT_SOURCE_DIR}/patches/cpuinfo/win_arm_fp16_detection_fallback.patch + ${Patch_EXECUTABLE} -p1 < ${PROJECT_SOURCE_DIR}/patches/cpuinfo/patch_vcpkg_arm64ec_support.patch FIND_PACKAGE_ARGS NAMES cpuinfo ) elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") diff --git a/cmake/onnxruntime_unittests.cmake b/cmake/onnxruntime_unittests.cmake index 23eccb22476df..c32aa7f4ae75a 100644 --- a/cmake/onnxruntime_unittests.cmake +++ b/cmake/onnxruntime_unittests.cmake @@ -1609,8 +1609,8 @@ if (NOT onnxruntime_ENABLE_TRAINING_TORCH_INTEROP) endif() - - if(onnxruntime_USE_QNN) + # Build ep_weight_sharing_ctx_gen for all supported EPs (QNN, TensorRT, OpenVINO, VitisAI) + if(onnxruntime_USE_QNN OR onnxruntime_USE_TENSORRT OR onnxruntime_USE_OPENVINO OR onnxruntime_USE_VITISAI) #qnn ctx generator set(ep_weight_sharing_ctx_gen_src_dir ${TEST_SRC_DIR}/ep_weight_sharing_ctx_gen) set(ep_weight_sharing_ctx_gen_src_patterns diff --git a/cmake/patches/cpuinfo/fix_missing_sysfs_fallback.patch b/cmake/patches/cpuinfo/fix_missing_sysfs_fallback.patch index 005cd458fdd2b..47a1054e25107 100644 --- a/cmake/patches/cpuinfo/fix_missing_sysfs_fallback.patch +++ b/cmake/patches/cpuinfo/fix_missing_sysfs_fallback.patch @@ -1,10 +1,19 @@ diff --git a/src/linux/processors.c b/src/linux/processors.c -index 47bee76..d0c5569 100644 +index fd040a3..2ca8ec4 100644 --- a/src/linux/processors.c +++ b/src/linux/processors.c -@@ -2,0 +3 @@ +@@ -3,6 +3,7 @@ + #include + #include + #include +#include -@@ -291,0 +293,22 @@ + + #if !defined(__ANDROID__) + /* +@@ -289,6 +290,28 @@ static bool max_processor_number_parser(uint32_t processor_list_start, uint32_t + return true; + } + +static uint32_t cpuinfo_linux_get_max_processor_from_sysconf( + uint32_t max_processors_count, + const char* processor_list_name) { @@ -27,13 +36,31 @@ index 47bee76..d0c5569 100644 + return max_processor; +} + -@@ -301 +324 @@ + uint32_t cpuinfo_linux_get_max_possible_processor(uint32_t max_processors_count) { + uint32_t max_possible_processor = 0; + if (!cpuinfo_linux_parse_cpulist( +@@ -298,7 +321,7 @@ uint32_t cpuinfo_linux_get_max_possible_processor(uint32_t max_processors_count) + #else + cpuinfo_log_warning("failed to parse the list of possible processors in %s", POSSIBLE_CPULIST_FILENAME); + #endif - return UINT32_MAX; + return cpuinfo_linux_get_max_processor_from_sysconf(max_processors_count, POSSIBLE_CPULIST_FILENAME); -@@ -323 +346 @@ + } + if (max_possible_processor >= max_processors_count) { + cpuinfo_log_warning( +@@ -320,7 +343,7 @@ uint32_t cpuinfo_linux_get_max_present_processor(uint32_t max_processors_count) + #else + cpuinfo_log_warning("failed to parse the list of present processors in %s", PRESENT_CPULIST_FILENAME); + #endif - return UINT32_MAX; + return cpuinfo_linux_get_max_processor_from_sysconf(max_processors_count, PRESENT_CPULIST_FILENAME); -@@ -357,0 +381,31 @@ + } + if (max_present_processor >= max_processors_count) { + cpuinfo_log_warning( +@@ -355,6 +378,37 @@ static bool detect_processor_parser(uint32_t processor_list_start, uint32_t proc + return true; + } + +static bool cpuinfo_linux_detect_processors_from_sysconf( + uint32_t max_processors_count, + uint32_t* processor0_flags, @@ -65,7 +92,13 @@ index 47bee76..d0c5569 100644 + return true; +} + -@@ -373 +427,6 @@ + bool cpuinfo_linux_detect_possible_processors( + uint32_t max_processors_count, + uint32_t* processor0_flags, +@@ -370,7 +424,12 @@ bool cpuinfo_linux_detect_possible_processors( + return true; + } else { + cpuinfo_log_warning("failed to parse the list of possible processors in %s", POSSIBLE_CPULIST_FILENAME); - return false; + return cpuinfo_linux_detect_processors_from_sysconf( + max_processors_count, @@ -73,7 +106,13 @@ index 47bee76..d0c5569 100644 + processor_struct_size, + possible_flag, + POSSIBLE_CPULIST_FILENAME); -@@ -392 +451,6 @@ + } + } + +@@ -389,7 +448,12 @@ bool cpuinfo_linux_detect_present_processors( + return true; + } else { + cpuinfo_log_warning("failed to parse the list of present processors in %s", PRESENT_CPULIST_FILENAME); - return false; + return cpuinfo_linux_detect_processors_from_sysconf( + max_processors_count, @@ -81,3 +120,6 @@ index 47bee76..d0c5569 100644 + processor_struct_size, + present_flag, + PRESENT_CPULIST_FILENAME); + } + } + diff --git a/cmake/patches/cpuinfo/patch_vcpkg_arm64ec_support.patch b/cmake/patches/cpuinfo/patch_vcpkg_arm64ec_support.patch index af0f039b6c2a3..18ed80f7944f8 100644 --- a/cmake/patches/cpuinfo/patch_vcpkg_arm64ec_support.patch +++ b/cmake/patches/cpuinfo/patch_vcpkg_arm64ec_support.patch @@ -1,5 +1,5 @@ diff --git a/CMakeLists.txt b/CMakeLists.txt -index aedc983..dab589e 100644 +index 072c987..e43d6ab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,6 +72,17 @@ IF(CMAKE_SYSTEM_NAME MATCHES "FreeBSD" AND CPUINFO_TARGET_PROCESSOR STREQUAL "am @@ -7,7 +7,7 @@ index aedc983..dab589e 100644 IF(IS_APPLE_OS AND CMAKE_OSX_ARCHITECTURES MATCHES "^(x86_64|arm64.*)$") SET(CPUINFO_TARGET_PROCESSOR "${CMAKE_OSX_ARCHITECTURES}") +ELSEIF(MSVC AND CMAKE_VERSION VERSION_GREATER_EQUAL "3.10") -+ # Use CMAKE_C_COMPILER_ARCHITECTURE_ID. MSVC values are documented as available since CMake 3.10. ++ # Use CMAKE_C_COMPILER_ARCHITECTURE_ID for non-VS generators (e.g. Ninja) with MSVC. + IF(CMAKE_C_COMPILER_ARCHITECTURE_ID STREQUAL "X86") + SET(CPUINFO_TARGET_PROCESSOR "x86") + ELSEIF(CMAKE_C_COMPILER_ARCHITECTURE_ID STREQUAL "x64") diff --git a/cmake/patches/cpuinfo/win_arm_fp16_detection_fallback.patch b/cmake/patches/cpuinfo/win_arm_fp16_detection_fallback.patch deleted file mode 100644 index 44ac0f13f5466..0000000000000 --- a/cmake/patches/cpuinfo/win_arm_fp16_detection_fallback.patch +++ /dev/null @@ -1,19 +0,0 @@ -diff --git a/src/arm/windows/init.c b/src/arm/windows/init.c -index 5c0a5f3..a07fbe4 100644 ---- a/src/arm/windows/init.c -+++ b/src/arm/windows/init.c -@@ -249,6 +249,14 @@ static void set_cpuinfo_isa_fields(void) { - // guarantee that, but it holds in practice. - cpuinfo_isa.rdm = dotprod; - -+ // PF_ARM_V82_FP16_INSTRUCTIONS_AVAILABLE may not be available in older -+ // Windows versions. If fp16arith was not detected with -+ // IsProcessorFeaturePresent(PF_ARM_V82_FP16_INSTRUCTIONS_AVAILABLE), fall -+ // back to using the value of dotprod. -+ if (!cpuinfo_isa.fp16arith) { -+ cpuinfo_isa.fp16arith = dotprod; -+ } -+ - /* Windows API reports all or nothing for cryptographic instructions. */ - const bool crypto = IsProcessorFeaturePresent(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE) != 0; - cpuinfo_isa.aes = crypto; diff --git a/cmake/vcpkg-ports/cpuinfo/patch_vcpkg_arm64ec_support.patch b/cmake/vcpkg-ports/cpuinfo/patch_vcpkg_arm64ec_support.patch index af0f039b6c2a3..18ed80f7944f8 100644 --- a/cmake/vcpkg-ports/cpuinfo/patch_vcpkg_arm64ec_support.patch +++ b/cmake/vcpkg-ports/cpuinfo/patch_vcpkg_arm64ec_support.patch @@ -1,5 +1,5 @@ diff --git a/CMakeLists.txt b/CMakeLists.txt -index aedc983..dab589e 100644 +index 072c987..e43d6ab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,6 +72,17 @@ IF(CMAKE_SYSTEM_NAME MATCHES "FreeBSD" AND CPUINFO_TARGET_PROCESSOR STREQUAL "am @@ -7,7 +7,7 @@ index aedc983..dab589e 100644 IF(IS_APPLE_OS AND CMAKE_OSX_ARCHITECTURES MATCHES "^(x86_64|arm64.*)$") SET(CPUINFO_TARGET_PROCESSOR "${CMAKE_OSX_ARCHITECTURES}") +ELSEIF(MSVC AND CMAKE_VERSION VERSION_GREATER_EQUAL "3.10") -+ # Use CMAKE_C_COMPILER_ARCHITECTURE_ID. MSVC values are documented as available since CMake 3.10. ++ # Use CMAKE_C_COMPILER_ARCHITECTURE_ID for non-VS generators (e.g. Ninja) with MSVC. + IF(CMAKE_C_COMPILER_ARCHITECTURE_ID STREQUAL "X86") + SET(CPUINFO_TARGET_PROCESSOR "x86") + ELSEIF(CMAKE_C_COMPILER_ARCHITECTURE_ID STREQUAL "x64") diff --git a/cmake/vcpkg-ports/cpuinfo/portfile.cmake b/cmake/vcpkg-ports/cpuinfo/portfile.cmake index 67bd18e61cc28..9140a233e2ccd 100644 --- a/cmake/vcpkg-ports/cpuinfo/portfile.cmake +++ b/cmake/vcpkg-ports/cpuinfo/portfile.cmake @@ -6,13 +6,12 @@ endif() vcpkg_from_github( OUT_SOURCE_PATH SOURCE_PATH REPO pytorch/cpuinfo - REF 403d652dca4c1046e8145950b1c0997a9f748b57 - SHA512 f7cd6dc44bd1120af610cae1337ed4c0f557ba78d2de9c73fed350fa3dfe9512643a1619ae55f5a540c6316a87d641856cca27297bb8766e48f39b7b7a59da1f - HEAD_REF master + REF 4628dc060ce4e82345dc166bbac875609db4ff69 + SHA512 db7a93279f2f6daaf825fbd8552935d8ed671d276b65ad614e11f722b6a6848e663850d65180d33b554d67ef1a36aae842feb368699f90be8f21172a1af1924e + HEAD_REF main PATCHES patch_cpuinfo_h_for_arm64ec.patch patch_vcpkg_arm64ec_support.patch # https://github.com/pytorch/cpuinfo/pull/324 - win_arm_fp16_detection_fallback.patch # https://github.com/pytorch/cpuinfo/pull/348 ) vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS diff --git a/cmake/vcpkg-ports/cpuinfo/win_arm_fp16_detection_fallback.patch b/cmake/vcpkg-ports/cpuinfo/win_arm_fp16_detection_fallback.patch deleted file mode 100644 index 44ac0f13f5466..0000000000000 --- a/cmake/vcpkg-ports/cpuinfo/win_arm_fp16_detection_fallback.patch +++ /dev/null @@ -1,19 +0,0 @@ -diff --git a/src/arm/windows/init.c b/src/arm/windows/init.c -index 5c0a5f3..a07fbe4 100644 ---- a/src/arm/windows/init.c -+++ b/src/arm/windows/init.c -@@ -249,6 +249,14 @@ static void set_cpuinfo_isa_fields(void) { - // guarantee that, but it holds in practice. - cpuinfo_isa.rdm = dotprod; - -+ // PF_ARM_V82_FP16_INSTRUCTIONS_AVAILABLE may not be available in older -+ // Windows versions. If fp16arith was not detected with -+ // IsProcessorFeaturePresent(PF_ARM_V82_FP16_INSTRUCTIONS_AVAILABLE), fall -+ // back to using the value of dotprod. -+ if (!cpuinfo_isa.fp16arith) { -+ cpuinfo_isa.fp16arith = dotprod; -+ } -+ - /* Windows API reports all or nothing for cryptographic instructions. */ - const bool crypto = IsProcessorFeaturePresent(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE) != 0; - cpuinfo_isa.aes = crypto; diff --git a/onnxruntime/core/common/cpuid_info.cc b/onnxruntime/core/common/cpuid_info.cc index ebf3cc9f50be6..ec5c1386e8336 100644 --- a/onnxruntime/core/common/cpuid_info.cc +++ b/onnxruntime/core/common/cpuid_info.cc @@ -405,4 +405,13 @@ CPUIDInfo::CPUIDInfo() { #endif #endif // defined(CPUIDINFO_ARCH_RISCV64) } + +CPUIDInfo::~CPUIDInfo() { +#if defined(CPUINFO_SUPPORTED) + if (pytorch_cpuinfo_init_) { + cpuinfo_deinitialize(); + pytorch_cpuinfo_init_ = false; + } +#endif +} } // namespace onnxruntime diff --git a/onnxruntime/core/common/cpuid_info.h b/onnxruntime/core/common/cpuid_info.h index bf502c645c9eb..6eed234332f46 100644 --- a/onnxruntime/core/common/cpuid_info.h +++ b/onnxruntime/core/common/cpuid_info.h @@ -110,6 +110,7 @@ class CPUIDInfo { static void LogEarlyWarning(std::string_view message); CPUIDInfo(); + ~CPUIDInfo(); void VendorInfoInit(); diff --git a/onnxruntime/core/platform/posix/env.cc b/onnxruntime/core/platform/posix/env.cc index 0270bf9d4d79c..c34d8b3dbf696 100644 --- a/onnxruntime/core/platform/posix/env.cc +++ b/onnxruntime/core/platform/posix/env.cc @@ -657,6 +657,11 @@ class PosixEnv : public Env { } } } + ~PosixEnv() { + if (cpuinfo_available_) { + cpuinfo_deinitialize(); + } + } bool cpuinfo_available_{false}; #endif // ORT_USE_CPUINFO }; diff --git a/onnxruntime/core/providers/qnn/builder/qnn_backend_manager.cc b/onnxruntime/core/providers/qnn/builder/qnn_backend_manager.cc index 5758ff3ad2847..f586fc8e117a6 100644 --- a/onnxruntime/core/providers/qnn/builder/qnn_backend_manager.cc +++ b/onnxruntime/core/providers/qnn/builder/qnn_backend_manager.cc @@ -1871,13 +1871,13 @@ Status QnnBackendManager::ExtractBackendProfilingInfo(qnn::profile::ProfilingInf // ETW disabled previously, but enabled now if (ProfilingLevel::INVALID == profiling_level_etw_ && tracelogging_provider_ep_enabled) { - LOGS(*logger_, ERROR) << "ETW disabled previously, but enabled now. Can't do the switch! Won't output any profiling."; + LOGS(*logger_, WARNING) << "ETW disabled previously, but enabled now. Can't do the switch! Won't output any profiling."; return Status::OK(); } // ETW enabled previously, but disabled now if (ProfilingLevel::INVALID != profiling_level_etw_ && !tracelogging_provider_ep_enabled) { - LOGS(*logger_, ERROR) << "ETW enabled previously, but disabled now. Can't do the switch! Won't output any profiling."; + LOGS(*logger_, WARNING) << "ETW enabled previously, but disabled now. Can't do the switch! Won't output any profiling."; return Status::OK(); }