同步操作将从 Gitee 极速下载/cpp-taskflow 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
<?xml version='1.0' encoding='UTF-8' standalone='no'?><doxygen xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="compound.xsd" version="1.8.14"><compounddef id="SingleTaskCUDA" kind="page"><compoundname>SingleTaskCUDA</compoundname><title>Single Task</title><tableofcontents/><briefdescription></briefdescription><detaileddescription><para><ref refid="classtf_1_1cudaFlow" kindref="compound">tf::cudaFlow</ref> provides a template method, <ref refid="classtf_1_1cudaFlow_1ac2906cb0002fc411a983d100a3d58d62" kindref="member">tf::cudaFlow::single_task</ref>, for creating a task to run the given callable using a single kernel thread.</para><sect1 id="SingleTaskCUDA_1CUDASingleTaskIncludeTheHeader"><title>Include the Header</title><para>You need to include the header file, <computeroutput>taskflow/cuda/algorithm/for_each.hpp</computeroutput>, for creating a single-threaded task.</para></sect1><sect1 id="SingleTaskCUDA_1SingleTaskCUDASingleTask"><title>Run a Task with a Single Thread</title><para>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 <computeroutput>gpu_variable</computeroutput> to 1.</para><para><programlisting filename=".cpp"><codeline><highlight class="keywordtype">int</highlight><highlight class="normal">*<sp/>gpu_variable;</highlight></codeline><codeline><highlight class="normal">cudaMalloc(&gpu_variable,<sp/></highlight><highlight class="keyword">sizeof</highlight><highlight class="normal">(</highlight><highlight class="keywordtype">int</highlight><highlight class="normal">));</highlight></codeline><codeline><highlight class="normal"><ref refid="classtf_1_1Task" kindref="compound">tf::Task</ref><sp/>=<sp/>taskflow.<ref refid="classtf_1_1FlowBuilder_1a60d7a666cab71ecfa3010b2efb0d6b57" kindref="member">emplace</ref>([&]<sp/>(<ref refid="classtf_1_1cudaFlow" kindref="compound">tf::cudaFlow</ref>&<sp/>cf)<sp/>{</highlight></codeline><codeline><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>create<sp/>a<sp/>single<sp/>task<sp/>to<sp/>set<sp/>the<sp/>gpu_variable<sp/>to<sp/>1</highlight><highlight class="normal"></highlight></codeline><codeline><highlight class="normal"><sp/><sp/><ref refid="classtf_1_1cudaTask" kindref="compound">tf::cudaTask</ref><sp/>set_par<sp/>=<sp/>cf.<ref refid="classtf_1_1cudaFlow_1ac2906cb0002fc411a983d100a3d58d62" kindref="member">single_task</ref>([gpu_variable]<sp/>__device__<sp/>()<sp/>{</highlight></codeline><codeline><highlight class="normal"><sp/><sp/><sp/><sp/>*gpu_variable<sp/>=<sp/>1;</highlight></codeline><codeline><highlight class="normal"><sp/><sp/>})</highlight></codeline><codeline><highlight class="normal"><sp/><sp/></highlight></codeline><codeline><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>create<sp/>two<sp/>kernel<sp/>tasks<sp/>that<sp/>need<sp/>access<sp/>to<sp/>gpu_variable</highlight><highlight class="normal"></highlight></codeline><codeline><highlight class="normal"><sp/><sp/><ref refid="classtf_1_1cudaTask" kindref="compound">tf::cudaTask</ref><sp/>kernel1<sp/>=<sp/>cf.<ref refid="classtf_1_1cudaFlow_1aa6e734462c8b8d922f44e621f94b104c" kindref="member">kernel</ref>(grid1,<sp/>block1,<sp/>shm1,<sp/>my_kernel_1,<sp/>...);</highlight></codeline><codeline><highlight class="normal"><sp/><sp/><ref refid="classtf_1_1cudaTask" kindref="compound">tf::cudaTask</ref><sp/>kernel2<sp/>=<sp/>cf.<ref refid="classtf_1_1cudaFlow_1aa6e734462c8b8d922f44e621f94b104c" kindref="member">kernel</ref>(grid2,<sp/>block2,<sp/>shm2,<sp/>my_kernel_2,<sp/>...);</highlight></codeline><codeline><highlight class="normal"></highlight></codeline><codeline><highlight class="normal"><sp/><sp/>set_par.<ref refid="classtf_1_1cudaTask_1abdd68287ec4dff4216af34d1db44d1b4" kindref="member">precede</ref>(kernel1,<sp/>kernel2);</highlight></codeline><codeline><highlight class="normal">});</highlight></codeline></programlisting></para><para>Since the callable runs on GPU, it must be declared with a <computeroutput>__device__</computeroutput> specifier.</para></sect1><sect1 id="SingleTaskCUDA_1SingleTaskCUDAMiscellaneousItems"><title>Miscellaneous Items</title><para>The single-task algorithm is also available in <ref refid="classtf_1_1cudaFlowCapturer_1ac944c7d20056e0633ef84f1a25b52296" kindref="member">tf::cudaFlowCapturer::single_task</ref>. </para></sect1></detaileddescription></compounddef></doxygen>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。