Index: test-suite/trunk/MicroBenchmarks/ImageProcessing/CMakeLists.txt =================================================================== --- test-suite/trunk/MicroBenchmarks/ImageProcessing/CMakeLists.txt +++ test-suite/trunk/MicroBenchmarks/ImageProcessing/CMakeLists.txt @@ -2,3 +2,4 @@ add_subdirectory(AnisotropicDiffusion) add_subdirectory(Interpolation) add_subdirectory(Blur) +add_subdirectory(Dilate) Index: test-suite/trunk/MicroBenchmarks/ImageProcessing/Dilate/CMakeLists.txt =================================================================== --- test-suite/trunk/MicroBenchmarks/ImageProcessing/Dilate/CMakeLists.txt +++ test-suite/trunk/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) Index: test-suite/trunk/MicroBenchmarks/ImageProcessing/Dilate/dilate.h =================================================================== --- test-suite/trunk/MicroBenchmarks/ImageProcessing/Dilate/dilate.h +++ test-suite/trunk/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_ */ Index: test-suite/trunk/MicroBenchmarks/ImageProcessing/Dilate/dilate.reference_output =================================================================== --- test-suite/trunk/MicroBenchmarks/ImageProcessing/Dilate/dilate.reference_output +++ test-suite/trunk/MicroBenchmarks/ImageProcessing/Dilate/dilate.reference_output @@ -0,0 +1 @@ +5f1e986b006f95a80a1bbf0d316fc41c Index: test-suite/trunk/MicroBenchmarks/ImageProcessing/Dilate/dilateKernel.c =================================================================== --- test-suite/trunk/MicroBenchmarks/ImageProcessing/Dilate/dilateKernel.c +++ test-suite/trunk/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; + } + } +} Index: test-suite/trunk/MicroBenchmarks/ImageProcessing/Dilate/main.cpp =================================================================== --- test-suite/trunk/MicroBenchmarks/ImageProcessing/Dilate/main.cpp +++ test-suite/trunk/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 + +#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