From be3985210ed336477b2e1317fd13c6cf1494adb1 Mon Sep 17 00:00:00 2001 From: AlexeyAB Date: Sun, 4 Jul 2021 06:31:45 +0300 Subject: [PATCH] fix possible bug --- src/convolutional_kernels.cu | 3 ++- src/parser.c | 33 +++++++++++++++++++-------------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/convolutional_kernels.cu b/src/convolutional_kernels.cu index f44016c52ca..1e9cdd9c739 100644 --- a/src/convolutional_kernels.cu +++ b/src/convolutional_kernels.cu @@ -165,7 +165,8 @@ half *cuda_make_f16_from_f32_array(float *src, size_t n) void forward_convolutional_layer_gpu(convolutional_layer l, network_state state) { - state.train = l.train; + if (l.train == 0) state.train = 0; + if (l.stream >= 0) { switch_stream(l.stream); } diff --git a/src/parser.c b/src/parser.c index db28e737571..1a345b5cc1b 100644 --- a/src/parser.c +++ b/src/parser.c @@ -1413,16 +1413,18 @@ network parse_network_cfg_custom(char *filename, int batch, int time_steps) // find l.stopbackward = option_find_int_quiet(options, "stopbackward", 0); node *n_tmp = n; int count_tmp = 0; - while (n_tmp) { - s = (section *)n_tmp->val; - options = s->options; - int stopbackward = option_find_int_quiet(options, "stopbackward", 0); - if (stopbackward == 1) { - last_stop_backward = count_tmp; - printf("last_stop_backward = %d \n", last_stop_backward); + if (params.train == 1) { + while (n_tmp) { + s = (section *)n_tmp->val; + options = s->options; + int stopbackward = option_find_int_quiet(options, "stopbackward", 0); + if (stopbackward == 1) { + last_stop_backward = count_tmp; + printf("last_stop_backward = %d \n", last_stop_backward); + } + n_tmp = n_tmp->next; + ++count_tmp; } - n_tmp = n_tmp->next; - ++count_tmp; } int old_params_train = params.train; @@ -1700,15 +1702,18 @@ network parse_network_cfg_custom(char *filename, int batch, int time_steps) for (k = 0; k < last_stop_backward; ++k) { layer l = net.layers[k]; if (l.keep_delta_gpu) { - if (!l.delta) l.delta = (float*)xcalloc(l.outputs*l.batch, sizeof(float)); + if (!l.delta) { + net.layers[k].delta = (float*)xcalloc(l.outputs*l.batch, sizeof(float)); + } #ifdef GPU - if (!l.delta_gpu) l.delta_gpu = (float *)cuda_make_array(NULL, l.outputs*l.batch); + if (!l.delta_gpu) { + net.layers[k].delta_gpu = (float *)cuda_make_array(NULL, l.outputs*l.batch); + } #endif } - l.onlyforward = 1; - l.train = 0; - net.layers[k] = l; + net.layers[k].onlyforward = 1; + net.layers[k].train = 0; } }