BeBOP Optimized Sparse Kernel Interface Library  1.0.1h
Defines | Enumerations | Functions

Conversion between CSR and MBCSR format. More...

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <oski/config.h>
#include <oski/common.h>
#include <oski/modloader.h>
#include <oski/matrix.h>
#include <oski/CSR/format.h>
#include <oski/MBCSR/format.h>
#include <oski/MBCSR/module.h>
#include <oski/xforms_internal.h>

Defines

#define IS_BOUNDED(j, j_min, j_max)   ((j) >= (j_min) && (j) <= (j_max))
 Returns a non-zero value <==> j is in [j_min, j_max].

Enumerations

enum  mirrordir_t {
  NO_MIRROR = 0, LOWER_TO_UPPER = 1, LOWER_TO_UPPER_CONJ = 2, UPPER_TO_LOWER = 3,
  UPPER_TO_LOWER_CONJ = 4
}
 Direction option for MirrorDiagBlocks(). More...

Functions

static oski_index_t ScatterBlockRow (const oski_index_t *ptr, const oski_index_t *ind, const oski_value_t *val, oski_index_t n, oski_index_t indbase, oski_index_t i0, oski_index_t r, oski_index_t c, oski_index_t d0, oski_index_t *has_block_col, oski_index_t *inds, oski_value_t *blocks, oski_value_t *diag)
 Scatter...
static void UnscatterBlockRow (const oski_index_t *ptr, const oski_index_t *ind, oski_index_t indbase, oski_index_t i0, oski_index_t r, oski_index_t c, oski_index_t d0, oski_index_t *has_block_col)
 Unscatter...
static int AllocateBlocks (oski_index_t num_block_rows, oski_index_t num_blocks, oski_index_t r, oski_index_t c, oski_index_t **p_ind, oski_value_t **p_blocks, oski_value_t **p_diagblocks)
 Allocate space for a given number of blocks, including their indices and diagonal blocks.
static int ConvertSubmatFromCSR (oski_index_t M, oski_index_t n, oski_index_t i0, oski_index_t d0, const oski_index_t *ptr, const oski_index_t *ind, const oski_value_t *val, oski_index_t indbase, oski_index_t r, oski_index_t c, oski_index_t **p_bptr, oski_index_t **p_bind, oski_value_t **p_bval, oski_value_t **p_bdiag)
 Given an input matrix $A$ stored in CSR format, convert a submatrix $A(I,:)$ to $r\times c$ MBCSR format.
static void SetUnitDiag (oski_index_t num_blocks, oski_index_t block_size, oski_value_t *blocks)
 Given a packed array of $M$ $b\times b$ blocks, sets the diagonal entries of each block to 1.
static int ConvertFromCSR (oski_index_t m, oski_index_t n, const oski_index_t *ptr, const oski_index_t *ind, const oski_value_t *val, oski_index_t indbase, oski_index_t has_unit_diag_implicit, oski_index_t r, oski_index_t c, oski_index_t *p_M1, oski_index_t **p_ptr1, oski_index_t **p_ind1, oski_value_t **p_val1, oski_value_t **p_diag1, oski_index_t *p_M2, oski_index_t *p_r2, oski_index_t **p_ptr2, oski_index_t **p_ind2, oski_value_t **p_val2, oski_value_t **p_diag2, oski_index_t *p_num_rows_left)
 Convert the portions of the CSR matrix that correspond to partitions $A_1$ and $A_2$ in MBCSR format.
static void SetModuleName (oski_submatMBCSR_t *B)
 Initializes the cached module name for an MBCSR submatrix.
static void InitSubmatCSR (const oski_matCSR_t *A, const oski_matcommon_t *props, oski_index_t row_start, oski_index_t num_rows, oski_matCSR_t *A_sub, oski_matcommon_t *props_sub)
 Given a CSR matrix $A$, compute a shallow copy corresponding to a subset of the rows of $A$.
