[CUDA] The problem about writing video card memory.

Source: Internet
Author: User

Today, I tried to implement FFT using cuda, and encountered a problem. If you call the cufft library directly, the memory copy-to-data processing time is about. However, it is said that cufft is not the most efficient, so I want to exercise it myself.

 

My idea is to map each row of two-dimensional data to a block, and each vertex is a thread.

First, copy the data to the global memory of the video card, and then copy the data to the shared memory of each block, because reading global memory will occupy more instruction cycles.

The next step is to process this shared memory, but it will be very slow every time you write it. Later, I carefully read the part of the bank conflict and staggered the memory corresponding to the adjacent thread for storage, which is much better, however, although this only includes one-dimensional fft (without matrix transpose or another one-dimensional transformation), it still takes about the same time as the cufft library.

 

Check carefully and find that the percentage of time occupied by writing memory is large, and you do not know how to shorten the time.

_ Global __< br/> void FFT_2D_Radix2 (DATA_TYPE * dg_buffer, int N) <br/>{< br/> int tid, rev, pos, pre, stride = 33; <br/> tid = threadIdx. x; <br/> rev = bit_reverse3 (tid, tail_zero_nums (N); <br/> _ shared _ DATA_TYPE s_DataR [MATRIX_SIZE]; // 512*4 = 2kB <br/> _ shared _ DATA_TYPE s_DataI [MATRIX_SIZE]; // 512*4 = 2kB <br/> _ shared _ DATA_TYPE s_CosTable [MATRIX_SIZE]; // 512*4 = 2kB <br/> _ shared _ DATA_TYPE s_SinTable [MATRIX_SIZE]; // 512*4 = 2kB </p> <p> pos = tid * stride % MATRIX_SIZE; <br/> s_DataR [pos] = dg_buffer [blockIdx. x * BLOCK_SIZE + rev]; <br/> s_DataI [pos] = dg_buffer [N * N + blockIdx. x * BLOCK_SIZE + rev]; </p> <p> float theta = GV_2PI/N; <br/> s_SinTable [pos] = _ sinf (theta * tid ); <br/> s_CosTable [pos] = _ cosf (theta * tid); <br/> _ syncthreads (); </p> <p> int step, w; </p> <p> for (step = 1; step <N; step = step * 2) <br/> {<br/> if (tid & step) <br/>{< br/> w = (tid & (step-1) * stride % MATRIX_SIZE; <br/> DATA_TYPE tempR = s_DataR [pos] * s_CosTable [w] + s_DataI [pos] * s_SinTable [w]; <br/> DATA_TYPE tempI = s_DataI [pos] * s_CosTable [w]-s_DataR [pos] * s_SinTable [w]; <br/> pre = (tid-step) * stride % MATRIX_SIZE; </p> <p> s_DataR [pos] = s_DataR [pre]-tempR; <br/> s_DataI [pos] = s_DataI [pre]-tempI; <br/> s_DataR [pre] + = tempR; <br/> s_DataI [pre] + = tempI; /**/<br/>}< br/> _ syncthreads (); <br/>}</p> <p>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.