xforms.c File Reference


Detailed Description

Save/restore tuning transformations.

#include <string.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>
#include <lua/include/lua.h>
#include <lua/include/lualib.h>
#include <lua/include/lauxlib.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)
 Routine to create a Lua matrix representation from a CSR representation for a simple matrix type.
int oski_CreateLuaMatReprGeneric2IndexFromCSR (lua_State *L, const char *mattype)
 Routine to create a Lua matrix representation from a CSR representation for a matrix type that, on creation, expects two integer index arguments.

Variables

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


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.

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.

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.

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.

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] )'.

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.

int oski_CreateLuaMatReprGenericFromCSR lua_State *  L,
const char *  mattype
 

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

Todo:
else: possible leak

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.

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?

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] A Matrix whose tuned representation is to be changed.
[in] new_mat The new matrix representation.
[in] xforms The 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.

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] L Lua transformation engine state.

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

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

Parameters:
[in] L Lua engine in which to run the code.
[in] xforms String 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 )


Variable Documentation

const struct luaL_reg g_luamatlib_f[] [static]
 

Initial value:

 {
  {"new", NewLuaMat},
  {NULL, NULL}
}
OLUA_MAT static members.

const struct luaL_reg g_luamatlib_m[] [static]
 

Initial value:

 {
  {"__tostring", ToStringLuaMat},
  {"__gc", GCLuaMat},
  {"__call", ConvertLuaMat},
  {NULL, NULL}
}
OLUA_MAT object methods.


Generated on Wed Sep 19 16:41:23 2007 for BeBOP Optimized Sparse Kernel Interface Library by  doxygen 1.4.6