aboutsummaryrefslogtreecommitdiff
path: root/nerv/matrix/matrix.h
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/matrix.h
parent9642bd16922b288c81dee25f17373466ae6888c4 (diff)
add CuContext/MContextwrapped-handles
Diffstat (limited to 'nerv/matrix/matrix.h')
-rw-r--r--nerv/matrix/matrix.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/nerv/matrix/matrix.h b/nerv/matrix/matrix.h
new file mode 100644
index 0000000..788f596
--- /dev/null
+++ b/nerv/matrix/matrix.h
@@ -0,0 +1,24 @@
+#ifndef NERV_LUA_MATRIX_H
+#define NERV_LUA_MATRIX_H
+#include "../lib/luaT/luaT.h"
+#define _MATRIX_GET_CONTEXT(L, p, tname, ctname) \
+ do { \
+ if (lua_gettop(L) < p) \
+ { \
+ luaT_pushmetatable(L, tname); \
+ lua_getfield(L, -1, "_default_context"); \
+ context = luaT_checkudata(L, -1, ctname); \
+ lua_pop(L, 2); \
+ } \
+ else \
+ { \
+ context = luaT_checkudata(L, p, ctname); \
+ } \
+ } while (0)
+
+extern const char *nerv_cuda_context_tname;
+extern const char *nerv_host_context_tname;
+extern const char *nerv_matrix_host_tname;
+#define MATRIX_GET_CONTEXT(L, p) _MATRIX_GET_CONTEXT(L, p, nerv_matrix_(tname), MATRIX_CONTEXT_TNAME)
+#define MMATRIX_GET_CONTEXT(L, p) _MATRIX_GET_CONTEXT(L, p, nerv_matrix_host_tname, nerv_host_context_tname)
+#endif