Skip to content

Commit

Permalink
Thread pool rewrite, add per-worker barrier types
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 726523134
  • Loading branch information
jan-wassenberg authored and copybara-github committed Mar 3, 2025
1 parent c9001cb commit b73272d
Show file tree
Hide file tree
Showing 4 changed files with 733 additions and 465 deletions.
8 changes: 4 additions & 4 deletions hwy/contrib/thread_pool/spin.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ struct SpinResult {
// are rarely called from SIMD code, hence we do not integrate this into
// `HWY_TARGET` and its runtime dispatch mechanism. Returned by `Type()`, also
// used by callers to set the `disabled` argument for `DetectSpin`.
enum class SpinType {
enum class SpinType : uint8_t {
kMonitorX, // AMD
kUMonitor, // Intel
kPause
Expand All @@ -80,9 +80,9 @@ static inline const char* ToString(SpinType type) {
return "UMonitor_C0.2";
case SpinType::kPause:
return "Pause";
default:
return nullptr;
}

return nullptr;
}

// Indirect function calls turn out to be too expensive because this is called
Expand Down Expand Up @@ -244,7 +244,7 @@ static inline SpinType DetectSpin(int disabled = 0) {

// Calls `func(spin)` for the given `spin_type`.
template <class Func>
void CallWithSpin(SpinType spin_type, const Func& func) {
void CallWithSpin(SpinType spin_type, Func&& func) {
switch (spin_type) {
#if HWY_ENABLE_MONITORX
case SpinType::kMonitorX:
Expand Down
4 changes: 2 additions & 2 deletions hwy/contrib/thread_pool/spin_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ struct TestPingPongT {
const double t0 = hwy::platform::Now();
std::atomic_flag error = ATOMIC_FLAG_INIT;

std::atomic<size_t> reps1;
std::atomic<size_t> reps2;
alignas(HWY_ALIGNMENT) std::atomic<size_t> reps1;
alignas(HWY_ALIGNMENT) std::atomic<size_t> reps2;

constexpr size_t kF64PerLine = HWY_ALIGNMENT / 8;
alignas(HWY_ALIGNMENT) std::atomic<double> before_thread_done[kF64PerLine];
Expand Down
Loading

0 comments on commit b73272d

Please sign in to comment.