From 1e9ca96f2db5002c14ed324df5cacf08866369ac Mon Sep 17 00:00:00 2001 From: Folke Vesterlund Date: Mon, 27 May 2019 13:45:14 +0200 Subject: [PATCH] Fix overflow issue in threshold --- main.cu | 2 +- utils.hpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/main.cu b/main.cu index 4a1b951..8614068 100644 --- a/main.cu +++ b/main.cu @@ -65,7 +65,7 @@ int main(int argc,char **argv){ cudaMallocManaged(&d_img , numPixels * sizeof(char)); // Pre process image - int imgMean = util::mean(image.data, numPixels); + unsigned int imgMean = util::mean(image.data, numPixels); util::threshold(d_img, image.data, imgMean, numPixels); // Run and time kernel diff --git a/utils.hpp b/utils.hpp index a80dc5a..00d0b67 100644 --- a/utils.hpp +++ b/utils.hpp @@ -26,8 +26,8 @@ namespace util{ // Compute mean of image data - int mean(const unsigned char* img, const int N){ - int mean = 0; + unsigned int mean(const unsigned char* img, const int N){ + unsigned int mean = 0; for(int i = 0; i