From 87dfc12a295c17ea02188b0fe0e6b55943191582 Mon Sep 17 00:00:00 2001 From: Yu Yang Date: Fri, 14 Apr 2017 14:40:01 +0800 Subject: [PATCH] Follow comments --- .../examples/model_inference/dense/main.c | 6 +++++ .../model_inference/multi_thread/main.c | 22 ++++++++++--------- .../examples/model_inference/sequence/main.c | 7 ++++++ .../model_inference/sparse_binary/main.c | 6 +++++ paddle/capi/tests/test_Init.cpp | 0 5 files changed, 31 insertions(+), 10 deletions(-) delete mode 100644 paddle/capi/tests/test_Init.cpp diff --git a/paddle/capi/examples/model_inference/dense/main.c b/paddle/capi/examples/model_inference/dense/main.c index 4dddd65bbf..e03fe748f6 100644 --- a/paddle/capi/examples/model_inference/dense/main.c +++ b/paddle/capi/examples/model_inference/dense/main.c @@ -59,5 +59,11 @@ int main() { } printf("\n"); + CHECK(paddle_matrix_destroy(prob)); + CHECK(paddle_arguments_destroy(out_args)); + CHECK(paddle_matrix_destroy(mat)); + CHECK(paddle_arguments_destroy(in_args)); + CHECK(paddle_gradient_machine_destroy(machine)); + return 0; } diff --git a/paddle/capi/examples/model_inference/multi_thread/main.c b/paddle/capi/examples/model_inference/multi_thread/main.c index 23f8629765..ab0eb32c58 100644 --- a/paddle/capi/examples/model_inference/multi_thread/main.c +++ b/paddle/capi/examples/model_inference/multi_thread/main.c @@ -4,24 +4,24 @@ #include "../common/common.h" #define CONFIG_BIN "./trainer_config.bin" -#define NUM_THREAD 1000 +#define NUM_THREAD 4 #define NUM_ITER 1000 pthread_mutex_t mutex; void* thread_main(void* gm_ptr) { paddle_gradient_machine machine = (paddle_gradient_machine)(gm_ptr); - + paddle_arguments in_args = paddle_arguments_create_none(); + // Create input matrix. + paddle_matrix mat = paddle_matrix_create(/* sample_num */ 1, + /* size */ 784, + /* useGPU */ false); + paddle_arguments out_args = paddle_arguments_create_none(); + paddle_matrix prob = paddle_matrix_create_none(); for (int iter = 0; iter < NUM_ITER; ++iter) { - paddle_arguments in_args = paddle_arguments_create_none(); // There is only one input of this network. CHECK(paddle_arguments_resize(in_args, 1)); - // Create input matrix. - paddle_matrix mat = paddle_matrix_create(/* sample_num */ 1, - /* size */ 784, - /* useGPU */ false); - paddle_real* array; // Get First row. @@ -33,12 +33,10 @@ void* thread_main(void* gm_ptr) { CHECK(paddle_arguments_set_value(in_args, 0, mat)); - paddle_arguments out_args = paddle_arguments_create_none(); CHECK(paddle_gradient_machine_forward(machine, in_args, out_args, /* isTrain */ false)); - paddle_matrix prob = paddle_matrix_create_none(); CHECK(paddle_arguments_value(out_args, 0, prob)); @@ -53,6 +51,10 @@ void* thread_main(void* gm_ptr) { pthread_mutex_unlock(&mutex); } + CHECK(paddle_matrix_destroy(prob)); + CHECK(paddle_arguments_destroy(out_args)); + CHECK(paddle_matrix_destroy(mat)); + CHECK(paddle_arguments_destroy(in_args)); CHECK(paddle_gradient_machine_destroy(machine)); return NULL; } diff --git a/paddle/capi/examples/model_inference/sequence/main.c b/paddle/capi/examples/model_inference/sequence/main.c index 7e71bb8b8a..142793cdb3 100644 --- a/paddle/capi/examples/model_inference/sequence/main.c +++ b/paddle/capi/examples/model_inference/sequence/main.c @@ -59,5 +59,12 @@ int main() { } printf("\n"); + CHECK(paddle_matrix_destroy(prob)); + CHECK(paddle_arguments_destroy(out_args)); + CHECK(paddle_ivector_destroy(seq_pos)); + CHECK(paddle_ivector_destroy(sentence)); + CHECK(paddle_arguments_destroy(in_args)); + CHECK(paddle_gradient_machine_destroy(machine)); + return 0; } diff --git a/paddle/capi/examples/model_inference/sparse_binary/main.c b/paddle/capi/examples/model_inference/sparse_binary/main.c index c5e653dbc2..776ad87891 100644 --- a/paddle/capi/examples/model_inference/sparse_binary/main.c +++ b/paddle/capi/examples/model_inference/sparse_binary/main.c @@ -60,5 +60,11 @@ int main() { } printf("\n"); + CHECK(paddle_matrix_destroy(prob)); + CHECK(paddle_arguments_destroy(out_args)); + CHECK(paddle_matrix_destroy(mat)); + CHECK(paddle_arguments_destroy(in_args)); + CHECK(paddle_gradient_machine_destroy(machine)); + return 0; } diff --git a/paddle/capi/tests/test_Init.cpp b/paddle/capi/tests/test_Init.cpp deleted file mode 100644 index e69de29bb2..0000000000 -- GitLab