Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReductionToBand: Dynamic number of workers for Panel computation (bulk) #1232

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace dlaf::eigensolver::internal {

inline size_t getReductionToBandPanelNWorkers() noexcept {
inline size_t get_red2band_panel_nworkers() noexcept {
// Note: precautionarily we leave at least 1 thread "free" to do other stuff (if possible)
const std::size_t available_workers = pika::resource::get_thread_pool("default").get_os_thread_count();
const std::size_t min_workers = 1;
Expand Down
41 changes: 25 additions & 16 deletions include/dlaf/eigensolver/reduction_to_band/impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,23 +311,28 @@ void computePanelReflectors(MatrixLikeA& mat_a, MatrixLikeTaus& mat_taus, const
panel_tiles.emplace_back(matrix::splitTile(mat_a.readwrite(i), spec));
}

const std::size_t nthreads = getReductionToBandPanelNWorkers();
auto s =
ex::when_all(ex::just(std::make_unique<pika::barrier<>>(nthreads),
const std::size_t nworkers = [nrtiles = panel_tiles.size()]() {
const std::size_t min_workers = 1;
const std::size_t available_workers = get_red2band_panel_nworkers();
const std::size_t ideal_workers = to_sizet(nrtiles);
return std::clamp(ideal_workers, min_workers, available_workers);
}();
ex::start_detached(
ex::when_all(ex::just(std::make_unique<pika::barrier<>>(nworkers),
std::vector<common::internal::vector<T>>{}), // w (internally required)
mat_taus.readwrite(LocalTileIndex(j_sub, 0)),
ex::when_all_vector(std::move(panel_tiles))) |
di::continues_on(di::getBackendScheduler<Backend::MC>(thread_priority::high)) |
ex::bulk(nthreads, [nthreads, cols = panel_view.cols()](const std::size_t index, auto& barrier_ptr,
ex::bulk(nworkers, [nworkers, cols = panel_view.cols()](const std::size_t index, auto& barrier_ptr,
auto& w, auto& taus, auto& tiles) {
const auto barrier_busy_wait = getReductionToBandBarrierBusyWait();
const std::size_t batch_size = util::ceilDiv(tiles.size(), nthreads);
const std::size_t batch_size = util::ceilDiv(tiles.size(), nworkers);
const std::size_t begin = index * batch_size;
const std::size_t end = std::min(index * batch_size + batch_size, tiles.size());
const SizeType nrefls = taus.size().rows();

if (index == 0) {
w.resize(nthreads);
w.resize(nworkers);
}

for (SizeType j = 0; j < nrefls; ++j) {
Expand Down Expand Up @@ -357,8 +362,7 @@ void computePanelReflectors(MatrixLikeA& mat_a, MatrixLikeTaus& mat_taus, const
updateTrailingPanel(has_head, tiles, j, w[0], taus({j, 0}), begin, end);
barrier_ptr->arrive_and_wait(barrier_busy_wait);
}
});
ex::start_detached(std::move(s));
}));
}

template <Backend B, Device D, class T>
Expand Down Expand Up @@ -632,27 +636,33 @@ void computePanelReflectors(TriggerSender&& trigger, comm::IndexT_MPI rank_v0,
panel_tiles.emplace_back(matrix::splitTile(mat_a.readwrite(i), spec));
}

const std::size_t nthreads = getReductionToBandPanelNWorkers();
auto s =
ex::when_all(ex::just(std::make_unique<pika::barrier<>>(nthreads),
const std::size_t nworkers = [nrtiles = panel_tiles.size()]() {
const std::size_t min_workers = 1;
const std::size_t available_workers = get_red2band_panel_nworkers();
const std::size_t ideal_workers = util::ceilDiv(to_sizet(nrtiles), to_sizet(2));
return std::clamp(ideal_workers, min_workers, available_workers);
}();

ex::start_detached(
ex::when_all(ex::just(std::make_unique<pika::barrier<>>(nworkers),
std::vector<common::internal::vector<T>>{}), // w (internally required)
mat_taus.readwrite(GlobalTileIndex(j_sub, 0)),
ex::when_all_vector(std::move(panel_tiles)),
std::forward<CommSender>(mpi_col_chain_panel), std::forward<TriggerSender>(trigger)) |
di::continues_on(di::getBackendScheduler<Backend::MC>(pika::execution::thread_priority::high)) |
ex::bulk(nthreads, [nthreads, rank_v0,
ex::bulk(nworkers, [nworkers, rank_v0,
cols = panel_view.cols()](const std::size_t index, auto& barrier_ptr, auto& w,
auto& taus, auto& tiles, auto&& pcomm) {
const bool rankHasHead = rank_v0 == pcomm.get().rank();

const auto barrier_busy_wait = getReductionToBandBarrierBusyWait();
const std::size_t batch_size = util::ceilDiv(tiles.size(), nthreads);
const std::size_t batch_size = util::ceilDiv(tiles.size(), nworkers);
const std::size_t begin = index * batch_size;
const std::size_t end = std::min(index * batch_size + batch_size, tiles.size());
const SizeType nrefls = taus.size().rows();

if (index == 0) {
w.resize(nthreads);
w.resize(nworkers);
}

for (SizeType j = 0; j < nrefls; ++j) {
Expand Down Expand Up @@ -685,8 +695,7 @@ void computePanelReflectors(TriggerSender&& trigger, comm::IndexT_MPI rank_v0,
updateTrailingPanel(has_head, tiles, j, w[0], taus({j, 0}), begin, end);
barrier_ptr->arrive_and_wait(barrier_busy_wait);
}
});
ex::start_detached(std::move(s));
}));
}

template <Backend B, Device D, class T>
Expand Down
Loading