Add our own blas-like routines that use stockfish's thread pool for parallelization.

This commit is contained in:
Tomasz Sobczyk
2020-10-28 14:41:51 +01:00
committed by nodchip
parent ee0917a345
commit c56a4a36eb
5 changed files with 1202 additions and 0 deletions

View File

@@ -39,6 +39,15 @@
/// pointer to an entry its life time is unlimited and we don't have
/// to care about someone changing the entry under our feet.
namespace Detail {
template <typename T>
struct TypeIdentity {
using Type = T;
};
}
class Thread {
std::mutex mutex;
@@ -120,6 +129,26 @@ struct ThreadPool : public std::vector<Thread*> {
// to the state of the `worker` function object.
void execute_with_workers(const std::function<void(Thread&)>& worker);
template <typename IndexT, typename FuncT>
void for_each_index_with_workers(
IndexT begin,
typename Detail::TypeIdentity<IndexT>::Type end,
FuncT func)
{
std::atomic<IndexT> i_atomic = begin;
execute_with_workers(
[&i_atomic, end, func](Thread& th) mutable {
for(;;) {
const auto i = i_atomic.fetch_add(1);
if (i >= end)
break;
func(th, i);
}
});
}
void start_thinking(Position&, StateListPtr&, const Search::LimitsType&, bool = false);
void clear();
void set(size_t);