Loading...
Searching...
No Matches
gpr::linalg::KokkosWorkspace Class Reference

#include <gpr/linalg/KokkosWorkspace.h>

Classes

struct  Impl

Public Member Functions

 KokkosWorkspace ()=default
 ~KokkosWorkspace ()=default
 KokkosWorkspace (const KokkosWorkspace &)=delete
KokkosWorkspace & operator= (const KokkosWorkspace &)=delete
EigenMatrix forward (const EigenMatrix &factor, const EigenMatrix &rhs)
 L X = B.
EigenMatrix backward (const EigenMatrix &factor, const EigenMatrix &rhs)
 L^T X = B.
EigenMatrix solve (const EigenMatrix &factor, const EigenMatrix &rhs)
 L L^T X = B with one right-hand-side upload and one result download.
Eigen::VectorXd squaredNorms (const EigenMatrix &factor, const EigenMatrix &rhs)
 Squared column norms of L^{-1} B; only the norms are downloaded.
EigenMatrix inverse (const EigenMatrix &factor)
 (L L^T)^{-1}, formed on the device from the resident factor.
KokkosTransferStats transferStats () const
void resetTransferStats ()
 Zeroes the counters; the resident factor is kept.
void clear ()
 Releases the resident factor and all device buffers; counters are kept.

Friends

class KokkosFactor

Detailed Description

Device copy of one physical host factor plus reusable device buffers. Every call takes the factor explicitly. The resident copy is reused only when the supplied factor has the same shape and identical stored entries as the host witness of the last upload; any other factor, including the same storage after in-place mutation, is uploaded again. Inputs and results remain host matrices. Calls on one workspace are serialized. Device storage is released at the start of Kokkos::finalize, after which device operations throw std::logic_error.

The execution-space state is created on the first call. A default-constructed workspace is empty, so a non-Kokkos build can embed one without linking the Kokkos runtime.

Definition at line 37 of file KokkosWorkspace.h.

Constructor & Destructor Documentation

◆ KokkosWorkspace() [1/2]

gpr::linalg::KokkosWorkspace::KokkosWorkspace ( )
default

◆ ~KokkosWorkspace()

gpr::linalg::KokkosWorkspace::~KokkosWorkspace ( )
default

◆ KokkosWorkspace() [2/2]

gpr::linalg::KokkosWorkspace::KokkosWorkspace ( const KokkosWorkspace & )
delete

Member Function Documentation

◆ backward()

EigenMatrix gpr::linalg::KokkosWorkspace::backward ( const EigenMatrix & factor,
const EigenMatrix & rhs )

L^T X = B.

Definition at line 568 of file KokkosBackend.cpp.

570{
571 ensureState();
572 std::lock_guard<std::mutex> lock(impl_->mutex);
573 if (!impl_->checkSolve(L, B)) return EigenMatrix(L.rows(), B.cols());
574 KernelWall wall(KernelWall::Kind::Solve);
575 impl_->beginSolve(L, B);
576 detail::solve_lower(detail::exec_space{}, impl_->factor, impl_->work, true);
577 return impl_->download(impl_->work);
578}
Eigen::Matrix< double, EigenDynamic, EigenDynamic, EigenMatrixStorage > EigenMatrix
Definition Macros.h:20

◆ clear()

void gpr::linalg::KokkosWorkspace::clear ( )

Releases the resident factor and all device buffers; counters are kept.

Definition at line 646 of file KokkosBackend.cpp.

647{
648 ensureState();
649 std::lock_guard<std::mutex> lock(impl_->mutex);
650 impl_->release();
651}

◆ forward()

EigenMatrix gpr::linalg::KokkosWorkspace::forward ( const EigenMatrix & factor,
const EigenMatrix & rhs )

L X = B.

Definition at line 556 of file KokkosBackend.cpp.

557{
558 ensureState();
559 std::lock_guard<std::mutex> lock(impl_->mutex);
560 if (!impl_->checkSolve(L, B)) return EigenMatrix(L.rows(), B.cols());
561 KernelWall wall(KernelWall::Kind::Solve);
562 impl_->beginSolve(L, B);
563 detail::solve_lower(detail::exec_space{}, impl_->factor, impl_->work,
564 false);
565 return impl_->download(impl_->work);
566}

