Index: test-suite/trunk/MicroBenchmarks/CMakeLists.txt =================================================================== --- test-suite/trunk/MicroBenchmarks/CMakeLists.txt +++ test-suite/trunk/MicroBenchmarks/CMakeLists.txt @@ -4,3 +4,5 @@ add_subdirectory(XRay) add_subdirectory(LCALS) add_subdirectory(harris) +add_subdirectory(ImageProcessing) + Index: test-suite/trunk/MicroBenchmarks/ImageProcessing/utils/ImageHelper.h =================================================================== --- test-suite/trunk/MicroBenchmarks/ImageProcessing/utils/ImageHelper.h +++ test-suite/trunk/MicroBenchmarks/ImageProcessing/utils/ImageHelper.h @@ -0,0 +1,15 @@ +/** +This file contains some utility functions that Image processing kernels require + +Written by Pankaj Kukreja +Indian Institute of Technology Hyderabad +*/ + +#ifndef _IMAGEHELPER_H_ +#define _IMAGEHELPER_H_ + +void initializeRandomImage(int *image, int height, int width); +void initializeRandomColouredImage(int *image, int height, int width); +void saveImage(int *image, const char *outputFile, int height, int width); + +#endif /* _IMAGEHELPER_H_ */ Index: test-suite/trunk/MicroBenchmarks/ImageProcessing/utils/ImageHelper.cpp =================================================================== --- test-suite/trunk/MicroBenchmarks/ImageProcessing/utils/ImageHelper.cpp +++ test-suite/trunk/MicroBenchmarks/ImageProcessing/utils/ImageHelper.cpp @@ -0,0 +1,90 @@ +/** +This file contains some utility functions that Image processing kernels require + +Written by Pankaj Kukreja +Indian Institute of Technology Hyderabad +*/ + +#include "ImageHelper.h" +#include "glibc_compat_rand.h" +#include // For reading and saving Image +#include // For std::cerr + +// Initialize a random Image +void initializeRandomImage(int *image, int height, int width) { + glibc_compat_srand(7); + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + image[i * width + j] = glibc_compat_rand() % 256; + } + } +} + +// Save Image to outputFile +void saveImage(int *image, const char *outputFile, int height, int width) { + std::ofstream outfile; + outfile.open(outputFile, std::ios::out | std::ios::trunc); + + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + // Just for safety + if (image[i * width + j] > 255) { + outfile << 255 << " "; + } else if (image[i * width + j] < 0) { + outfile << 0 << " "; + } else { + outfile << image[i * width + j] << " "; + } + } + outfile << std::endl; + } +} + +// Initializes a random RGB Image +void initializeRandomColouredImage(int *image, int height, int width) { + glibc_compat_srand(7); + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + image[i * (width * 3) + j * 3 + 0] = glibc_compat_rand() % 256; + image[i * (width * 3) + j * 3 + 1] = glibc_compat_rand() % 256; + image[i * (width * 3) + j * 3 + 2] = glibc_compat_rand() % 256; + } + } +} + +// Read Pixel values of a black n white Image from $inputFile +void initializeImage(int *image, char *inputFile, int height, int width) { + std::ifstream inFile(inputFile, std::ios::binary); + + if (!inFile) { + std::cerr << " Can't open file " << inputFile << std::endl; + exit(1); + } + + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + inFile >> image[i * width + j]; + } + } + inFile.close(); +} + +// Read Pixel values of a coloured Image from $inputFile +void initializeColoredImage(int *image, char *inputFile, int height, + int width) { + std::ifstream inFile(inputFile, std::ios::binary); + + if (!inFile) { + std::cerr << " Can't open file " << inputFile << std::endl; + exit(1); + } + + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + inFile >> image[i * width + j + 0]; // R + inFile >> image[i * width + j + 1]; // G + inFile >> image[i * width + j + 2]; // B + } + } + inFile.close(); +} Index: test-suite/trunk/MicroBenchmarks/ImageProcessing/utils/glibc_compat_rand.h =================================================================== --- test-suite/trunk/MicroBenchmarks/ImageProcessing/utils/glibc_compat_rand.h +++ test-suite/trunk/MicroBenchmarks/ImageProcessing/utils/glibc_compat_rand.h @@ -0,0 +1,20 @@ +/*===------------- glibc_compat_rand.h- glibc rand emulation --------------===*\ +|* +|* The LLVM Compiler Infrastructure +|* +|* This file is distributed under the University of Illinois Open Source +|* License. See LICENSE.TXT for details. +|* +\*===----------------------------------------------------------------------===*/ + +#ifndef GLIBC_COMPAT_RAND_H +#define GLIBC_COMPAT_RAND_H +#ifdef __cplusplus +extern "C" { +#endif +int glibc_compat_rand(void); +void glibc_compat_srand(unsigned int seed); +#ifdef __cplusplus +} +#endif +#endif /* GLIBC_COMPAT_RAND_H */ Index: test-suite/trunk/MicroBenchmarks/ImageProcessing/utils/glibc_compat_rand.c =================================================================== --- test-suite/trunk/MicroBenchmarks/ImageProcessing/utils/glibc_compat_rand.c +++ test-suite/trunk/MicroBenchmarks/ImageProcessing/utils/glibc_compat_rand.c @@ -0,0 +1,60 @@ +/*===------------ glibc_compat_rand.c - glibc rand emulation --------------===*\ + * + * The LLVM Compiler Infrastructure + * + * This file is distributed under the University of Illinois Open Source + * License. See LICENSE.TXT for details. + * +\*===----------------------------------------------------------------------===*/ + +#include "glibc_compat_rand.h" + +/** + * This rand implementation is designed to emulate the implementation of + * rand/srand in recent versions of glibc. This is used for programs which + * require this specific rand implementation in order to pass verification + * tests. + * + * For more information, see: http://www.mathstat.dal.ca/~selinger/random/ + **/ + +#define TABLE_SIZE 344 +static unsigned int table[TABLE_SIZE]; +static int next; + +int glibc_compat_rand(void) { + /* Calculate the indices i-3 and i-31 in the circular vector. */ + int i3 = (next < 3) ? (TABLE_SIZE + next - 3) : (next - 3); + int i31 = (next < 31) ? (TABLE_SIZE + next - 31) : (next - 31); + + table[next] = table[i3] + table[i31]; + unsigned int r = table[next] >> 1; + + ++next; + if (next >= TABLE_SIZE) + next = 0; + + return r; +} + +void glibc_compat_srand(unsigned int seed) { + if (seed == 0) + seed = 1; + + table[0] = seed; + + for (int i = 1; i < 31; i++) { + int r = (16807ll * table[i - 1]) % 2147483647; + if (r < 0) + r += 2147483647; + + table[i] = r; + } + + for (int i = 31; i < 34; i++) + table[i] = table[i - 31]; + for (int i = 34; i < TABLE_SIZE; i++) + table[i] = table[i - 31] + table[i - 3]; + + next = 0; +}