Index: MicroBenchmarks/ImageProcessing/CMakeLists.txt =================================================================== --- MicroBenchmarks/ImageProcessing/CMakeLists.txt +++ MicroBenchmarks/ImageProcessing/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(Dilate) Index: MicroBenchmarks/ImageProcessing/Dilate/CMakeLists.txt =================================================================== --- MicroBenchmarks/ImageProcessing/Dilate/CMakeLists.txt +++ 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.cpp main.cpp dilateKernel.cpp) + +target_link_libraries(Dilate benchmark) Index: MicroBenchmarks/ImageProcessing/Dilate/dilate.h =================================================================== --- MicroBenchmarks/ImageProcessing/Dilate/dilate.h +++ MicroBenchmarks/ImageProcessing/Dilate/dilate.h @@ -0,0 +1,15 @@ +/** +Pankaj Kukreja +github.com/proton0001 +Indian Institute of Technology Hyderabad +*/ + +#ifndef _DILATE_H_ +#define _DILATE_H_ + +#define HEIGHT 1024 +#define WIDTH 1024 + +void dilateKernel(int *src, int *dst, int height, int width, int *temporary); + +#endif /* _DILATE_H_ */ Index: MicroBenchmarks/ImageProcessing/Dilate/dilate.reference_output =================================================================== --- MicroBenchmarks/ImageProcessing/Dilate/dilate.reference_output +++ MicroBenchmarks/ImageProcessing/Dilate/dilate.reference_output @@ -0,0 +1 @@ +5f1e986b006f95a80a1bbf0d316fc41c Index: MicroBenchmarks/ImageProcessing/Dilate/dilateKernel.cpp =================================================================== --- MicroBenchmarks/ImageProcessing/Dilate/dilateKernel.cpp +++ MicroBenchmarks/ImageProcessing/Dilate/dilateKernel.cpp @@ -0,0 +1,52 @@ +/** + Source: + https://github.com/mompes/CUDA-dilation-and-erosion-filters/blob/master/erosionCPU.cpp + + Pankaj Kukreja + github.com/proton0001 + Indian Institute of Technology Hyderabad +*/ +#include "dilate.h" +#define MAX(a, b) (a > b) ? a : b; +#define MIN(a, b) (a < b) ? a : b; +#include // malloc, free + +// inpImage[HEIGHT * WIDTH] +// outImage[height * width] +void dilateKernel(int *inpImage, int *outImage, int height, int width, int *temporary) { + + typedef int inputMatrix[HEIGHT][WIDTH]; + inputMatrix *inputImage; + inputImage = (inputMatrix *)inpImage; + + typedef int outputMatrix[height][width]; + outputMatrix *outputImage; + outputImage = (outputMatrix *)outImage; + + outputMatrix *temp; + temp = (outputMatrix *)temporary; + + 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)0 && (i+k) + +#define BENCHMARK_LIB +#ifdef BENCHMARK_LIB +#include "benchmark/benchmark.h" +#endif + +int *inputImage; + +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; + outputImage = (int *)malloc(sizeof(int) * (HEIGHT) * (WIDTH)); + int *temp; + temp = (int *)malloc(sizeof(int) * (HEIGHT) * (WIDTH)); + + if (outputImage == NULL || temp == NULL) { + std::cerr << "Insufficient memory\n"; + exit(EXIT_FAILURE); + } + + dilateKernel(inputImage, outputImage, HEIGHT, WIDTH, 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) { + + int height = state.range(0); + int width = state.range(1); + int *outputImage; + outputImage = (int *)malloc(sizeof(int) * (height) * (width)); + int *temp; + temp = (int *)malloc(sizeof(int) * (HEIGHT) * (WIDTH)); + if (outputImage == NULL) { + std::cerr << "Insufficient memory\n"; + exit(EXIT_FAILURE); + } + + dilateKernel(inputImage, outputImage, height, width, temp); + + for (auto _ : state) { + dilateKernel(inputImage, outputImage, height, width, temp); + } + + if (state.range(0) == 20) { + saveImage(outputImage, (const char *)"testFailed.txt", height, width); + } + free(temp); + free(outputImage); +} +BENCHMARK(BENCHMARK_DILATE) + ->Args({128, 128}) + ->Args({256, 256}) + ->Args({512, 512}) + ->Args({1024, 1024}) + ->Unit(benchmark::kMicrosecond); +#endif