static int ConvertCSRLeftoverRows (const oski_matCSR_t *A, const oski_matcommon_t *props, oski_index_t row_start, oski_index_t num_rows, oski_index_t r, oski_index_t c, oski_matBCSR_t **p_B)
 Given a CSR matrix $A$, convert all the rows beginning at some row $i$ to $r\times c$ BCSR format.
static void MirrorDiagBlocks (mirrordir_t dir, oski_value_t *blocks, oski_index_t num_blocks, oski_index_t b)
 For each diagonal block $B$ of a matrix which is either symmetric or Hermitian, store $B$ using full-storage such that $B = \mathrm{op}(B)$ where $\mathrm{op}(B) \in \{B^T, B^H\}$, as appropriate.
static oski_index_t CalcNnzStored_CSR (oski_index_t m, const oski_matCSR_t *A)
static oski_index_t CalcNnzStored_BCSR (const oski_matBCSR_t *A)
static oski_index_t CalcNnzStored_submatMBCSR (const oski_submatMBCSR_t *A)
static oski_index_t CalcNnzStored_MBCSR (const oski_matMBCSR_t *A)
static double CalcFillRatio (const oski_matMBCSR_t *A, const oski_matCSR_t *A_orig, const oski_matcommon_t *props)
void * oski_CreateMatReprFromCSR (const oski_matCSR_t *mat, const oski_matcommon_t *props,...)
 The variable argument list must contain the following parameters, in the order listed:
oski_matCSR_toski_ConvertMatReprToCSR (const void *mat, const oski_matcommon_t *props)
 Method: Convert to CSR format.
static int CopySubmat (const oski_submatMBCSR_t *A, oski_submatMBCSR_t *B)
static void DestroySubmat (oski_submatMBCSR_t *const A)
 Destroys any memory allocated for the fields of a submatrix.
static void DestroySubmatBCSR (oski_matBCSR_t *A)
 Free BCSR matrix representation.
void oski_DestroyMatRepr (void *mat)
 Method: Destroy matrix type-specific representation.
void * oski_CopyMatRepr (const void *mat, const oski_matcommon_t *props)
 Method: Duplicate a matrix representation.
int oski_CreateLuaMatReprFromCSR (lua_State *L)
 The MBCSR implementation expects the following arguments on the stack:
void oski_EnableMBCSRMatTransMatMult (oski_matMBCSR_t *A, int v)
void oski_EnableMBCSRMatMultAndMatMult (oski_matMBCSR_t *A, int v)
void oski_EnableMBCSRMatMultAndMatTransMult (oski_matMBCSR_t *A, int v)
void oski_EnableMBCSRMatPowMult (oski_matMBCSR_t *A, int v)
void oski_EnableMBCSRMatTransPowMult (oski_matMBCSR_t *A, int v)

Detailed Description

Conversion between CSR and MBCSR format.


Enumeration Type Documentation

Direction option for MirrorDiagBlocks().


Function Documentation

static int AllocateBlocks ( oski_index_t  num_block_rows,
oski_index_t  num_blocks,
oski_index_t  r,
oski_index_t  c,
oski_index_t **  p_ind,
oski_value_t **  p_blocks,
oski_value_t **  p_diagblocks 
) [static]

Allocate space for a given number of blocks, including their indices and diagonal blocks.

All returned arrays are initialized to 0.

Returns:
A non-zero value and sets the output pointers <==> the allocation was successful. Otherwise, returns 0 and leaves the output pointers unchanged.

References oski_Free, oski_Malloc, and oski_ZeroMem().

Referenced by ConvertSubmatFromCSR().

static int ConvertFromCSR ( oski_index_t  m,
oski_index_t  n,
const oski_index_t *  ptr,
const oski_index_t *  ind,
const oski_value_t *  val,
oski_index_t  indbase,
oski_index_t  has_unit_diag_implicit,
oski_index_t  r,
oski_index_t  c,
oski_index_t *  p_M1,
oski_index_t **  p_ptr1,
oski_index_t **  p_ind1,
oski_value_t **  p_val1,
oski_value_t **  p_diag1,
oski_index_t *  p_M2,
oski_index_t *  p_r2,
oski_index_t **  p_ptr2,
oski_index_t **  p_ind2,
oski_value_t **  p_val2,
oski_value_t **  p_diag2,
oski_index_t *  p_num_rows_left 
) [static]

