Loading...
Searching...
No Matches
LocalExecutor.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// Copyright (c) gpridge developers
3
4#include "LocalExecutor.h"
5
6#include <algorithm>
7#include <atomic>
8#include <stdexcept>
9
10#include "LinalgThreads.h"
11
12namespace gpr::linalg {
13namespace {
14std::atomic<int> requested_kernel_threads{1};
15std::atomic<int> default_concurrency{1};
16} // namespace
17
18void configureKernelThreads(int threads)
19{
20 const LocalExecutor validated(threads);
21 requested_kernel_threads.store(validated.concurrency(),
22 std::memory_order_relaxed);
24}
25
27{
28 // The linalg count is the assembly team; --kernel-threads can widen it
29 // but its default of one must not shrink it.
30 int team = requested_kernel_threads.load(std::memory_order_relaxed);
32 team = std::max(team, configuredLinalgThreads());
33 default_concurrency.store(team, std::memory_order_relaxed);
34}
35
37 : LocalExecutor(default_concurrency.load(std::memory_order_relaxed))
38{
39}
40
42{
43 if (concurrency < 1 || (concurrency > 1 && !parallelAvailable()))
44 throw std::invalid_argument(
45 "kernel threads require a positive count and parallel STL support");
46}
47
49{
50#if defined(GPR_USE_STDPAR) || defined(USE_OPENMP)
51 return true;
52#else
53 return false;
54#endif
55}
56
57} // namespace gpr::linalg
int concurrency() const noexcept
static bool parallelAvailable() noexcept
Dense and structured linear algebra behind the GP: Cholesky and eigen solvers, linear operators,...
void refreshKernelTeam()
void configureKernelThreads(int threads)
int configuredLinalgThreads() noexcept
Requested dense numerical budget, independent of nested BLAS controls.
STL namespace.