[test-suite] r339004 - Add utilities functions for Image Processing Kernels

Pankaj Kukreja via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 6 03:57:46 PDT 2018


Author: proton
Date: Mon Aug  6 03:57:46 2018
New Revision: 339004

URL: http://llvm.org/viewvc/llvm-project?rev=339004&view=rev
Log:
Add utilities functions for Image Processing Kernels

Kernels will be added in seperate patches

Reviewers: Meinersbur

Differential Revision: https://reviews.llvm.org/D49339

Added:
    test-suite/trunk/MicroBenchmarks/ImageProcessing/
    test-suite/trunk/MicroBenchmarks/ImageProcessing/utils/
    test-suite/trunk/MicroBenchmarks/ImageProcessing/utils/ImageHelper.cpp
    test-suite/trunk/MicroBenchmarks/ImageProcessing/utils/ImageHelper.h
    test-suite/trunk/MicroBenchmarks/ImageProcessing/utils/glibc_compat_rand.c
    test-suite/trunk/MicroBenchmarks/ImageProcessing/utils/glibc_compat_rand.h
Modified:
    test-suite/trunk/MicroBenchmarks/CMakeLists.txt

Modified: test-suite/trunk/MicroBenchmarks/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MicroBenchmarks/CMakeLists.txt?rev=339004&r1=339003&r2=339004&view=diff
==============================================================================
--- test-suite/trunk/MicroBenchmarks/CMakeLists.txt (original)
+++ test-suite/trunk/MicroBenchmarks/CMakeLists.txt Mon Aug  6 03:57:46 2018
@@ -4,3 +4,5 @@ add_subdirectory(libs)
 add_subdirectory(XRay)
 add_subdirectory(LCALS)
 add_subdirectory(harris)
+add_subdirectory(ImageProcessing)
+

Added: test-suite/trunk/MicroBenchmarks/ImageProcessing/utils/ImageHelper.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MicroBenchmarks/ImageProcessing/utils/ImageHelper.cpp?rev=339004&view=auto
==============================================================================
--- test-suite/trunk/MicroBenchmarks/ImageProcessing/utils/ImageHelper.cpp (added)
+++ test-suite/trunk/MicroBenchmarks/ImageProcessing/utils/ImageHelper.cpp Mon Aug  6 03:57:46 2018
@@ -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 <fstream>  // For reading and saving Image
+#include <iostream> // 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();
+}

Added: test-suite/trunk/MicroBenchmarks/ImageProcessing/utils/ImageHelper.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MicroBenchmarks/ImageProcessing/utils/ImageHelper.h?rev=339004&view=auto
==============================================================================
--- test-suite/trunk/MicroBenchmarks/ImageProcessing/utils/ImageHelper.h (added)
+++ test-suite/trunk/MicroBenchmarks/ImageProcessing/utils/ImageHelper.h Mon Aug  6 03:57:46 2018
@@ -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_ */

Added: test-suite/trunk/MicroBenchmarks/ImageProcessing/utils/glibc_compat_rand.c
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MicroBenchmarks/ImageProcessing/utils/glibc_compat_rand.c?rev=339004&view=auto
==============================================================================
--- test-suite/trunk/MicroBenchmarks/ImageProcessing/utils/glibc_compat_rand.c (added)
+++ test-suite/trunk/MicroBenchmarks/ImageProcessing/utils/glibc_compat_rand.c Mon Aug  6 03:57:46 2018
@@ -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;
+}

Added: test-suite/trunk/MicroBenchmarks/ImageProcessing/utils/glibc_compat_rand.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MicroBenchmarks/ImageProcessing/utils/glibc_compat_rand.h?rev=339004&view=auto
==============================================================================
--- test-suite/trunk/MicroBenchmarks/ImageProcessing/utils/glibc_compat_rand.h (added)
+++ test-suite/trunk/MicroBenchmarks/ImageProcessing/utils/glibc_compat_rand.h Mon Aug  6 03:57:46 2018
@@ -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 */




More information about the llvm-commits mailing list