Convert the portions of the CSR matrix that correspond to partitions $A_1$ and $A_2$ in MBCSR format.

Returns:
The starting row index (0-based) in the input CSR data structure where partition $A_3$ should begin. The caller should call the BCSR routine to convert this part of the matrix.

References ConvertSubmatFromCSR(), oski_Free, and SetUnitDiag().

Referenced by oski_CreateMatReprFromCSR().

static int ConvertSubmatFromCSR ( oski_index_t  M,
oski_index_t  n,
oski_index_t  i0,
oski_index_t  d0,
const oski_index_t *  ptr,
const oski_index_t *  ind,
const oski_value_t *  val,
oski_index_t  indbase,
oski_index_t  r,
oski_index_t  c,
oski_index_t **  p_bptr,
oski_index_t **  p_bind,
oski_value_t **  p_bval,
oski_value_t **  p_bdiag 
) [static]

Given an input matrix $A$ stored in CSR format, convert a submatrix $A(I,:)$ to $r\times c$ MBCSR format.

The caller must also select an arbitrary starting column of $A(I,:)$ to be the starting point for the block diagonal of $r\times r$ blocks.

Parameters:
[in]MNumber of block rows in the subset $I$, i.e., $I$ consists of $M\cdot r$ rows.
[in]nNumber of columns of $A$.
[in]i0Starting row in the index range $I$.
[in]d0First column index of the block diagonal.
[in]ptrRow pointers for $A$.
[in]indColumn indices for $A$.
[in]valExplicitly stored values for $A$.
[in]indbaseIndex base (0 or 1) for: i0, d0, ptr, ind.
[in]rOff-diagonal row block size, $r$.
[in]cOff-diagonal column block size, $c$.
[in,out]p_bptrPointer to a pointer in which to store a newly allocated array of block-row pointers. The caller may set this pointer to NULL if none are desired.
[in,out]p_bindPointer to a pointer in which to store a newly allocated array of block column indices. The caller may set this pointer to NULL if none are desired.
[in,out]p_bvalPointer to a pointer in which to store a newly allocated array of stored-value off-diagonal blocks. The caller may set this pointer to NULL if none are desired.
[in,out]p_bdiagPointer to a pointer in which to store a newly allocated array of block diagonal values. The caller may set this pointer to NULL if none are desired.
Returns:
0 if any error occurs (typically on memory allocation failure) and leaves all output pointers unchanged, or 1 if successful with all non-NULL output pointers initialized.
Precondition:
$r$ divides $m$.

References AllocateBlocks(), oski_Free, oski_Malloc, oski_ZeroMem(), ScatterBlockRow(), and UnscatterBlockRow().

Referenced by ConvertFromCSR().

static void DestroySubmat ( oski_submatMBCSR_t *const  A) [static]
static void DestroySubmatBCSR ( oski_matBCSR_t A) [static]

Free BCSR matrix representation.

References OSKI_MATTYPE_METHOD.

Referenced by oski_DestroyMatRepr().

static void InitSubmatCSR ( const oski_matCSR_t A,
const oski_matcommon_t props,
oski_index_t  row_start,
oski_index_t  num_rows,
oski_matCSR_t A_sub,
oski_matcommon_t props_sub 
) [static]
static void MirrorDiagBlocks ( mirrordir_t  dir,
oski_value_t *  blocks,
oski_index_t  num_blocks,
oski_index_t  b 
) [static]

For each diagonal block $B$ of a matrix which is either symmetric or Hermitian, store $B$ using full-storage such that $B = \mathrm{op}(B)$ where $\mathrm{op}(B) \in \{B^T, B^H\}$, as appropriate.

