File: cuda_std_single_task.dox

package info (click to toggle)
taskflow 3.9.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 45,948 kB
  • sloc: cpp: 39,058; xml: 35,572; python: 12,935; javascript: 1,732; makefile: 59; sh: 16
file content (49 lines) | stat: -rw-r--r-- 1,166 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
namespace tf {

/** @page CUDASTDSingleTask Single %Task 

%Taskflow provides a standard template method for running a callable 
using a single GPU thread.

@tableofcontents

@section CUDASTDSingleTaskIncludeTheHeader Include the Header

You need to include the header file, `%taskflow/cuda/algorithm/for_each.hpp`, 
for creating a single-threaded task.

@code{.cpp}
#include <taskflow/cuda/algorithm/for_each.hpp>
@endcode

@section CUDASTDSingleTaskRunATaskWithASingleThread Run a Task with a Single Thread

You can launch a kernel with only one GPU thread running it,
which is handy when you want to set up a single or a few variables
that do not need multiple threads.
The following example creates a single-task kernel that sets a device variable
to @c 1.

@code{.cpp}
tf::cudaStream stream;
tf::cudaDefaultExecutionPolicy policy(stream);

// launch the single-task kernel asynchronously through the policy
tf::cuda_single_task(policy, [gpu_variable] __device__ () {
  *gpu_Variable = 1;
});

// wait for the kernel completes
stream.synchronize();
@endcode

Since the callable runs on GPU, it must be declared with a <tt>%__device__</tt> specifier.

*/
}