◆ inverse()

EigenMatrix gpr::linalg::KokkosWorkspace::inverse ( const EigenMatrix & factor)

(L L^T)^{-1}, formed on the device from the resident factor.

Definition at line 612 of file KokkosBackend.cpp.

613{
614 ensureState();
615 std::lock_guard<std::mutex> lock(impl_->mutex);
616 if (L.rows() != L.cols())
617 throw std::invalid_argument("Kokkos inverse requires a square factor");
618 const auto n = static_cast<std::size_t>(
619 detail::kokkosSolverExtent(static_cast<std::size_t>(L.rows())));
620 impl_->rejectFinalized();
621 if (n == 0) return EigenMatrix(0, 0);
622 KernelWall wall(KernelWall::Kind::Solve);
623 impl_->requireRuntime();
624 impl_->bindFactor(L);
625 detail::reserve_view(impl_->work, n, n, "gpr workspace inverse root");
626 detail::reserve_view(impl_->product, n, n, "gpr workspace inverse");
627 detail::cholesky_inverse_on_device(impl_->factor, impl_->work,
628 impl_->product);
629 return impl_->download(impl_->product);
630}

◆ operator=()

KokkosWorkspace & gpr::linalg::KokkosWorkspace::operator= ( const KokkosWorkspace & )
delete

◆ resetTransferStats()

void gpr::linalg::KokkosWorkspace::resetTransferStats ( )

Zeroes the counters; the resident factor is kept.

Definition at line 639 of file KokkosBackend.cpp.

640{
641 ensureState();
642 std::lock_guard<std::mutex> lock(impl_->mutex);
643 impl_->stats = KokkosTransferStats{};
644}

◆ solve()

EigenMatrix gpr::linalg::KokkosWorkspace::solve ( const EigenMatrix & factor,
const EigenMatrix & rhs )

L L^T X = B with one right-hand-side upload and one result download.

Definition at line 580 of file KokkosBackend.cpp.

581{
582 ensureState();
583 std::lock_guard<std::mutex> lock(impl_->mutex);
584 if (!impl_->checkSolve(L, B)) return EigenMatrix(L.rows(), B.cols());
585 KernelWall wall(KernelWall::Kind::Solve);
586 impl_->beginSolve(L, B);
587 detail::solve_lower(detail::exec_space{}, impl_->factor, impl_->work,
588 false);
589 detail::solve_lower(detail::exec_space{}, impl_->factor, impl_->work, true);
590 return impl_->download(impl_->work);
591}

◆ squaredNorms()

Eigen::VectorXd gpr::linalg::KokkosWorkspace::squaredNorms ( const EigenMatrix & factor,
const EigenMatrix & rhs )

Squared column norms of L^{-1} B; only the norms are downloaded.

Definition at line 593 of file KokkosBackend.cpp.

595{
596 ensureState();
597 std::lock_guard<std::mutex> lock(impl_->mutex);
598 if (!impl_->checkSolve(L, B)) return Eigen::VectorXd::Zero(B.cols());
599 KernelWall wall(KernelWall::Kind::Solve);
600 impl_->beginSolve(L, B);
601 detail::solve_lower(detail::exec_space{}, impl_->factor, impl_->work,
602 false);
603 detail::reserve_view(impl_->norms, static_cast<std::size_t>(B.cols()),
604 "gpr workspace norms");
605 detail::column_squared_norms(impl_->work, impl_->norms);
606 Eigen::VectorXd result;
607 detail::to_eigen(impl_->norms, result);
608 impl_->stats.result_download_bytes += detail::byte_count(result.size());
609 return result;
610}

◆ transferStats()

KokkosTransferStats gpr::linalg::KokkosWorkspace::transferStats ( ) const

Definition at line 632 of file KokkosBackend.cpp.

633{
634 ensureState();
635 std::lock_guard<std::mutex> lock(impl_->mutex);
636 return impl_->stats;
637}

◆ KokkosFactor

friend class KokkosFactor
friend

Definition at line 63 of file KokkosWorkspace.h.


The documentation for this class was generated from the following files: