<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en-us" xml:lang="en-us"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta> <meta http-equiv="X-UA-Compatible" content="IE=edge"></meta> <meta name="copyright" content="(C) Copyright 2005"></meta> <meta name="DC.rights.owner" content="(C) Copyright 2005"></meta> <meta name="DC.Type" content="cuda_reference"></meta> <meta name="DC.Title" content="Stream synchronization behavior"></meta> <meta name="DC.Format" content="XHTML"></meta> <meta name="DC.Identifier" content="stream-sync-behavior"></meta> <link rel="stylesheet" type="text/css" href="../common/formatting/commonltr.css"></link> <link rel="stylesheet" type="text/css" href="../common/formatting/site.css"></link> <title>CUDA Runtime API :: CUDA Toolkit Documentation</title> <!--[if lt IE 9]> <script src="../common/formatting/html5shiv-printshiv.min.js"></script> <![endif]--> <script type="text/javascript" charset="utf-8" src="../common/scripts/tynt/tynt.js"></script> <script type="text/javascript" charset="utf-8" src="../common/formatting/jquery.min.js"></script> <script type="text/javascript" charset="utf-8" src="../common/formatting/jquery.ba-hashchange.min.js"></script> <script type="text/javascript" charset="utf-8" src="../common/formatting/jquery.scrollintoview.min.js"></script> <script type="text/javascript" src="../search/htmlFileList.js"></script> <script type="text/javascript" src="../search/htmlFileInfoList.js"></script> <script type="text/javascript" src="../search/nwSearchFnt.min.js"></script> <script type="text/javascript" src="../search/stemmers/en_stemmer.min.js"></script> <script type="text/javascript" src="../search/index-1.js"></script> <script type="text/javascript" src="../search/index-2.js"></script> <script type="text/javascript" src="../search/index-3.js"></script> <link rel="canonical" href="http://docs.nvidia.com/cuda/cuda-runtime-api/index.html"></link> <link rel="stylesheet" type="text/css" href="../common/formatting/qwcode.highlight.css"></link> </head> <body> <header id="header"><span id="company">NVIDIA</span><span id="site-title">CUDA Toolkit Documentation</span><form id="search" method="get" action="search"> <input type="text" name="search-text"></input><fieldset id="search-location"> <legend>Search In:</legend> <label><input type="radio" name="search-type" value="site"></input>Entire Site</label> <label><input type="radio" name="search-type" value="document"></input>Just This Document</label></fieldset> <button type="reset">clear search</button> <button id="submit" type="submit">search</button></form> </header> <div id="site-content"> <nav id="site-nav"> <div class="category closed"><a href="../index.html" title="The root of the site.">CUDA Toolkit v6.5</a></div> <div class="category"><a href="index.html" title="CUDA Runtime API">CUDA Runtime API</a></div> <ul> <li> <div class="section-link"><a href="api-sync-behavior.html#api-sync-behavior">1. API synchronization behavior </a></div> </li> <li> <div class="section-link"><a href="stream-sync-behavior.html#stream-sync-behavior">2. Stream synchronization behavior</a></div> </li> <li> <div class="section-link"><a href="modules.html#modules">3. Modules</a></div> <ul> <li> <div class="section-link"><a href="group__CUDART__DEVICE.html#group__CUDART__DEVICE">3.1. Device Management</a></div> </li> <li> <div class="section-link"><a href="group__CUDART__THREAD__DEPRECATED.html#group__CUDART__THREAD__DEPRECATED">3.2. Thread Management [DEPRECATED]</a></div> </li> <li> <div class="section-link"><a href="group__CUDART__ERROR.html#group__CUDART__ERROR">3.3. Error Handling</a></div> </li> <li> <div class="section-link"><a href="group__CUDART__STREAM.html#group__CUDART__STREAM">3.4. Stream Management</a></div> </li> <li> <div class="section-link"><a href="group__CUDART__EVENT.html#group__CUDART__EVENT">3.5. Event Management</a></div> </li> <li> <div class="section-link"><a href="group__CUDART__EXECUTION.html#group__CUDART__EXECUTION">3.6. Execution Control</a></div> </li> <li> <div class="section-link"><a href="group__CUDART__OCCUPANCY.html#group__CUDART__OCCUPANCY">3.7. Occupancy</a></div> </li> <li> <div class="section-link"><a href="group__CUDART__MEMORY.html#group__CUDART__MEMORY">3.8. Memory Management</a></div> </li> <li> <div class="section-link"><a href="group__CUDART__UNIFIED.html#group__CUDART__UNIFIED">3.9. Unified Addressing</a></div> </li> <li> <div class="section-link"><a href="group__CUDART__PEER.html#group__CUDART__PEER">3.10. Peer Device Memory Access</a></div> </li> <li> <div class="section-link"><a href="group__CUDART__OPENGL.html#group__CUDART__OPENGL">3.11. OpenGL Interoperability</a></div> </li> <li> <div class="section-link"><a href="group__CUDART__OPENGL__DEPRECATED.html#group__CUDART__OPENGL__DEPRECATED">3.12. OpenGL Interoperability [DEPRECATED]</a></div> </li> <li> <div class="section-link"><a href="group__CUDART__D3D9.html#group__CUDART__D3D9">3.13. Direct3D 9 Interoperability</a></div> </li> <li> <div class="section-link"><a href="group__CUDART__D3D9__DEPRECATED.html#group__CUDART__D3D9__DEPRECATED">3.14. Direct3D 9 Interoperability [DEPRECATED]</a></div> </li> <li> <div class="section-link"><a href="group__CUDART__D3D10.html#group__CUDART__D3D10">3.15. Direct3D 10 Interoperability</a></div> </li> <li> <div class="section-link"><a href="group__CUDART__D3D10__DEPRECATED.html#group__CUDART__D3D10__DEPRECATED">3.16. Direct3D 10 Interoperability [DEPRECATED]</a></div> </li> <li> <div class="section-link"><a href="group__CUDART__D3D11.html#group__CUDART__D3D11">3.17. Direct3D 11 Interoperability</a></div> </li> <li> <div class="section-link"><a href="group__CUDART__D3D11__DEPRECATED.html#group__CUDART__D3D11__DEPRECATED">3.18. Direct3D 11 Interoperability [DEPRECATED]</a></div> </li> <li> <div class="section-link"><a href="group__CUDART__VDPAU.html#group__CUDART__VDPAU">3.19. VDPAU Interoperability</a></div> </li> <li> <div class="section-link"><a href="group__CUDART__INTEROP.html#group__CUDART__INTEROP">3.20. Graphics Interoperability</a></div> </li> <li> <div class="section-link"><a href="group__CUDART__TEXTURE.html#group__CUDART__TEXTURE">3.21. Texture Reference Management</a></div> </li> <li> <div class="section-link"><a href="group__CUDART__SURFACE.html#group__CUDART__SURFACE">3.22. Surface Reference Management</a></div> </li> <li> <div class="section-link"><a href="group__CUDART__TEXTURE__OBJECT.html#group__CUDART__TEXTURE__OBJECT">3.23. Texture Object Management</a></div> </li> <li> <div class="section-link"><a href="group__CUDART__SURFACE__OBJECT.html#group__CUDART__SURFACE__OBJECT">3.24. Surface Object Management</a></div> </li> <li> <div class="section-link"><a href="group__CUDART____VERSION.html#group__CUDART____VERSION">3.25. Version Management</a></div> </li> <li> <div class="section-link"><a href="group__CUDART__HIGHLEVEL.html#group__CUDART__HIGHLEVEL">3.26. C++ API Routines</a></div> </li> <li> <div class="section-link"><a href="group__CUDART__DRIVER.html#group__CUDART__DRIVER">3.27. Interactions with the CUDA Driver API</a></div> </li> <li> <div class="section-link"><a href="group__CUDART__PROFILER.html#group__CUDART__PROFILER">3.28. Profiler Control</a></div> </li> <li> <div class="section-link"><a href="group__CUDART__TYPES.html#group__CUDART__TYPES">3.29. Data types used by CUDA Runtime</a></div> </li> </ul> </li> <li> <div class="section-link"><a href="annotated.html#annotated">4. Data Structures</a></div> <ul> <li> <div class="section-link"><a href="class____cudaOccupancyB2DHelper.html#class____cudaOccupancyB2DHelper">4.1. __cudaOccupancyB2DHelper</a></div> </li> <li> <div class="section-link"><a href="structcudaChannelFormatDesc.html#structcudaChannelFormatDesc">4.2. cudaChannelFormatDesc</a></div> </li> <li> <div class="section-link"><a href="structcudaDeviceProp.html#structcudaDeviceProp">4.3. cudaDeviceProp</a></div> </li> <li> <div class="section-link"><a href="structcudaExtent.html#structcudaExtent">4.4. cudaExtent</a></div> </li> <li> <div class="section-link"><a href="structcudaFuncAttributes.html#structcudaFuncAttributes">4.5. cudaFuncAttributes</a></div> </li> <li> <div class="section-link"><a href="structcudaIpcEventHandle__t.html#structcudaIpcEventHandle__t">4.6. cudaIpcEventHandle_t</a></div> </li> <li> <div class="section-link"><a href="structcudaIpcMemHandle__t.html#structcudaIpcMemHandle__t">4.7. cudaIpcMemHandle_t</a></div> </li> <li> <div class="section-link"><a href="structcudaMemcpy3DParms.html#structcudaMemcpy3DParms">4.8. cudaMemcpy3DParms</a></div> </li> <li> <div class="section-link"><a href="structcudaMemcpy3DPeerParms.html#structcudaMemcpy3DPeerParms">4.9. cudaMemcpy3DPeerParms</a></div> </li> <li> <div class="section-link"><a href="structcudaPitchedPtr.html#structcudaPitchedPtr">4.10. cudaPitchedPtr</a></div> </li> <li> <div class="section-link"><a href="structcudaPointerAttributes.html#structcudaPointerAttributes">4.11. cudaPointerAttributes</a></div> </li> <li> <div class="section-link"><a href="structcudaPos.html#structcudaPos">4.12. cudaPos</a></div> </li> <li> <div class="section-link"><a href="structcudaResourceDesc.html#structcudaResourceDesc">4.13. cudaResourceDesc</a></div> </li> <li> <div class="section-link"><a href="structcudaResourceViewDesc.html#structcudaResourceViewDesc">4.14. cudaResourceViewDesc</a></div> </li> <li> <div class="section-link"><a href="structcudaTextureDesc.html#structcudaTextureDesc">4.15. cudaTextureDesc</a></div> </li> <li> <div class="section-link"><a href="structsurfaceReference.html#structsurfaceReference">4.16. surfaceReference</a></div> </li> <li> <div class="section-link"><a href="structtextureReference.html#structtextureReference">4.17. textureReference</a></div> </li> </ul> </li> <li> <div class="section-link"><a href="functions.html#functions">5. Data Fields</a></div> </li> <li> <div class="section-link"><a href="deprecated.html#deprecated">6. Deprecated List</a></div> </li> <li> <div class="section-link"><a href="notices-header.html#notices-header">Notices</a></div> <ul></ul> </li> </ul> </nav> <div id="resize-nav"></div> <nav id="search-results"> <h2>Search Results</h2> <ol></ol> </nav> <div id="contents-container"> <div id="breadcrumbs-container"> <div id="breadcrumbs"><a href="api-sync-behavior.html" shape="rect">< Previous</a> | <a href="modules.html" shape="rect">Next ></a></div> <div id="release-info">CUDA Runtime API (<a href="../../pdf/CUDA_Runtime_API.pdf">PDF</a>) - v6.5 (<a href="https://developer.nvidia.com/cuda-toolkit-archive">older</a>) - Last updated August 1, 2014 - <a href="mailto:cudatools@nvidia.com?subject=CUDA Toolkit Documentation Feedback: CUDA Runtime API">Send Feedback</a> - <span class="st_facebook"></span><span class="st_twitter"></span><span class="st_linkedin"></span><span class="st_reddit"></span><span class="st_slashdot"></span><span class="st_tumblr"></span><span class="st_sharethis"></span></div> </div> <article id="contents"> <div class="topic nested1" id="stream-sync-behavior"><a name="stream-sync-behavior" shape="rect"> <!-- --></a><h2 class="topictitle2">2. Stream synchronization behavior</h2> <div class="body refbody"> <div class="section" id="stream-sync-behavior__null-stream"><a name="stream-sync-behavior__null-stream" shape="rect"> <!-- --></a><h2 class="title sectiontitle">NULL stream</h2> <p class="p"> The NULL stream or stream 0 is an implicit stream which synchronizes with all other streams in the same <samp class="ph codeph">CUcontext</samp> except for non-blocking streams, described below. (For applications using the runtime APIs only, there will be one context per device.) When an action is taken in the NULL stream such as a kernel launch or <samp class="ph codeph">cudaStreamWaitEvent()</samp>, the NULL stream first waits on all blocking streams, the action is queued in the NULL stream, and then all blocking streams wait on the NULL stream. </p> <p class="p"> For example, the following code launches a kernel <samp class="ph codeph">k_1</samp> in stream <samp class="ph codeph">s</samp>, then <samp class="ph codeph">k_2</samp> in the NULL stream, then <samp class="ph codeph">k_3</samp> in stream <samp class="ph codeph">s</samp>: </p><pre xml:space="preserve"> k_1<<<1, 1, 0, s>>>(); k_2<<<1, 1>>>(); k_3<<<1, 1, 0, s>>>();</pre><p class="p"> The resulting behavior is that <samp class="ph codeph">k_2</samp> will block on <samp class="ph codeph">k_1</samp> and <samp class="ph codeph">k_3</samp> will block on <samp class="ph codeph">k_2</samp>. </p> <p class="p"> Actions are added in the NULL stream by passing <samp class="ph codeph">0</samp> as the <samp class="ph codeph">cudaStream_t</samp> parameter of applicable APIs, or by calling the corresponding synchronous APIs which do not take the <samp class="ph codeph">cudaStream_t</samp> parameter. The NULL stream is also the default for kernel launches if a stream is not specified. </p> <p class="p"> Non-blocking streams which do not synchronize with the NULL stream can be created using the <samp class="ph codeph">cudaStreamNonBlocking</samp> flag with the stream creation APIs. </p> </div> </div> </div> <hr id="contents-end"></hr> </article> </div> </div> <script language="JavaScript" type="text/javascript" charset="utf-8" src="../common/formatting/common.min.js"></script> <script language="JavaScript" type="text/javascript" charset="utf-8" src="../common/scripts/google-analytics/google-analytics-write.js"></script> <script language="JavaScript" type="text/javascript" charset="utf-8" src="../common/scripts/google-analytics/google-analytics-tracker.js"></script> <script type="text/javascript">var switchTo5x=true;</script><script type="text/javascript" src="http://w.sharethis.com/button/buttons.js"></script><script type="text/javascript">stLight.options({publisher: "998dc202-a267-4d8e-bce9-14debadb8d92", doNotHash: false, doNotCopy: false, hashAddressBar: false});</script></body> </html>