namespace gpr::linalg::canonical

Overview

namespace canonical {
 
// typedefs
 
typedef Eigen::Map<Eigen::MatrixXd, 0, Eigen::OuterStride<>> TileMap;
typedef Eigen::Map<Eigen::MatrixXd, Eigen::Aligned64> AlignedMap;
 
// enums
 
enum Triangle;
 
// structs
 
struct SubstitutionCache;
struct TileGeometry;
 
// classes
 
class AlignedBlockCache;
class AlignedBuffer;
class AlignedTile;
 
// global variables
 
int kExactMinColumns = 32;
std::int64_t kTransposeBatchEntries = std::int64_t{1}<<24;
 
// global functions
 
std::atomic<int>& choleskyPanelGroup();
TileGeometry geometryOf(DistributedState& st, const int* desc);
TileMap tileAt(double* base, int lld, const TileGeometry& g, int row_tile, int col_tile, int rows, int cols);
void requireWorkspaceBudget(DistributedState& st, const char* what, std::int64_t needed, AvailableMemory available);
void trsm(DistributedState& st, Triangle triangle, const double* T, const int* desc_t, double* B, const int* desc_b, int n, int ncols, bool lower_rhs);
std::int64_t transposeWorkspaceBytes(const int* desc, int local_cols, std::int64_t batch_entries);
std::vector<double> transposeFactor(DistributedState& st, const double* L, const int* desc, int n, std::int64_t batch_entries = 0);
void trsmLowerFactor(DistributedState& st, const double* L, const int* desc_l, double* B, const int* desc_b, int n, int ncols, bool transpose);
void trsmCachedLowerFactor(DistributedState& st, double* B, const int* desc_b, int n, int ncols, bool transpose);
void trsmLowerFactorCached(DistributedState& st, SubstitutionCache& cache, const double* L, const int* desc_l, double* B, const int* desc_b, int n, int ncols, bool transpose);
void solveLowerFactorCached(DistributedState& st, SubstitutionCache& cache, const double* L, const int* desc_l, double* B, const int* desc_b, int n, int ncols);
Eigen::MatrixXd gramTiles(const Eigen::MatrixXd& x, int nb);
void solveLowerFactor(DistributedState& st, const double* L, const int* desc_l, double* B, const int* desc_b, int n, int ncols);
void choleskyInverseLower(DistributedState& st, const double* L, const int* desc, int n, std::vector<double>& inverse, std::optional<const double*> upper = std::nullopt);
void extendBorder(DistributedState& st, const DistributedState::TileCommunicators& comms, const TileGeometry& g, double* A, int lld, int n, int first_new, int tiles);
int exactOuterWidth();
bool potrfLowerExact(DistributedState& st, const schemeii::Context& ctx, double* A, const int* desc, int n, int n_factored);
bool potrfLower(DistributedState& st, double* A, const int* desc, int n, int n_factored = 0);
bool wideTileProductAvailable();
 
template <bool TransposeRight = false, class Target, class Left, class Right>
void subtractTileProduct(Target&& out, const Left& left, const Right& right);
 
} // namespace canonical

Detailed Documentation

Typedefs

typedef Eigen::Map<Eigen::MatrixXd, Eigen::Aligned64> AlignedMap

A packed tile of an AlignedBuffer, typed as AlignedTile::map().

Global Variables

int kExactMinColumns = 32

Solves T X = B in place (X overwrites B) for a tiled triangular T.

T is read on its stored triangle only. For Triangle::Lower the tile rows are visited in ascending order (forward substitution) and for Triangle::Upper in descending order (back substitution). When lower_rhs is true, B holds a matrix whose tiles above the tile diagonal are zero and only tiles on or below the diagonal of X are computed; this halves the work for the inverse.

Collective over the grid. T and B share the block size of their descriptors; B has n rows and ncols columns. Right-hand sides from which a substitution step takes its update from one Scheme II product; narrower solves use the fixed-order kernel. Compared with the global column count, so the choice does not follow the grid.

std::int64_t kTransposeBatchEntries = std::int64_t{1}<<24

Entries of one message batch of the factor transpose: 2^24 doubles (128 MiB), at least one tile.

Global Functions

std::atomic<int>& choleskyPanelGroup()

Panels the tile Cholesky factors before it applies them, together, to the trailing tiles. Every tile still receives the updates of the panels one at a time in ascending order, so the factor does not depend on this count; a trailing tile is loaded and stored once per group instead of once per panel. Substitution uses the same group count to amortize its tile copies while preserving the order of every update.

void requireWorkspaceBudget(DistributedState& st, const char* what, std::int64_t needed, AvailableMemory available)

All ranks refuse a workspace when any rank lacks its local share. No peer can enter the following data exchange after another rank throws.

std::int64_t transposeWorkspaceBytes(const int* desc, int local_cols, std::int64_t batch_entries)

Bytes transposeFactor claims beyond the factor: the transposed factor (the local array of desc) and one send and one receive batch.

std::vector<double> transposeFactor(DistributedState& st, const double* L, const int* desc, int n, std::int64_t batch_entries = 0)

