Kokkos Node API and Local Linear Algebra Kernels Version of the Day
Public Member Functions
TSQR::CacheBlocker< Ordinal, Scalar > Class Template Reference

Break a tall skinny matrix by rows into cache blocks. More...

#include <Tsqr_CacheBlocker.hpp>

Inheritance diagram for TSQR::CacheBlocker< Ordinal, Scalar >:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 CacheBlocker (const Ordinal num_rows, const Ordinal num_cols, const CacheBlockingStrategy< Ordinal, Scalar > &strategy)
 Constructor.
 CacheBlocker ()
 Default constructor, so that CacheBlocker is DefaultConstructible.
 CacheBlocker (const CacheBlocker &rhs)
 Copy constructor.
CacheBlockeroperator= (const CacheBlocker &rhs)
 Assignment operator.
size_t TEUCHOS_DEPRECATED cache_block_size () const
 Cache size hint (in bytes).
size_t cache_size_hint () const
 Cache size hint (in bytes).
Ordinal nrows () const
 Number of rows in the matrix to block.
Ordinal ncols () const
 Number of columns in the matrix to block.
template<class MatrixViewType >
MatrixViewType split_top_block (MatrixViewType &A, const bool contiguous_cache_blocks) const
 Split A in place into [A_top; A_rest].
template<class MatrixViewType >
MatrixViewType top_block (const MatrixViewType &A, const bool contiguous_cache_blocks) const
 View of the topmost cache block of A.
template<class MatrixViewType >
MatrixViewType split_bottom_block (MatrixViewType &A, const bool contiguous_cache_blocks) const
 Split A in place into [A_rest; A_bot].
template<class MatrixViewType >
void fill_with_zeros (MatrixViewType A, const bool contiguous_cache_blocks) const
 Fill the matrix A with zeros, respecting cache blocks.
void fill_with_zeros (const Ordinal num_rows, const Ordinal num_cols, Scalar A[], const Ordinal lda, const bool contiguous_cache_blocks) const
 Fill the matrix A with zeros, respecting cache blocks.
void cache_block (const Ordinal num_rows, const Ordinal num_cols, Scalar A_out[], const Scalar A_in[], const Ordinal lda_in) const
 Cache-block the given A_in matrix into A_out.
void un_cache_block (const Ordinal num_rows, const Ordinal num_cols, Scalar A_out[], const Ordinal lda_out, const Scalar A_in[]) const
 "Un"-cache-block the given A_in matrix into A_out.
template<class MatrixViewType >
MatrixViewType get_cache_block (MatrixViewType A, const typename MatrixViewType::ordinal_type cache_block_index, const bool contiguous_cache_blocks) const
 Return the cache block with index cache_block_index.
bool operator== (const CacheBlockingStrategy< Ordinal, Scalar > &rhs) const
 Equality operator.

Detailed Description

template<class Ordinal, class Scalar>
class TSQR::CacheBlocker< Ordinal, Scalar >

Break a tall skinny matrix by rows into cache blocks.

Author:
Mark Hoemmen

A CacheBlocker uses a particular cache blocking strategy to partition an nrows by ncols matrix by rows into cache blocks. The entries in a cache block may be stored contiguously, or as non-contiguous partitions of a matrix stored conventionally (in column-major order).

