convert.c File Reference

Conversion between CSR and SPARSITY-style BCSR (i.e., register blocking) 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/CSR/module.h>
#include <oski/BCSR/format.h>
#include <oski/BCSR/module.h>
#include <oski/xforms_internal.h>

Functions

static int ConvertFullBlocksFromCSR (const oski_index_t *ptr, const oski_index_t *ind, const oski_value_t *val, oski_index_t base, oski_index_t m, oski_index_t n, oski_index_t r, oski_index_t c, oski_index_t **p_bptr, oski_index_t **p_bind, oski_value_t **p_bval)
 Given an $m\times n$ CSR matrix $A$, convert the first $m-\mathrm{mod}(m,r)$ rows into $r\times c$ BCSR format.
static int ConvertFromCSR (oski_matBCSR_t *A, oski_index_t r, oski_index_t c, const oski_index_t *ptr, const oski_index_t *ind, const oski_value_t *val, oski_index_t m, oski_index_t n, oski_index_t base)
 Convert from full CSR to BCSR.
static int ExpandSymm (const oski_matCSR_t *mat, const oski_matcommon_t *props, oski_matCSR_t **p_mat_full)
void * oski_CreateMatReprFromCSR (const oski_matCSR_t *mat, const oski_matcommon_t *props,...)
 Method: Instantiate from an existing CSR representation.
static void CopyOne (const oski_matBCSR_t *A, oski_matCSR_t *B, oski_index_t i0)
static int ConvertToCSR (const oski_matBCSR_t *A, const oski_matcommon_t *props, oski_matCSR_t *B)
oski_matCSR_toski_ConvertMatReprToCSR (const void *mat, const oski_matcommon_t *props)
 Method: Convert to CSR format.
void * oski_CopyMatRepr (const void *mat, const oski_matcommon_t *props)
 Method: Duplicate a matrix representation.
void oski_DestroyMatRepr (void *mat)
 Method: Destroy matrix type-specific representation.
int oski_CreateLuaMatReprFromCSR (lua_State *L)
 The BCSR implementation expects the following arguments on the stack:
  1. Destination matrix type ('BCSR')
  2. Source matrix ('CSR')
  3. Row block size ('r')
  4. Column block size ('c').


Detailed Description

Conversion between CSR and SPARSITY-style BCSR (i.e., register blocking) format.


Function Documentation

static int ConvertFromCSR ( oski_matBCSR_t A,
oski_index_t  r,
oski_index_t  c,
const oski_index_t *  ptr,
const oski_index_t *  ind,
const oski_value_t *  val,
oski_index_t  m,
oski_index_t  n,
oski_index_t  base 
) [static]

static int ConvertFullBlocksFromCSR ( const oski_index_t *  ptr,
const oski_index_t *  ind,
const oski_value_t *  val,
oski_index_t  base,
oski_index_t  m,
oski_index_t  n,
oski_index_t  r,
oski_index_t  c,
oski_index_t **  p_bptr,
oski_index_t **  p_bind,
oski_value_t **  p_bval 
) [static]

Given an $m\times n$ CSR matrix $A$, convert the first $m-\mathrm{mod}(m,r)$ rows into $r\times c$ BCSR format.

If the converted matrix has $n_b$ blocks, this implementation executes in $O(\mbox{stored non-zeros}) = O(n_b\cdot r\cdot c)$ time, but requires $O(n\cdot r)$ auxiliary storage space to store a dense copy of one block row.

This long procedure is divided into two phases:

  1. Count the exact number of new blocks to create.
  2. Convert to block format, one block row at a time.

This routine assumes the CSR matrix uses full storage, but otherwise is flexible with regard to the following variations:

  • 0 or 1-based indexing
  • 'ptr[0]' does not have to start at 'base' (i.e., caller can pass a subset of rows of a larger matrix)
  • Column indices do not have to be sorted.

Parameters:
[in] ptr CSR row pointers.
[in] ind CSR column indices.
[in] val CSR explicitly stored values.
[in] base Index base (0-based or 1-based)
[in] m Logical number of matrix rows
[in] n Logical number of matrix columns
[in] r Desired row block size
[in] c Desired column block size
[in,out] p_bptr Used to return the BCSR block row pointers. Must not equal NULL.
[in,out] p_bind Used to return the BCSR block column indices. Must not equal NULL.
[in,out] p_bval Used to return the explicitly stored blocks. Must not equal NULL.
Note:
Block column indices are unsorted on output.
Returns:
On success, returns 0 and sets *p_bptr, *p_bind, and *p_bval to the BCSR representation. Otherwise, returns an error code and leaves p_bptr, p_bind, and p_bval unchanged. or an error code otherwise.

References ERR_BAD_ARG, ERR_OUT_OF_MEMORY, oski_CopyMem, oski_Free, oski_FreeAll(), oski_Malloc, oski_MultiMalloc(), oski_ZeroMem(), VAL_ASSIGN, and VAL_INC.

Referenced by ConvertFromCSR().

int oski_CreateLuaMatReprFromCSR ( lua_State *  L  ) 

The BCSR implementation expects the following arguments on the stack:

  1. Destination matrix type ('BCSR')
  2. Source matrix ('CSR')
  3. Row block size ('r')
  4. Column block size ('c').

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


Generated on Fri Apr 8 22:35:19 2011 for BeBOP Optimized Sparse Kernel Interface Library by  doxygen 1.5.9