diff options
Diffstat (limited to 'nerv/matrix/cumatrix.c')
-rw-r--r-- | nerv/matrix/cumatrix.c | 44 |
1 files changed, 10 insertions, 34 deletions
diff --git a/nerv/matrix/cumatrix.c b/nerv/matrix/cumatrix.c index af34fb4..1bcb0f1 100644 --- a/nerv/matrix/cumatrix.c +++ b/nerv/matrix/cumatrix.c @@ -1,6 +1,7 @@ #define NERV_GENERIC_CUMATRIX #include "../common.h" -#include "cuda_helper.h" +#include "../lib/matrix/cumatrix.h" +#include "../lib/matrix/cuda_helper.h" #include <string.h> #define PROFILE_HASHMAP_SIZE 123457 static cublasHandle_t cublas_handle; @@ -8,54 +9,29 @@ static cudaEvent_t profile_start, profile_stop; static HashMap *profile; static int print_profile(lua_State *L) { - (void)L; - size_t i; - fprintf(stderr, "*** [nerv cumatrix profile] **\n"); - for (i = 0; i < profile->size; i++) - { - HashNode *ptr; - for (ptr = profile->bucket[i]; ptr; ptr = ptr->next) - { - fprintf(stderr, "%s:\t%.6f\n", ptr->key, *(float *)ptr->val); - } - } + nerv_cumatrix_print_profile(); return 0; } static int clear_profile(lua_State *L) { - (void)L; - hashmap_clear(profile); + nerv_cumatrix_clear_profile(); return 0; } -void accu_profile(const char *name, float delta) { - float *val = hashmap_getval(profile, name); - if (!val) - { - val = malloc(sizeof(float)); - *val = 0; - hashmap_setval(profile, name, val); - } - *val += delta; -} - static const luaL_Reg cumatrix_methods[] = { {"print_profile", print_profile}, {"clear_profile", clear_profile}, {NULL, NULL} }; -extern void nerv_matrix_cuda_float_init(lua_State *L); -extern void nerv_matrix_cuda_double_init(lua_State *L); +extern void nerv_matrix_cuda_float_lua_init(lua_State *L); +extern void nerv_matrix_cuda_double_lua_init(lua_State *L); -void nerv_cumatrix_init(lua_State *L) { +void nerv_lua_cumatrix_init(lua_State *L) { luaL_register(L, NULL, cumatrix_methods); - cublasCreate(&cublas_handle); - cudaEventCreate(&profile_start); - cudaEventCreate(&profile_stop); - profile = hashmap_create(PROFILE_HASHMAP_SIZE, bkdr_hash, strcmp); - nerv_matrix_cuda_float_init(L); - nerv_matrix_cuda_double_init(L); + nerv_cumatrix_init(); + nerv_matrix_cuda_float_lua_init(L); + nerv_matrix_cuda_double_lua_init(L); } #define MATRIX_USE_FLOAT |