Changes

Jump to: navigation, search

TudyBert

1,527 bytes removed, 14:29, 19 April 2013
Assignment 3
}
 
I enjoyed parallelizing this program and really wish I could have figured out the CERN project. To make myself feel better I also parallelized the rotate image method.
Here's the final optimized code for rotating an image around its centre:
 
 
<div>
__global__ <span style='color:#7f0055; font-weight:bold; '>void</span> cudaRotateImage(<span style='color:#7f0055; font-weight:bold; '>int</span> *result, <span style='color:#7f0055; font-weight:bold; '>const</span> <span style='color:#7f0055; font-weight:bold; '>int</span> *work, <span style='color:#7f0055; font-weight:bold; '>int</span> ni, <span style='color:#7f0055; font-weight:bold; '>int</span> nj, <span style='color:#7f0055; font-weight:bold; '>float</span> rads)
 
{
 
<span style='color:#7f0055; font-weight:bold; '>int</span> r0, c0;
 
<span style='color:#7f0055; font-weight:bold; '>int</span> r1, c1;
 
<span style='color:#7f0055; font-weight:bold; '>int</span> jdx = blockIdx.x * blockDim.x + threadIdx.x;
 
<span style='color:#7f0055; font-weight:bold; '>int</span> idx = blockIdx.y * blockDim.y + threadIdx.y;
 
<span style='color:#7f0055; font-weight:bold; '>int</span> k = idx + jdx * blockDim.x * gridDim.x;
 
r0 = ni / 2;
 
c0 = nj / 2;
 
 
 
r1 = (<span style='color:#7f0055; font-weight:bold; '>int</span>) (r0 + ((idx - r0) * <span style='color:#7f0055; font-weight:bold; '>cos</span>(rads)) - ((jdx - c0) * <span style='color:#7f0055; font-weight:bold; '>sin</span>(rads)));
 
c1 = (<span style='color:#7f0055; font-weight:bold; '>int</span>) (c0 + ((idx - r0) * <span style='color:#7f0055; font-weight:bold; '>sin</span>(rads)) + ((jdx - c0) * <span style='color:#7f0055; font-weight:bold; '>cos</span>(rads)));
 
 
<span style='color:#7f0055; font-weight:bold; '>if</span>(!(r1 >= ni || r1 &lt; 0 || c1 >=nj || c1 &lt; 0))
 
{
 
result[c1 * nj + r1] = work[k];
 
}
}<I was going to paste the code snippet here but I'm getting frustrated with the formatting. Why is it so difficult to nicely format code on a Wiki? [http:/div>/pastebin.com/ZZV9KRJN Here] it is.
1
edit

Navigation menu