summaryrefslogtreecommitdiff
path: root/HST-S/baselines/gpu
diff options
context:
space:
mode:
Diffstat (limited to 'HST-S/baselines/gpu')
-rw-r--r--HST-S/baselines/gpu/Makefile51
-rw-r--r--HST-S/baselines/gpu/README24
-rw-r--r--HST-S/baselines/gpu/input/image_VanHateren.imlbin0 -> 3145728 bytes
-rw-r--r--HST-S/baselines/gpu/kernel.cpp83
-rw-r--r--HST-S/baselines/gpu/kernel.cu113
-rw-r--r--HST-S/baselines/gpu/kernel.h51
-rw-r--r--HST-S/baselines/gpu/main.cpp322
-rw-r--r--HST-S/baselines/gpu/support/common.h45
-rw-r--r--HST-S/baselines/gpu/support/cuda-setup.h78
-rw-r--r--HST-S/baselines/gpu/support/partitioner.h213
-rw-r--r--HST-S/baselines/gpu/support/timer.h73
-rw-r--r--HST-S/baselines/gpu/support/verify.h66
12 files changed, 1119 insertions, 0 deletions
diff --git a/HST-S/baselines/gpu/Makefile b/HST-S/baselines/gpu/Makefile
new file mode 100644
index 0000000..620be83
--- /dev/null
+++ b/HST-S/baselines/gpu/Makefile
@@ -0,0 +1,51 @@
+#
+# Copyright (c) 2016 University of Cordoba and University of Illinois
+# All rights reserved.
+#
+# Developed by: IMPACT Research Group
+# University of Cordoba and University of Illinois
+# http://impact.crhc.illinois.edu/
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# with the Software without restriction, including without limitation the
+# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+# sell copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# > Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimers.
+# > Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimers in the
+# documentation and/or other materials provided with the distribution.
+# > Neither the names of IMPACT Research Group, University of Cordoba,
+# University of Illinois nor the names of its contributors may be used
+# to endorse or promote products derived from this Software without
+# specific prior written permission.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH
+# THE SOFTWARE.
+#
+
+CXX=/usr/local/cuda/bin/nvcc
+CXX_FLAGS=-std=c++11
+
+LIB=-L/usr/lib/ -L/usr/local/cuda/lib64 -lm
+
+INC=-I/usr/local/cuda/include
+
+DEP=kernel.cpp kernel.h main.cpp kernel.cu support/common.h support/cuda-setup.h support/partitioner.h support/timer.h support/verify.h
+SRC=main.cpp kernel.cpp kernel.cu
+EXE=hsti
+
+all:
+ $(CXX) $(CXX_FLAGS) $(SRC) $(LIB) $(INC) -o $(EXE)
+
+clean:
+ rm -f $(EXE)
+
diff --git a/HST-S/baselines/gpu/README b/HST-S/baselines/gpu/README
new file mode 100644
index 0000000..4d6fdcc
--- /dev/null
+++ b/HST-S/baselines/gpu/README
@@ -0,0 +1,24 @@
+Histogram - input partition (HST)
+
+Compilation instructions:
+
+ make
+
+Execution instructions
+
+ ./hsti -n 1006632960 -g 512
+
+For more options:
+
+ ./hsti -h
+
+
+Note:
+The input folder contains one image from Van Hateren's natural image database
+(http://www.kyb.tuebingen.mpg.de/?id=227). Image pixels are 12-bit depth. Thus,
+for calculation of the B-bin histogram of an image, the corresponding histogram
+bin is computed as ((pixel * B) >> 12).
+Monochrome images from other databases or synthetic images can also be used. The
+read input function (in main.cpp) might need to be changed accordingly. If image
+pixels are b-bit depth and the histogram contains B bins, the histogram bin will
+be computed as ((pixel * B) >> b).
diff --git a/HST-S/baselines/gpu/input/image_VanHateren.iml b/HST-S/baselines/gpu/input/image_VanHateren.iml
new file mode 100644
index 0000000..1ae6047
--- /dev/null
+++ b/HST-S/baselines/gpu/input/image_VanHateren.iml
Binary files differ
diff --git a/HST-S/baselines/gpu/kernel.cpp b/HST-S/baselines/gpu/kernel.cpp
new file mode 100644
index 0000000..eab0dfe
--- /dev/null
+++ b/HST-S/baselines/gpu/kernel.cpp
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2016 University of Cordoba and University of Illinois
+ * All rights reserved.
+ *
+ * Developed by: IMPACT Research Group
+ * University of Cordoba and University of Illinois
+ * http://impact.crhc.illinois.edu/
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * with the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * > Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimers.
+ * > Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimers in the
+ * documentation and/or other materials provided with the distribution.
+ * > Neither the names of IMPACT Research Group, University of Cordoba,
+ * University of Illinois nor the names of its contributors may be used
+ * to endorse or promote products derived from this Software without
+ * specific prior written permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH
+ * THE SOFTWARE.
+ *
+ */
+
+#include "kernel.h"
+#include "support/partitioner.h"
+#include <math.h>
+#include <thread>
+#include <vector>
+#include <algorithm>
+
+// CPU threads--------------------------------------------------------------------------------------
+void run_cpu_threads(std::atomic_uint *histo, unsigned int *data, int size, int bins, int n_threads, int chunk, int n_tasks, float alpha
+#ifdef CUDA_8_0
+ , std::atomic_int *worklist
+#endif
+ ) {
+ std::vector<std::thread> cpu_threads;
+ for(int k = 0; k < n_threads; k++) {
+ cpu_threads.push_back(std::thread([=]() {
+
+#ifdef CUDA_8_0
+ Partitioner p = partitioner_create(n_tasks, alpha, k, n_threads, worklist);
+#else
+ Partitioner p = partitioner_create(n_tasks, alpha, k, n_threads);
+#endif
+
+ unsigned int Hs[bins];
+ // Local histogram initialization
+ for(int i = 0; i < bins; i++) {
+ Hs[i] = 0;
+ }
+
+ for(int i = cpu_first(&p); cpu_more(&p); i = cpu_next(&p)) {
+ for(int j = 0; j < chunk; j++) {
+ // Read pixel
+ unsigned int d = ((data[i * chunk + j] * bins) >> 12);
+
+ // Vote in histogram
+ Hs[d]++;
+ }
+ }
+
+ // Merge to global histogram
+ for(int i = 0; i < bins; i++) {
+ (&histo[i])->fetch_add(Hs[i]);
+ }
+
+ }));
+ }
+ std::for_each(cpu_threads.begin(), cpu_threads.end(), [](std::thread &t) { t.join(); });
+}
diff --git a/HST-S/baselines/gpu/kernel.cu b/HST-S/baselines/gpu/kernel.cu
new file mode 100644
index 0000000..fdbb2c6
--- /dev/null
+++ b/HST-S/baselines/gpu/kernel.cu
@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) 2016 University of Cordoba and University of Illinois
+ * All rights reserved.
+ *
+ * Developed by: IMPACT Research Group
+ * University of Cordoba and University of Illinois
+ * http://impact.crhc.illinois.edu/
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * with the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * > Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimers.
+ * > Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimers in the
+ * documentation and/or other materials provided with the distribution.
+ * > Neither the names of IMPACT Research Group, University of Cordoba,
+ * University of Illinois nor the names of its contributors may be used
+ * to endorse or promote products derived from this Software without
+ * specific prior written permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH
+ * THE SOFTWARE.
+ *
+ */
+
+#define _CUDA_COMPILER_
+
+#include "support/common.h"
+#include "support/partitioner.h"
+
+// CUDA kernel ------------------------------------------------------------------------------------------
+__global__ void Histogram_kernel(int size, int bins, int n_tasks, float alpha, unsigned int *data,
+ unsigned int *histo
+#ifdef CUDA_8_0
+ , int *worklist
+#endif
+ ) {
+
+ extern __shared__ unsigned int l_mem[];
+ unsigned int* l_histo = l_mem;
+#ifdef CUDA_8_0
+ int* l_tmp = (int*)&l_histo[bins];
+#endif
+
+#ifdef CUDA_8_0
+ Partitioner p = partitioner_create(n_tasks, alpha, worklist, l_tmp);
+#else
+ Partitioner p = partitioner_create(n_tasks, alpha);
+#endif
+
+ // Block and thread index
+ const int bx = blockIdx.x;
+ const int tx = threadIdx.x;
+ const int bD = blockDim.x;
+ const int gD = gridDim.x;
+
+ // Sub-histograms initialization
+ for(int pos = tx; pos < bins; pos += bD) {
+ l_histo[pos] = 0;
+ }
+
+ __syncthreads(); // Intra-block synchronization
+
+ // Main loop
+ for(int i = gpu_first(&p); gpu_more(&p); i = gpu_next(&p)) {
+
+ // Global memory read
+ unsigned int d = data[i * bD + tx];
+
+ // Atomic vote in shared memory
+ atomicAdd(&l_histo[((d * bins) >> 12)], 1);
+ }
+
+ __syncthreads(); // Intra-block synchronization
+
+ // Merge per-block histograms and write to global memory
+ for(int pos = tx; pos < bins; pos += bD) {
+// Atomic addition in global memory
+#ifdef CUDA_8_0
+ atomicAdd_system(histo + pos, l_histo[pos]);
+#else
+ atomicAdd(histo + pos, l_histo[pos]);
+#endif
+ }
+}
+
+cudaError_t call_Histogram_kernel(int blocks, int threads, int size, int bins, int n_tasks, float alpha,
+ unsigned int *data, unsigned int *histo, int l_mem_size
+#ifdef CUDA_8_0
+ , int* worklist
+#endif
+ ){
+ dim3 dimGrid(blocks);
+ dim3 dimBlock(threads);
+ Histogram_kernel<<<dimGrid, dimBlock, l_mem_size>>>(size, bins, n_tasks, alpha,
+ data, histo
+#ifdef CUDA_8_0
+ , worklist
+#endif
+ );
+ cudaError_t err = cudaGetLastError();
+ return err;
+}
diff --git a/HST-S/baselines/gpu/kernel.h b/HST-S/baselines/gpu/kernel.h
new file mode 100644
index 0000000..525d372
--- /dev/null
+++ b/HST-S/baselines/gpu/kernel.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2016 University of Cordoba and University of Illinois
+ * All rights reserved.
+ *
+ * Developed by: IMPACT Research Group
+ * University of Cordoba and University of Illinois
+ * http://impact.crhc.illinois.edu/
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * with the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * > Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimers.
+ * > Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimers in the
+ * documentation and/or other materials provided with the distribution.
+ * > Neither the names of IMPACT Research Group, University of Cordoba,
+ * University of Illinois nor the names of its contributors may be used
+ * to endorse or promote products derived from this Software without
+ * specific prior written permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH
+ * THE SOFTWARE.
+ *
+ */
+
+#include <cuda_runtime.h>
+#include <atomic>
+#include "support/common.h"
+
+void run_cpu_threads(std::atomic_uint *histo, unsigned int *data, int size, int bins, int num_threads, int chunk, int n_tasks, float alpha
+#ifdef CUDA_8_0
+ , std::atomic_int *wl
+#endif
+ );
+
+cudaError_t call_Histogram_kernel(int blocks, int threads, int size, int bins, int n_tasks, float alpha,
+ unsigned int *data, unsigned int *histo, int l_mem_size
+#ifdef CUDA_8_0
+ , int* worklist
+#endif
+ );
diff --git a/HST-S/baselines/gpu/main.cpp b/HST-S/baselines/gpu/main.cpp
new file mode 100644
index 0000000..e0b5dfa
--- /dev/null
+++ b/HST-S/baselines/gpu/main.cpp
@@ -0,0 +1,322 @@
+/*
+ * Copyright (c) 2016 University of Cordoba and University of Illinois
+ * All rights reserved.
+ *
+ * Developed by: IMPACT Research Group
+ * University of Cordoba and University of Illinois
+ * http://impact.crhc.illinois.edu/
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * with the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * > Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimers.
+ * > Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimers in the
+ * documentation and/or other materials provided with the distribution.
+ * > Neither the names of IMPACT Research Group, University of Cordoba,
+ * University of Illinois nor the names of its contributors may be used
+ * to endorse or promote products derived from this Software without
+ * specific prior written permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH
+ * THE SOFTWARE.
+ *
+ */
+
+#include "support/cuda-setup.h"
+#include "kernel.h"
+#include "support/common.h"
+#include "support/timer.h"
+#include "support/verify.h"
+
+#include <unistd.h>
+#include <thread>
+#include <assert.h>
+
+// Params ---------------------------------------------------------------------
+struct Params {
+
+ int device;
+ int n_gpu_threads;
+ int n_gpu_blocks;
+ int n_threads;
+ int n_warmup;
+ int n_reps;
+ float alpha;
+ int in_size;
+ int n_bins;
+
+ Params(int argc, char **argv) {
+ device = 0;
+ n_gpu_threads = 256;
+ n_gpu_blocks = 16;
+ n_threads = 4;
+ n_warmup = 5;
+ n_reps = 50;
+ alpha = 0.2;
+ in_size = 1536 * 1024 * 640;
+ n_bins = 256;
+ int opt;
+ while((opt = getopt(argc, argv, "hd:i:g:t:w:r:a:n:b:")) >= 0) {
+ switch(opt) {
+ case 'h':
+ usage();
+ exit(0);
+ break;
+ case 'd': device = atoi(optarg); break;
+ case 'i': n_gpu_threads = atoi(optarg); break;
+ case 'g': n_gpu_blocks = atoi(optarg); break;
+ case 't': n_threads = atoi(optarg); break;
+ case 'w': n_warmup = atoi(optarg); break;
+ case 'r': n_reps = atoi(optarg); break;
+ case 'a': alpha = atof(optarg); break;
+ case 'n': in_size = atoi(optarg); break;
+ case 'b': n_bins = atoi(optarg); break;
+ default:
+ fprintf(stderr, "\nUnrecognized option!\n");
+ usage();
+ exit(0);
+ }
+ }
+ if(alpha == 0.0) {
+ assert(n_gpu_threads > 0 && "Invalid # of device threads!");
+ assert(n_gpu_blocks > 0 && "Invalid # of device blocks!");
+ } else if(alpha == 1.0) {
+ assert(n_threads > 0 && "Invalid # of host threads!");
+ } else if(alpha > 0.0 && alpha < 1.0) {
+ assert(n_gpu_threads > 0 && "Invalid # of device threads!");
+ assert(n_gpu_blocks > 0 && "Invalid # of device blocks!");
+ assert(n_threads > 0 && "Invalid # of host threads!");
+ } else {
+#ifdef CUDA_8_0
+ assert((n_gpu_threads > 0 && n_gpu_blocks > 0 || n_threads > 0) && "Invalid # of host + device workers!");
+#else
+ assert(0 && "Illegal value for -a");
+#endif
+ }
+ }
+
+ void usage() {
+ fprintf(stderr,
+ "\nUsage: ./hsti [options]"
+ "\n"
+ "\nGeneral options:"
+ "\n -h help"
+ "\n -d <D> CUDA device ID (default=0)"
+ "\n -i <I> # of device threads per block (default=256)"
+ "\n -g <G> # of device blocks (default=16)"
+ "\n -t <T> # of host threads (default=4)"
+ "\n -w <W> # of untimed warmup iterations (default=5)"
+ "\n -r <R> # of timed repetition iterations (default=50)"
+ "\n"
+ "\nData-partitioning-specific options:"
+ "\n -a <A> fraction of input elements to process on host (default=0.2)"
+#ifdef CUDA_8_0
+ "\n NOTE: Dynamic partitioning used when <A> is not between 0.0 and 1.0"
+#else
+ "\n NOTE: <A> must be between 0.0 and 1.0"
+#endif
+ "\n"
+ "\nBenchmark-specific options:"
+ "\n -n <N> input size (default=1572864, i.e., 1536x1024)"
+ "\n -b <B> # of bins in histogram (default=256)"
+ "\n");
+ }
+};
+
+// Input Data -----------------------------------------------------------------
+void read_input(unsigned int *input, const Params &p) {
+
+ char dctFileName[100];
+ FILE *File = NULL;
+
+ // Open input file
+ unsigned short temp;
+ sprintf(dctFileName, "./input/image_VanHateren.iml");
+ if((File = fopen(dctFileName, "rb")) != NULL) {
+ for(int y = 0; y < p.in_size; y++) {
+ int fr = fread(&temp, sizeof(unsigned short), 1, File);
+ input[y] = (unsigned int)ByteSwap16(temp);
+ if(input[y] >= 4096)
+ input[y] = 4095;
+ }
+ fclose(File);
+ } else {
+ printf("%s does not exist\n", dctFileName);
+ exit(1);
+ }
+}
+
+// Main ------------------------------------------------------------------------------------------
+int main(int argc, char **argv) {
+
+ Params p(argc, argv);
+ CUDASetup setcuda(p.device);
+ Timer timer;
+ cudaError_t cudaStatus;
+
+ // Allocate buffers
+ timer.start("Allocation");
+ int n_tasks = divceil(p.in_size, p.n_gpu_threads);
+#ifdef CUDA_8_0
+ unsigned int *h_in;
+ cudaStatus = cudaMallocManaged(&h_in, p.in_size * sizeof(unsigned int));
+ std::atomic_uint *h_histo;
+ cudaStatus = cudaMallocManaged(&h_histo, p.n_bins * sizeof(std::atomic_uint));
+ unsigned int * d_in = h_in;
+ std::atomic_uint *d_histo = h_histo;
+ std::atomic_int * worklist;
+ cudaStatus = cudaMallocManaged(&worklist, sizeof(std::atomic_int));
+#else
+ unsigned int * h_in = (unsigned int *)malloc(p.in_size * sizeof(unsigned int));
+ std::atomic_uint *h_histo = (std::atomic_uint *)malloc(p.n_bins * sizeof(std::atomic_uint));
+ unsigned int * h_histo_merge = (unsigned int *)malloc(p.n_bins * sizeof(unsigned int));
+ unsigned int * d_in;
+ cudaStatus = cudaMalloc((void**)&d_in, p.in_size * sizeof(unsigned int));
+ unsigned int * d_histo;
+ cudaStatus = cudaMalloc((void**)&d_histo, p.n_bins * sizeof(unsigned int));
+ ALLOC_ERR(h_in, h_histo, h_histo_merge);
+#endif
+ CUDA_ERR();
+ cudaDeviceSynchronize();
+ timer.stop("Allocation");
+ timer.print("Allocation", 1);
+
+ // Initialize
+ timer.start("Initialization");
+ const int max_gpu_threads = setcuda.max_gpu_threads();
+ read_input(h_in, p);
+#ifdef CUDA_8_0
+ for(int i = 0; i < p.n_bins; i++) {
+ h_histo[i].store(0);
+ }
+#else
+ memset(h_histo, 0, p.n_bins * sizeof(unsigned int));
+#endif
+ cudaDeviceSynchronize();
+ timer.stop("Initialization");
+ timer.print("Initialization", 1);
+
+#ifndef CUDA_8_0
+ // Copy to device
+ timer.start("Copy To Device");
+ cudaStatus = cudaMemcpy(d_in, h_in, p.in_size * sizeof(unsigned int), cudaMemcpyHostToDevice);
+ cudaStatus = cudaMemcpy(d_histo, h_histo, p.n_bins * sizeof(unsigned int), cudaMemcpyHostToDevice);
+ cudaDeviceSynchronize();
+ CUDA_ERR();
+ timer.stop("Copy To Device");
+ timer.print("Copy To Device", 1);
+#endif
+
+ // Loop over main kernel
+ for(int rep = 0; rep < p.n_warmup + p.n_reps; rep++) {
+
+ // Reset
+#ifdef CUDA_8_0
+ if(p.alpha < 0.0 || p.alpha > 1.0) { // Dynamic partitioning
+ worklist[0].store(0);
+ }
+ for(int i = 0; i < p.n_bins; i++) {
+ h_histo[i].store(0);
+ }
+#else
+ memset(h_histo, 0, p.n_bins * sizeof(unsigned int));
+ cudaStatus = cudaMemcpy(d_histo, h_histo, p.n_bins * sizeof(unsigned int), cudaMemcpyHostToDevice);
+ cudaDeviceSynchronize();
+ CUDA_ERR();
+#endif
+
+ if(rep >= p.n_warmup)
+ timer.start("Kernel");
+
+ p.n_gpu_blocks = p.in_size / p.n_gpu_threads;
+
+ // Launch GPU threads
+ // Kernel launch
+ if(p.n_gpu_blocks > 0) {
+ assert(p.n_gpu_threads <= max_gpu_threads &&
+ "The thread block size is greater than the maximum thread block size that can be used on this device");
+ cudaStatus = call_Histogram_kernel(p.n_gpu_blocks, p.n_gpu_threads, p.in_size, p.n_bins, n_tasks,
+ p.alpha, d_in, (unsigned int*)d_histo, p.n_bins * sizeof(unsigned int)
+#ifdef CUDA_8_0
+ + sizeof(int), (int*)worklist
+#endif
+ );
+ CUDA_ERR();
+ }
+
+ // Launch CPU threads
+ std::thread main_thread(run_cpu_threads, h_histo, h_in, p.in_size, p.n_bins, p.n_threads, p.n_gpu_threads,
+ n_tasks, p.alpha
+#ifdef CUDA_8_0
+ , worklist
+#endif
+ );
+
+ cudaDeviceSynchronize();
+ main_thread.join();
+
+ if(rep >= p.n_warmup)
+ timer.stop("Kernel");
+ }
+ timer.print("Kernel", p.n_reps);
+
+#ifndef CUDA_8_0
+ // Copy back
+ timer.start("Copy Back and Merge");
+ cudaStatus = cudaMemcpy(h_histo_merge, d_histo, p.n_bins * sizeof(unsigned int), cudaMemcpyDeviceToHost);
+ CUDA_ERR();
+ cudaDeviceSynchronize();
+ for(unsigned int i = 0; i < p.n_bins; ++i) {
+ h_histo_merge[i] += (unsigned int)h_histo[i];
+ }
+ timer.stop("Copy Back and Merge");
+ timer.print("Copy Back and Merge", 1);
+#endif
+
+ // Verify answer
+#ifdef CUDA_8_0
+ verify((unsigned int *)h_histo, h_in, p.in_size, p.n_bins);
+#else
+ verify((unsigned int *)h_histo_merge, h_in, p.in_size, p.n_bins);
+#endif
+
+ // Free memory
+ timer.start("Deallocation");
+#ifdef CUDA_8_0
+ cudaStatus = cudaFree(h_in);
+ cudaStatus = cudaFree(h_histo);
+ cudaStatus = cudaFree(worklist);
+#else
+ free(h_in);
+ free(h_histo);
+ free(h_histo_merge);
+ cudaStatus = cudaFree(d_in);
+ cudaStatus = cudaFree(d_histo);
+#endif
+ CUDA_ERR();
+ cudaDeviceSynchronize();
+ timer.stop("Deallocation");
+ timer.print("Deallocation", 1);
+
+ // Release timers
+ timer.release("Allocation");
+ timer.release("Initialization");
+ timer.release("Copy To Device");
+ timer.release("Kernel");
+ timer.release("Copy Back and Merge");
+ timer.release("Deallocation");
+
+ printf("Test Passed\n");
+ return 0;
+}
diff --git a/HST-S/baselines/gpu/support/common.h b/HST-S/baselines/gpu/support/common.h
new file mode 100644
index 0000000..2383eff
--- /dev/null
+++ b/HST-S/baselines/gpu/support/common.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2016 University of Cordoba and University of Illinois
+ * All rights reserved.
+ *
+ * Developed by: IMPACT Research Group
+ * University of Cordoba and University of Illinois
+ * http://impact.crhc.illinois.edu/
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * with the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * > Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimers.
+ * > Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimers in the
+ * documentation and/or other materials provided with the distribution.
+ * > Neither the names of IMPACT Research Group, University of Cordoba,
+ * University of Illinois nor the names of its contributors may be used
+ * to endorse or promote products derived from this Software without
+ * specific prior written permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH
+ * THE SOFTWARE.
+ *
+ */
+
+#ifndef _COMMON_H_
+#define _COMMON_H_
+
+#define ByteSwap16(n) (((((unsigned int)n) << 8) & 0xFF00) | ((((unsigned int)n) >> 8) & 0x00FF))
+
+#define PRINT 0
+
+#define divceil(n, m) (((n)-1) / (m) + 1)
+
+#endif
diff --git a/HST-S/baselines/gpu/support/cuda-setup.h b/HST-S/baselines/gpu/support/cuda-setup.h
new file mode 100644
index 0000000..7b7eefe
--- /dev/null
+++ b/HST-S/baselines/gpu/support/cuda-setup.h
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2016 University of Cordoba and University of Illinois
+ * All rights reserved.
+ *
+ * Developed by: IMPACT Research Group
+ * University of Cordoba and University of Illinois
+ * http://impact.crhc.illinois.edu/
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * with the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * > Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimers.
+ * > Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimers in the
+ * documentation and/or other materials provided with the distribution.
+ * > Neither the names of IMPACT Research Group, University of Cordoba,
+ * University of Illinois nor the names of its contributors may be used
+ * to endorse or promote products derived from this Software without
+ * specific prior written permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH
+ * THE SOFTWARE.
+ *
+ */
+
+#include <cuda.h>
+#include <cuda_runtime.h>
+#include <fstream>
+
+// Allocation error checking
+#define ERR_1(v1) \
+ if(v1 == NULL) { \
+ fprintf(stderr, "Allocation error at %s, %d\n", __FILE__, __LINE__); \
+ exit(-1); \
+ }
+#define ERR_2(v1,v2) ERR_1(v1) ERR_1(v2)
+#define ERR_3(v1,v2,v3) ERR_2(v1,v2) ERR_1(v3)
+#define ERR_4(v1,v2,v3,v4) ERR_3(v1,v2,v3) ERR_1(v4)
+#define ERR_5(v1,v2,v3,v4,v5) ERR_4(v1,v2,v3,v4) ERR_1(v5)
+#define ERR_6(v1,v2,v3,v4,v5,v6) ERR_5(v1,v2,v3,v4,v5) ERR_1(v6)
+#define GET_ERR_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
+#define ALLOC_ERR(...) GET_ERR_MACRO(__VA_ARGS__,ERR_6,ERR_5,ERR_4,ERR_3,ERR_2,ERR_1)(__VA_ARGS__)
+
+#define CUDA_ERR() \
+ if(cudaStatus != cudaSuccess) { \
+ fprintf(stderr, "CUDA error: %s\n at %s, %d\n", cudaGetErrorString(cudaStatus), __FILE__, __LINE__); \
+ exit(-1); \
+ }
+
+struct CUDASetup {
+
+ cudaDeviceProp device_prop;
+
+ CUDASetup(int device) {
+ cudaError_t cudaStatus;
+ cudaStatus = cudaSetDevice(device);
+ CUDA_ERR();
+
+ cudaStatus = cudaGetDeviceProperties(&device_prop, device);
+ CUDA_ERR();
+ fprintf(stderr, "%s\t", device_prop.name);
+
+ }
+
+ int max_gpu_threads() {
+ return device_prop.maxThreadsPerBlock;
+ }
+};
diff --git a/HST-S/baselines/gpu/support/partitioner.h b/HST-S/baselines/gpu/support/partitioner.h
new file mode 100644
index 0000000..61dbe87
--- /dev/null
+++ b/HST-S/baselines/gpu/support/partitioner.h
@@ -0,0 +1,213 @@
+/*
+ * Copyright (c) 2016 University of Cordoba and University of Illinois
+ * All rights reserved.
+ *
+ * Developed by: IMPACT Research Group
+ * University of Cordoba and University of Illinois
+ * http://impact.crhc.illinois.edu/
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * with the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * > Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimers.
+ * > Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimers in the
+ * documentation and/or other materials provided with the distribution.
+ * > Neither the names of IMPACT Research Group, University of Cordoba,
+ * University of Illinois nor the names of its contributors may be used
+ * to endorse or promote products derived from this Software without
+ * specific prior written permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH
+ * THE SOFTWARE.
+ *
+ */
+
+#ifndef _PARTITIONER_H_
+#define _PARTITIONER_H_
+
+#ifndef _CUDA_COMPILER_
+#include <iostream>
+#endif
+
+#if !defined(_CUDA_COMPILER_) && defined(CUDA_8_0)
+#include <atomic>
+#endif
+
+// Partitioner definition -----------------------------------------------------
+
+typedef struct Partitioner {
+
+ int n_tasks;
+ int cut;
+ int current;
+#ifndef _CUDA_COMPILER_
+ int thread_id;
+ int n_threads;
+#endif
+
+
+#ifdef CUDA_8_0
+ // CUDA 8.0 support for dynamic partitioning
+ int strategy;
+#ifdef _CUDA_COMPILER_
+ int *worklist;
+ int *tmp;
+#else
+ std::atomic_int *worklist;
+#endif
+#endif
+
+} Partitioner;
+
+// Partitioning strategies
+#define STATIC_PARTITIONING 0
+#define DYNAMIC_PARTITIONING 1
+
+// Create a partitioner -------------------------------------------------------
+
+#ifdef _CUDA_COMPILER_
+__device__
+#endif
+inline Partitioner partitioner_create(int n_tasks, float alpha
+#ifndef _CUDA_COMPILER_
+ , int thread_id, int n_threads
+#endif
+#ifdef CUDA_8_0
+#ifdef _CUDA_COMPILER_
+ , int *worklist
+ , int *tmp
+#else
+ , std::atomic_int *worklist
+#endif
+#endif
+ ) {
+ Partitioner p;
+ p.n_tasks = n_tasks;
+#ifndef _CUDA_COMPILER_
+ p.thread_id = thread_id;
+ p.n_threads = n_threads;
+#endif
+ if(alpha >= 0.0 && alpha <= 1.0) {
+ p.cut = p.n_tasks * alpha;
+#ifdef CUDA_8_0
+ p.strategy = STATIC_PARTITIONING;
+#endif
+ } else {
+#ifdef CUDA_8_0
+ p.strategy = DYNAMIC_PARTITIONING;
+ p.worklist = worklist;
+#ifdef _CUDA_COMPILER_
+ p.tmp = tmp;
+#endif
+#endif
+ }
+ return p;
+}
+
+// Partitioner iterators: first() ---------------------------------------------
+
+#ifndef _CUDA_COMPILER_
+
+inline int cpu_first(Partitioner *p) {
+#ifdef CUDA_8_0
+ if(p->strategy == DYNAMIC_PARTITIONING) {
+ p->current = p->worklist->fetch_add(1);
+ } else
+#endif
+ {
+ p->current = p->thread_id;
+ }
+ return p->current;
+}
+
+#else
+
+__device__ inline int gpu_first(Partitioner *p) {
+#ifdef CUDA_8_0
+ if(p->strategy == DYNAMIC_PARTITIONING) {
+ if(threadIdx.y == 0 && threadIdx.x == 0) {
+ p->tmp[0] = atomicAdd_system(p->worklist, 1);
+ }
+ __syncthreads();
+ p->current = p->tmp[0];
+ } else
+#endif
+ {
+ p->current = p->cut + blockIdx.x;
+ }
+ return p->current;
+}
+
+#endif
+
+// Partitioner iterators: more() ----------------------------------------------
+
+#ifndef _CUDA_COMPILER_
+
+inline bool cpu_more(const Partitioner *p) {
+#ifdef CUDA_8_0
+ if(p->strategy == DYNAMIC_PARTITIONING) {
+ return (p->current < p->n_tasks);
+ } else
+#endif
+ {
+ return (p->current < p->cut);
+ }
+}
+
+#else
+
+__device__ inline bool gpu_more(const Partitioner *p) {
+ return (p->current < p->n_tasks);
+}
+
+#endif
+
+// Partitioner iterators: next() ----------------------------------------------
+
+#ifndef _CUDA_COMPILER_
+
+inline int cpu_next(Partitioner *p) {
+#ifdef CUDA_8_0
+ if(p->strategy == DYNAMIC_PARTITIONING) {
+ p->current = p->worklist->fetch_add(1);
+ } else
+#endif
+ {
+ p->current = p->current + p->n_threads;
+ }
+ return p->current;
+}
+
+#else
+
+__device__ inline int gpu_next(Partitioner *p) {
+#ifdef CUDA_8_0
+ if(p->strategy == DYNAMIC_PARTITIONING) {
+ if(threadIdx.y == 0 && threadIdx.x == 0) {
+ p->tmp[0] = atomicAdd_system(p->worklist, 1);
+ }
+ __syncthreads();
+ p->current = p->tmp[0];
+ } else
+#endif
+ {
+ p->current = p->current + gridDim.x;
+ }
+ return p->current;
+}
+
+#endif
+
+#endif
diff --git a/HST-S/baselines/gpu/support/timer.h b/HST-S/baselines/gpu/support/timer.h
new file mode 100644
index 0000000..fceab04
--- /dev/null
+++ b/HST-S/baselines/gpu/support/timer.h
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2016 University of Cordoba and University of Illinois
+ * All rights reserved.
+ *
+ * Developed by: IMPACT Research Group
+ * University of Cordoba and University of Illinois
+ * http://impact.crhc.illinois.edu/
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * with the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * > Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimers.
+ * > Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimers in the
+ * documentation and/or other materials provided with the distribution.
+ * > Neither the names of IMPACT Research Group, University of Cordoba,
+ * University of Illinois nor the names of its contributors may be used
+ * to endorse or promote products derived from this Software without
+ * specific prior written permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH
+ * THE SOFTWARE.
+ *
+ */
+
+#include <cuda_runtime.h>
+#include <sys/time.h>
+#include <iostream>
+#include <map>
+#include <string>
+
+using namespace std;
+
+struct Timer {
+
+ map<string, cudaEvent_t> startTime;
+ map<string, cudaEvent_t> stopTime;
+ map<string, float> time;
+
+ void start(string name) {
+ if(!time.count(name)) {
+ cudaEventCreate(&startTime[name]);
+ cudaEventCreate(&stopTime[name]);
+ time[name] = 0.0;
+ }
+ cudaEventRecord(startTime[name], 0);
+ }
+
+ void stop(string name) {
+ cudaEventRecord(stopTime[name],0);
+ cudaEventSynchronize(stopTime[name]);
+ float part_time = 0.0;
+ cudaEventElapsedTime(&part_time, startTime[name], stopTime[name]);
+ time[name] += part_time;
+ }
+
+ void print(string name, unsigned int REP) { printf("%s Time (ms): %f\n", name.c_str(), time[name] / REP); }
+
+ void release(string name){
+ cudaEventDestroy(startTime[name]);
+ cudaEventDestroy(stopTime[name]);
+ }
+};
diff --git a/HST-S/baselines/gpu/support/verify.h b/HST-S/baselines/gpu/support/verify.h
new file mode 100644
index 0000000..9cb9e53
--- /dev/null
+++ b/HST-S/baselines/gpu/support/verify.h
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2016 University of Cordoba and University of Illinois
+ * All rights reserved.
+ *
+ * Developed by: IMPACT Research Group
+ * University of Cordoba and University of Illinois
+ * http://impact.crhc.illinois.edu/
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * with the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * > Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimers.
+ * > Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimers in the
+ * documentation and/or other materials provided with the distribution.
+ * > Neither the names of IMPACT Research Group, University of Cordoba,
+ * University of Illinois nor the names of its contributors may be used
+ * to endorse or promote products derived from this Software without
+ * specific prior written permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH
+ * THE SOFTWARE.
+ *
+ */
+
+#include "common.h"
+#include <math.h>
+#include <string.h>
+
+inline int compare_output(unsigned int *outp, unsigned int *outpCPU, int bins) {
+ for(int i = 0; i < bins; i++) {
+ if(outp[i] != outpCPU[i]) {
+ printf("Test failed\n");
+ exit(EXIT_FAILURE);
+ }
+ }
+ return 0;
+}
+
+// Sequential implementation for comparison purposes
+inline void HistogramCPU(unsigned int *histo, unsigned int *data, int size, int bins) {
+ for(int i = 0; i < size; i++) {
+ // Read pixel
+ unsigned int d = ((data[i] * bins) >> 12);
+ // Vote in histogram
+ histo[d]++;
+ }
+}
+
+inline void verify(unsigned int *histo, unsigned int *input, int size, int bins) {
+ unsigned int *gold = (unsigned int *)malloc(bins * sizeof(unsigned int));
+ memset(gold, 0, bins * sizeof(unsigned int));
+ HistogramCPU(gold, input, size, bins);
+ compare_output(histo, gold, bins);
+ free(gold);
+}