The quiz 1 of Intro to Parallel Program
来源:互联网 发布:手机删除软件残留 编辑:程序博客网 时间:2024/05/16 17:50
Homework 1
Color to Greyscale Conversion
A common way to represent color images isknown as RGBA - the color is specified by how much Red, Green, and Blue is init. The 'A' stands for Alpha and is used for transparency; it will be ignoredin this homework.
Each channel Red, Blue, Green, and Alpha isrepresented by one byte. Since we are using one byte for each color there are256 different possible values for each color. This means we use 4 bytes per pixel.
Greyscale images are represented by asingle intensity value per pixel which is one byte in size.
To convert an image from color to grayscaleone simple method is to set the intensity to the average of the RGBchannels. But we will use a moresophisticated method that takes into account how the eye perceives color andweights the channels unequally.
The eye responds most strongly to greenfollowed by red and then blue. The NTSC (National Television System Committee)recommends the following formula for color to greyscale conversion:
I = .299f * R + .587f * G + .114f * B
Notice the trailing f's on the numberswhich indicate that they are single precision floating point constants and notdouble precision constants.
You should fill in the kernel as well asset the block and grid sizes so that the entire image is processed.
At first, we need to figure out thetransform from 2D matrix to 1D vector. For example, x represents the row ofmatrix, y represents the column of matrix. Then (x, y) is x * total row +y = y* total cols + x.
Then calculate the new pixels.
int r = threadIdx.x +blockIdx.x*blockDim.x;
int c = threadIdx.y +blockIdx.y*blockDim.y;
int index = r*numCols + c; (c*numRows+r)
greyImage [index] =rgbaImage[index].x*.299f + rgbaImage[index].y*.587f + rgbaImage[index].z*.114f;
About the size of block and grid.
We could defind the blockSideLen at first.
int blockSideLen = 32;
const dim3 blockSize(blockSideLen,blockSideLen, 1); //TODO
const dim3 gridSize( numRows/blockSideLen+1, numCols/blockSideLen +1, 1); //TODO
threadIdx: thread within block
threadIdx.x, threadIdx.y, threadIdx.z
BlockDim: the size of block
How many threads are there in this blockalong x,y,z
BlockIdx: Similar to thread.
GridDim: Similar to block
rgba_to_greyscale<<<gridSize,blockSize>>>(d_rgbaImage, d_greyImage, numRows, numCols);
cudaDeviceSynchronize();checkCudaErrors(cudaGetLastError());
Thanks to the people who are discussing in forums.
Note:
记录一下threadIdx之类供忘记后回忆:
threadIdx: thread within block: threadIdx.x, threadIdx.y, threadIdx,z
blockDim:the size of block. how many threads are there in one block (along x, y , z). it is actually like threadIdx.
blockIdxL block within grid. blockIdx.x, blockIdx.y, blockIdx.z
gridDim. Size of grid (how many blocks are there in one grid (along x, y , z). it is actually like blockIdx.)
- The quiz 1 of Intro to Parallel Program
- Lesson 2: Udacity Intro to Parallel Programming
- Quiz: The basics of C
- An intro to modern OpenGL. Chapter 1: The Graphics Pipelinehttp://duriansoftware.com/joe/An-intro-to
- A function to retrieve the directory of a program
- Code to print the byte representation of program objects
- The quick intro to libipq
- Parallel Reduction --- (0) Intro
- How to craw the Info of BiliBIli with python in Parallel
- How to craw the Info of BiliBIli with python in Parallel and MySQL storage
- Think Python:Chapter 1:The way of the program 笔记
- Write a program that prints the numbers from 1 to 100,but for multiples of three print “Fizz” inste
- Brief Intro to Strings of Foundation Framework
- Brief Intro to Collections of Foundation Frameworks
- Brief Intro to Notifications of Foundation Framework
- Brief Intro to NSError of Foundation Framework
- Brief Intro to NSException of Foundation Framework
- The intro of .NET Compact Framework
- 51Nod 1432 独木舟
- 正则表达式语法
- *(a + i) = temp->data;、*(a + i) = temp->data;
- How To Install Visual Studio Code On Ubuntu
- dbmvlwgh
- The quiz 1 of Intro to Parallel Program
- 51Nod-2006-飞行员配对(二分图最大匹配)
- Mysql5.7解压版的安装和卸载及常见问题
- java笔记(五):多线程--Thread和Runnable
- 回归算法注意点
- 搞科研----摸着石头过河
- Redhat 安装部署 Vsftpd
- POJ2247 HDU1058 UVA443 ZOJ1095 Humble Numbers【数学计算+打表】
- xilinx xapp 列表