diff options
author | Determinant <ted.sybil@gmail.com> | 2016-02-24 17:26:45 +0800 |
---|---|---|
committer | Determinant <ted.sybil@gmail.com> | 2016-02-24 17:26:45 +0800 |
commit | 550680eacd00555817df19d2b59a20a92df77c42 (patch) | |
tree | be9e39e2115fa95e99e32791898ba5593ca3b23f /nerv/lib | |
parent | e91fc2ddaa74dd2c46ce93c9e92020d66c037c8e (diff) |
clean up code
Diffstat (limited to 'nerv/lib')
-rw-r--r-- | nerv/lib/common.c | 2 | ||||
-rw-r--r-- | nerv/lib/common.h | 15 | ||||
-rw-r--r-- | nerv/lib/matrix/cuda_helper.h | 15 | ||||
-rw-r--r-- | nerv/lib/matrix/cumatrix.c | 5 | ||||
-rw-r--r-- | nerv/lib/matrix/generic/mmatrix.c | 2 | ||||
-rw-r--r-- | nerv/lib/matrix/mmatrix.c | 17 |
6 files changed, 29 insertions, 27 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); |