2. performWork<<<2, 4>>>()
GPU
DATA
GPUGPU
Often there are more data
elements than there are
threads in the grid
0 1 2 3 0 1 2 3
0
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
3. performWork<<<2, 4>>>()
GPU
DATA
GPUGPU
0 1 2 3 0 1 2 3
0
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
In such scenarios threads
cannot work on only one
element
5. performWork<<<2, 4>>>()
GPU
DATA
GPUGPU
0 1 2 3 0 1 2 3
0
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
One way to address this
programmatically is with a
grid-stride loop
6. performWork<<<2, 4>>>()
GPU
DATA
GPUGPU
0 1 2 3 0 1 2 3
0
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
In a grid-stride loop, the
thread’s first element is
calculated as usual, with
threadIdx.x +
blockIdx.x *
blockDim.x
7. performWork<<<2, 4>>>()
GPU
DATA
GPUGPU
0 1 2 3 0 1 2 3
0
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
The thread then strides
forward by the number of
threads in the grid
(blockDim.x *
gridDim.x), in this case
8
8. performWork<<<2, 4>>>()
GPU
DATA
GPUGPU
0 1 2 3 0 1 2 3
0
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
It continues in this way until
its data index is greater than
the number of data
elements
9. performWork<<<2, 4>>>()
GPU
DATA
GPUGPU
0 1 2 3 0 1 2 3
0
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
It continues in this way until
its data index is greater than
the number of data
elements
10. performWork<<<2, 4>>>()
GPU
DATA
GPUGPU
0 1 2 3 0 1 2 3
0
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
With all threads working in
this way, all elements are
covered
11. performWork<<<2, 4>>>()
GPU
DATA
GPUGPU
0 1 2 3 0 1 2 3
0
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
With all threads working in
this way, all elements are
covered
12. performWork<<<2, 4>>>()
GPU
DATA
GPUGPU
0 1 2 3 0 1 2 3
0
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
With all threads working in
this way, all elements are
covered
13. performWork<<<2, 4>>>()
GPU
DATA
GPUGPU
0 1 2 3 0 1 2 3
0
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
With all threads working in
this way, all elements are
covered
14. performWork<<<2, 4>>>()
GPU
DATA
GPUGPU
0 1 2 3 0 1 2 3
0
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
With all threads working in
this way, all elements are
covered
15. performWork<<<2, 4>>>()
GPU
DATA
GPUGPU
0 1 2 3 0 1 2 3
0
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
With all threads working in
this way, all elements are
covered
16. performWork<<<2, 4>>>()
GPU
DATA
GPUGPU
0 1 2 3 0 1 2 3
0
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
With all threads working in
this way, all elements are
covered
17. performWork<<<2, 4>>>()
GPU
DATA
GPUGPU
0 1 2 3 0 1 2 3
0
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
With all threads working in
this way, all elements are
covered
18. performWork<<<2, 4>>>()
GPU
DATA
GPUGPU
0 1 2 3 0 1 2 3
0
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
With all threads working in
this way, all elements are
covered