aboutsummaryrefslogtreecommitdiff
path: root/nerv/matrix/mmatrix.c
diff options
context:
space:
mode:
authorDeterminant <ted.sybil@gmail.com>2016-02-24 16:58:32 +0800
committerDeterminant <ted.sybil@gmail.com>2016-02-24 16:58:32 +0800
commite91fc2ddaa74dd2c46ce93c9e92020d66c037c8e (patch)
tree94165c3c81b1af93e9b77b408372c0d9ff23dd6b /nerv/matrix/mmatrix.c
parent9642bd16922b288c81dee25f17373466ae6888c4 (diff)
add CuContext/MContextwrapped-handles
Diffstat (limited to 'nerv/matrix/mmatrix.c')
-rw-r--r--nerv/matrix/mmatrix.c51
1 files changed, 50 insertions, 1 deletions
diff --git a/nerv/matrix/mmatrix.c b/nerv/matrix/mmatrix.c
index a68506d..45cb238 100644
--- a/nerv/matrix/mmatrix.c
+++ b/nerv/matrix/mmatrix.c
@@ -1,17 +1,64 @@
#define NERV_GENERIC_MMATRIX
#include <stdlib.h>
+#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
@@ -29,8 +76,10 @@ static void host_matrix_(init_extra)(lua_State *L) {
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, &status);
+ Matrix *self = nerv_matrix_(perm_gen)(ncol, context, &status);
NERV_LUA_CHECK_STATUS(L, status);
luaT_pushudata(L, self, nerv_matrix_(tname));
return 1;