About when to use Cudadevicesynchronize

Source: Internet
Author: User
transferred from: http://blog.csdn.net/mathgeophysics/article/details/19905935
When to call cudadevicesynchronize Why does we need cudadevicesynchronize (); In kernels with device-printf?

Although CUDA kernel launches is asynchronous, all gpu-related tasks placed in one stream (which is default behaviour) AR e executed sequentially.

So, for example,

Kernel1<<<x,y>>> (...); Kernel start execution, CPU continues to Next statement
Kernel2<<<x,y>>> (...); Kernel is placed in queue and would start after Kernel1 finishes, CPU continues to Next statement
cudamemcpy (...); CPU blocks until ememory is copied, memory copy starts only


and the second explanation for Google Chinese is less complete: which cases should use Cudadevicesynchronize (). -CSDN forum-csdn 
cudastreamsynchronize vs Cudadevicesynchronize vs cudathreadsynchronize

These is all barriers. Barriers prevent code execution beyond the barrier until some condition is met. Cudadevicesynchronize ()  halts execution in the cpu/host thread (that the cudadevicesynchronize is issued in) until T He GPUs have finished processing all previously requested cuda tasks (kernels, data copies, etc.) cudathreadsynchronize () &nb Sp;as you ' ve discovered, is just a deprecated version of cudadevicesynchronize. Deprecated just means that it still works for now, but it's recommended not the use it (use Cudadevicesynchronize instead) And in the future, it may become unsupported. But cudathreadsynchronize () and cudadevicesynchronize () is basically identical. Cudastreamsynchronize ()  is similar to the above of the functions, but it prevents further execution in the CPU host thre Ad until the GPU has finished processing all previously requested Cuda Tasks that were issued in the referenced Strea M. so cudastreamsynchronize () takes a stream ID as it' s only parameter. Cuda tasks issued in and streams may or may is complete when the CPU code execution continues beyond this barrier.

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.