From 6e720b961f7edac9c3a41affe0ca40dd0ec9fc85 Mon Sep 17 00:00:00 2001 From: Determinant Date: Sun, 7 Jun 2015 11:55:09 +0800 Subject: fix memory leak in profiling; other minor changes --- matrix/cuda_helper.h | 13 +++++-------- matrix/cumatrix.c | 1 + matrix/generic/cumatrix.c | 2 ++ matrix/generic/mmatrix.c | 6 ------ 4 files changed, 8 insertions(+), 14 deletions(-) (limited to 'matrix') diff --git a/matrix/cuda_helper.h b/matrix/cuda_helper.h index d6effdb..fde6f18 100644 --- a/matrix/cuda_helper.h +++ b/matrix/cuda_helper.h @@ -62,17 +62,14 @@ static const char *cublasGetErrorString(cublasStatus_t err) { #define PROFILE_START \ do { \ - cudaEvent_t start, stop; \ - cudaEventCreate(&start); \ - cudaEventCreate(&stop); \ - cudaEventRecord(start, 0); + cudaEventRecord(profile_start, 0); #define PROFILE_STOP \ - cudaEventRecord(stop, 0); \ - cudaEventSynchronize(stop); \ + cudaEventRecord(profile_stop, 0); \ + cudaEventSynchronize(profile_stop); \ float milliseconds = 0; \ - cudaEventElapsedTime(&milliseconds, start, stop); \ + cudaEventElapsedTime(&milliseconds, profile_start, profile_stop); \ accu_profile(__func__, milliseconds / 1000); \ } while (0); -#define PROFILE_END +#define PROFILE_END #endif diff --git a/matrix/cumatrix.c b/matrix/cumatrix.c index 4ebc5ff..ee5ecaa 100644 --- a/matrix/cumatrix.c +++ b/matrix/cumatrix.c @@ -2,6 +2,7 @@ #include "../common.h" #include "cuda_helper.h" static cublasHandle_t cublas_handle; +static cudaEvent_t profile_start, profile_stop; static HashMap *profile; int print_profile(lua_State *L) { diff --git a/matrix/generic/cumatrix.c b/matrix/generic/cumatrix.c index 956e1e6..a340aef 100644 --- a/matrix/generic/cumatrix.c +++ b/matrix/generic/cumatrix.c @@ -443,6 +443,8 @@ static const luaL_Reg nerv_matrix_(extra_methods)[] = { static void cuda_matrix_(init)(lua_State *L) { luaN_append_methods(L, nerv_matrix_(extra_methods)); cublasCreate(&cublas_handle); + cudaEventCreate(&profile_start); + cudaEventCreate(&profile_stop); profile = hashmap_create(PROFILE_HASHMAP_SIZE, bkdr_hash, strcmp); } diff --git a/matrix/generic/mmatrix.c b/matrix/generic/mmatrix.c index 2045d65..b0f0791 100644 --- a/matrix/generic/mmatrix.c +++ b/matrix/generic/mmatrix.c @@ -87,15 +87,9 @@ int nerv_matrix_(save)(lua_State *L) { MATRIX_ELEM *row = MATRIX_ROW_PTR(self, i); for (j = 0; j < ncol; j++) if (fprintf(fp, MATRIX_ELEM_WRITE_FMT " ", row[j]) < 0) - { - free(self); return 0; - } if (fprintf(fp, "\n") < 0) - { - free(self); return 0; - } } return 0; } -- cgit v1.2.3