Open main menu

CDOT Wiki β

Changes

Three-Star

109 bytes removed, 15:43, 8 April 2018
Assignment 3
__global__ void rotateKernel(int* oldImage, int* newImage, int rows, int cols, float rads) {
//changed to coalesced access
'''int c''' = blockIdx.x * blockDim.x + threadIdx.x;
 
'''int r''' = blockIdx.y * blockDim.y + threadIdx.y;
int r0 = rows / 2;
 
int c0 = cols / 2;
 
float sinRads = sinf(rads);
 
float cosRads = cosf(rads);
 
/*__shared__ int s[ntpb * ntpb];
s[r * cols + c] = oldImage[r * cols + c];*/
if (r < rows && c < cols)
{
int r1 = (int)(r0 + ((r - r0) * cosRads) - ((c - c0) * sinRads));
 
int c1 = (int)(c0 + ((r - r0) * sinRads) + ((c - c0) * cosRads));
if (inBounds(r1, c1, rows, cols))
{
 
newImage[r1 * cols + c1] = oldImage[r * cols + c];
}
}
Using Coalesced Memory (changed matrix access from column to row)
 
{|
|
122
edits