In Problem Set #2 you will be implementing a parallel algorithm for blurring images.
Here is an example of the effect we're talking about.
Here's your original image and here's the image after we apply a blur effect to that original image.
Blurring an image involves averaging a local neighborhood of pixels,
and it is expressed naturally using a parallel stencil operation.
Stencil operations come up all the time in all types of application domains.
This is why we are going to focus in on stencil in this homework.
Let's take a closer look at a simple example demonstrating the kind of local averaging that we are talking about here.
Suppose we have the following pixel representation of an image,
and we want to calculate the average intensity value for this pixel right here.
What do we do?
First we take the value of this pixel, and then we add this value to the value of all its neighbors.
So 10 4 6 2 1 2 3 and 6, and once when we add up all these values then we take the average.
Since we have 9 elements or 9 pixels here, then we multiply the sum by 1/9,
and that is how you would calculate the average intensity value for a pixel in an image.
If we do this operation for every pixel in the image,
we will arrive at a blurred version of input image.
However it turns out that performing an unweighted average of pixels can sometimes look really ugly,
and we can achieve a better looking blur by computing a weighted average of these pixels.
What I mean by weighted average is the following.
Rather than multiplying 1/9 to each pixel value here, we will multiply each pixel value by a different weight.
So w1 is different than w2. And w2 may be different than w3.
And w3 may be different than w4.
And that is the approach that we will take in Problem Set #2.
Here is an image produced by weighted blur,
and here is an image produced by unweighted blur,
and as you can see that the weighted blur
is much smoother than the unweighted blur counterpart.
In this problem set we will give you a small 2D array that contains weight values between 0 and 1 as follows.
But this is just an example.
The actual weight values that we will use will look like this:
the smooth shape of the weights, as you can see here,
will produce the nice looking blur effect that we saw earlier.
And also, here's a note.
We will blur color images by blurring each color channel independently,
and we will include a more detailed mathematical formula on blurring computations in the instructor comments.
This is what you need to do for Problem Set #2.
First, you will need to write the actual blur kernel.
Second, you will need to actually write the kernel that separates the color image to its R, G, B channels.
And third we will give you the opportunity to allocate memory on the device for the filter,
so you will have an opportunity to code CUDA mem copies.
And fourth, you will have to set the correct or the optimal grid and block size for this problem set.
And, as you remember in Problem Set #1,
the grid and the block size has a huge impact on your program's execution time.
Set the size correctly and be careful.
Lastly your submission will be evaluated based on correctness and speed.
But we recommend that you focus on correctness first.
Then after your blurring kernal is run correctly then we recommend that you try to make it run faster.
And lastly we have supplied serial code that you can reference and compare your solution against.
Good luck on writing Problem Set #2.
If you have any questions, feel free to ask in the class forums.
在问题集2中你将要在模糊画面中实现并行算法。
这是此算法的一组示例效果。
这是原始图片，而这边呢则是我们对原始图片使用了模糊效果之后的图片。
模糊一张图片涉及到平均局部像素的工作，
同时通过使用模板并行作业使其表现得自然。
模板作业在各类应用程序域中都会应用到。
这就是为什么我们要在此次作业中关注模板的原因。
让我们再仔细得看一下我们在这讲到的阐述领域平均的简单示例。
假设我们用以下像素代表一张图片，
我们想要计算出此处像素的平均亮度值。
我们该怎么做呢？
首先我们取出此像素的值，然后将这个值与它周围的所有值相加。
所以说就是10 4 6 2 1 2 3和6，一旦我们将其相加，我们就得到它的平均值。
由于我们这有9个像素值，所以我们将结果乘以1/9，
这就是如何计算一张图片某像素平均亮度值的方法了。
如果我们为这张相片每一处像素都做此操作的话，
我们将得到输入图片的一个模糊版本。
然而结果证明，对像素执行未加权平均，有些时候效果很不好。
通过计算这些像素的加权平均值，我们能够得到一个更好的模糊效果。
我指的加权平均值是这样计算的。
与此处每个像素值乘以1/9不同，我们将为每个像素值乘以不同的加权。
这意味着w1不同于为w2，而w2则可能不同于w3。
w3则很可能与w4的值不一样。
这就是我们在问题集2中将要用到的方法。
这是一张由加权模糊制作的照片，
而这张则是非加权模糊制作的照片，
大家可以看到加权模糊的物体
比非加权模糊的更为平滑。
在此问题集中，我们将给你如下的一个小的包含加权值在0到1之间的二维数组。
当然这只是一个示例。
实际我们使用的加权值看起来应该是这样的：
加权的平滑形状，你们可以在这里看到，
将生成我们之前看到的那种漂亮的模糊效果。
同时，请注意。
我们将通过单独模糊每个色彩通道来模糊色彩图像，
同时在指导意见下，我们将使用一个更为详细的数学公式来进行模糊计算。
这就是大家在问题集2中需要了解掌握的内容。
第一，你需要写出实际模糊核心。
第二，你需要写出实际分割色彩图像到R,G,B通道的核心。
第三，我们将给你一个机会为设备上的过滤器分配内存，
这就是说你有机会能够为统一计算设备架构（CUDA）内存编码。
第四，你需要为此问题集设置正确的或者说最佳的网格和程序块大小。
这是因为，正如在问题集1中提到过的，
网格与程序块大小对你程序的执行有相当大的影响。
正确地设置大小，一定要小心。
最后，你提交的结果将会被基于正确性和运行速度来评估。
但我们建议你首先要注意正确性。
在确保你的模糊核心正确运行后，我们建议你尝试使其运行得更快。
最后提一下的是，我们提供了可以参考和进行结果比较的串行代码。
祝大家在问题集2中好运。
如你有任何问题，随时在课堂论坛中提出即可。