-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Print warning when too few logical cores are available
- Loading branch information
Showing
7 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#pragma once | ||
|
||
#include <cstdint> | ||
|
||
namespace celerity { | ||
namespace detail { | ||
|
||
uint32_t affinity_cores_available(); | ||
|
||
/* a priori we need 3 threads, plus 1 for parallel-task workers and at least one more for host-task. | ||
This depends on the application invoking celerity. */ | ||
constexpr static uint64_t min_cores_needed = 5; | ||
|
||
} // namespace detail | ||
} // namespace celerity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#pragma once | ||
|
||
#include <cstdint> | ||
#include <type_traits> | ||
|
||
namespace celerity { | ||
namespace detail { | ||
namespace utils { | ||
|
||
template <typename BitMaskT> | ||
constexpr inline uint32_t popcount(const BitMaskT bit_mask) noexcept { | ||
static_assert(std::is_integral_v<BitMaskT> && std::is_unsigned_v<BitMaskT>, "popcount argument needs to be an unsigned integer type."); | ||
|
||
uint32_t counter = 0; | ||
for(auto b = bit_mask; b; b >>= 1) { | ||
counter += b & 1; | ||
} | ||
return counter; | ||
} | ||
|
||
} // namespace utils | ||
} // namespace detail | ||
} // namespace celerity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
#include <cassert> | ||
#include <cstdint> | ||
|
||
#include <pthread.h> | ||
#include <sched.h> | ||
|
||
#include "affinity.h" | ||
|
||
namespace celerity { | ||
namespace detail { | ||
|
||
uint32_t affinity_cores_available() { | ||
cpu_set_t available_cores; | ||
const auto affinity_error = pthread_getaffinity_np(pthread_self(), sizeof(cpu_set_t), &available_cores); | ||
assert(affinity_error == 0 && "Error retrieving affinity mask."); | ||
return CPU_COUNT(&available_cores); | ||
} | ||
|
||
} // namespace detail | ||
} // namespace celerity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include <cassert> | ||
|
||
#include <Windows.h> | ||
|
||
#include "affinity.h" | ||
#include "utils.h" | ||
|
||
namespace celerity { | ||
namespace detail { | ||
|
||
uint32_t affinity_cores_available() { | ||
using native_cpu_set = DWORD_PTR; | ||
|
||
native_cpu_set available_cores; | ||
[[maybe_unused]] native_cpu_set sys_affinity_mask; | ||
const auto affinity_error = GetProcessAffinityMask(GetCurrentProcess(), &available_cores, &sys_affinity_mask); | ||
assert(affinity_error != FALSE && "Error retrieving affinity mask."); | ||
return utils::popcount(available_cores); | ||
} | ||
|
||
} // namespace detail | ||
} // namespace celerity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters