BeBOP Optimized Sparse Kernel Interface Library  1.0.1h
Functions | Variables
xforms.c File Reference

Save/restore tuning transformations. More...

#include <string.h>
#include <lua/include/lua.h>
#include <lua/include/lualib.h>
#include <lua/include/lauxlib.h>
#include <oski/common.h>
#include <oski/mangle.h>
#include <oski/mattypes_internal.h>
#include <oski/tune.h>
#include <oski/xforms.h>
#include <oski/xforms_internal.h>

Functions

char * oski_GetMatTransforms (const oski_matrix_t A_tunable)
 Returns a string representation of the data structure transformations that were applied to the given matrix during tuning.
static void DumpLuaArg (lua_State *L, int arg)
 Print the type and, if possible, value of the element at the given position in the Lua stack.
static int RequireLua (lua_State *L, const char *modname)
 Implements a call to Lua's "require()" function.
static void RegisterLuaMatTypes (lua_State *L)
 Traverse the list of available matrix types, and create globally visible Lua matrix types in the given Lua state.
static int NewLuaMat (lua_State *L)
 Leaves a newly instantiated OLUA_MAT object on the top of L's stack.
static oski_matlua_tCheckLuaMat (lua_State *L)
 Examines the first item (position 1) on the stack and returns it if it is a valid OLUA_MATTAB object.
static int ToStringLuaMat (lua_State *L)
 A.__tostring(): Returns a string representation of the specified LuaMat object.
static int GCLuaMat (lua_State *L)
 A.__gc(x): Called when the system garbage collects x.
static char * MakeLuaConvMethodName (const oski_matlua_t *A_source, const oski_matlua_t *A_dest)
 Returns a newly created string method name for a Lua-callback matrix type conversion routine.
static oski_matlua_tConvertLuaMatToCSR (lua_State *L, int index)
 Converts the Lua matrix at position 'index' on the stack to CSR format, and leaves the new matrix at the top of the stack.
static int AreSameLuaMatTypes (const oski_matlua_t *A, const oski_matlua_t *B)
 Returns 1 if the input OSKI-Lua matrices have the same type (e.g., are both BCSR(int, double)).
