CSCE569

Assignment 1 – CSCE569, Spring 2018

Due: 11:55PM Feburary 9, Friday 2018


2-Dimensional Matrix-Matrix Multiplication and Matrix-Vector Multiplication with Different Matrix Storage

In this assignment, you will implement two C functions, one for performing 2-dimensional matrix-matrix multiplication, and the other for matrix vector multiplication. The function signatures are already given as follows and you can use the class examples (mm.c and matvec.c) as the starting point for creating your implementation.

/* C[N][M] = A[N][K] * B[K][M] */
void mm(int N, int K, int M, REAL * A, REAL * B, REAL * C, int A_rowMajor, int B_rowMajor);

/* C[N] = A[N][M] * B[M] */
void mv(int N, int M, REAL *A, REAL *B, REAL *C, int A_rowMajor);

The memory of each matrix (A, B, or C) is provided using REAL * A, and its dimensions are specified as function parameters (N, K, or M). The elements of a 2-dimensional matrix could be stored in either row major or column major, identified using A_rowMajor (or B_rowMajor). If A_rowMajor is non-zero, elements of A are stored in row major, otherwise, they are stored in column major. Your function should be able to handle any combination of the storage type of each matrix in the arguments, e.g. there are four cases for mm function and two cases for mv function. The results in matrix C should be always in row major.

The two source files provided include helper functions for initializing the matrix and for timing the execution, and a skeleton main function. You can compile and build the executable using gcc compiler (e.g. gcc -fopenmp -O0 mm.c -o mm), in which –O0 is the flag optimization level 0 (no optimization). You can try –O2 or –O3 optimization flag. The output of your program should include both the time of computation (ms) and FLOPS performance. Please ignore the OpenMP parallel function (e.g. mm_omp_parallel) at the moment.

Image Histogram and Smoothing using OpenCV

In this assignment, you will implement two image processing algorithms, Image Histogram and Smoothing. OpenCV will be used for reading, writing and displaying images, and for getting and setting pixel values of an image. The read_timer() function provided in mm.c or matvec.c can be used for timing purpose. The output of your program should include both the time of computation (ms) and FLOPS performance.

Histogram calculation

Image histogram provides a graphical representation of the intensity distribution of an image by quantifying the number of pixels for each intensity value considered. The description of image histogram and an OpenCV example for calcualting histogram can be found from OpenCV Tutorial for Histogram Calculation, and this C code provide a very concise implementation for the algorithm.

Image smoothing

Image smoothing, which also referred to as image blurring is a simple and frequently used image processing operation. Depending the effects we want the smoothing operation to be applied to an image, we can apply different filter (coefficients matrix) to an image using the same algorithms. The description and an OpenCV example can be found from OpenCV Tutorial for Smoothing Images, and this C code provide concise code for image filtering algorithms.

For your implementation, while you can look at the OpenCV’s implementation for Histogram calculation and Image smoothing, they are much more complicated that we we need for the purpose of this assignment. It would be much easier you adapt the implmentation in the two C codes to the OpenCV image processing framework.

The methods for reading/writing/displaying an image and for getting/setting a pixel value of an image are pretty simple in OpenCV, which can be found from this short description with code sample for operating images. For your implementation, the recommendation is to start with the program for changing the contrast and brightness of an image, which provides executable codes for those operations.

Source Code to Start

The Assignment_1.zip package contains all the files you need, including mm.c, matvec.c, Histogram.cpp, and Smoothing.cpp, cmake CMakeLists.txt, image data, other sample souce files, an excel file for creating figures, this webpage, and a README.md file. The HistogramOpenCV.cpp, SmoothingOpenCV.cpp and DisplayImage.cpp files for OpenCV image processing are all from the OpenCV tutorial mentioned above and they are for your reference only. For your Histogram and Smoothing implementation, you should start with the ContractBrightness.cpp file and modify the code according to the implementation done in HIST.C and FILTER.C. README.md provide instructions for how to build each executable.

Machine to use for development

Submission

Your submission should be a single zipped file named LastNameFirstName.zip that include source code files and one report document file named as LastNameFirstNameAssignment1.pdf. The easiest way is to do your implementation in a folder unpacked from Assignment_1.zip. After that, add the report file and re-package the folder and submit it. The source files contain your implementations, and each file should be invidually compiled to generate executables. The report is max 3-page report that includes:

  1. Short description on how you implement mm, mv, image histogram and smoothing.
  2. Performance report using two figures when running mm and mv with 1024x1024 and 2048x2048 matrix sizes (more sizes of configuration are welcome). Figure 1 reports the execution times in ms for mv compiled with –O0 and –O3 optimization flags for gcc, Figure 2 reports execution times in ms for mm compiled with –O0 and –O3 optimization flags for gcc. An excel sheet is provided for creating those figures by simply inputing your execution results and the figure will be automatically populated and generated by Excel. In your report, you should explain the reasons of the performance differences between different matrix storage types (row major or column major) and the reasons of performance differences between –O0 and –O3 optimization flags (check gcc manual page and search internet to find correct answers, and explain in your English).
  3. Please indicate in your report, which machine you use and the CPU and memory information of your machine, using cat /proc/cpuinfo command.
  4. In your report, compute and report CPU peak performance based on the CPU you are using, and then compute and report the performance efficiency of each function (mm, mv, histogram and smoothing). Please be noted that your program is sequential and only use one core, so the performance efficiency = program FLOPS / per-core peak.
  5. Explanation of the performance results shown in your figures and draw meaningful conclusions.

Grading:

  1. Functions implementations: 60 points (10 for mm.c, 10 for matvec.c, 20 for Histogram.cpp and 20 for Smoothing.cpp). For source file that cannot be compiled, you only receive max 60% of function implementation points. For compliable, but with execution errors or incorrectness, you receive max 80% of function implementation points.
  2. Report: 40 points.

Assignment Policy

  1. Programming assignments are to be done individually. You may discuss assignments with others, but you must code your own solutions and submit them with a write-up in your own words. Indicate clearly the name(s) of student(s) you collaborated with, if any.
  2. Although homework assignments will not be pledged, per se, the submitted solutions must be your work and not copied from other students’ assignments or other sources.
  3. You may not transmit or receive code from anyone in the class in any way–visually (by showing someone your code), electronically (by emailing, posting, or otherwise sending someone your code), verbally (by reading your code to someone), or in any other way.
  4. You may not collaborate with people who are not your classmates, TAs, or instructor in any way. For example, you may not post questions to programming forums.
  5. Any violations of these rules will be reported to the honor council. Check the syllabus for the late policy and academic conduct.