<p><ahref="classtf_1_1cudaFlow.html" class="m-doc">tf::<wbr/>cudaFlow</a> provides a template method, <ahref="classtf_1_1cudaFlow.html#ac2906cb0002fc411a983d100a3d58d62" class="m-doc">tf::<wbr/>cudaFlow::<wbr/>single_task</a>, for creating a task to run the given callable using a single kernel thread.</p><sectionid="CUDASingleTaskIncludeTheHeader"><h2><ahref="#CUDASingleTaskIncludeTheHeader">Include the Header</a></h2><p>You need to include the header file, <code>taskflow/cuda/algorithm/for_each.hpp</code>, for creating a single-threaded task.</p><preclass="m-code"><spanclass="cp">#include</span><spanclass="w"></span><spanclass="cpf"><taskflow/cuda/algorithm/for_each.hpp></span></pre></section><sectionid="SingleTaskCUDASingleTask"><h2><ahref="#SingleTaskCUDASingleTask">Run a Task with a Single Thread</a></h2><p>You can create a task to run a kernel function just once, i.e., using one GPU thread. This is handy when you want to set up a single or a few global variables that do not need multiple threads and will be used by multiple kernels afterwards. The following example creates a single-task kernel that sets a device variable to <code>1</code>.</p><preclass="m-code"><spanclass="kt">int</span><spanclass="o">*</span><spanclass="w"></span><spanclass="n">gpu_variable</span><spanclass="p">;</span>
<spanclass="n">stream</span><spanclass="p">.</span><spanclass="n">synchronize</span><spanclass="p">();</span></pre><p>Since the callable runs on GPU, it must be declared with a <code>__device__</code> specifier.</p></section><sectionid="SingleTaskCUDAMiscellaneousItems"><h2><ahref="#SingleTaskCUDAMiscellaneousItems">Miscellaneous Items</a></h2><p>The single-task algorithm is also available in <ahref="classtf_1_1cudaFlowCapturer.html#ac944c7d20056e0633ef84f1a25b52296" class="m-doc">tf::<wbr/>cudaFlowCapturer::<wbr/>single_task</a>.</p></section>
</div>
</div>
</div>
</article></main>
<divclass="m-doc-search" id="search">
<ahref="#!" onclick="return hideSearch()"></a>
<divclass="m-container">
<divclass="m-row">
<divclass="m-col-m-8 m-push-m-2">
<divclass="m-doc-search-header m-text m-small">
<div><spanclass="m-label m-default">Tab</span> / <spanclass="m-label m-default">T</span> to search, <spanclass="m-label m-default">Esc</span> to close</div>