Returns U = L^T in the tile layout of L: tile (i, k) of U is the transpose of tile (k, i) of L. Only the lower triangle of L is read. Collective.

Tiles move between each pair of ranks in batches of at most batch_entries (kTransposeBatchEntries when zero), so the workspace beyond U is two batches rather than a copy of every tile sent and received. Before U is allocated, U and the batches are compared with this rank’s share of the node’s available memory; a shortfall throws std::runtime_error naming both, in place of an allocation the OOM killer ends mid-run.

void trsmLowerFactor(DistributedState& st, const double* L, const int* desc_l, double* B, const int* desc_b, int n, int ncols, bool transpose)

Solves L X = B (transpose == false) or L^T X = B (transpose == true) in place for the lower Cholesky factor L in the block-cyclic layout.

void trsmCachedLowerFactor(DistributedState& st, double* B, const int* desc_b, int n, int ncols, bool transpose)

Same as trsmLowerFactor for the factor cached in st: the transposed factor is built once per factorization and reused by every back substitution.

void trsmLowerFactorCached(DistributedState& st, SubstitutionCache& cache, const double* L, const int* desc_l, double* B, const int* desc_b, int n, int ncols, bool transpose)

Solves L X = B (transpose == false) or L^T X = B in place for a factor that outlives the call, reusing the transposed factor kept in cache.

void solveLowerFactorCached(DistributedState& st, SubstitutionCache& cache, const double* L, const int* desc_l, double* B, const int* desc_b, int n, int ncols)

Solves L L^T X = B in place against a cached factor.

Eigen::MatrixXd gramTiles(const Eigen::MatrixXd& x, int nb)

Gram matrix X^T X of a replicated matrix, accumulated over row tiles in ascending order with one dense product per (column tile, column tile, row tile). Every rank evaluates it from identical data in the same order, so the bits do not depend on the process grid that produced X.

void solveLowerFactor(DistributedState& st, const double* L, const int* desc_l, double* B, const int* desc_b, int n, int ncols)

Solves L L^T X = B in place: forward substitution with L, then back substitution with the transposed factor, which is built once.

void choleskyInverseLower(DistributedState& st, const double* L, const int* desc, int n, std::vector<double>& inverse, std::optional<const double*> upper = std::nullopt)

Overwrites inverse with K^{-1} = L^{-T} L^{-1} on and below the tile diagonal (tiles above the diagonal hold zero), in the layout of desc. L is the lower Cholesky factor in the same layout; upper, when given, is its transpose from transposeFactor, which is otherwise built and dropped. Cache presence is independent of the local pointer: a rank with no matrix columns has an empty cached transpose and can pass an engaged null pointer.

void extendBorder(DistributedState& st, const DistributedState::TileCommunicators& comms, const TileGeometry& g, double* A, int lld, int n, int first_new, int tiles)

Brings the border tiles (tile rows from first_new on) of a partly factored matrix to the state they have in a right-looking factorization after the panel steps 0 .. first_new - 1: every border tile (i, j) with j < first_new holds L_ij, and every border tile (i1, i2) with i2 >= first_new has received the updates of those panels, in ascending panel order. The tiles of the factored block move once, to the process rows that own border tiles, in place of a broadcast of every panel to every rank. Collective.

int exactOuterWidth()

Width, in matrix rows, of the outer blocks of the exact factorization. The trailing update of one outer block is one Scheme II product with this inner dimension, which amortizes the residue reconstruction. The value depends on nothing but the environment, never on the grid.

bool potrfLowerExact(DistributedState& st, const schemeii::Context& ctx, double* A, const int* desc, int n, int n_factored)

potrfLower with exact Scheme II trailing products and fixed-order panel kernels. Outer blocks of exactOuterWidth() / nb tiles: inside an outer block the panel is factored right-looking tile by tile (fixed-order diagonal Cholesky, panel solve and inner updates); the rest of the trailing matrix receives one exact product A_ij -= L_iB L_jB^T per outer block B. Every tile receives the same operations in the same order on every grid that shares nb, and with n_factored > 0 the border rows receive exactly the operations of a factorization of the whole matrix.

bool potrfLower(DistributedState& st, double* A, const int* desc, int n, int n_factored = 0)

Cholesky factorization of the lower triangle of the tiled symmetric positive definite matrix A, in place: on success the lower triangle holds L with A = L L^T. Right-looking tile algorithm: the diagonal tile is factored by one rank, the panel is solved tile by tile, and each trailing tile receives its updates in ascending panel order from whole-tile products. Collective. Returns false, on every rank, when a diagonal tile is not positive definite.

When n_factored > 0 (a multiple of the block size) the leading n_factored x n_factored block already holds its factor, and the rows below it hold the unfactored border; the call extends the factor to order n. Every tile then receives the same updates in the same order as in a factorization of the whole matrix.

template <bool TransposeRight = false, class Target, class Left, class Right>
void subtractTileProduct(Target&& out, const Left& left, const Right& right)

Subtract a dense product from a column-major tile. Full packed operands support a strided result; partial or strided operands use Eigen.