Loading...
Searching...
No Matches
gpr::linalg::KokkosWorkspace::Impl Struct Reference

Public Member Functions

void release ()
void rejectFinalized () const
void requireRuntime ()
void bindFactor (const EigenMatrix &supplied)
void uploadRhs (const EigenMatrix &rhs)
EigenMatrix download (const detail::device_matrix_t &source)
bool checkSolve (const EigenMatrix &L, const EigenMatrix &B) const
void beginSolve (const EigenMatrix &L, const EigenMatrix &B)
bool checkBoundSolve (const EigenMatrix &B) const

Public Attributes

std::mutex mutex
std::weak_ptr< Impl > self
bool hook_registered = false
bool finalized = false
EigenMatrix witness
bool resident = false
detail::device_matrix_t factor
detail::device_matrix_t work
detail::device_matrix_t product
detail::device_vector_t norms
KokkosTransferStats stats

Detailed Description

Definition at line 433 of file KokkosBackend.cpp.

Member Function Documentation

◆ beginSolve()

void gpr::linalg::KokkosWorkspace::Impl::beginSolve ( const EigenMatrix & L,
const EigenMatrix & B )
inline

Definition at line 526 of file KokkosBackend.cpp.

527 {
529 bindFactor(L);
530 uploadRhs(B);
531 }
void uploadRhs(const EigenMatrix &rhs)
void bindFactor(const EigenMatrix &supplied)

◆ bindFactor()

void gpr::linalg::KokkosWorkspace::Impl::bindFactor ( const EigenMatrix & supplied)
inline

Definition at line 480 of file KokkosBackend.cpp.

481 {
482 if (resident && detail::same_entries(supplied, witness)) return;
483 resident = false;
484 witness = supplied;
485 const auto n = static_cast<std::size_t>(witness.rows());
486 detail::reserve_view(factor, n, n, "gpr workspace factor");
487 detail::audited_deep_copy(factor, detail::wrap(witness),
488 detail::byte_count(witness.size()),
489 detail::CopyRole::ToExecution);
490 ++stats.factor_uploads;
491 stats.factor_upload_bytes += detail::byte_count(witness.size());
492 resident = true;
493 }

◆ checkBoundSolve()

bool gpr::linalg::KokkosWorkspace::Impl::checkBoundSolve ( const EigenMatrix & B) const
inline

Definition at line 533 of file KokkosBackend.cpp.

534 {
536 if (B.rows() != static_cast<Eigen::Index>(factor.extent(0)))
537 throw std::invalid_argument(
538 "Kokkos factor solve has incompatible shapes");
539 detail::kokkosSolverExtent(static_cast<std::size_t>(B.cols()));
540 return B.rows() != 0 && B.cols() != 0;
541 }

◆ checkSolve()

bool gpr::linalg::KokkosWorkspace::Impl::checkSolve ( const EigenMatrix & L,
const EigenMatrix & B ) const
inline

Definition at line 515 of file KokkosBackend.cpp.

516 {
517 if (L.rows() != L.cols() || B.rows() != L.rows())
518 throw std::invalid_argument(
519 "Kokkos triangular solve has incompatible shapes");
520 detail::kokkosSolverExtent(static_cast<std::size_t>(L.rows()));
521 detail::kokkosSolverExtent(static_cast<std::size_t>(B.cols()));
523 return L.rows() != 0 && B.cols() != 0;
524 }

◆ download()

EigenMatrix gpr::linalg::KokkosWorkspace::Impl::download ( const detail::device_matrix_t & source)
inline

Definition at line 506 of file KokkosBackend.cpp.

507 {
508 EigenMatrix result;
509 detail::to_eigen(source, result);
510 stats.result_download_bytes += detail::byte_count(result.size());
511 return result;
512 }
Eigen::Matrix< double, EigenDynamic, EigenDynamic, EigenMatrixStorage > EigenMatrix
Definition Macros.h:20