static int ConvertLuaMat (lua_State *L)
 Mat.__call( A, ...
static int OpenLuaMatMod (lua_State *L)
 Load OSKI-Lua matrix module and metatable.
static lua_State * OpenLua (void)
 Start a OSKI-Lua process.
static void CloseLua (lua_State *L)
 Shutdown a OSKI-Lua process.
static int RunLua (lua_State *L, const char *xforms)
 Execute a OSKI-Lua program to transform a matrix data structure.
static int CreateLuaMatObj (lua_State *L, const oski_matcommon_t *props, oski_matspecific_t *mat, const char *name)
 Instantiates new OLUA_MAT object wrapper around the matrix (props, mat) and assigns it to the global variable 'name'.
int oski_FreeInputMatRepr (oski_matrix_t A)
 If the given matrix has a valid tuned representation and does not share its input representation, then this routine destroys the input matrix representation.
int oski_ReplaceTunedMatRepr (oski_matrix_t A, oski_matspecific_t *new_mat, const char *xforms)
 Replace a matrix's tuned representation with a new one.
int oski_ApplyMatTransforms (oski_matrix_t A_tunable, const char *xforms)
 Replace the current data structure for a given matrix object with a new data structure specified by a given string.
int oski_CreateLuaMatReprGenericFromCSR (lua_State *L, const char *mattype)
 This routine can be used for any 'simple' matrix type which expects no arguments on the Lua stack besides the matrix types:
int oski_CreateLuaMatReprGeneric2IndexFromCSR (lua_State *L, const char *mattype)
 This conversion routine may be used with any matrix type that expects two positive integer index arguments on the Lua stack:

Variables

static struct luaL_reg g_luamatlib_f []
 OLUA_MAT static members.
static struct luaL_reg g_luamatlib_m []
 OLUA_MAT object methods.

Detailed Description

Save/restore tuning transformations.


Function Documentation

static oski_matlua_t* CheckLuaMat ( lua_State *  L) [static]

Examines the first item (position 1) on the stack and returns it if it is a valid OLUA_MATTAB object.

Returns NULL otherwise.

References OLUA_MATTAB.

Referenced by ConvertLuaMat(), GCLuaMat(), and ToStringLuaMat().

static int ConvertLuaMat ( lua_State *  L) [static]

Mat.__call( A, ...

) --> A( ... ): Implements data structure conversion.

Assumed contents of the Lua stack:

  • 1 Destination matrix type
  • 2 Source matrix, in a compatible CSR format
  • 3, ... Any destination type-specific arguments.

References AreSameLuaMatTypes(), CheckLuaMat(), ConvertLuaMatToCSR(), ERR_NOT_IMPLEMENTED, oski_matlua_t::ind_type, MakeLuaConvMethodName(), oski_matlua_t::mat, oski_matlua_t::mattype_name, oski_DuplicateString(), OSKI_ERR_NOT_IMPLEMENTED, oski_Free, oski_HandleError, oski_LookupMatTypeIdMethod(), oski_LookupMatTypeMethod(), oski_PrintDebugMessage(), oski_matlua_t::props, oski_matspecific_t::repr, oski_matspecific_t::type_id, and oski_matlua_t::val_type.

static oski_matlua_t* ConvertLuaMatToCSR ( lua_State *  L,
int  index 
) [static]

Converts the Lua matrix at position 'index' on the stack to CSR format, and leaves the new matrix at the top of the stack.

Returns a pointer to the matrix object.

If an error occurs, this routine leaves the stack unchanged and returns NULL.

References ERR_NOT_IMPLEMENTED, oski_matlua_t::ind_type, INVALID_ID, oski_matlua_t::mat, oski_matlua_t::mattype_name, oski_DuplicateString(), oski_HandleError, oski_LookupMatTypeId(), oski_LookupMatTypeMethod(), oski_matlua_t::props, oski_matspecific_t::repr, oski_matspecific_t::type_id, and oski_matlua_t::val_type.

Referenced by ConvertLuaMat().

static int CreateLuaMatObj ( lua_State *  L,
const oski_matcommon_t props,
oski_matspecific_t mat,
const char *  name 
) [static]

Instantiates new OLUA_MAT object wrapper around the matrix (props, mat) and assigns it to the global variable 'name'.

The new object is left at the top of the stack.

Returns:
0 on success, or an error code on error.

References ERR_OUT_OF_MEMORY, tagBebop_mattype_t::id_index_type, tagBebop_mattype_t::id_value_type, oski_matlua_t::ind_type, oski_matlua_t::mat, oski_matlua_t::mattype_name, tagBebop_mattype_t::name, oski_DuplicateString(), oski_FindMatTypeRecord(), oski_matlua_t::props, oski_matspecific_t::repr, oski_matspecific_t::type_id, and oski_matlua_t::val_type.

Referenced by oski_ApplyMatTransforms().

static int NewLuaMat ( lua_State *  L) [static]

Leaves a newly instantiated OLUA_MAT object on the top of L's stack.

This routine implements 'Mat.new( [base_type_name] )'.

References oski_matlua_t::mattype_name, OLUA_MATTAB, and oski_DuplicateString().

static lua_State* OpenLua ( void  ) [static]

Start a OSKI-Lua process.

Calls the error handler on error and returns NULL. Otherwise, returns a pointer to valid OSKI-Lua state.

Todo:
Create global OSKI-Lua matrix types for all registered types.

References ERR_LOAD_MOD, OpenLuaMatMod(), oski_HandleError, oski_PrintDebugMessage(), RegisterLuaMatTypes(), and RequireLua().

Referenced by oski_ApplyMatTransforms().

int oski_CreateLuaMatReprGeneric2IndexFromCSR ( lua_State *  L,
const char *  mattype 
)

This conversion routine may be used with any matrix type that expects two positive integer index arguments on the Lua stack:

Routine to create a Lua matrix representation from a CSR representation for a matrix type that, on creation, expects two integer index arguments.

  1. Destination matrix type (e.g., 'MBCSR', 'BCSR', 'CB')
  2. Source matrix ('CSR')
  3. First index (e.g., the row block size 'r')
  4. Second index (e.g., the column block size 'c')

References ERR_BAD_ARG, oski_matlua_t::ind_type, MACRO_TO_STRING, oski_matlua_t::mat, oski_matlua_t::mattype_name, oski_DuplicateString(), oski_HandleError, OSKI_IND_ID, OSKI_MATTYPE_ID, OSKI_MATTYPE_METHOD, OSKI_VAL_ID, oski_matlua_t::props, oski_matspecific_t::repr, oski_matspecific_t::type_id, and oski_matlua_t::val_type.

int oski_CreateLuaMatReprGenericFromCSR ( lua_State *  L,
const char *  mattype 
)

This routine can be used for any 'simple' matrix type which expects no arguments on the Lua stack besides the matrix types:

Routine to create a Lua matrix representation from a CSR representation for a simple matrix type.

  1. Destination matrix type (e.g., 'CSC', 'GCSR')
  2. Source matrix ('CSR')
Todo:
else: possible leak

References ERR_BAD_ARG, oski_matlua_t::ind_type, MACRO_TO_STRING, oski_matlua_t::mat, oski_matlua_t::mattype_name, oski_DuplicateString(), oski_HandleError, OSKI_IND_ID, OSKI_MATTYPE_ID, OSKI_MATTYPE_METHOD, OSKI_VAL_ID, oski_matlua_t::props, oski_matspecific_t::repr, oski_matspecific_t::type_id, and oski_matlua_t::val_type.

If the given matrix has a valid tuned representation and does not share its input representation, then this routine destroys the input matrix representation.

Returns:
An error code on error. Otherwise, this function returns 0, regardless of whether the input matrix representation could be legally destroyed.
Todo:
Possible leak?

References ERR_BAD_MAT, oski_matstruct_t::input_mat, INVALID_ID, INVALID_MAT, oski_matstruct_t::is_shared, OSKI_MATTYPEID_METHOD, oski_PrintDebugMessage(), oski_matspecific_t::repr, oski_matstruct_t::tuned_mat, and oski_matspecific_t::type_id.

int oski_ReplaceTunedMatRepr ( oski_matrix_t  A,
oski_matspecific_t new_mat,
const char *  xforms 
)

Replace a matrix's tuned representation with a new one.

Parameters:
[in,out]AMatrix whose tuned representation is to be changed.
[in]new_matThe new matrix representation.
[in]xformsThe corresponding transformation string used to create 'new_mat'.
Returns:
0 on success, or an error code. Does not call the error handler.

If new_mat points to A's tuned matrix representation, this function immediately returns 0.

If A is invalid, this function returns ERR_BAD_MAT.

References ERR_BAD_MAT, INVALID_ID, INVALID_MAT, oski_DuplicateString(), oski_Free, OSKI_MATTYPEID_METHOD, oski_PrintDebugMessage(), oski_matspecific_t::repr, oski_matstruct_t::tuned_mat, oski_matstruct_t::tuned_xforms, and oski_matspecific_t::type_id.

static void RegisterLuaMatTypes ( lua_State *  L) [static]

Traverse the list of available matrix types, and create globally visible Lua matrix types in the given Lua state.

Parameters:
[in,out]LLua transformation engine state.

References tagBebop_mattype_t::desc, tagBebop_mattype_t::modname, tagBebop_mattype_t::name, oski_FindMatTypeRecord(), oski_GetNumMatTypes(), oski_PrintDebugMessage(), and RequireLua().

Referenced by OpenLua().

static int RequireLua ( lua_State *  L,
const char *  modname 
) [static]

Implements a call to Lua's "require()" function.

References ERR_OLUA_STARTUP, and oski_HandleError.

Referenced by OpenLua(), and RegisterLuaMatTypes().

static int RunLua ( lua_State *  L,
const char *  xforms 
) [static]

Execute a OSKI-Lua program to transform a matrix data structure.

Parameters:
[in]LLua engine in which to run the code.
[in]xformsString program representing the transformation to execute.
Returns:
0 on success, or an error code.

If an error occurs while trying to execute the transformation, converts the error code to its equivalent BeBOP error code, and leaves the Lua error message on L's stack.

Available OSKI-Lua globals:

  • InputMat (SparseMat)
  • indtype, valtype (strings)

OSKI-Lua syntax examples:

-- Program 1: Convert to 4x2 blocked format
return BCSR( InputMat, 4, 2 );

Lua-native module code:

Make the following C-implemented routines available in Lua:

loadmattype( type_name, ind_type, val_type )

References ERR_BAD_SYNTAX, ERR_CANT_CONVERT, ERR_OLUA_NORET, and ERR_OUT_OF_MEMORY.

Referenced by oski_ApplyMatTransforms().


Variable Documentation

struct luaL_reg g_luamatlib_f[] [static]
Initial value:
 {
  {"new", NewLuaMat},
  {NULL, NULL}
}

OLUA_MAT static members.

Referenced by OpenLuaMatMod().

struct luaL_reg g_luamatlib_m[] [static]
Initial value:
 {
  {"__tostring", ToStringLuaMat},
  {"__gc", GCLuaMat},
  {"__call", ConvertLuaMat},
  {NULL, NULL}
}

OLUA_MAT object methods.

Referenced by OpenLuaMatMod().