Parameters:
[in]blocksArray of r x r blocks.
[in]num_blocksNumber of blocks in 'blocks'.
[in]bBlock size.
[in]opDesired transpose operation (OP_TRANS, OP_CONJ_TRANS).
[in]dirDirection in which to mirror the block.
Precondition:
The input parameter dir is valid if A is not NULL. If A is NULL or has no diagonal, or if op is not one of {OP_TRANS, OP_CONJ_TRANS}, returns taking no action.

References VAL_ASSIGN, and VAL_ASSIGN_CONJ.

Referenced by oski_CreateMatReprFromCSR().

int oski_CreateLuaMatReprFromCSR ( lua_State *  L)

The MBCSR implementation expects the following arguments on the stack:

Matrix-type specific method to convert from a CSR matrix, with arguments passed on the Lua stack.

  1. Destination matrix type ('MBCSR')
  2. Source matrix ('CSR')
  3. Row block size ('r')
  4. Column block size ('c')
static oski_index_t ScatterBlockRow ( const oski_index_t *  ptr,
const oski_index_t *  ind,
const oski_value_t *  val,
oski_index_t  n,
oski_index_t  indbase,
oski_index_t  i0,
oski_index_t  r,
oski_index_t  c,
oski_index_t  d0,
oski_index_t *  has_block_col,
oski_index_t *  inds,
oski_value_t *  blocks,
oski_value_t *  diag 
) [static]

Scatter...

Parameters:
[in]ptrCSR row pointers, in the base specified by 'indbase'.
[in]indCSR column indices, in the base specified by 'indbase'.
[in]valCSR explicitly stored values.
[in]nMaximum number of columns.
[in]indbaseIndex base (0 or 1).
[in]i0Index of the first row in the block row to scatter, in the base specified by 'indbase'.
[in]rRow block size (i.e., number of rows in the block row starting at 'i0' to consider).
[in]cColumn block size.
[in]d0Index of the first column of the 'r x r' diagonal block, in the base specified by 'indbase'.
[in,out]has_block_colArray of flags indicating whether a given block exists in the block row being scattered.
[in,out]blocksValues of each block in the block row.
[in,out]diagValues of the diagonal block.
Precondition:
ptr != NULL && has_block_col != NULL
Todo:
Update documentation for this routine.

References IS_BOUNDED, and VAL_INC.

Referenced by ConvertSubmatFromCSR().

static void SetUnitDiag ( oski_index_t  num_blocks,
oski_index_t  block_size,
oski_value_t *  blocks 
) [static]

Given a packed array of $M$ $b\times b$ blocks, sets the diagonal entries of each block to 1.

Precondition:
If num_blocks > 0, then blocks != NULL.

References VAL_SET_ONE.

Referenced by ConvertFromCSR().

static void UnscatterBlockRow ( const oski_index_t *  ptr,
const oski_index_t *  ind,
oski_index_t  indbase,
oski_index_t  i0,
oski_index_t  r,
oski_index_t  c,
oski_index_t  d0,
oski_index_t *  has_block_col 
) [static]

Unscatter...

Parameters:
[in]scatter_opSCATTER_RESET or SCATTER_SET.
[in]indbaseIndex base (0 or 1).
[in]ptrCSR row pointers, in the base specified by 'indbase'.
[in]indCSR column indices, in the base specified by 'indbase'.
[in]valCSR explicitly stored values.
[in]i0Index of the first row in the block row to scatter, in the base specified by 'indbase'.
[in]rRow block size (i.e., number of rows in the block row starting at 'i0' to consider).
[in]cColumn block size.
[in]d0Index of the first column of the 'r x r' diagonal block, in the base specified by 'indbase'.
[in,out]has_block_colArray of flags indicating whether a given block exists in the block row being scattered.
[in,out]blocksValues of each block in the block row.
[in,out]diagValues of the diagonal block.
Precondition:
ptr != NULL && has_block_col != NULL

References IS_BOUNDED.

Referenced by ConvertSubmatFromCSR().