BeBOP Optimized Sparse Kernel Interface Library
1.0.1h
|
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_t * | CheckLuaMat (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_t * | ConvertLuaMatToCSR (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. |
Save/restore tuning transformations.
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:
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.
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.
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.
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.
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_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.
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.
[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'. |
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.
[in,out] | L | Lua 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.
[in] | L | Lua engine in which to run the code. |
[in] | xforms | String program representing the transformation to execute. |
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:
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().
struct luaL_reg g_luamatlib_f[] [static] |
{ {"new", NewLuaMat}, {NULL, NULL} }
OLUA_MAT static members.
Referenced by OpenLuaMatMod().
struct luaL_reg g_luamatlib_m[] [static] |
{ {"__tostring", ToStringLuaMat}, {"__gc", GCLuaMat}, {"__call", ConvertLuaMat}, {NULL, NULL} }
OLUA_MAT object methods.
Referenced by OpenLuaMatMod().