summaryrefslogtreecommitdiff
path: root/0001-remove-nsync.patch
diff options
context:
space:
mode:
Diffstat (limited to '0001-remove-nsync.patch')
-rw-r--r--0001-remove-nsync.patch221
1 files changed, 221 insertions, 0 deletions
diff --git a/0001-remove-nsync.patch b/0001-remove-nsync.patch
new file mode 100644
index 0000000..8bf253c
--- /dev/null
+++ b/0001-remove-nsync.patch
@@ -0,0 +1,221 @@
+From 6bff27675821cacc40b7150eee7fc99476fd336e Mon Sep 17 00:00:00 2001
+From: binsz <274620705z@gmail.com>
+Date: Tue, 30 Jan 2024 23:10:57 +0800
+Subject: [PATCH] remove nsync
+
+---
+ cmake/CMakeLists.txt | 4 ++--
+ .../external/onnxruntime_external_deps.cmake | 4 ++--
+ cmake/onnxruntime_unittests.cmake | 22 +++++++++----------
+ include/onnxruntime/core/platform/ort_mutex.h | 20 ++++++++---------
+ onnxruntime/core/platform/posix/ort_mutex.cc | 6 ++---
+ 5 files changed, 28 insertions(+), 28 deletions(-)
+
+diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
+index 82a4547..eaebef8 100644
+--- a/cmake/CMakeLists.txt
++++ b/cmake/CMakeLists.txt
+@@ -922,7 +922,7 @@ function(onnxruntime_set_compile_flags target_name)
+ target_compile_options(${target_name} PRIVATE "-Wno-unused-parameter")
+ endif()
+ target_compile_definitions(${target_name} PUBLIC -DNSYNC_ATOMIC_CPP11)
+- onnxruntime_add_include_to_target(${target_name} nsync::nsync_cpp)
++ # onnxruntime_add_include_to_target(${target_name} nsync::nsync_cpp)
+ endif()
+ foreach(ORT_FLAG ${ORT_PROVIDER_FLAGS})
+ target_compile_definitions(${target_name} PRIVATE ${ORT_FLAG})
+@@ -1574,7 +1574,7 @@ if (WIN32)
+ list(APPEND onnxruntime_EXTERNAL_LIBRARIES ${SYS_PATH_LIB})
+ list(APPEND onnxruntime_EXTERNAL_LIBRARIES debug Dbghelp)
+ else()
+- list(APPEND onnxruntime_EXTERNAL_LIBRARIES nsync::nsync_cpp)
++ # list(APPEND onnxruntime_EXTERNAL_LIBRARIES nsync::nsync_cpp)
+ list(APPEND onnxruntime_EXTERNAL_LIBRARIES ${ICONV_LIB} ${CMAKE_DL_LIBS} Threads::Threads)
+ endif()
+
+diff --git a/cmake/external/onnxruntime_external_deps.cmake b/cmake/external/onnxruntime_external_deps.cmake
+index 1e971e5..e338068 100644
+--- a/cmake/external/onnxruntime_external_deps.cmake
++++ b/cmake/external/onnxruntime_external_deps.cmake
+@@ -64,7 +64,7 @@ if (onnxruntime_BUILD_BENCHMARKS)
+ )
+ endif()
+
+-if (NOT WIN32)
++if (FALSE AND NOT WIN32)
+ FetchContent_Declare(
+ google_nsync
+ URL ${DEP_URL_google_nsync}
+@@ -284,7 +284,7 @@ if (onnxruntime_BUILD_BENCHMARKS)
+ onnxruntime_fetchcontent_makeavailable(google_benchmark)
+ endif()
+
+-if (NOT WIN32)
++if (FALSE AND NOT WIN32)
+ #nsync tests failed on Mac Build
+ set(NSYNC_ENABLE_TESTS OFF CACHE BOOL "" FORCE)
+ onnxruntime_fetchcontent_makeavailable(google_nsync)
+diff --git a/cmake/onnxruntime_unittests.cmake b/cmake/onnxruntime_unittests.cmake
+index 695e218..38f9719 100644
+--- a/cmake/onnxruntime_unittests.cmake
++++ b/cmake/onnxruntime_unittests.cmake
+@@ -697,7 +697,7 @@ if(MSVC)
+ else()
+ target_compile_definitions(onnxruntime_test_utils PUBLIC -DNSYNC_ATOMIC_CPP11)
+ target_include_directories(onnxruntime_test_utils PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${ONNXRUNTIME_ROOT})
+- onnxruntime_add_include_to_target(onnxruntime_test_utils nsync::nsync_cpp)
++ # onnxruntime_add_include_to_target(onnxruntime_test_utils nsync::nsync_cpp)
+ endif()
+ if (onnxruntime_USE_NCCL)
+ target_include_directories(onnxruntime_test_utils PRIVATE ${NCCL_INCLUDE_DIRS})
+@@ -732,7 +732,7 @@ if(MSVC)
+ else()
+ target_compile_definitions(onnx_test_runner_common PUBLIC -DNSYNC_ATOMIC_CPP11)
+ target_include_directories(onnx_test_runner_common PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${ONNXRUNTIME_ROOT})
+- onnxruntime_add_include_to_target(onnx_test_runner_common nsync::nsync_cpp)
++ # onnxruntime_add_include_to_target(onnx_test_runner_common nsync::nsync_cpp)
+ endif()
+ if (MSVC AND NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
+ #TODO: fix the warnings, they are dangerous
+@@ -1119,7 +1119,7 @@ if (NOT onnxruntime_ENABLE_TRAINING_TORCH_INTEROP)
+ # "Global initializer calls a non-constexpr function." BENCHMARK_CAPTURE macro needs this.
+ target_compile_options(onnxruntime_mlas_benchmark PRIVATE /wd26426)
+ else()
+- target_link_libraries(onnxruntime_mlas_benchmark PRIVATE nsync::nsync_cpp ${CMAKE_DL_LIBS})
++ # target_link_libraries(onnxruntime_mlas_benchmark PRIVATE nsync::nsync_cpp ${CMAKE_DL_LIBS})
+ endif()
+ if (CPUINFO_SUPPORTED AND NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
+ target_link_libraries(onnxruntime_mlas_benchmark PRIVATE cpuinfo)
+@@ -1196,7 +1196,7 @@ if (NOT onnxruntime_ENABLE_TRAINING_TORCH_INTEROP)
+ ${onnxruntime_EXTERNAL_LIBRARIES}
+ ${GETOPT_LIB_WIDE} ${SYS_PATH_LIB} ${CMAKE_DL_LIBS})
+ if(NOT WIN32)
+- list(APPEND onnxruntime_perf_test_libs nsync::nsync_cpp)
++ # list(APPEND onnxruntime_perf_test_libs nsync::nsync_cpp)
+ if(onnxruntime_USE_SNPE)
+ list(APPEND onnxruntime_perf_test_libs onnxruntime_providers_snpe)
+ endif()
+@@ -1240,7 +1240,7 @@ if (NOT onnxruntime_ENABLE_TRAINING_TORCH_INTEROP)
+ # test inference using shared lib
+ set(onnxruntime_shared_lib_test_LIBS onnxruntime_mocked_allocator onnxruntime_test_utils onnxruntime_common onnx_proto)
+ if(NOT WIN32)
+- list(APPEND onnxruntime_shared_lib_test_LIBS nsync::nsync_cpp)
++ # list(APPEND onnxruntime_shared_lib_test_LIBS nsync::nsync_cpp)
+ if(onnxruntime_USE_SNPE)
+ list(APPEND onnxruntime_shared_lib_test_LIBS onnxruntime_providers_snpe)
+ endif()
+@@ -1367,9 +1367,9 @@ if (NOT onnxruntime_ENABLE_TRAINING_TORCH_INTEROP)
+ if (CPUINFO_SUPPORTED AND NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
+ target_link_libraries(onnxruntime_mlas_test PRIVATE cpuinfo)
+ endif()
+- if(NOT WIN32)
+- target_link_libraries(onnxruntime_mlas_test PRIVATE nsync::nsync_cpp ${CMAKE_DL_LIBS})
+- endif()
++ # if(NOT WIN32)
++ # target_link_libraries(onnxruntime_mlas_test PRIVATE nsync::nsync_cpp ${CMAKE_DL_LIBS})
++ # endif()
+ if (CMAKE_SYSTEM_NAME STREQUAL "Android")
+ target_link_libraries(onnxruntime_mlas_test PRIVATE ${android_shared_libs})
+ endif()
+@@ -1631,9 +1631,9 @@ if (onnxruntime_BUILD_SHARED_LIB AND NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten"
+
+ set(onnxruntime_logging_apis_test_LIBS onnxruntime_common onnxruntime_test_utils)
+
+- if(NOT WIN32)
+- list(APPEND onnxruntime_logging_apis_test_LIBS nsync::nsync_cpp ${CMAKE_DL_LIBS})
+- endif()
++ # if(NOT WIN32)
++ # list(APPEND onnxruntime_logging_apis_test_LIBS nsync::nsync_cpp ${CMAKE_DL_LIBS})
++ # endif()
+
+ AddTest(DYN
+ TARGET onnxruntime_logging_apis_test
+diff --git a/include/onnxruntime/core/platform/ort_mutex.h b/include/onnxruntime/core/platform/ort_mutex.h
+index e24665f..2ea7272 100644
+--- a/include/onnxruntime/core/platform/ort_mutex.h
++++ b/include/onnxruntime/core/platform/ort_mutex.h
+@@ -102,13 +102,13 @@ std::cv_status OrtCondVar::wait_for(std::unique_lock<OrtMutex>& cond_mutex,
+ }
+ } // namespace onnxruntime
+ #else
+-#include "nsync.h"
++#include <pthread.h>
+ #include <mutex> //for unique_lock
+ #include <condition_variable> //for cv_status
+ namespace onnxruntime {
+
+ class OrtMutex {
+- nsync::nsync_mu data_ = NSYNC_MU_INIT;
++ pthread_mutex_t data_ = PTHREAD_MUTEX_INITIALIZER;
+
+ public:
+ constexpr OrtMutex() = default;
+@@ -116,16 +116,16 @@ class OrtMutex {
+ OrtMutex(const OrtMutex&) = delete;
+ OrtMutex& operator=(const OrtMutex&) = delete;
+
+- void lock() { nsync::nsync_mu_lock(&data_); }
+- bool try_lock() noexcept { return nsync::nsync_mu_trylock(&data_) == 0; }
+- void unlock() noexcept { nsync::nsync_mu_unlock(&data_); }
++ void lock() { pthread_mutex_lock(&data_); }
++ bool try_lock() noexcept { return pthread_mutex_lock(&data_) == 0; }
++ void unlock() noexcept { pthread_mutex_unlock(&data_); }
+
+- using native_handle_type = nsync::nsync_mu*;
++ using native_handle_type = pthread_mutex_t*;
+ native_handle_type native_handle() { return &data_; }
+ };
+
+ class OrtCondVar {
+- nsync::nsync_cv native_cv_object = NSYNC_CV_INIT;
++ pthread_cond_t native_cv_object = PTHREAD_COND_INITIALIZER;
+
+ public:
+ constexpr OrtCondVar() noexcept = default;
+@@ -134,8 +134,8 @@ class OrtCondVar {
+ OrtCondVar(const OrtCondVar&) = delete;
+ OrtCondVar& operator=(const OrtCondVar&) = delete;
+
+- void notify_one() noexcept { nsync::nsync_cv_signal(&native_cv_object); }
+- void notify_all() noexcept { nsync::nsync_cv_broadcast(&native_cv_object); }
++ void notify_one() noexcept { pthread_cond_signal(&native_cv_object); }
++ void notify_all() noexcept { pthread_cond_broadcast(&native_cv_object); }
+
+ void wait(std::unique_lock<OrtMutex>& lk);
+ template <class _Predicate>
+@@ -151,7 +151,7 @@ class OrtCondVar {
+ */
+ template <class Rep, class Period>
+ std::cv_status wait_for(std::unique_lock<OrtMutex>& cond_mutex, const std::chrono::duration<Rep, Period>& rel_time);
+- using native_handle_type = nsync::nsync_cv*;
++ using native_handle_type = pthread_cond_t*;
+ native_handle_type native_handle() { return &native_cv_object; }
+
+ private:
+diff --git a/onnxruntime/core/platform/posix/ort_mutex.cc b/onnxruntime/core/platform/posix/ort_mutex.cc
+index e124ce1..5397793 100644
+--- a/onnxruntime/core/platform/posix/ort_mutex.cc
++++ b/onnxruntime/core/platform/posix/ort_mutex.cc
+@@ -27,7 +27,7 @@ void OrtCondVar::timed_wait_impl(std::unique_lock<OrtMutex>& lk,
+ abs_deadline.tv_sec = ts_sec_max;
+ abs_deadline.tv_nsec = 999999999;
+ }
+- nsync::nsync_cv_wait_with_deadline(&native_cv_object, lk.mutex()->native_handle(), abs_deadline, nullptr);
++ pthread_cond_timedwait(&native_cv_object, lk.mutex()->native_handle(), &abs_deadline);
+ }
+
+ void OrtCondVar::wait(std::unique_lock<OrtMutex>& lk) {
+@@ -36,7 +36,7 @@ void OrtCondVar::wait(std::unique_lock<OrtMutex>& lk) {
+ ORT_THROW("OrtCondVar wait failed: mutex not locked");
+ }
+ #endif
+- nsync::nsync_cv_wait(&native_cv_object, lk.mutex()->native_handle());
++ pthread_cond_wait(&native_cv_object, lk.mutex()->native_handle());
+ }
+
+-} // namespace onnxruntime
+\ No newline at end of file
++} // namespace onnxruntime
+--
+2.41.0
+