Skip to content

Commit

Permalink
Moving TPAUSE support check to spinpause.h, move both mm_pause and tp…
Browse files Browse the repository at this point in the history
…ause to SpinPause function.
  • Loading branch information
kleiti committed Apr 18, 2024
1 parent be6d515 commit 0ef0c10
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
16 changes: 9 additions & 7 deletions include/onnxruntime/core/common/spin_pause.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,29 @@

#if defined(_M_AMD64) || defined(__x86_64__)
#include <cstdint>
#include "core/common/cpuid_info.h"
#endif

namespace onnxruntime {

const bool tpause = CPUIDInfo::GetCPUIDInfo().HasTPAUSE();
const std::uint64_t spin_delay_cycles = 2000;

namespace concurrency {

// Intrinsic to use in spin-loops

inline void SpinPause() {
#if defined(_M_AMD64) || defined(__x86_64__)
if(tpause) {
_tpause(0x0, __rdtsc() + spin_delay_cycles);
}
else{
_mm_pause();
#endif
}

inline void SpinTPAUSE() {
#if defined(_M_AMD64) || defined(__x86_64__)
const std::uint64_t spin_delay_cycles = 2000;
_tpause(0x0, __rdtsc() + spin_delay_cycles);
#endif
}

} // namespace concurrency

} // namespace onnxruntime

15 changes: 2 additions & 13 deletions include/onnxruntime/core/platform/EigenNonBlockingThreadPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@
#include "core/platform/ort_spin_lock.h"
#include "core/platform/Barrier.h"

#if defined(CPUINFO_SUPPORTED) && !defined(__APPLE__) && !defined(__ANDROID__) && !defined(__wasm__) && !defined(_AIX)
#include <cpuinfo.h>
#endif

// ORT thread pool overview
// ------------------------
//
Expand Down Expand Up @@ -1539,7 +1535,6 @@ class ThreadPoolTempl : public onnxruntime::concurrency::ExtendedThreadPoolInter
constexpr int log2_spin = 20;
const int spin_count = allow_spinning_ ? (1ull << log2_spin) : 0;
const int steal_count = spin_count / 100;
const bool tpause = CPUIDInfo::GetCPUIDInfo().HasTPAUSE();

SetDenormalAsZero(set_denormal_as_zero_);
profiler_.LogThreadId(thread_id);
Expand All @@ -1559,14 +1554,8 @@ class ThreadPoolTempl : public onnxruntime::concurrency::ExtendedThreadPoolInter
if (spin_loop_status_.load(std::memory_order_relaxed) == SpinLoopStatus::kIdle) {
break;
}

if (tpause) {
onnxruntime::concurrency::SpinTPAUSE();
}
else {
onnxruntime::concurrency::SpinPause();
}
}
onnxruntime::concurrency::SpinPause();
}

// Attempt to block
if (!t) {
Expand Down

0 comments on commit 0ef0c10

Please sign in to comment.