aboutsummaryrefslogtreecommitdiff
path: root/matrix/generic/cumatrix.c
diff options
context:
space:
mode:
authorDeterminant <[email protected]>2015-05-28 14:09:25 +0800
committerDeterminant <[email protected]>2015-05-28 14:09:25 +0800
commitfa2ad1f126428adf80aa318cf18694b251a8a710 (patch)
tree5976c5013846b30174aee86b28b8029ea5e6f5ab /matrix/generic/cumatrix.c
parent9791a4c03cd6ae0f7403daa8f6ba84b6c523c5a7 (diff)
parentba66e109a89d5aff4d709cf0865da60d4d873fee (diff)
Merge branch 'master' of https://github.com/cloudygoose/nerv into cloudygoose-master
Conflicts: examples/cumatrix_from_mmatrix.lua
Diffstat (limited to 'matrix/generic/cumatrix.c')
-rw-r--r--matrix/generic/cumatrix.c31
1 files changed, 27 insertions, 4 deletions
diff --git a/matrix/generic/cumatrix.c b/matrix/generic/cumatrix.c
index d350162..2deb7a3 100644
--- a/matrix/generic/cumatrix.c
+++ b/matrix/generic/cumatrix.c
@@ -170,9 +170,30 @@ static int nerv_matrix_(fill)(lua_State *L) {
return 0;
}
+static int nerv_matrix_(copy_fromd)(lua_State *L) {
+ Matrix *a = luaT_checkudata(L, 1, nerv_matrix_(tname));
+ Matrix *b = luaT_checkudata(L, 2, nerv_matrix_(tname));
+ CHECK_SAME_DIMENSION(a, b);
+ cudaMemcpy2D(MATRIX_ELEM_PTR(a), a->stride,
+ MATRIX_ELEM_PTR(b), b->stride,
+ sizeof(MATRIX_ELEM) * b->ncol, b->nrow,
+ cudaMemcpyDeviceToDevice);
+ return 0;
+}
+
+static int nerv_matrix_(copy_tod)(lua_State *L) {
+ Matrix *a = luaT_checkudata(L, 1, nerv_matrix_(tname));
+ Matrix *b = luaT_checkudata(L, 2, nerv_matrix_(tname));
+ CHECK_SAME_DIMENSION(a, b);
+ cudaMemcpy2D(MATRIX_ELEM_PTR(b), b->stride,
+ MATRIX_ELEM_PTR(a), a->stride,
+ sizeof(MATRIX_ELEM) * a->ncol, a->nrow,
+ cudaMemcpyDeviceToDevice);
+ return 0;
+}
extern const char *MATRIX_CUMATRIX_HOST_TNAME;
-static int nerv_matrix_(copy_from)(lua_State *L) {
+static int nerv_matrix_(copy_fromh)(lua_State *L) {
Matrix *a = luaT_checkudata(L, 1, nerv_matrix_(tname));
Matrix *b = luaT_checkudata(L, 2, MATRIX_CUMATRIX_HOST_TNAME);
CHECK_SAME_DIMENSION(a, b);
@@ -183,7 +204,7 @@ static int nerv_matrix_(copy_from)(lua_State *L) {
return 0;
}
-static int nerv_matrix_(copy_to)(lua_State *L) {
+static int nerv_matrix_(copy_toh)(lua_State *L) {
Matrix *a = luaT_checkudata(L, 1, nerv_matrix_(tname));
Matrix *b = luaT_checkudata(L, 2, MATRIX_CUMATRIX_HOST_TNAME);
CHECK_SAME_DIMENSION(a, b);
@@ -216,8 +237,10 @@ static const luaL_Reg nerv_matrix_(extra_methods)[] = {
{"colsum", nerv_matrix_(colsum)},
{"rowsum", nerv_matrix_(rowsum)},
{"rowmax", nerv_matrix_(rowmax)},
- {"copy_from", nerv_matrix_(copy_from)},
- {"copy_to", nerv_matrix_(copy_to)},
+ {"copy_fromh", nerv_matrix_(copy_fromh)},
+ {"copy_fromd", nerv_matrix_(copy_fromd)},
+ {"copy_toh", nerv_matrix_(copy_toh)},
+ {"copy_tod", nerv_matrix_(copy_tod)},
{"trans", nerv_matrix_(trans)},
/* in-place calc */
{"add", nerv_matrix_(add)},