#define NERV_GENERIC_MMATRIX #include #include "../lib/matrix/mmatrix.h" #include "../lib/common.h" const char *nerv_host_context_tname = "nerv.MContext"; int nerv_host_context_lua_print_profile(lua_State *L) { nerv_host_context_print_profile(luaT_checkudata(L, 1, nerv_host_context_tname)); return 0; } int nerv_host_context_lua_clear_profile(lua_State *L) { nerv_host_context_clear_profile(luaT_checkudata(L, 1, nerv_host_context_tname)); return 0; } int nerv_host_context_lua_new(lua_State *L) { Status status; MContext *self = nerv_host_context_create(&status); NERV_LUA_CHECK_STATUS(L, status); luaT_pushudata(L, self, nerv_host_context_tname); return 1; } int nerv_host_context_lua_destroy(lua_State *L) { Status status; MContext *self = luaT_checkudata(L, 1, nerv_host_context_tname); nerv_host_context_destroy(self, &status); NERV_LUA_CHECK_STATUS(L, status); return 1; } static const luaL_Reg nerv_host_context_methods[] = { {"print_profile", nerv_host_context_lua_print_profile}, {"clear_profile", nerv_host_context_lua_clear_profile}, {NULL, NULL} }; void nerv_host_context_lua_init(lua_State *L) { luaT_newmetatable(L, nerv_host_context_tname, NULL, nerv_host_context_lua_new, nerv_host_context_lua_destroy, NULL); luaL_register(L, NULL, nerv_host_context_methods); } void nerv_matrix_host_float_lua_init(lua_State *L); void nerv_matrix_host_double_lua_init(lua_State *L); void nerv_matrix_host_int_lua_init(lua_State *L); void nerv_lua_mmatrix_init(lua_State *L) { srand(1); nerv_host_context_lua_init(L); nerv_matrix_host_float_lua_init(L); nerv_matrix_host_double_lua_init(L); nerv_matrix_host_int_lua_init(L); } #define MATRIX_CONTEXT MContext #define MATRIX_CONTEXT_TNAME nerv_host_context_tname #define MATRIX_USE_FLOAT #define host_matrix_(NAME) host_matrix_float_##NAME #define nerv_matrix_(NAME) nerv_matrix_host_float_##NAME #define MATRIX_MMATRIX_CUDA_TNAME nerv_matrix_cuda_float_tname const char *nerv_matrix_(tname) = "nerv.MMatrixFloat"; #define MMATRIX_INIT(L) host_matrix_(init_extra)(L) static const luaL_Reg nerv_matrix_(extra_methods_int)[]; static void host_matrix_(init_extra)(lua_State *L) { luaN_append_methods(L, nerv_matrix_(extra_methods_int)); } #include "generic/mmatrix.c" #include "../lib/matrix/mmatrix.h" static int nerv_matrix_(lua_perm_gen)(lua_State *L) { Status status; MATRIX_CONTEXT *context; MATRIX_GET_CONTEXT(L, 2); int i, ncol = luaL_checkinteger(L, 1); Matrix *self = nerv_matrix_(perm_gen)(ncol, context, &status); NERV_LUA_CHECK_STATUS(L, status); luaT_pushudata(L, self, nerv_matrix_(tname)); return 1; } static const luaL_Reg nerv_matrix_(extra_methods_int)[] = { {"perm_gen", nerv_matrix_(lua_perm_gen)}, {NULL, NULL} }; #undef nerv_matrix_ #undef host_matrix_ #undef MATRIX_USE_FLOAT #undef MATRIX_ELEM #undef MATRIX_ELEM_PTR #undef MATRIX_ELEM_PTR_BASE #undef MATRIX_ELEM_FMT #undef MATRIX_ELEM_WRITE_FMT #undef MMATRIX_INIT #undef MATRIX_MMATRIX_CUDA_TNAME #define NERV_GENERIC_MMATRIX #define MATRIX_USE_DOUBLE #define host_matrix_(NAME) host_matrix_double_##NAME #define nerv_matrix_(NAME) nerv_matrix_host_double_##NAME #define MATRIX_MMATRIX_CUDA_TNAME nerv_matrix_cuda_double_tname const char *nerv_matrix_(tname) = "nerv.MMatrixDouble"; #include "generic/mmatrix.c" #undef nerv_matrix_ #undef host_matrix_ #undef MATRIX_USE_DOUBLE #undef MATRIX_ELEM #undef MATRIX_ELEM_PTR #undef MATRIX_ELEM_PTR_BASE #undef MATRIX_ELEM_FMT #undef MATRIX_ELEM_WRITE_FMT #define NERV_GENERIC_MMATRIX #define MATRIX_USE_INT #define host_matrix_(NAME) host_matrix_int_##NAME #define nerv_matrix_(NAME) nerv_matrix_host_int_##NAME const char *nerv_matrix_(tname) = "nerv.MMatrixInt"; #include "generic/mmatrix.c"