|
BeBOP Optimized Sparse Kernel Interface Library
1.0.1h
|
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 stored in CSR format, convert a submatrix to MBCSR format. | |
| static void | SetUnitDiag (oski_index_t num_blocks, oski_index_t block_size, oski_value_t *blocks) |
Given a packed array of 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 and 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 , compute a shallow copy corresponding to a subset of the rows of . | |
| 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 , convert all the rows beginning at some row to 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 of a matrix which is either symmetric or Hermitian, store using full-storage such that where , 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_t * | oski_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) |
Conversion between CSR and MBCSR format.
| enum mirrordir_t |
Direction option for MirrorDiagBlocks().
| 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.
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
and
in MBCSR format.
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
stored in CSR format, convert a submatrix
to
MBCSR format.
The caller must also select an arbitrary starting column of
to be the starting point for the block diagonal of
blocks.
| [in] | M | Number of block rows in the subset , i.e., consists of rows. |
| [in] | n | Number of columns of . |
| [in] | i0 | Starting row in the index range . |
| [in] | d0 | First column index of the block diagonal. |
| [in] | ptr | Row pointers for . |
| [in] | ind | Column indices for . |
| [in] | val | Explicitly stored values for . |
| [in] | indbase | Index base (0 or 1) for: i0, d0, ptr, ind. |
| [in] | r | Off-diagonal row block size, . |
| [in] | c | Off-diagonal column block size, . |
| [in,out] | p_bptr | Pointer 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_bind | Pointer 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_bval | Pointer 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_bdiag | Pointer 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. |
divides
. References AllocateBlocks(), oski_Free, oski_Malloc, oski_ZeroMem(), ScatterBlockRow(), and UnscatterBlockRow().
Referenced by ConvertFromCSR().
| static void DestroySubmat | ( | oski_submatMBCSR_t *const | A | ) | [static] |
Destroys any memory allocated for the fields of a submatrix.
References tagOski_submatMBCSR_t::bdiag, tagOski_submatMBCSR_t::bind, tagOski_submatMBCSR_t::bptr, tagOski_submatMBCSR_t::bval, tagOski_submatMBCSR_t::mod_name, tagOski_submatMBCSR_t::num_block_rows, and oski_Free.
Referenced by oski_CopyMatRepr(), and oski_DestroyMatRepr().
| 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] |
Given a CSR matrix
, compute a shallow copy corresponding to a subset of the rows of
.
References oski_matCSR_t::base_index, oski_matCSR_t::has_unit_diag_implicit, oski_matCSR_t::is_lower, oski_matCSR_t::is_shared, oski_matCSR_t::is_upper, oski_matcommon_t::num_cols, oski_matcommon_t::num_nonzeros, oski_matcommon_t::num_rows, oski_CopyMem, oski_ZeroMem(), oski_matCSR_t::ptr, and oski_matCSR_t::stored.
Referenced by ConvertCSRLeftoverRows().
| static void MirrorDiagBlocks | ( | mirrordir_t | dir, |
| oski_value_t * | blocks, | ||
| oski_index_t | num_blocks, | ||
| oski_index_t | b | ||
| ) | [static] |
For each diagonal block
of a matrix which is either symmetric or Hermitian, store
using full-storage such that
where
, as appropriate.
| [in] | blocks | Array of r x r blocks. |
| [in] | num_blocks | Number of blocks in 'blocks'. |
| [in] | b | Block size. |
| [in] | op | Desired transpose operation (OP_TRANS, OP_CONJ_TRANS). |
| [in] | dir | Direction in which to mirror the block. |
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.
| 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...
| [in] | ptr | CSR row pointers, in the base specified by 'indbase'. |
| [in] | ind | CSR column indices, in the base specified by 'indbase'. |
| [in] | val | CSR explicitly stored values. |
| [in] | n | Maximum number of columns. |
| [in] | indbase | Index base (0 or 1). |
| [in] | i0 | Index of the first row in the block row to scatter, in the base specified by 'indbase'. |
| [in] | r | Row block size (i.e., number of rows in the block row starting at 'i0' to consider). |
| [in] | c | Column block size. |
| [in] | d0 | Index of the first column of the 'r x r' diagonal block, in the base specified by 'indbase'. |
| [in,out] | has_block_col | Array of flags indicating whether a given block exists in the block row being scattered. |
| [in,out] | blocks | Values of each block in the block row. |
| [in,out] | diag | Values of the diagonal block. |
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
blocks, sets the diagonal entries of each block to 1.
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...
| [in] | scatter_op | SCATTER_RESET or SCATTER_SET. |
| [in] | indbase | Index base (0 or 1). |
| [in] | ptr | CSR row pointers, in the base specified by 'indbase'. |
| [in] | ind | CSR column indices, in the base specified by 'indbase'. |
| [in] | val | CSR explicitly stored values. |
| [in] | i0 | Index of the first row in the block row to scatter, in the base specified by 'indbase'. |
| [in] | r | Row block size (i.e., number of rows in the block row starting at 'i0' to consider). |
| [in] | c | Column block size. |
| [in] | d0 | Index of the first column of the 'r x r' diagonal block, in the base specified by 'indbase'. |
| [in,out] | has_block_col | Array of flags indicating whether a given block exists in the block row being scattered. |
| [in,out] | blocks | Values of each block in the block row. |
| [in,out] | diag | Values of the diagonal block. |
References IS_BOUNDED.
Referenced by ConvertSubmatFromCSR().
1.7.6.1