From 4b0be8c7011c9d39c102d64147af9a181db76179 Mon Sep 17 00:00:00 2001
From: AlexeyAB <alexeyab84@gmail.com>
Date: Wed, 21 Feb 2018 12:06:11 +0000
Subject: [PATCH] Optimized resizing of network for random=1
---
src/network.c | 14 ++++++++------
src/convolutional_layer.c | 24 ++++++++++++++----------
2 files changed, 22 insertions(+), 16 deletions(-)
diff --git a/src/convolutional_layer.c b/src/convolutional_layer.c
index a3247d0..ca83486 100644
--- a/src/convolutional_layer.c
+++ b/src/convolutional_layer.c
@@ -359,6 +359,8 @@
void resize_convolutional_layer(convolutional_layer *l, int w, int h)
{
+ int old_w = l->w;
+ int old_h = l->h;
l->w = w;
l->h = h;
int out_w = convolutional_out_width(*l);
@@ -378,19 +380,21 @@
}
#ifdef GPU
- cuda_free(l->delta_gpu);
- cuda_free(l->output_gpu);
+ if (old_w < w || old_h < h) {
+ cuda_free(l->delta_gpu);
+ cuda_free(l->output_gpu);
- l->delta_gpu = cuda_make_array(l->delta, l->batch*l->outputs);
- l->output_gpu = cuda_make_array(l->output, l->batch*l->outputs);
+ l->delta_gpu = cuda_make_array(l->delta, l->batch*l->outputs);
+ l->output_gpu = cuda_make_array(l->output, l->batch*l->outputs);
- if(l->batch_normalize){
- cuda_free(l->x_gpu);
- cuda_free(l->x_norm_gpu);
+ if (l->batch_normalize) {
+ cuda_free(l->x_gpu);
+ cuda_free(l->x_norm_gpu);
- l->x_gpu = cuda_make_array(l->output, l->batch*l->outputs);
- l->x_norm_gpu = cuda_make_array(l->output, l->batch*l->outputs);
- }
+ l->x_gpu = cuda_make_array(l->output, l->batch*l->outputs);
+ l->x_norm_gpu = cuda_make_array(l->output, l->batch*l->outputs);
+ }
+ }
#ifdef CUDNN
cudnn_convolutional_setup(l);
#endif
diff --git a/src/network.c b/src/network.c
index 0c1b9af..e83941f 100644
--- a/src/network.c
+++ b/src/network.c
@@ -328,6 +328,12 @@
cuda_set_device(net->gpu_index);
if(gpu_index >= 0){
cuda_free(net->workspace);
+ if (net->input_gpu) {
+ cuda_free(*net->input_gpu);
+ *net->input_gpu = 0;
+ cuda_free(*net->truth_gpu);
+ *net->truth_gpu = 0;
+ }
}
#endif
int i;
@@ -340,6 +346,7 @@
//fflush(stderr);
for (i = 0; i < net->n; ++i){
layer l = net->layers[i];
+ printf(" %d: layer = %d,", i, l.type);
if(l.type == CONVOLUTIONAL){
resize_convolutional_layer(&l, w, h);
}else if(l.type == CROP){
@@ -371,13 +378,8 @@
}
#ifdef GPU
if(gpu_index >= 0){
- if(net->input_gpu) {
- cuda_free(*net->input_gpu);
- *net->input_gpu = 0;
- cuda_free(*net->truth_gpu);
- *net->truth_gpu = 0;
- }
net->workspace = cuda_make_array(0, (workspace_size-1)/sizeof(float)+1);
+ printf(" CUDA allocate done! \n");
}else {
free(net->workspace);
net->workspace = calloc(1, workspace_size);
--
Gitblit v1.10.0