◆ rejectFinalized()

void gpr::linalg::KokkosWorkspace::Impl::rejectFinalized ( ) const
inline

Definition at line 457 of file KokkosBackend.cpp.

458 {
459 if (finalized || Kokkos::is_finalized())
460 throw std::logic_error("cannot use a finalized Kokkos runtime");
461 }

◆ release()

void gpr::linalg::KokkosWorkspace::Impl::release ( )
inline

Definition at line 447 of file KokkosBackend.cpp.

448 {
449 resident = false;
450 witness.resize(0, 0);
451 factor = detail::device_matrix_t();
452 work = detail::device_matrix_t();
453 product = detail::device_matrix_t();
454 norms = detail::device_vector_t();
455 }

◆ requireRuntime()

void gpr::linalg::KokkosWorkspace::Impl::requireRuntime ( )
inline

Definition at line 463 of file KokkosBackend.cpp.

464 {
465 detail::ensure_kokkos();
466 if (hook_registered) return;
467 // Kokkos keeps its finalize hooks in an unsynchronized container.
468 static std::mutex hook_mutex;
469 std::lock_guard<std::mutex> lock(hook_mutex);
470 Kokkos::push_finalize_hook([weak = self]() {
471 if (const std::shared_ptr<Impl> owner = weak.lock()) {
472 std::lock_guard<std::mutex> guard(owner->mutex);
473 owner->finalized = true;
474 owner->release();
475 }
476 });
477 hook_registered = true;
478 }

◆ uploadRhs()

void gpr::linalg::KokkosWorkspace::Impl::uploadRhs ( const EigenMatrix & rhs)
inline

Definition at line 495 of file KokkosBackend.cpp.

496 {
497 detail::reserve_view(work, static_cast<std::size_t>(rhs.rows()),
498 static_cast<std::size_t>(rhs.cols()),
499 "gpr workspace rhs");
500 detail::audited_deep_copy(work, detail::wrap(rhs),
501 detail::byte_count(rhs.size()),
502 detail::CopyRole::ToExecution);
503 stats.rhs_upload_bytes += detail::byte_count(rhs.size());
504 }

Member Data Documentation

◆ factor

detail::device_matrix_t gpr::linalg::KokkosWorkspace::Impl::factor

Definition at line 441 of file KokkosBackend.cpp.

◆ finalized

bool gpr::linalg::KokkosWorkspace::Impl::finalized = false

Definition at line 437 of file KokkosBackend.cpp.

◆ hook_registered

bool gpr::linalg::KokkosWorkspace::Impl::hook_registered = false

Definition at line 436 of file KokkosBackend.cpp.

◆ mutex

std::mutex gpr::linalg::KokkosWorkspace::Impl::mutex

Definition at line 434 of file KokkosBackend.cpp.

◆ norms

detail::device_vector_t gpr::linalg::KokkosWorkspace::Impl::norms

Definition at line 444 of file KokkosBackend.cpp.

◆ product

detail::device_matrix_t gpr::linalg::KokkosWorkspace::Impl::product

Definition at line 443 of file KokkosBackend.cpp.

◆ resident

bool gpr::linalg::KokkosWorkspace::Impl::resident = false

Definition at line 440 of file KokkosBackend.cpp.

◆ self

std::weak_ptr<Impl> gpr::linalg::KokkosWorkspace::Impl::self

Definition at line 435 of file KokkosBackend.cpp.

◆ stats

KokkosTransferStats gpr::linalg::KokkosWorkspace::Impl::stats

Definition at line 445 of file KokkosBackend.cpp.

◆ witness

EigenMatrix gpr::linalg::KokkosWorkspace::Impl::witness

Definition at line 439 of file KokkosBackend.cpp.

◆ work

detail::device_matrix_t gpr::linalg::KokkosWorkspace::Impl::work

Definition at line 442 of file KokkosBackend.cpp.


The documentation for this struct was generated from the following file: