From fb2730d87f509103f18d805ba7dd12e0837c29f8 Mon Sep 17 00:00:00 2001 From: iarspider Date: Fri, 20 May 2022 02:24:18 +0200 Subject: [PATCH] Update py-onnx-runtime to 1.10; update CMS patch (#30725) * Update py-onnx-runtime to 1.10; update CMS patch * Update package.py --- .../packages/py-onnx-runtime/cms_1_10.patch | 142 ++++++++++++++++++ .../packages/py-onnx-runtime/package.py | 4 + 2 files changed, 146 insertions(+) create mode 100644 var/spack/repos/builtin/packages/py-onnx-runtime/cms_1_10.patch diff --git a/var/spack/repos/builtin/packages/py-onnx-runtime/cms_1_10.patch b/var/spack/repos/builtin/packages/py-onnx-runtime/cms_1_10.patch new file mode 100644 index 0000000000..3365fb75e2 --- /dev/null +++ b/var/spack/repos/builtin/packages/py-onnx-runtime/cms_1_10.patch @@ -0,0 +1,142 @@ +diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt +index acbde7f56a8..eb9f7bb9fbf 100644 +--- a/cmake/CMakeLists.txt ++++ b/cmake/CMakeLists.txt +@@ -718,7 +718,7 @@ if (onnxruntime_BUILD_BENCHMARKS) + endif() + endif() + +-if (NOT WIN32 AND NOT onnxruntime_PREFER_SYSTEM_LIB) ++if (NOT WIN32) + add_subdirectory(${PROJECT_SOURCE_DIR}/external/nsync EXCLUDE_FROM_ALL) + endif() + # External dependencies +diff --git a/include/onnxruntime/core/platform/ort_mutex.h b/include/onnxruntime/core/platform/ort_mutex.h +index e24665f5142..ddc11953fbc 100644 +--- a/include/onnxruntime/core/platform/ort_mutex.h ++++ b/include/onnxruntime/core/platform/ort_mutex.h +@@ -101,7 +101,7 @@ std::cv_status OrtCondVar::wait_for(std::unique_lock& cond_mutex, + return steady_clock::now() - steady_now < rel_time ? std::cv_status::no_timeout : std::cv_status::timeout; + } + } // namespace onnxruntime +-#else ++#elif !defined(__aarch64__) + #include "nsync.h" + #include //for unique_lock + #include //for cv_status +@@ -186,4 +186,11 @@ std::cv_status OrtCondVar::wait_for(std::unique_lock& cond_mutex, + return steady_clock::now() - steady_now < rel_time ? std::cv_status::no_timeout : std::cv_status::timeout; + } + }; // namespace onnxruntime ++#else ++#include ++#include ++namespace onnxruntime { ++using OrtMutex = std::mutex; ++using OrtCondVar = std::condition_variable; ++} // namespace onnxruntime + #endif +diff --git a/include/onnxruntime/core/session/onnxruntime_cxx_api.h b/include/onnxruntime/core/session/onnxruntime_cxx_api.h +index 048421099bd..4430185d496 100644 +--- a/include/onnxruntime/core/session/onnxruntime_cxx_api.h ++++ b/include/onnxruntime/core/session/onnxruntime_cxx_api.h +@@ -379,9 +379,9 @@ struct ModelMetadata : Base { + */ + struct Session : Base { + explicit Session(std::nullptr_t) {} ///< Create an empty Session object, must be assigned a valid one to be used +- Session(Env& env, const ORTCHAR_T* model_path, const SessionOptions& options); ///< Wraps OrtApi::CreateSession +- Session(Env& env, const ORTCHAR_T* model_path, const SessionOptions& options, OrtPrepackedWeightsContainer* prepacked_weights_container); ///< Wraps OrtApi::CreateSessionWithPrepackedWeightsContainer +- Session(Env& env, const void* model_data, size_t model_data_length, const SessionOptions& options); ///< Wraps OrtApi::CreateSessionFromArray ++ Session(const Env& env, const ORTCHAR_T* model_path, const SessionOptions& options); ///< Wraps OrtApi::CreateSession ++ Session(const Env& env, const ORTCHAR_T* model_path, const SessionOptions& options, OrtPrepackedWeightsContainer* prepacked_weights_container); ///< Wraps OrtApi::CreateSessionWithPrepackedWeightsContainer ++ Session(const Env& env, const void* model_data, size_t model_data_length, const SessionOptions& options); ///< Wraps OrtApi::CreateSessionFromArray + + /** \brief Run the model returning results in an Ort allocated vector. + * +diff --git a/include/onnxruntime/core/session/onnxruntime_cxx_inline.h b/include/onnxruntime/core/session/onnxruntime_cxx_inline.h +index 1f31dffca87..b9d2cdfc475 100644 +--- a/include/onnxruntime/core/session/onnxruntime_cxx_inline.h ++++ b/include/onnxruntime/core/session/onnxruntime_cxx_inline.h +@@ -538,16 +538,16 @@ inline SessionOptions& SessionOptions::AppendExecutionProvider_OpenVINO(const Or + return *this; + } + +-inline Session::Session(Env& env, const ORTCHAR_T* model_path, const SessionOptions& options) { ++inline Session::Session(const Env& env, const ORTCHAR_T* model_path, const SessionOptions& options) { + ThrowOnError(GetApi().CreateSession(env, model_path, options, &p_)); + } + +-inline Session::Session(Env& env, const ORTCHAR_T* model_path, const SessionOptions& options, ++inline Session::Session(const Env& env, const ORTCHAR_T* model_path, const SessionOptions& options, + OrtPrepackedWeightsContainer* prepacked_weights_container) { + ThrowOnError(GetApi().CreateSessionWithPrepackedWeightsContainer(env, model_path, options, prepacked_weights_container, &p_)); + } + +-inline Session::Session(Env& env, const void* model_data, size_t model_data_length, const SessionOptions& options) { ++inline Session::Session(const Env& env, const void* model_data, size_t model_data_length, const SessionOptions& options) { + ThrowOnError(GetApi().CreateSessionFromArray(env, model_data, model_data_length, options, &p_)); + } + +diff --git a/onnxruntime/core/mlas/lib/platform.cpp b/onnxruntime/core/mlas/lib/platform.cpp +index de7fee8c07a..6d97cf07a05 100644 +--- a/onnxruntime/core/mlas/lib/platform.cpp ++++ b/onnxruntime/core/mlas/lib/platform.cpp +@@ -16,6 +16,7 @@ Module Name: + --*/ + + #include "mlasi.h" ++#include + + #if defined(MLAS_TARGET_POWER) && defined(__linux__) + #include +@@ -197,8 +198,11 @@ Return Value: + // + + uint64_t xcr0 = MlasReadExtendedControlRegister(_XCR_XFEATURE_ENABLED_MASK); ++ const char *cpu_opt = std::getenv("MLAS_DYNAMIC_CPU_ARCH"); ++ if (cpu_opt == nullptr) cpu_opt = "99"; ++ auto opt = std::stoi(cpu_opt); + +- if ((xcr0 & 0x6) == 0x6) { ++ if (opt > 0 && (xcr0 & 0x6) == 0x6) { + + this->GemmFloatKernel = MlasGemmFloatKernelAvx; + +@@ -231,7 +235,7 @@ Return Value: + __cpuid_count(7, 0, Cpuid7[0], Cpuid7[1], Cpuid7[2], Cpuid7[3]); + #endif + +- if (((Cpuid1[2] & 0x1000) != 0) && ((Cpuid7[1] & 0x20) != 0)) { ++ if (opt > 1 && ((Cpuid1[2] & 0x1000) != 0) && ((Cpuid7[1] & 0x20) != 0)) { + + this->GemmU8S8Dispatch = &MlasGemmU8S8DispatchAvx2; + this->GemmU8S8Kernel = MlasGemmU8S8KernelAvx2; +@@ -290,7 +294,7 @@ Return Value: + // operating system supports saving AVX512F state. + // + +- if (((Cpuid7[1] & 0x10000) != 0) && ((xcr0 & 0xE0) == 0xE0)) { ++ if (opt > 2 && ((Cpuid7[1] & 0x10000) != 0) && ((xcr0 & 0xE0) == 0xE0)) { + + this->GemmFloatKernel = MlasGemmFloatKernelAvx512F; + this->GemmDoubleKernel = MlasGemmDoubleKernelAvx512F; +diff --git a/onnxruntime/core/platform/posix/ort_mutex.cc b/onnxruntime/core/platform/posix/ort_mutex.cc +index 8a5d41eb360..89111c9daa5 100644 +--- a/onnxruntime/core/platform/posix/ort_mutex.cc ++++ b/onnxruntime/core/platform/posix/ort_mutex.cc +@@ -1,6 +1,7 @@ + // Copyright (c) Microsoft Corporation. All rights reserved. + // Licensed under the MIT License. + ++#if !defined(__aarch64__) + #include "core/common/common.h" + #include "core/platform/ort_mutex.h" + #include +@@ -40,4 +41,5 @@ void OrtCondVar::wait(std::unique_lock& lk) { + nsync::nsync_cv_wait(&native_cv_object, lk.mutex()->native_handle()); + } + +-} // namespace onnxruntime +\ No newline at end of file ++} // namespace onnxruntime ++#endif diff --git a/var/spack/repos/builtin/packages/py-onnx-runtime/package.py b/var/spack/repos/builtin/packages/py-onnx-runtime/package.py index d2eef4d69c..e1475eb5cf 100644 --- a/var/spack/repos/builtin/packages/py-onnx-runtime/package.py +++ b/var/spack/repos/builtin/packages/py-onnx-runtime/package.py @@ -19,6 +19,7 @@ class PyOnnxRuntime(CMakePackage, PythonPackage): homepage = "https://github.com/microsoft/onnxruntime" git = "https://github.com/microsoft/onnxruntime.git" + version('1.10.0', tag='v1.10.0', submodules=True) version('1.7.2', tag='v1.7.2', submodules=True) variant('cuda', default=False, description='Build with CUDA support') @@ -35,6 +36,7 @@ class PyOnnxRuntime(CMakePackage, PythonPackage): depends_on('py-cerberus', type=('build', 'run')) depends_on('py-wheel', type='build') depends_on('py-onnx', type=('build', 'run')) + depends_on('py-flatbuffers', type=('build', 'run')) depends_on('zlib') depends_on('libpng') depends_on('py-pybind11', type='build') @@ -47,6 +49,8 @@ class PyOnnxRuntime(CMakePackage, PythonPackage): # Adopted from CMS experiment's fork of onnxruntime # https://github.com/cms-externals/onnxruntime/compare/5bc92df...d594f80 patch('cms.patch', level=1, when='@1.7.2') + # https://github.com/cms-externals/onnxruntime/compare/0d9030e...7a6355a + patch('cms_1_10.patch', whe='@1.10') # https://github.com/microsoft/onnxruntime/issues/4234#issuecomment-698077636 patch('libiconv.patch', level=0, when='@1.7.2') # https://github.com/microsoft/onnxruntime/commit/de4089f8cbe0baffe56a363cc3a41595cc8f0809.patch