Skip to content
Snippets Groups Projects
Commit 1bda9451 authored by dansa828's avatar dansa828
Browse files

lab 3 done

parent 35158f07
Branches
No related tags found
No related merge requests found
...@@ -19,31 +19,35 @@ ...@@ -19,31 +19,35 @@
unsigned char median_kernel(skepu::Region2D<unsigned char> image, size_t elemPerPx) unsigned char median_kernel(skepu::Region2D<unsigned char> image, size_t elemPerPx)
{ {
int row_size = image.oi*2+1; //const int SIZE = ((50*2)+1)*((50*2)+1);
int col_size = image.oj*2+1; unsigned char imageArray[10201];
int n = row_size*col_size;
int i, j, x, y, x_next, y_next;
unsigned char temp; unsigned char temp;
for (i = 0; i < n-1; i++){ int k = 0;
// Last i elements are already in place
for (j = 0; j < n-i-1; j += elemPerPx) {
x = j%row_size;
y = (j-x)/row_size;
x_next = (j+elemPerPx)%row_size; for(int i = -image.oi; i <= image.oi; i++)
y_next = (j+elemPerPx-x_next)/row_size; {
for(int j = -image.oj; j <= image.oj; j += elemPerPx)
{
imageArray[k] = image(i, j);
k++;
}
}
//Bubblesort
for (int i = 0; i < k-1; i++){
for (int j = 0; j < k-i-1; j++) {
if (imageArray[j] > imageArray[j+1]) {
temp = imageArray[j];
imageArray[j] = imageArray[j+1];
imageArray[j+1] = temp;
if (image(x,y) > image(x_next, y_next)) {
temp = image(x,y);
printf("%uc\n", temp);
//image.data[x,y] = image(x_next, y_next);
//image.data[x_next, y_next] = temp;
} }
} }
} }
return image(0,0); int median = (k-1)/2;
return imageArray[median];
} }
/* /*
unsigned char median_kernel_vector(skepu::Region2D<unsigned char> image, skepu::Vector<unsigned char> sortingVec, size_t elemPerPx) unsigned char median_kernel_vector(skepu::Region2D<unsigned char> image, skepu::Vector<unsigned char> sortingVec, size_t elemPerPx)
......
...@@ -24,6 +24,10 @@ with shared (critical section) or distributed work pool. ...@@ -24,6 +24,10 @@ with shared (critical section) or distributed work pool.
## Lab 2 ## Lab 2
## Lab 3
#### Question 1.1: Why does SkePU have a "fused" MapReduce when there already are separate Map and Reduce skeletons? Hint: Think about memory access patterns. #### Question 1.1: Why does SkePU have a "fused" MapReduce when there already are separate Map and Reduce skeletons? Hint: Think about memory access patterns.
If you use Map and Reduce in a fused variant, you only have to access the shared memory vector once, and load each element to the local cache to that processor. If you use Map and Reduce in a fused variant, you only have to access the shared memory vector once, and load each element to the local cache to that processor.
...@@ -41,10 +45,10 @@ Especially for OpenCL, the bottleneck is loading the data from the CPU to the GP ...@@ -41,10 +45,10 @@ Especially for OpenCL, the bottleneck is loading the data from the CPU to the GP
#### Question 2.1: Which version of the averaging filter (unified, separable) is the most efficient? Why? #### Question 2.1: Which version of the averaging filter (unified, separable) is the most efficient? Why?
#### Question 3.1: In data-parallel skeletons like MapOverlap, all elements are processed independently of each other. Is this a good fit for the median filter? Why/why not? #### Question 3.1: In data-parallel skeletons like MapOverlap, all elements are processed independently of each other. Is this a good fit for the median filter? Why/why not?
Could be more efficient if the current pixel checked its neighbours instead of processing it independently. With median filtering, large areas of almost the same color appears.
#### Question 3.2: Describe the sequence of instructions executed in your user-function. Is it data dependent? What does this mean for e.g., automatic vectorization, or the GPU backend? #### Question 3.2: Describe the sequence of instructions executed in your user-function. Is it data dependent? What does this mean for e.g., automatic vectorization, or the GPU backend?
Add the elements of the defined region to a array with predefined size. Sort the elements in the array and extract the element in the middle, the median and return. The bubblesort is data dependent, which means it cannot be parallelized.
## Lab 3
## Lab 4 ## Lab 4
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment