Assignment2
Assignment2
Assignment 2
Task 2a
Write a normal C/C++ program (not using OpenCL) that reads the contents from a text file called
“plaintext.txt” (a test file has been provided). The program should prompt the user to input a valid n
value, then encrypt the plaintext using the shift cipher method described above, and output the
ciphertext into an output text file called “ciphertext.txt”. To ensure that the encryption was
performed correctly, your program must also decrypt the ciphertext into a file called “decrypted.txt”
to check whether it matches the original plaintext (albeit in upper case).
(3 marks)
Task 2b
Write an OpenCL program to perform the same functionality as in Task 2a, but in parallel. Note
that it is more efficient to use OpenCL vector datatypes for processing in the kernel, as less work-
items will be required.
(3 marks)
Task 2c
Write an OpenCL program to perform parallel encryption, and decryption, by substituting
characters based on the following lookup table:
a b c d e f g h i j k l m n o p q r s t u v w x y z
G X S Q F A R O W B L M T H C V P N Z U I E Y D K J
Based on the table above, for encryption the letter a (or A) will be replaced by G, b (or B) will be
replaced by X, c (or C) will be replaced by S, etc.
(4 marks)
1
Note that to avoid leaking information (e.g., word length), by convention the ciphertext is usually converted to upper
case letters that are organised in groups of five-letter blocks and anything that is not a letter is removed. However, for
this assignment, DO NOT remove anything that is not a letter and DO NOT organise in groups of five-letters.
i. Write an OpenCL program that accepts a colour image and outputs a filtered image using
Gaussian blurring based on the 7x7 window weights provided above.
(1 mark)
ii. Instead of using the 7x7 window (the naïve approach), an alternate approach is to run the
filter in 2 passes. The first pass will perform blurring in the horizontal direction; the result
will then undergo a second pass to blur it in the vertical direction (enqueue the kernel twice
to perform blurring in each direction). The result will be similar to the single window
approach, but the amount of computation will be different.
For example, using a 7x7 window approach, each pixel will have to perform a weighted sum
on 49 pixels. In the 2-pass approach, each pixel will have to perform a weighted sum on 7
pixels in each pass, processing a total of 14 pixels. This is illustrated below:
Your task is to implement the parallel 2-pass approach. For this, use the following weights
for the horizontal pass as well as the vertical pass:
0.00598 0.060626 0.241843 0.383103 0.241843 0.060626 0.00598
(3 marks)
Task 3c (Bloom effect)
Bloom effects are commonly used in graphics, movies, video games, etc. This part combines the
work from Tasks 3a and 3b. The basic steps to create an image with a bloom effect are illustrated as
follows:
2
Note that Figure 1(b) shows a down-sampled image (i.e. the image has been shrunk). It is more efficient to process a
down-sampled image during the blurring step because there are fewer pixels to process. This also works well for
blurring since referencing the pixels from the smaller image in the final step will also cause blurring (blurring caused by
effectively up-sampling back to the original image size. In fact, some approaches simply use down-sampling for
blurring). To make things easier, for this assignment you do not have to perform down-sampling/up-sampling.
For ALL tasks, include screenshots with your submission. The screenshots are to demonstrate that
the programs work on your computer.
For Task 3, include examples of output images obtained from your program.
References
The images were sourced from
http://http.developer.nvidia.com/GPUGems/gpugems_ch21.html