aboutsummaryrefslogtreecommitdiff
path: root/MicroBenchmarks
diff options
context:
space:
mode:
authorPankaj Kukreja <cs15btech11029@iith.ac.in>2018-08-13 13:45:04 +0000
committerPankaj Kukreja <cs15btech11029@iith.ac.in>2018-08-13 13:45:04 +0000
commitc2298f7635f6cc7e4ea52b00ac7842cccc0f9102 (patch)
tree15521aede3cf113d700c3254a3f4dba9dbb41cb9 /MicroBenchmarks
parentbce559ba0563a866918cf9e419f133f98198026c (diff)
Add Image dilate kernel(for grayscale Images) using Benchmark Library
Reviewers: Meinersbur Differential Revision: https://reviews.llvm.org/D49883 git-svn-id: https://llvm.org/svn/llvm-project/test-suite/trunk@339564 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'MicroBenchmarks')
-rw-r--r--MicroBenchmarks/ImageProcessing/CMakeLists.txt1
-rw-r--r--MicroBenchmarks/ImageProcessing/Dilate/CMakeLists.txt11
-rw-r--r--MicroBenchmarks/ImageProcessing/Dilate/dilate.h12
-rw-r--r--MicroBenchmarks/ImageProcessing/Dilate/dilate.reference_output1
-rw-r--r--MicroBenchmarks/ImageProcessing/Dilate/dilateKernel.c35
-rw-r--r--MicroBenchmarks/ImageProcessing/Dilate/main.cpp107
6 files changed, 167 insertions, 0 deletions
diff --git a/MicroBenchmarks/ImageProcessing/CMakeLists.txt b/MicroBenchmarks/ImageProcessing/CMakeLists.txt
index f148ebc4..87085a1c 100644
--- a/MicroBenchmarks/ImageProcessing/CMakeLists.txt
+++ b/MicroBenchmarks/ImageProcessing/CMakeLists.txt
@@ -2,3 +2,4 @@ add_subdirectory(Dither)
add_subdirectory(AnisotropicDiffusion)
add_subdirectory(Interpolation)
add_subdirectory(Blur)
+add_subdirectory(Dilate)
diff --git a/MicroBenchmarks/ImageProcessing/Dilate/CMakeLists.txt b/MicroBenchmarks/ImageProcessing/Dilate/CMakeLists.txt
new file mode 100644
index 00000000..8b657d9c
--- /dev/null
+++ b/MicroBenchmarks/ImageProcessing/Dilate/CMakeLists.txt
@@ -0,0 +1,11 @@
+set(IMAGEPROC_UTILS MicroBenchmarks/ImageProcessing/utils)
+list(APPEND CPPFLAGS -I ${CMAKE_SOURCE_DIR}/${IMAGEPROC_UTILS} -std=c++11)
+
+llvm_test_verify("${CMAKE_SOURCE_DIR}/HashProgramOutput.sh ${CMAKE_CURRENT_BINARY_DIR}/dilateOutput.txt")
+llvm_test_verify("${FPCMP} ${CMAKE_CURRENT_BINARY_DIR}/dilateOutput.txt ${CMAKE_CURRENT_SOURCE_DIR}/dilate.reference_output")
+
+llvm_test_run(WORKDIR ${CMAKE_CURRENT_BINARY_DIR})
+
+llvm_test_executable(Dilate ../utils/ImageHelper.cpp ../utils/glibc_compat_rand.c main.cpp dilateKernel.c)
+
+target_link_libraries(Dilate benchmark)
diff --git a/MicroBenchmarks/ImageProcessing/Dilate/dilate.h b/MicroBenchmarks/ImageProcessing/Dilate/dilate.h
new file mode 100644
index 00000000..2924de72
--- /dev/null
+++ b/MicroBenchmarks/ImageProcessing/Dilate/dilate.h
@@ -0,0 +1,12 @@
+/**
+Pankaj Kukreja
+github.com/proton0001
+Indian Institute of Technology Hyderabad
+*/
+#ifndef _DILATE_H_
+#define _DILATE_H_
+
+#define HEIGHT 1024
+#define WIDTH 1024
+
+#endif /* _DILATE_H_ */
diff --git a/MicroBenchmarks/ImageProcessing/Dilate/dilate.reference_output b/MicroBenchmarks/ImageProcessing/Dilate/dilate.reference_output
new file mode 100644
index 00000000..0df74a3d
--- /dev/null
+++ b/MicroBenchmarks/ImageProcessing/Dilate/dilate.reference_output
@@ -0,0 +1 @@
+5f1e986b006f95a80a1bbf0d316fc41c
diff --git a/MicroBenchmarks/ImageProcessing/Dilate/dilateKernel.c b/MicroBenchmarks/ImageProcessing/Dilate/dilateKernel.c
new file mode 100644
index 00000000..058b17c6
--- /dev/null
+++ b/MicroBenchmarks/ImageProcessing/Dilate/dilateKernel.c
@@ -0,0 +1,35 @@
+/**
+ Source:
+ https://github.com/mompes/CUDA-dilation-and-erosion-filters/blob/master/erosionCPU.cpp
+ Modified by Pankaj Kukreja (github.com/proton0001)
+ Indian Institute of Technology Hyderabad
+*/
+#include "dilate.h"
+#define MAX(a, b) (a > b) ? a : b;
+
+void dilateKernel(int height, int width, int inputImage[HEIGHT][WIDTH],
+ int outputImage[height][width], int temp[height][width]) {
+ for (int i = 0; i < height; i++) {
+ for (int j = 0; j < width; j++) {
+ int value = 0;
+ for (int k = -1; k <= 1; k++) {
+ if ((j + k) > 0 && (j + k) < width) {
+ value = MAX(inputImage[i][j + k], value);
+ }
+ }
+ temp[i][j] = value;
+ }
+ }
+
+ for (int i = 0; i < height; i++) {
+ for (int j = 0; j < width; j++) {
+ int value = 0;
+ for (int k = -1; k <= 1; k++) {
+ if ((i + k) > 0 && (i + k) < height) {
+ value = MAX(temp[i + k][j], value);
+ }
+ }
+ outputImage[i][j] = value;
+ }
+ }
+}
diff --git a/MicroBenchmarks/ImageProcessing/Dilate/main.cpp b/MicroBenchmarks/ImageProcessing/Dilate/main.cpp
new file mode 100644
index 00000000..33416fe1
--- /dev/null
+++ b/MicroBenchmarks/ImageProcessing/Dilate/main.cpp
@@ -0,0 +1,107 @@
+/**
+ Pankaj Kukreja
+ github.com/proton0001
+ Indian Institute of Technology Hyderabad
+*/
+#include "ImageHelper.h"
+#include "dilate.h"
+#include <iostream>
+
+#define BENCHMARK_LIB
+#ifdef BENCHMARK_LIB
+#include "benchmark/benchmark.h"
+#endif
+
+int *inputImage;
+extern "C" void dilateKernel(int height, int width, int *inputImage,
+ int *outputImage, int *temporary);
+
+int main(int argc, char *argv[]) {
+#ifdef BENCHMARK_LIB
+ ::benchmark::Initialize(&argc, argv);
+#endif
+
+ const char *dilateOutputFileName = (const char *)"./dilateOutput.txt";
+
+ inputImage = (int *)malloc(sizeof(int) * HEIGHT * WIDTH);
+
+ if (inputImage == NULL) {
+ std::cerr << "Insufficient memory\n";
+ exit(EXIT_FAILURE);
+ }
+
+ initializeRandomImage(inputImage, HEIGHT, WIDTH);
+
+#ifdef BENCHMARK_LIB
+ ::benchmark::RunSpecifiedBenchmarks();
+#endif
+ int *outputImage = (int *)malloc(sizeof(int) * HEIGHT * WIDTH);
+ int *temp = (int *)malloc(sizeof(int) * HEIGHT * WIDTH);
+
+ if (outputImage == NULL || temp == NULL) {
+ std::cerr << "Insufficient memory\n";
+ exit(EXIT_FAILURE);
+ }
+
+ dilateKernel(HEIGHT, WIDTH, inputImage, outputImage, temp);
+
+ for (int j = 0; j < WIDTH; j++) {
+ outputImage[0 * WIDTH + j] = 0;
+ outputImage[(HEIGHT - 1) * WIDTH + j] = 0;
+ }
+
+ for (int i = 0; i < HEIGHT; i++) {
+ outputImage[i * WIDTH + 0] = 0;
+ outputImage[i * WIDTH + (WIDTH - 1)] = 0;
+ }
+
+ saveImage(outputImage, dilateOutputFileName, HEIGHT, WIDTH);
+ free(temp);
+ free(outputImage);
+ free(inputImage);
+ return (EXIT_SUCCESS);
+}
+
+#ifdef BENCHMARK_LIB
+void BENCHMARK_DILATE(benchmark::State &state) {
+ /* taking height = width */
+ int height = state.range(0);
+ int width = state.range(0);
+
+ int *outputImage = (int *)malloc(sizeof(int) * height * width);
+ int *temp = (int *)malloc(sizeof(int) * height * width);
+ if (outputImage == NULL) {
+ std::cerr << "Insufficient memory\n";
+ exit(EXIT_FAILURE);
+ }
+
+ /* This call is to warm up the cache */
+ dilateKernel(height, width, inputImage, outputImage, temp);
+
+ for (auto _ : state) {
+ dilateKernel(height, width, inputImage, outputImage, temp);
+ }
+
+ /* Since we are not passing state.range as 20 this if case will always be
+ * false. This call is to make compiler think that outputImage may be used
+ * later so that above kernel calls will not optimize out */
+ if (state.range(0) == 20) {
+ saveImage(outputImage, (const char *)"testFailed.txt", height, width);
+ }
+ free(temp);
+ free(outputImage);
+}
+
+#define MINIMUM_DIM (HEIGHT > WIDTH) ? WIDTH : HEIGHT
+#if MINIMUM_DIM > 512
+BENCHMARK(BENCHMARK_DILATE)
+ ->RangeMultiplier(2)
+ ->Range(128, MINIMUM_DIM)
+ ->Unit(benchmark::kMicrosecond);
+#else
+BENCHMARK(BENCHMARK_DILATE)
+ ->RangeMultiplier(2)
+ ->Range(1, MINIMUM_DIM)
+ ->Unit(benchmark::kMicrosecond);
+#endif
+#endif