aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--nerv/lib/common.c2
-rw-r--r--nerv/lib/common.h15
-rw-r--r--nerv/lib/matrix/cuda_helper.h15
-rw-r--r--nerv/lib/matrix/cumatrix.c5
-rw-r--r--nerv/lib/matrix/generic/mmatrix.c2
-rw-r--r--nerv/lib/matrix/mmatrix.c17
-rw-r--r--nerv/matrix/cumatrix.c1
-rw-r--r--nerv/matrix/generic/cumatrix.c4
-rw-r--r--nerv/matrix/generic/matrix.c2
9 files changed, 32 insertions, 31 deletions
diff --git a/nerv/lib/common.c b/nerv/lib/common.c
index 879ae9d..7fd2331 100644
--- a/nerv/lib/common.c
+++ b/nerv/lib/common.c
@@ -4,7 +4,7 @@ int nerv_error(lua_State *L, const char *err_mesg_fmt, ...) {
va_list ap;
va_start(ap, err_mesg_fmt);
lua_pushstring(L, "[nerv] internal error: ");
- lua_pushvfstring(L, err_mesg_fmt, ap);
+ lua_pushvfstring(L, err_mesg_fmt, ap);
lua_concat(L, 2);
lua_error(L);
va_end(ap);
diff --git a/nerv/lib/common.h b/nerv/lib/common.h
index 3283ac1..3d98574 100644
--- a/nerv/lib/common.h
+++ b/nerv/lib/common.h
@@ -61,6 +61,21 @@ typedef struct Status {
nerv_error_status(L, &status); \
} while (0)
+#define CHECK_SAME_DIMENSION(a, b, status) \
+ do { \
+ if (!(a->nrow == b->nrow && a->ncol == b->ncol)) \
+ NERV_EXIT_STATUS(status, MAT_MISMATCH_DIM, 0); \
+ } while (0)
+
+#define CHECK_SAME_DIMENSION_RET(a, b, status) \
+ do { \
+ if (!(a->nrow == b->nrow && a->ncol == b->ncol)) \
+ { \
+ NERV_SET_STATUS(status, MAT_MISMATCH_DIM, 0); \
+ return 0; \
+ } \
+ } while (0)
+
typedef struct HashNode {
const char *key;
void *val;
diff --git a/nerv/lib/matrix/cuda_helper.h b/nerv/lib/matrix/cuda_helper.h
index 5c75e38..2d18486 100644
--- a/nerv/lib/matrix/cuda_helper.h
+++ b/nerv/lib/matrix/cuda_helper.h
@@ -76,21 +76,6 @@
cudaDeviceSynchronize(); \
} while (0)
-#define CHECK_SAME_DIMENSION(a, b, status) \
- do { \
- if (!(a->nrow == b->nrow && a->ncol == b->ncol)) \
- NERV_EXIT_STATUS(status, MAT_MISMATCH_DIM, 0); \
- } while (0)
-
-#define CHECK_SAME_DIMENSION_RET(a, b, status) \
- do { \
- if (!(a->nrow == b->nrow && a->ncol == b->ncol)) \
- { \
- NERV_SET_STATUS(status, MAT_MISMATCH_DIM, 0); \
- return 0; \
- } \
- } while (0)
-
static const char *cublasGetErrorString(cublasStatus_t err) {
switch (err)
{
diff --git a/nerv/lib/matrix/cumatrix.c b/nerv/lib/matrix/cumatrix.c
index 2fbe7d8..ff2ea22 100644
--- a/nerv/lib/matrix/cumatrix.c
+++ b/nerv/lib/matrix/cumatrix.c
@@ -1,9 +1,10 @@
#define NERV_GENERIC_CUMATRIX
#define MATRIX_CONTEXT CuContext
-#include "cumatrix.h"
-#include "cuda_helper.h"
#include <string.h>
#include <time.h>
+#include "../common.h"
+#include "cumatrix.h"
+#include "cuda_helper.h"
void nerv_cuda_context_print_profile(CuContext *context) {
HashMap *profile = context->profile;
diff --git a/nerv/lib/matrix/generic/mmatrix.c b/nerv/lib/matrix/generic/mmatrix.c
index ad334e3..485d778 100644
--- a/nerv/lib/matrix/generic/mmatrix.c
+++ b/nerv/lib/matrix/generic/mmatrix.c
@@ -7,10 +7,10 @@
host_matrix_(alloc)(dptr, stride, width, height, \
context, status)
#define NERV_GENERIC_MATRIX
-#include "../cuda_helper.h"
#include "../../common.h"
#include "../../io/chunk_file.h"
#include <string.h>
+#include <math.h>
#include <cblas.h>
#include <float.h>
diff --git a/nerv/lib/matrix/mmatrix.c b/nerv/lib/matrix/mmatrix.c
index f1cbc75..e40b160 100644
--- a/nerv/lib/matrix/mmatrix.c
+++ b/nerv/lib/matrix/mmatrix.c
@@ -1,17 +1,10 @@
#define NERV_GENERIC_MMATRIX
#define MATRIX_CONTEXT MContext
+#include <string.h>
#include <stdlib.h>
#include "../common.h"
#include "mmatrix.h"
-#define MATRIX_USE_FLOAT
-#define host_matrix_(NAME) host_matrix_float_##NAME
-#define nerv_matrix_(NAME) nerv_matrix_host_float_##NAME
-#define NERV_CBLAS_(NAME) cblas_s##NAME
-#include "generic/matrix.h"
-#include "generic/elem_type.h"
-#include "generic/mmatrix.c"
-
void nerv_host_context_print_profile(MContext *context) {
HashMap *profile = context->profile;
size_t i;
@@ -43,6 +36,14 @@ void nerv_host_context_destroy(MContext *context, Status *status) {
NERV_SET_STATUS(status, NERV_NORMAL, 0);
}
+#define MATRIX_USE_FLOAT
+#define host_matrix_(NAME) host_matrix_float_##NAME
+#define nerv_matrix_(NAME) nerv_matrix_host_float_##NAME
+#define NERV_CBLAS_(NAME) cblas_s##NAME
+#include "generic/matrix.h"
+#include "generic/elem_type.h"
+#include "generic/mmatrix.c"
+
Matrix *nerv_matrix_(perm_gen)(int ncol, MContext *context, Status *status) {
int i;
Matrix *self = nerv_matrix_(create)(1, ncol, context, status);
diff --git a/nerv/matrix/cumatrix.c b/nerv/matrix/cumatrix.c
index 26b055b..f6a4ed5 100644
--- a/nerv/matrix/cumatrix.c
+++ b/nerv/matrix/cumatrix.c
@@ -3,7 +3,6 @@
#include "../lib/matrix/cumatrix.h"
#include "../lib/matrix/cuda_helper.h"
#include <string.h>
-#define PROFILE_HASHMAP_SIZE 123457
const char *nerv_cuda_context_tname = "nerv.CuContext";
diff --git a/nerv/matrix/generic/cumatrix.c b/nerv/matrix/generic/cumatrix.c
index 16c0e3a..00e4ee3 100644
--- a/nerv/matrix/generic/cumatrix.c
+++ b/nerv/matrix/generic/cumatrix.c
@@ -1,4 +1,6 @@
#ifdef NERV_GENERIC_CUMATRIX
+#include "../matrix.h"
+#include "../../lib/matrix/generic/matrix.h"
#include "../../lib/matrix/generic/elem_type.h"
#define MATRIX_DATA_WRITE(L, data, idx, val) cuda_matrix_(write)(L, data, idx, val)
#define MATRIX_DATA_READ(L, data, idx) cuda_matrix_(read)(L, data, idx)
@@ -6,9 +8,7 @@
#define MATRIX_BASE_TNAME nerv_matrix_cuda_tname
#define NERV_GENERIC_MATRIX
#define NERV_GENERIC_CUKERNEL
-#include "../matrix.h"
#include "../../lib/common.h"
-#include "../../lib/matrix/generic/matrix.h"
#include "../../lib/matrix/generic/cumatrix.h"
#define BLAS_OP_N CUBLAS_OP_N
diff --git a/nerv/matrix/generic/matrix.c b/nerv/matrix/generic/matrix.c
index c2e57b8..8c2f871 100644
--- a/nerv/matrix/generic/matrix.c
+++ b/nerv/matrix/generic/matrix.c
@@ -1,7 +1,7 @@
#ifdef NERV_GENERIC_MATRIX
#include "../matrix.h"
-#include "../../lib/common.h"
#include "../../lib/matrix/generic/matrix.h"
+#include "../../lib/common.h"
extern const char *nerv_matrix_(tname);
extern const char *MATRIX_BASE_TNAME;