The CacheBlocker blocks any matrix with the same number of rows in the same way, regardless of the number of columns (the cache blocking strategy's number of columns is set on construction). This is useful for TSQR's apply() routine, which requires that the output matrix C be blocked in the same way as the input matrix Q (in which the Q factor is stored implicitly).

Definition at line 59 of file Tsqr_CacheBlocker.hpp.


Constructor & Destructor Documentation

template<class Ordinal, class Scalar>
TSQR::CacheBlocker< Ordinal, Scalar >::CacheBlocker ( const Ordinal  num_rows,
const Ordinal  num_cols,
const CacheBlockingStrategy< Ordinal, Scalar > &  strategy 
) [inline]

Constructor.

Parameters:
num_rowsNumber of rows in the matrix to block.
num_colsNumber of columns in the matrix to block.
strategyCache blocking strategy object (passed by copy).
Note:
The CacheBlocker's number of columns may differ from the number of columns associated with the cache blocking strategy. The strategy uses a fixed number of columns for all matrices with the same number of rows, so that it blocks all such matrices in the same way (at the same row indices). This is useful for TSQR's apply() and explicit_Q() methods.

Definition at line 91 of file Tsqr_CacheBlocker.hpp.

template<class Ordinal, class Scalar>
TSQR::CacheBlocker< Ordinal, Scalar >::CacheBlocker ( ) [inline]

Default constructor, so that CacheBlocker is DefaultConstructible.

Definition at line 103 of file Tsqr_CacheBlocker.hpp.

template<class Ordinal, class Scalar>
TSQR::CacheBlocker< Ordinal, Scalar >::CacheBlocker ( const CacheBlocker< Ordinal, Scalar > &  rhs) [inline]

Copy constructor.

Definition at line 110 of file Tsqr_CacheBlocker.hpp.


Member Function Documentation

template<class Ordinal, class Scalar>
CacheBlocker& TSQR::CacheBlocker< Ordinal, Scalar >::operator= ( const CacheBlocker< Ordinal, Scalar > &  rhs) [inline]

Assignment operator.

Definition at line 118 of file Tsqr_CacheBlocker.hpp.

template<class Ordinal, class Scalar>
size_t TEUCHOS_DEPRECATED TSQR::CacheBlocker< Ordinal, Scalar >::cache_block_size ( ) const [inline]

Cache size hint (in bytes).

This method is deprecated, because the name is misleading. Please call cache_size_hint() instead.

Definition at line 130 of file Tsqr_CacheBlocker.hpp.

template<class Ordinal, class Scalar>
size_t TSQR::CacheBlocker< Ordinal, Scalar >::cache_size_hint ( ) const [inline]

Cache size hint (in bytes).

Definition at line 135 of file Tsqr_CacheBlocker.hpp.

template<class Ordinal, class Scalar>
Ordinal TSQR::CacheBlocker< Ordinal, Scalar >::nrows ( ) const [inline]

Number of rows in the matrix to block.

Definition at line 138 of file Tsqr_CacheBlocker.hpp.

template<class Ordinal, class Scalar>
Ordinal TSQR::CacheBlocker< Ordinal, Scalar >::ncols ( ) const [inline]

Number of columns in the matrix to block.

Definition at line 141 of file Tsqr_CacheBlocker.hpp.

template<class Ordinal, class Scalar>
template<class MatrixViewType >
MatrixViewType TSQR::CacheBlocker< Ordinal, Scalar >::split_top_block ( MatrixViewType &  A,
const bool  contiguous_cache_blocks 
) const [inline]

Split A in place into [A_top; A_rest].

Return the topmost cache block A_top of A, and modify A in place to be the "rest" of the matrix A_rest.

Parameters:
A[in/out] On input: view of the matrix to split. On output: the "rest" of the matrix. If there is only one cache block, A_top contains all of the matrix and A is empty on output.
contiguous_cache_blocks[in] Whether cache blocks in the matrix A are stored contiguously (default is false).
Returns:
View of the topmost cache block A_top.
Note:
The number of rows in A_top depends on the number of columns with which this CacheBlocker was set up (rather than the number of columns in A, which may not be the same). The idea is to have the number and distribution of rows in the cache blocks be the same as the original nrows() by ncols() matrix with which this CacheBlocker was initialized.

Definition at line 165 of file Tsqr_CacheBlocker.hpp.

template<class Ordinal, class Scalar>
template<class MatrixViewType >
MatrixViewType TSQR::CacheBlocker< Ordinal, Scalar >::top_block ( const MatrixViewType &  A,
const bool  contiguous_cache_blocks 
) const [inline]

View of the topmost cache block of A.

The matrix view A is copied so the view itself won't be modified.

Parameters:
A[in] View of the matrix to block.
contiguous_cache_blocks[in] Whether cache blocks in the matrix A are stored contiguously (default is false).
Returns:
View of the topmost cache block of A.

Definition at line 186 of file Tsqr_CacheBlocker.hpp.

template<class Ordinal, class Scalar>
template<class MatrixViewType >
MatrixViewType TSQR::CacheBlocker< Ordinal, Scalar >::split_bottom_block ( MatrixViewType &  A,
const bool  contiguous_cache_blocks 
) const [inline]

Split A in place into [A_rest; A_bot].

Return the bottommost cache block A_bot of A, and modify A in place to be the "rest" of the matrix A_rest.

Parameters:
A[in/out] On input: view of the matrix to split. On output: the "rest" of the matrix. If there is only one cache block, A_bot contains all of the matrix and A is empty on output.
contiguous_cache_blocks[in] Whether cache blocks in the matrix A are stored contiguously (default is false).
Returns:
View of the bottommost cache block A_bot.

Definition at line 214 of file Tsqr_CacheBlocker.hpp.

template<class Ordinal, class Scalar>
template<class MatrixViewType >
void TSQR::CacheBlocker< Ordinal, Scalar >::fill_with_zeros ( MatrixViewType  A,
const bool  contiguous_cache_blocks 
) const [inline]

Fill the matrix A with zeros, respecting cache blocks.

A specialization of this method for a particular MatrixViewType will only compile if MatrixViewType has a method "fill(const Scalar)" or "fill(const Scalar&)". The intention is that the method be non-const and that it fill in the entries of the matrix with Scalar(0).

Parameters:
A[in/out] View of the matrix to fill with zeros.
contiguous_cache_blocks[in] Whether the cache blocks in A are stored contiguously.

Definition at line 241 of file Tsqr_CacheBlocker.hpp.

template<class Ordinal, class Scalar>
void TSQR::CacheBlocker< Ordinal, Scalar >::fill_with_zeros ( const Ordinal  num_rows,
const Ordinal  num_cols,
Scalar  A[],
const Ordinal  lda,
const bool  contiguous_cache_blocks 
) const [inline]

Fill the matrix A with zeros, respecting cache blocks.

This version of the method takes a raw pointer and matrix dimensions, rather than a matrix view object. If contiguous_cache_blocks==false, the matrix is stored either in column-major order with leading dimension lda; else, the matrix is stored in cache blocks, with each cache block's entries stored contiguously in column-major order.

Parameters:
num_rows[in] Number of rows in the matrix A.
num_cols[in] Number of columns in the matrix A.
A[out] The matrix to fill with zeros.
lda[in] Leading dimension (a.k.a. stride) of the matrix A.
contiguous_cache_blocks[in] Whether the cache blocks in A are stored contiguously.

Definition at line 274 of file Tsqr_CacheBlocker.hpp.

template<class Ordinal, class Scalar>
void TSQR::CacheBlocker< Ordinal, Scalar >::cache_block ( const Ordinal  num_rows,
const Ordinal  num_cols,
Scalar  A_out[],
const Scalar  A_in[],
const Ordinal  lda_in 
) const [inline]

Cache-block the given A_in matrix into A_out.

Given an nrows by ncols (with nrows >= ncols) matrix A_in, stored in column-major order with leading dimension lda_in (>= nrows), copy it into A_out in a cache-blocked row block format. Each cache block is a matrix in column-major order, and the elements of a cache block are stored consecutively in A_out. The number of rows in each cache block depends on the cache-blocking strategy that this CacheBlocker uses.

Parameters:
num_rows[in] Total number of rows in the matrices A_in and A_out
num_cols[in] Number of columns in the matrices A_in and A_out
A_out[out] nrows*ncols contiguous storage into which to write the cache-blocked output matrix.
A_in[in] nrows by ncols matrix, stored in column-major order with leading dimension lda_in >= nrows
lda_in[in] Leading dimension of the matrix A_in

Definition at line 317 of file Tsqr_CacheBlocker.hpp.

template<class Ordinal, class Scalar>
void TSQR::CacheBlocker< Ordinal, Scalar >::un_cache_block ( const Ordinal  num_rows,
const Ordinal  num_cols,
Scalar  A_out[],
const Ordinal  lda_out,
const Scalar  A_in[] 
) const [inline]

"Un"-cache-block the given A_in matrix into A_out.

Definition at line 349 of file Tsqr_CacheBlocker.hpp.

template<class Ordinal, class Scalar>
template<class MatrixViewType >
MatrixViewType TSQR::CacheBlocker< Ordinal, Scalar >::get_cache_block ( MatrixViewType  A,
const typename MatrixViewType::ordinal_type  cache_block_index,
const bool  contiguous_cache_blocks 
) const [inline]

Return the cache block with index cache_block_index.

Parameters:
A[in] The original matrix.
cache_block_index[in] Zero-based index of the cache block. If the index is out of bounds, silently return an empty matrix view.
contiguous_cache_blocks[in] Whether cache blocks are stored contiguously.
Returns:
Cache block of A with the given index, or an empty matrix view if the index is out of bounds.
Note:
This method is templated on MatrixViewType, so that it works with both MatView and ConstMatView.

Definition at line 396 of file Tsqr_CacheBlocker.hpp.

template<class Ordinal, class Scalar>
bool TSQR::CacheBlocker< Ordinal, Scalar >::operator== ( const CacheBlockingStrategy< Ordinal, Scalar > &  rhs) const [inline]

Equality operator.

Two cache blockers are "equal" if they correspond to matrices with the same dimensions (number of rows and number of columns), and if their cache blocking strategies are equal.

Definition at line 436 of file Tsqr_CacheBlocker.hpp.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends