Seven Weapons 2: replacing global memory reading with texture

Source: Internet
Author: User

Our algorithms include multiple kernel. If we use two global memory to store input/output, it is a waste of time.

For a single kernel, computing can be used to hide the latency of global memory only when the calculation amount is large. If you simply extract a piece of data, perform an operation, and write it back, most of the time is wasted waiting for memory transfer.

At this time, texture can be used as the input. Of course, when writing data, it must be written to global memory.

 

// Declare texture and linear memory

Texture <...> intersrctex;

Texture <...> interdsttex;

 

Float * d_intersrcdata, * d_interdstdata;

 

// Init

Cudamallocpitch (void **) & d_intersrcdata, & pitch, ppl * sizeof (float), LPF );
Cudamallocpitch (void **) & d_interdstdata, & pitch, ppl * sizeof (float), LPF );

Cudabindtexture2d (0, intersrctex, d_intersrcdata, floattexdesc, PPL, LPF, pitch );
Cudabindtexture2d (0, interdsttex, d_interdstdata, floattexdesc, PPL, LPF, pitch );

 

_ Global _ void func1 (texture <...> inputtex, float * outdata)

{

......

}

 

_ Global _ void func2 (texture <...> inputtex, float * outdata)

{

......

}

 

// Call the different kernels like this way

Void main ()

{

Func1 (intersrctex, d_interdstdata );

Func2 (interdsttex, d_intersrcdata );

 

}

 

In this way, at least the read data can be faster.

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.