From f047cfff99e00e28c02eb59b6d32386c122f9af6 Mon Sep 17 00:00:00 2001
From: Joseph Redmon <pjreddie@gmail.com>
Date: Sun, 08 Mar 2015 18:31:12 +0000
Subject: [PATCH] renamed sigmoid to logistic

---
 src/maxpool_layer.c |   34 +++++++++++++++++++++++++---------
 1 files changed, 25 insertions(+), 9 deletions(-)

diff --git a/src/maxpool_layer.c b/src/maxpool_layer.c
index 01eed45..ef7176d 100644
--- a/src/maxpool_layer.c
+++ b/src/maxpool_layer.c
@@ -1,4 +1,5 @@
 #include "maxpool_layer.h"
+#include "cuda.h"
 #include <stdio.h>
 
 image get_maxpool_image(maxpool_layer layer)
@@ -27,19 +28,34 @@
     layer->c = c;
     layer->size = size;
     layer->stride = stride;
-    layer->indexes = calloc(((h-1)/stride+1) * ((w-1)/stride+1) * c*batch, sizeof(int));
-    layer->output = calloc(((h-1)/stride+1) * ((w-1)/stride+1) * c*batch, sizeof(float));
-    layer->delta = calloc(((h-1)/stride+1) * ((w-1)/stride+1) * c*batch, sizeof(float));
+    int output_size = ((h-1)/stride+1) * ((w-1)/stride+1) * c * batch;
+    layer->indexes = calloc(output_size, sizeof(int));
+    layer->output =  calloc(output_size, sizeof(float));
+    layer->delta =   calloc(output_size, sizeof(float));
+    #ifdef GPU
+    layer->indexes_gpu = cuda_make_int_array(output_size);
+    layer->output_gpu  = cuda_make_array(layer->output, output_size);
+    layer->delta_gpu   = cuda_make_array(layer->delta, output_size);
+    #endif
     return layer;
 }
 
-void resize_maxpool_layer(maxpool_layer *layer, int h, int w, int c)
+void resize_maxpool_layer(maxpool_layer *layer, int h, int w)
 {
     layer->h = h;
     layer->w = w;
-    layer->c = c;
-    layer->output = realloc(layer->output, ((h-1)/layer->stride+1) * ((w-1)/layer->stride+1) * c * layer->batch* sizeof(float));
-    layer->delta = realloc(layer->delta, ((h-1)/layer->stride+1) * ((w-1)/layer->stride+1) * c * layer->batch*sizeof(float));
+    int output_size = ((h-1)/layer->stride+1) * ((w-1)/layer->stride+1) * layer->c * layer->batch;
+    layer->output = realloc(layer->output, output_size * sizeof(float));
+    layer->delta = realloc(layer->delta, output_size * sizeof(float));
+
+    #ifdef GPU
+    cuda_free((float *)layer->indexes_gpu);
+    cuda_free(layer->output_gpu);
+    cuda_free(layer->delta_gpu);
+    layer->indexes_gpu = cuda_make_int_array(output_size);
+    layer->output_gpu  = cuda_make_array(layer->output, output_size);
+    layer->delta_gpu   = cuda_make_array(layer->delta, output_size);
+    #endif
 }
 
 void forward_maxpool_layer(const maxpool_layer layer, float *input)
@@ -66,7 +82,7 @@
                             int index = cur_w + layer.w*(cur_h + layer.h*(k + b*layer.c));
                             int valid = (cur_h >= 0 && cur_h < layer.h &&
                                          cur_w >= 0 && cur_w < layer.w);
-                            float val = (valid != 0) ? input[index] : -INFINITY;
+                            float val = (valid != 0) ? input[index] : -FLT_MAX;
                             max_i = (val > max) ? index : max_i;
                             max   = (val > max) ? val   : max;
                         }
@@ -79,7 +95,7 @@
     }
 }
 
-void backward_maxpool_layer(const maxpool_layer layer, float *input, float *delta)
+void backward_maxpool_layer(const maxpool_layer layer, float *delta)
 {
     int i;
     int h = (layer.h-1)/layer.stride + 1;

--
Gitblit v1.10.0