Skip to content

Commit

Permalink
[kernels] use static llvm:ThreadPool in pipeline
Browse files Browse the repository at this point in the history
This patch adds a static llvm::ThreadPool which is to be used by the
MTWrapper for creating WorkerCPU instances.

closes #878
  • Loading branch information
philipportner committed Nov 1, 2024
1 parent e912c6f commit d35af16
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/runtime/local/vectorized/MTWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <utility>

#include <hwloc.h>
#include <llvm/Support/ThreadPool.h>

// TODO generalize for arbitrary inputs (not just binary)

Expand All @@ -56,6 +57,11 @@ template <typename DT> class MTWrapperBase {
PipelineHWlocInfo _topology;
DCTX(_ctx);

llvm::ThreadPool &getThreadPool() {
static llvm::ThreadPool pool(llvm::hardware_concurrency(_numCPPThreads));
return pool;
}

std::pair<size_t, size_t> getInputProperties(Structure **inputs, size_t numInputs, VectorSplit *splits) {
auto len = 0ul;
auto mem_required = 0ul;
Expand Down Expand Up @@ -85,6 +91,7 @@ template <typename DT> class MTWrapperBase {
_topology.physicalIds.size());
w = std::make_unique<WorkerCPU>(qvector, _topology.physicalIds, _topology.uniqueThreads, _ctx, verbose, 0,
batchSize, i, numQueues, queueMode, this->_victimSelection, pinWorkers);
this->getThreadPool().async([&w]() { w->run(); });
i++;
}
}
Expand Down Expand Up @@ -129,8 +136,7 @@ template <typename DT> class MTWrapperBase {
DCTX(ctx)) = 0;

void joinAll() {
for (auto &w : cpp_workers)
w->join();
this->getThreadPool().wait();
for (auto &w : cuda_workers)
w->join();
}
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/local/vectorized/Worker.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Worker {
}

virtual ~Worker() {
if (t->joinable())
if (t && t->joinable())
t->join();
};

Expand Down

0 comments on commit d35af16

Please sign in to comment.