Index: MicroBenchmarks/CMakeLists.txt =================================================================== --- MicroBenchmarks/CMakeLists.txt +++ MicroBenchmarks/CMakeLists.txt @@ -4,4 +4,5 @@ add_subdirectory(libs) add_subdirectory(XRay) add_subdirectory(LCALS) + add_subdirectory(harris) endif() Index: MicroBenchmarks/harris/CMakeLists.txt =================================================================== --- MicroBenchmarks/harris/CMakeLists.txt +++ MicroBenchmarks/harris/CMakeLists.txt @@ -0,0 +1,8 @@ +list(APPEND CPPFLAGS -std=c++11 ) +llvm_test_run() + +llvm_test_executable(harris harris_kernel.cpp init.cpp main.cpp) +target_link_libraries(harris benchmark) + +set(REFERENCE_OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/harris.reference.output) +llvm_test_verify("${FPCMP} ${CMAKE_CURRENT_BINARY_DIR}/output.txt ${REFERENCE_OUTPUT}") Index: MicroBenchmarks/harris/harris.h =================================================================== --- MicroBenchmarks/harris/harris.h +++ MicroBenchmarks/harris/harris.h @@ -0,0 +1,38 @@ +#include +#include +#include +#include +#include +#include + +// ============================================================================ +// ============================================================================ + +// Image Size +// #define HEIGHT 100 +// #define WIDTH 100 +// (Any box size will work) +// This parameter is used in input // used only in init_checkboard_image +#define BOX_SIZE 10 + +#define HEIGHT 100 +#define WIDTH 100 + + + +// ============================================================================ +// ============================================================================ + +// Some Parameters +#define THRESHOLD 0.1 /*For harris kernel*/ + +// ============================================================================ +// ============================================================================ + +void init_checkboard_image(int height, int width); // Initialize a checkboard image +void DUMP_IMAGE(int height, int width, float img[(2+HEIGHT)][2+WIDTH]); +void harris_kernel(int R, int C, float threshold, float img[(2+HEIGHT)][2+WIDTH]); + +// ============================================================================ + +extern float image[HEIGHT+2][WIDTH+2]; Index: MicroBenchmarks/harris/harris.reference.output =================================================================== --- MicroBenchmarks/harris/harris.reference.output +++ MicroBenchmarks/harris/harris.reference.output @@ -0,0 +1,100 @@ +7777777777000000000077777777770000000000777777777700000000007777777777000000000077777777770000000000 +7777777777000000000077777777770000000000777777777700000000007777777777000000000077777777770000000000 +7777777777000000000077777777770000000000777777777700000000007777777777000000000077777777770000000000 +7777777777000000000077777777770000000000777777777700000000007777777777000000000077777777770000000000 +7777777777000000000077777777770000000000777777777700000000007777777777000000000077777777770000000000 +7777777777000000000077777777770000000000777777777700000000007777777777000000000077777777770000000000 +7777777777000000000077777777770000000000777777777700000000007777777777000000000077777777770000000000 +7777777777000000000077777777770000000000777777777700000000007777777777000000000077777777770000000000 +7777777733330000003333777777333300000033337777773333000000333377777733330000003333777777333300000033 +7777777733330000003333777777333300000033337777773333000000333377777733330000003333777777333300000033 +0000000033337777773333000000333377777733330000003333777777333300000033337777773333000000333377777733 +0000000033337777773333000000333377777733330000003333777777333300000033337777773333000000333377777733 +0000000000777777777700000000007777777777000000000077777777770000000000777777777700000000007777777777 +0000000000777777777700000000007777777777000000000077777777770000000000777777777700000000007777777777 +0000000000777777777700000000007777777777000000000077777777770000000000777777777700000000007777777777 +0000000000777777777700000000007777777777000000000077777777770000000000777777777700000000007777777777 +0000000000777777777700000000007777777777000000000077777777770000000000777777777700000000007777777777 +0000000000777777777700000000007777777777000000000077777777770000000000777777777700000000007777777777 +0000000033337777773333000000333377777733330000003333777777333300000033337777773333000000333377777733 +0000000033337777773333000000333377777733330000003333777777333300000033337777773333000000333377777733 +7777777733330000003333777777333300000033337777773333000000333377777733330000003333777777333300000033 +7777777733330000003333777777333300000033337777773333000000333377777733330000003333777777333300000033 +7777777777000000000077777777770000000000777777777700000000007777777777000000000077777777770000000000 +7777777777000000000077777777770000000000777777777700000000007777777777000000000077777777770000000000 +7777777777000000000077777777770000000000777777777700000000007777777777000000000077777777770000000000 +7777777777000000000077777777770000000000777777777700000000007777777777000000000077777777770000000000 +7777777777000000000077777777770000000000777777777700000000007777777777000000000077777777770000000000 +7777777777000000000077777777770000000000777777777700000000007777777777000000000077777777770000000000 +7777777733330000003333777777333300000033337777773333000000333377777733330000003333777777333300000033 +7777777733330000003333777777333300000033337777773333000000333377777733330000003333777777333300000033 +0000000033337777773333000000333377777733330000003333777777333300000033337777773333000000333377777733 +0000000033337777773333000000333377777733330000003333777777333300000033337777773333000000333377777733 +0000000000777777777700000000007777777777000000000077777777770000000000777777777700000000007777777777 +0000000000777777777700000000007777777777000000000077777777770000000000777777777700000000007777777777 +0000000000777777777700000000007777777777000000000077777777770000000000777777777700000000007777777777 +0000000000777777777700000000007777777777000000000077777777770000000000777777777700000000007777777777 +0000000000777777777700000000007777777777000000000077777777770000000000777777777700000000007777777777 +0000000000777777777700000000007777777777000000000077777777770000000000777777777700000000007777777777 +0000000033337777773333000000333377777733330000003333777777333300000033337777773333000000333377777733 +0000000033337777773333000000333377777733330000003333777777333300000033337777773333000000333377777733 +7777777733330000003333777777333300000033337777773333000000333377777733330000003333777777333300000033 +7777777733330000003333777777333300000033337777773333000000333377777733330000003333777777333300000033 +7777777777000000000077777777770000000000777777777700000000007777777777000000000077777777770000000000 +7777777777000000000077777777770000000000777777777700000000007777777777000000000077777777770000000000 +7777777777000000000077777777770000000000777777777700000000007777777777000000000077777777770000000000 +7777777777000000000077777777770000000000777777777700000000007777777777000000000077777777770000000000 +7777777777000000000077777777770000000000777777777700000000007777777777000000000077777777770000000000 +7777777777000000000077777777770000000000777777777700000000007777777777000000000077777777770000000000 +7777777733330000003333777777333300000033337777773333000000333377777733330000003333777777333300000033 +7777777733330000003333777777333300000033337777773333000000333377777733330000003333777777333300000033 +0000000033337777773333000000333377777733330000003333777777333300000033337777773333000000333377777733 +0000000033337777773333000000333377777733330000003333777777333300000033337777773333000000333377777733 +0000000000777777777700000000007777777777000000000077777777770000000000777777777700000000007777777777 +0000000000777777777700000000007777777777000000000077777777770000000000777777777700000000007777777777 +0000000000777777777700000000007777777777000000000077777777770000000000777777777700000000007777777777 +0000000000777777777700000000007777777777000000000077777777770000000000777777777700000000007777777777 +0000000000777777777700000000007777777777000000000077777777770000000000777777777700000000007777777777 +0000000000777777777700000000007777777777000000000077777777770000000000777777777700000000007777777777 +0000000033337777773333000000333377777733330000003333777777333300000033337777773333000000333377777733 +0000000033337777773333000000333377777733330000003333777777333300000033337777773333000000333377777733 +7777777733330000003333777777333300000033337777773333000000333377777733330000003333777777333300000033 +7777777733330000003333777777333300000033337777773333000000333377777733330000003333777777333300000033 +7777777777000000000077777777770000000000777777777700000000007777777777000000000077777777770000000000 +7777777777000000000077777777770000000000777777777700000000007777777777000000000077777777770000000000 +7777777777000000000077777777770000000000777777777700000000007777777777000000000077777777770000000000 +7777777777000000000077777777770000000000777777777700000000007777777777000000000077777777770000000000 +7777777777000000000077777777770000000000777777777700000000007777777777000000000077777777770000000000 +7777777777000000000077777777770000000000777777777700000000007777777777000000000077777777770000000000 +7777777733330000003333777777333300000033337777773333000000333377777733330000003333777777333300000033 +7777777733330000003333777777333300000033337777773333000000333377777733330000003333777777333300000033 +0000000033337777773333000000333377777733330000003333777777333300000033337777773333000000333377777733 +0000000033337777773333000000333377777733330000003333777777333300000033337777773333000000333377777733 +0000000000777777777700000000007777777777000000000077777777770000000000777777777700000000007777777777 +0000000000777777777700000000007777777777000000000077777777770000000000777777777700000000007777777777 +0000000000777777777700000000007777777777000000000077777777770000000000777777777700000000007777777777 +0000000000777777777700000000007777777777000000000077777777770000000000777777777700000000007777777777 +0000000000777777777700000000007777777777000000000077777777770000000000777777777700000000007777777777 +0000000000777777777700000000007777777777000000000077777777770000000000777777777700000000007777777777 +0000000033337777773333000000333377777733330000003333777777333300000033337777773333000000333377777733 +0000000033337777773333000000333377777733330000003333777777333300000033337777773333000000333377777733 +7777777733330000003333777777333300000033337777773333000000333377777733330000003333777777333300000033 +7777777733330000003333777777333300000033337777773333000000333377777733330000003333777777333300000033 +7777777777000000000077777777770000000000777777777700000000007777777777000000000077777777770000000000 +7777777777000000000077777777770000000000777777777700000000007777777777000000000077777777770000000000 +7777777777000000000077777777770000000000777777777700000000007777777777000000000077777777770000000000 +7777777777000000000077777777770000000000777777777700000000007777777777000000000077777777770000000000 +7777777777000000000077777777770000000000777777777700000000007777777777000000000077777777770000000000 +7777777777000000000077777777770000000000777777777700000000007777777777000000000077777777770000000000 +7777777733330000003333777777333300000033337777773333000000333377777733330000003333777777333300000033 +7777777733330000003333777777333300000033337777773333000000333377777733330000003333777777333300000033 +0000000033337777773333000000333377777733330000003333777777333300000033337777773333000000333377777733 +0000000033337777773333000000333377777733330000003333777777333300000033337777773333000000333377777733 +0000000000777777777700000000007777777777000000000077777777770000000000777777777700000000007777777777 +0000000000777777777700000000007777777777000000000077777777770000000000777777777700000000007777777777 +0000000000777777777700000000007777777777000000000077777777770000000000777777777700000000007777777777 +0000000000777777777700000000007777777777000000000077777777770000000000777777777700000000007777777777 +0000000000777777777700000000007777777777000000000077777777770000000000777777777700000000007777777777 +0000000000777777777700000000007777777777000000000077777777770000000000777777777700000000007777777777 +0000000033337777773333000000333377777733330000003333777777333300000033337777773333000000333377777733 +0000000033337777773333000000333377777733330000003333777777333300000033337777773333000000333377777733 Index: MicroBenchmarks/harris/harris_kernel.cpp =================================================================== --- MicroBenchmarks/harris/harris_kernel.cpp +++ MicroBenchmarks/harris/harris_kernel.cpp @@ -0,0 +1,119 @@ +#include "harris.h" + + +// harris kernel from polymage_naive.cpp +void harris_kernel(int R, int C, float threshold, float img[(2+HEIGHT)][2+WIDTH]) +{ + float Ix [2+R][2+C]; + float Iy [2+R][2+C]; + float Ixx [2+R][2+C]; + float Ixy [2+R][2+C]; + float Iyy [2+R][2+C]; + float Sxx [2+R][2+C]; + float Sxy [2+R][2+C]; + float Syy [2+R][2+C]; + float det [2+R][2+C]; + float trace[2+R][2+C]; + + for (int _i0 = 1; (_i0-R-1 < 0); _i0++ ) { + for (int _i1 = 1; (_i1-C-1 <= 0); _i1++) { + Iy[_i0][_i1] = ((((((img[_i0 - 1][_i1 - 1] * -0.0833333333333f) + + (img[_i0 - 1][_i1 + 1] * 0.0833333333333f)) + + (img[ _i0][_i1 - 1] * -0.166666666667f )) + + (img[ _i0][_i1 + 1] * 0.166666666667f )) + + (img[_i0 + 1][_i1 - 1] * -0.0833333333333f)) + + (img[_i0 + 1][_i1 + 1] * 0.0833333333333f)); + } + } + + for (int _i0 = 1; (_i0-R-1 < 0); _i0++ ) { + for (int _i1 = 1; (_i1-C-1 <= 0); _i1++) { + Ix[_i0][_i1] = ((((((img[-1 + _i0] [-1 + _i1] * -0.0833333333333f) + + (img[ 1 + _i0] [-1 + _i1] * 0.0833333333333f)) + + (img[-1 + _i0] [ _i1] * -0.166666666667f )) + + (img[ 1 + _i0] [ _i1] * 0.166666666667f )) + + (img[-1 + _i0] [ 1 + _i1] * -0.0833333333333f)) + + (img[ 1 + _i0] [ 1 + _i1] * 0.0833333333333f)); + } + } + + for (int _i0 = 1; (_i0-R-1 < 0); _i0++ ) { + for (int _i1 = 1; (_i1-C-1 <= 0); _i1++) { + Iyy[_i0][_i1] = Iy[_i0][_i1] * Iy[_i0] [_i1]; + } + } + + for (int _i0 = 1; (_i0-R-1 < 0); _i0++ ) { + for (int _i1 = 1; (_i1-C-1 <= 0); _i1++) { + Ixy[_i0][_i1] = Ix[_i0][_i1] * Iy[_i0] [_i1]; + } + } + + for (int _i0 = 1; (_i0-R-1 < 0); _i0++ ) { + for (int _i1 = 1; (_i1-C-1 <= 0); _i1++) { + Ixx[_i0][_i1] = Ix[_i0] [_i1] * Ix[_i0][_i1]; + } + } + + for (int _i0 = 2; (_i0 < R); _i0++ ) { + for (int _i1 = 2; (_i1 < C); _i1++) { + Syy[_i0][_i1] = ((((((((Iyy[-1 + _i0][-1 + _i1] + + Iyy[-1 + _i0][ _i1]) + + Iyy[-1 + _i0][ 1 + _i1]) + + Iyy[ _i0][-1 + _i1]) + + Iyy[ _i0][ _i1]) + + Iyy[ _i0][ 1 + _i1]) + + Iyy[1 + _i0][-1 + _i1]) + + Iyy[1 + _i0][ _i1]) + + Iyy[1 + _i0][ 1 + _i1]); + } + } + for (int _i0 = 2; (_i0 < R); _i0++ ) { + for (int _i1 = 2; (_i1 < C); _i1++) { + Sxy[_i0][_i1] = ((((((((Ixy[-1 + _i0][-1 + _i1] + + Ixy[-1 + _i0][ _i1]) + + Ixy[-1 + _i0][ 1 + _i1]) + + Ixy[ _i0][-1 + _i1]) + + Ixy[ _i0][ _i1]) + + Ixy[ _i0][ 1 + _i1]) + + Ixy[ 1 + _i0][-1 + _i1]) + + Ixy[ 1 + _i0][ _i1]) + + Ixy[ 1 + _i0][ 1 + _i1]); + } + } + for (int _i0 = 2; (_i0 < R); _i0++ ) { + for (int _i1 = 2; (_i1 < C); _i1++) { + Sxx[_i0][_i1] = ((((((((Ixx[-1 + _i0][-1 + _i1] + + Ixx[-1 + _i0][ _i1]) + + Ixx[-1 + _i0][ 1 + _i1]) + + Ixx[ _i0][-1 + _i1]) + + Ixx[ _i0][ _i1]) + + Ixx[ _i0][ 1 + _i1]) + + Ixx[ 1 + _i0][-1 + _i1]) + + Ixx[ 1 + _i0][ _i1]) + + Ixx[ 1 + _i0][ 1 + _i1]); + } + } + for (int _i0 = 2; (_i0 < R); _i0++ ) { + for (int _i1 = 2; (_i1 < C); _i1++) { + trace[_i0][_i1] = (Sxx[_i0][_i1] + Syy[_i0][_i1]); + } + } + + for (int _i0 = 2; (_i0 < R); _i0++ ) { + for (int _i1 = 2; (_i1 < C); _i1++) { + det[_i0][_i1] = ((Sxx[_i0][_i1] * Syy[_i0][_i1]) - (Sxy[_i0][_i1] * Sxy[_i0][_i1])); + } + } + + for (int _i0 = 2; (_i0 < R); _i0++ ) { + for (int _i1 = 2; (_i1 < C); _i1++) { + int value = (det[_i0][_i1] - ((0.04f * trace[_i0][_i1]) * trace[_i0][_i1])); + if(value > threshold) + { + img[_i0][_i1] = 3; + } + } + } + return; +} Index: MicroBenchmarks/harris/init.cpp =================================================================== --- MicroBenchmarks/harris/init.cpp +++ MicroBenchmarks/harris/init.cpp @@ -0,0 +1,44 @@ +#include "harris.h" + +// This function initializes the input image to checkbox image +// Can be replaced with any other image initialization + +void init_checkboard_image(int height, int width) { + + // 2 different x and y, as we want alternate in both direction + int last_pixel_x = 0; + int last_pixel_y = 0; + + // Initialize a random image + for (int i = 0; i < height; i++) { + if (i % BOX_SIZE == 0) { + last_pixel_y = (last_pixel_y + 1) % 2; + } + last_pixel_x = last_pixel_y; + for (int j = 0; j < width; j++) { + if (j % BOX_SIZE == 0) { + last_pixel_x = (last_pixel_x + 1) % 2; + } + if (last_pixel_x == 0) + image[i][j] = 255; + else + image[i][j] = 0; + } + } +} + + +// Writes image matrix to a file (asuming values are only 0, 255 and 3. +// If different values are also there then remove % 8 +void DUMP_IMAGE(int height, int width, float arr[(2+HEIGHT)][2+WIDTH]) { + std::ofstream myfile; + myfile.open("output.txt"); + for (int i = 0; i < height - 2; i++) { + for (int j = 0; j < width - 2; j++) { + // std::cout << ((int)arr[i][j]) % 8 ; + myfile << int(arr[i][j]) % 8; + } + myfile << "\n"; + // std::cout << std::endl; + } +} \ No newline at end of file Index: MicroBenchmarks/harris/main.cpp =================================================================== --- MicroBenchmarks/harris/main.cpp +++ MicroBenchmarks/harris/main.cpp @@ -0,0 +1,107 @@ +/* For polymage-benchmarks-harris kernel + Copyright (c) 2015 Indian Institute of Science + All rights reserved. + + Written and provided by: + Ravi Teja Mullapudi, Vinay Vasista, Uday Bondhugula + Dept of Computer Science and Automation + Indian Institute of Science + Bangalore 560012 + India + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + 3. Neither the name of the Indian Institute of Science nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS MATERIAL IS PROVIDED BY Ravi Teja Mullapudi, Vinay Vasista, and Uday + Bondhugula, Indian Institute of Science ''AS IS'' AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + EVENT SHALL Ravi Teja Mullapudi, Vinay Vasista, CSA Indian Institute of + Science BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. +*/ + +// ============================================================================ +/* + * Pankaj Kukreja + * Indian Institute of Technology Hyderabad + * + * Acknowledgements + // ============================================================================ + * SHA1SUM computation source code from: + * https://github.com/vog/sha1 + * 100% Public Domain + // ============================================================================ + * HARRIS KERNEL (modified) + * https://github.com/bondhugula/polymage-benchmarks/ + * File: polymage-benchmarks/apps/harris/harris_polymage_naive.cpp +*/ +// ============================================================================ + + + +#include "harris.h" + + +float image[HEIGHT+2][WIDTH+2] = {0} ; + +#define BENCHMARK_LIB /*Comment this to not use google benchmark library*/ +#ifdef BENCHMARK_LIB +#include "benchmark/benchmark.h" +#endif + + +/* +This function is called in bechmark macro +-> Since the kernel modifes the original image array, I had to copy values to a +temporary array and then pass that array and then write the output to file. If +there is any better way to do this let me know. + +-> If I do not copy the values and directly pass image array, then some thread +may read the modified value of image array instead of original value. +*/ + +#ifdef BENCHMARK_LIB + float img[2+HEIGHT][2+WIDTH]; + void BENCHMARK_HARRIS(benchmark::State &state) { + for (auto _ : state) { + state.PauseTiming(); + std::memcpy(img, image, (2+HEIGHT)*(2+WIDTH) * sizeof(float)); + state.ResumeTiming(); + harris_kernel(HEIGHT, WIDTH, THRESHOLD, img); + } +} +BENCHMARK(BENCHMARK_HARRIS); +#endif + + +int main(int argc, char *argv[]) { + init_checkboard_image((HEIGHT + 2), (WIDTH + 2)); +#ifdef BENCHMARK_LIB + ::benchmark::Initialize(&argc, argv); + if (::benchmark::ReportUnrecognizedArguments(argc, argv)) + return 1; + ::benchmark::RunSpecifiedBenchmarks(); + DUMP_IMAGE(HEIGHT + 2, WIDTH + 2, img); +#else + harris_kernel(HEIGHT, WIDTH, THRESHOLD, image); + DUMP_IMAGE(HEIGHT + 2, WIDTH + 2, image); +#endif + return 0; +}