In this part of the project, you will have to implement a simple brightness and contrast adjustment filter for a 2D image with SIMD intrinsics. The brightness adjustment requires using a simple addition operation. The contrast adjustment requires using multiplication. The final calculated value should be converted back to an integer color channel value.
The overall formula is
// ...
channel_value = (unsigned char) (channel_value * contrast + brightness);
The image is represented as an array of pixel color values. Every pixel is represented as three-byte integers with channel values ranging from 0 to 255. Your test image is stored in the BMP/DIB format. Your code template provides a simple library to read, decode, and write some variants of bitmap images. You can refer to the following image (courtesy to Verpies) to understand how to work with bitmap data.
You are given the assembly code and all the SIMD instructions. This code is not portable between compilers. You have to convert it into SIMD intrinsics instruction by instruction.
-
Open the
brightness.c
file. -
Find the
TODO
comment. -
Write the intrinsics.
-
Test the code on Kaggle machines with the support of the AVX512 extensions. You can use the
com-392-451-project-1.ipynb
Jupiter notebook to prepare the environment on their server. You will have to register an account. Sometimes, you have to reload the notebook to get a server with the CPU supportingAVX512f
SIMD instructions. It is recommended to use theauca.space
server to develop and write code and only test on Kaggle machines.
In this part, you need to do an opposite operation. You have all the intrinsics to apply a Sepia filter to an image. You have to make the code less portable between compilers by writing inline assembly.
The Sepia filter converts a color image to a duotone image with a dark Brown-Gray color. The algorithm is explained in the following paper written by Petter Larsson and Eric Palmer.
-
Open the
sepia.c
file. -
Find the
TODO
comment. -
Write the inline assembly.
-
Test the code on Kaggle machines with the support of the AVX512 extensions. You can use the
com-392-451-project-1.ipynb
Jupiter notebook to prepare the environment on their server. You will have to register an account. Sometimes, you have to reload the notebook to get a server with the CPU supportingAVX512f
SIMD instructions. It is recommended to use theauca.space
server to develop and write code and only test on Kaggle machines.
-
In your private course repository that was given to you by the instructor during the lecture, create the path
project-1/part-1/
. -
Put the
brightness.c
andsepia.c
files into that directory. -
Commit and push your repository through Git. Submit the last commit ID to Canvas before the deadline.
You are now given a threaded implementation of the Sepia program in the
mt_sepia.c
file. You have to study the code to figure out how the POSIX
Threads interface is being used to utilize the power of a multicore/cpu machine.
After that, you have to port your inline assembly code from Part 1-2, recompiler
the program with the extra -pthread
flag, and ensure that everything still
works.
-
Open the
mt_sepia.c
file. -
Find the
TODO
comment. -
Move your inline assembly from Part 1-2.
-
Test the code on a machine with AVX512 support.
-
In your private course repository that was given to you by the instructor during the lecture, create the path
project-1/part-2/
. -
Put the
mt_sepia.c
file into that directory. -
Commit and push your repository through Git. Submit the last commit ID to Canvas before the deadline.
In this part, you have to create a multithreaded version of the brightness and
contrast filter. Create a copy of the brightness.c
file under the name
mt_brightness.c
. Use mt_sepia.c
to help you make the mt_brightness.c
utilize all the threads of your test machine.
-
Create the
mt_brightness.c
file frombrightness.c
. -
Make the multithreaded version of the code with the help of PThreads. Use
mt_sepia.c
and all the given extra header files to help you make the code multithreaded. -
Test the code on a machine with AVX512 support.
-
In your private course repository that was given to you by the instructor during the lecture, create the path
project-1/part-2/
. -
Put the
mt_brightness.c
file into that directory. -
Commit and push your repository through Git. Submit the last commit ID to Canvas before the deadline.
Check Canvas for information about the deadline for the first part.
man make
man gcc
man as
man gdb
man objdump
- Intel x86 Software Developer Manuals
- System V AMD64 ABI
- X86 Opcode Reference
- X86 Instruction Reference
- Optimizing Subroutines in Assembly Language
- C Programming: A Modern Approach, 2nd Edition by K. N. King
- Assembly Language for x86 Processors, 7th Edition by Kip R. Irvine