-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework wait: own files, partial struct specialization
- Loading branch information
Showing
5 changed files
with
152 additions
and
61 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
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,79 @@ | ||
//@HEADER | ||
// ************************************************************************ | ||
// | ||
// Kokkos v. 4.0 | ||
// Copyright (2022) National Technology & Engineering | ||
// Solutions of Sandia, LLC (NTESS). | ||
// | ||
// Under the terms of Contract DE-NA0003525 with NTESS, | ||
// the U.S. Government retains certain rights in this software. | ||
// | ||
// Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://kokkos.org/LICENSE for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//@HEADER | ||
|
||
#pragma once | ||
|
||
#include <KokkosComm/mpi/req.hpp> | ||
|
||
namespace KokkosComm::Impl { | ||
|
||
/* Enqueue a communication completion*/ | ||
template <KokkosExecutionSpace ExecSpace> | ||
struct Wait<ExecSpace, Mpi> { | ||
Wait(const ExecSpace &space, Req<Mpi> req) { | ||
// ensure that the execution space has completed all work before completing the communication | ||
space.fence(); | ||
MPI_Wait(&req.mpi_request(), MPI_STATUS_IGNORE); | ||
for (auto &f : req.record_->postWaits_) { | ||
f(); | ||
} | ||
req.record_->postWaits_.clear(); | ||
} | ||
}; | ||
|
||
template <KokkosExecutionSpace ExecSpace> | ||
struct WaitAll<ExecSpace, Mpi> { | ||
WaitAll(const ExecSpace &space, std::vector<Req<Mpi>> &reqs) { | ||
// ensure that the execution space has completed all work before completing the communication | ||
space.fence(); | ||
for (Req<Mpi> &req : reqs) { | ||
MPI_Wait(&req.mpi_request(), MPI_STATUS_IGNORE); | ||
for (auto &f : req.record_->postWaits_) { | ||
f(); | ||
} | ||
req.record_->postWaits_.clear(); | ||
} | ||
} | ||
}; | ||
|
||
/* Returns the index of the request that completed */ | ||
template <KokkosExecutionSpace ExecSpace> | ||
struct WaitAny<ExecSpace, Mpi> { | ||
static int execute(const ExecSpace &space, std::vector<Req<Mpi>> &reqs) { | ||
if (reqs.empty()) { | ||
return -1; | ||
} | ||
|
||
// ensure that the execution space has completed all work before completing the communication | ||
space.fence(); | ||
while (true) { // wait until something is done | ||
for (size_t i = 0; i < reqs.size(); ++i) { | ||
int completed; | ||
Req<Mpi> &req = reqs[i]; | ||
MPI_Test(&(req.mpi_request()), &completed, MPI_STATUS_IGNORE); | ||
if (completed) { | ||
for (auto &f : req.record_->postWaits_) { | ||
f(); | ||
} | ||
req.record_->postWaits_.clear(); | ||
return i; | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
|
||
} // namespace KokkosComm::Impl |
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,55 @@ | ||
//@HEADER | ||
// ************************************************************************ | ||
// | ||
// Kokkos v. 4.0 | ||
// Copyright (2022) National Technology & Engineering | ||
// Solutions of Sandia, LLC (NTESS). | ||
// | ||
// Under the terms of Contract DE-NA0003525 with NTESS, | ||
// the U.S. Government retains certain rights in this software. | ||
// | ||
// Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://kokkos.org/LICENSE for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//@HEADER | ||
|
||
#pragma once | ||
|
||
#include <Kokkos_Core.hpp> | ||
|
||
#include "fwd.hpp" | ||
#include "concepts.hpp" | ||
|
||
namespace KokkosComm { | ||
|
||
// FIXME: reverse order of these template params for automatic deduction | ||
template <KokkosExecutionSpace ExecSpace, CommunicationSpace CommSpace> | ||
void wait(const ExecSpace &space, Req<CommSpace> req) { | ||
Impl::Wait<ExecSpace, CommSpace>(space, req); | ||
} | ||
|
||
template <KokkosExecutionSpace ExecSpace, CommunicationSpace CommSpace> | ||
void wait_all(const ExecSpace &space, std::vector<Req<Mpi>> &reqs) { | ||
Impl::WaitAll<ExecSpace, CommSpace>(space, reqs); | ||
} | ||
|
||
template <KokkosExecutionSpace ExecSpace, CommunicationSpace CommSpace> | ||
int wait_any(const ExecSpace &space, std::vector<Req<Mpi>> &reqs) { | ||
return Impl::WaitAny<ExecSpace, CommSpace>::execute(space, reqs); | ||
} | ||
|
||
template <CommunicationSpace CommSpace> | ||
inline void wait(Req<CommSpace> req) { | ||
return wait<Kokkos::DefaultExecutionSpace, CommSpace>(Kokkos::DefaultExecutionSpace{}, req); | ||
} | ||
template <CommunicationSpace CommSpace> | ||
inline void wait_all(std::vector<Req<CommSpace>> &reqs) { | ||
wait_all<Kokkos::DefaultExecutionSpace, CommSpace>(Kokkos::DefaultExecutionSpace{}, reqs); | ||
} | ||
template <CommunicationSpace CommSpace> | ||
inline int wait_any(std::vector<Req<CommSpace>> &reqs) { | ||
return wait_any<Kokkos::DefaultExecutionSpace, CommSpace>(Kokkos::DefaultExecutionSpace{}, reqs); | ||
} | ||
|
||
} // namespace KokkosComm |