-
Notifications
You must be signed in to change notification settings - Fork 105
/
Copy pathindex.html
582 lines (521 loc) · 18.8 KB
/
index.html
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../common-revealjs/css/reveal.css">
<link rel="stylesheet" href="../common-revealjs/css/theme/white.css">
<link rel="stylesheet" href="../common-revealjs/css/custom.css">
<script>
// This is needed when printing the slides to pdf
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = window.location.search.match( /print-pdf/gi ) ? '../common-revealjs/css/print/pdf.css' : '../common-revealjs/css/print/paper.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
</script>
<script>
// This is used to display the static images on each slide,
// See global-images in this html file and custom.css
(function() {
if(window.addEventListener) {
window.addEventListener('load', () => {
let slides = document.getElementsByClassName("slide-background");
if (slides.length === 0) {
slides = document.getElementsByClassName("pdf-page")
}
// Insert global images on each slide
for(let i = 0, max = slides.length; i < max; i++) {
let cln = document.getElementById("global-images").cloneNode(true);
cln.removeAttribute("id");
slides[i].appendChild(cln);
}
// Remove top level global images
let elem = document.getElementById("global-images");
elem.parentElement.removeChild(elem);
}, false);
}
})();
</script>
</head>
<body>
<div class="reveal">
<div class="slides">
<div id="global-images" class="global-images">
<img src="../common-revealjs/images/sycl_academy.png" />
<img src="../common-revealjs/images/sycl_logo.png" />
<img src="../common-revealjs/images/trademarks.png" />
</div>
<!--Slide 1-->
<section class="hbox">
<div class="hbox" data-markdown>
## Data and Dependencies
</div>
</section>
<!--Slide 2-->
<section class="hbox" data-markdown>
## Learning Objectives
* Learn about how to create dependencies between kernel functions
* Learn about how to move data between the host and device(s)
* Learn about the differences between the buffer/accessor and USM data management models
* Learn how to represent basic data flow graphs
</section>
<!--Slide 3-->
<section>
<div class="hbox" data-markdown>
#### Access/buffer and USM
</div>
<div class="container" data-markdown>
There are two ways to move data and create dependencies between kernel functions in SYCL
</div>
<div class="container">
<div class="col" data-markdown>
Buffer/accessor data movement model
<br/>
* Data dependencies analysis
* Implicit data movement
</div>
<div class="col" data-markdown>
USM data movement model
<br/>
* Manual chaining of dependencies
* Explicit data movement
</div>
</div>
</section>
<!--Slide 4-->
<section>
<div class="hbox" data-markdown>
#### Creating dependencies
</div>
<div class="container">
<div class="col" data-markdown>
![SYCL](../common-revealjs/images/data_dependency.png "SYCL")
</div>
<div class="col" data-markdown>
* Kernel A first writes to the data
* Kernel B then reads from and writes to the data
* This creates a read-after-write (RAW) relationship
* There must be a dependency created between Kernel A and Kernel B
</div>
</div>
</section>
<!--Slide 5-->
<section>
<div class="hbox" data-markdown>
#### Moving data
</div>
<div class="container">
<div class="col" data-markdown>
![SYCL](../common-revealjs/images/data_movement.png "SYCL")
</div>
<div class="col" data-markdown>
* Here both kernel functions are enqueued to the same device, in this case a GPU
* The data must be copied to the GPU before the Kernel A is executed
* The data must remain on the GPU for Kernel B to be executed
* The data must be copied back to the host after Kernel B has executed
</div>
</div>
</section>
<!--Slide 6-->
<section>
<div class="hbox" data-markdown>
#### Data flow
</div>
<div class="container">
<div class="col" data-markdown>
![SYCL](../common-revealjs/images/data_flow.png "SYCL")
</div>
<div class="col" data-markdown>
* Combining kernel function dependencies and the data movement dependencies we have a final data flow graph
* This graph defines the order in which all commands must execute in order to maintain consistency
* In more complex data flow graphs there may be multiple orderings which can achieve the same consistency
</div>
</div>
</section>
<!--Slide 7-->
<section>
<div class="hbox" data-markdown>
#### Data flow with buffers and accessors
</div>
<div class="container">
<div class="col">
<code class="code-100pc"><pre>
sycl::buffer buf {data, sycl::range{1024}};
gpuQueue.submit([&](sycl::handler &cgh) {
sycl::accessor acc {buf, cgh};
cgh.parallel_for<kernel_a>(sycl::range{1024},
[=](sycl::id<1> idx) {
acc[idx] = /* some computation */
});
});
gpuQueue.submit([&](sycl::handler &cgh) {
sycl::accessor acc{buf, cgh};
cgh.parallel_for<kernel_b>(sycl::range{1024},
[=](sycl::id<1> idx) {
acc[idx] = /* some computation */
});
});
gpuQueue.wait();
</code></pre>
</div>
<div class="col" data-markdown>
* The buffer/accessor data management model data model is descriptive
* Dependencies and data movement is inferred from the access requirements of command groups
* The SYCL runtime is responsible for guaranteeing that data dependencies and consistency are maintained
</div>
</div>
</section>
<!--Slide 8-->
<section>
<div class="hbox" data-markdown>
#### Data flow with buffers and accessors
</div>
<div class="container">
<div class="col">
<code class="code-100pc"><pre>
<mark>sycl::buffer buf {data, sycl::range{1024}};</mark>
gpuQueue.submit([&](sycl::handler &cgh) {
sycl::accessor acc {buf, cgh};
cgh.parallel_for<kernel_a>(sycl::range{1024},
[=](sycl::id<1> idx) {
acc[idx] = /* some computation */
});
});
gpuQueue.submit([&](sycl::handler &cgh) {
sycl::accessor acc {buf, cgh};
cgh.parallel_for<kernel_b>(sycl::range{1024},
[=](sycl::id<1> idx) {
acc[idx] = /* some computation */
});
});
gpuQueue.wait();
</code></pre>
</div>
<div class="col" data-markdown>
* A `buffer` object is responsible for managing data between the host and one or more devices
* It is also responsible for tracking dependencies on the data it manages
* It will also allocating memory and move data when necessary.
* Note that a `buffer` is lazy and will not allocate or move data until it is asked to
</div>
</div>
</section>
<!--Slide 9-->
<section>
<div class="hbox" data-markdown>
#### Data flow with buffers and accessors
</div>
<div class="container">
<div class="col">
<code class="code-100pc"><pre>
sycl::buffer buf {data, sycl::range{1024}};
gpuQueue.submit([&](sycl::handler &cgh) {
<mark>sycl::accessor acc{buf, cgh};</mark>
cgh.parallel_for<my_kernel>(sycl::range{1024},
[=](sycl::id<1> idx) {
acc[idx] = /* some computation */
});
});
gpuQueue.submit([&](sycl::handler &cgh) {
<mark>sycl::accessor acc{buf, cgh};</mark>
cgh.parallel_for<my_kernel>(sycl::range{1024},
[=](sycl::id<1> idx) {
acc[idx] = /* some computation */
});
});
gpuQueue.wait();
</code></pre>
</div>
<div class="col" data-markdown>
* An `accessor` object is responsible for describing data access requirements
* It describes what data a kernel function is accessing and how it is accessing it
* The `buffer` object uses this information to create infer dependencies and data movement
</div>
</div>
</section>
<!--Slide 10-->
<section>
<div class="hbox" data-markdown>
#### Data flow with buffers and accessors
</div>
<div class="container">
<div class="col">
<code class="code-100pc"><pre>
buf = sycl::buffer(data, sycl::range{1024});
gpuQueue.submit([&](sycl::handler &cgh) {
sycl::accessor acc {buf, <mark>cgh</mark>};
cgh.parallel_for<my_kernel>(sycl::range{1024},
[=](sycl::id<1> idx) {
acc[idx] = /* some computation */
});
});
gpuQueue.submit([&](sycl::handler &cgh) {
sycl::accessor acc {buf, <mark>cgh</mark>};
cgh.parallel_for<my_kernel>(sycl::range{1024},
[=](sycl::id<1> idx) {
acc[idx] = /* some computation */
});
});
gpuQueue.wait();
</code></pre>
</div>
<div class="col" data-markdown>
* Associating the `accessor` object with the `handler` connects the access dependency to the kernel function
* It also associates the access requirement with the device being targeted
</div>
</div>
</section>
<!--Slide 11-->
<section>
<div class="hbox" data-markdown>
#### Data flow with USM
</div>
<div class="container">
<div class="col">
<code class="code-100pc"><pre>
auto devicePtr =
sycl::malloc_device<int>(1024, gpuQueue);
auto e1 = gpuQueue.memcpy(devicePtr, data, sizeof(int));
auto e2 = gpuQueue.parallel_for<kernel_a>(
sycl::range{1024}, e1, [=](sycl::id<1> idx) {
devicePtr[idx] = /* some computation */
});
auto e3 = gpuQueue.parallel_for<kernel_b>(
sycl::range{1024}, e2, [=](sycl::id<1> idx) {
devicePtr[idx] = /* some computation */
});
auto e4 = gpuQueue.memcpy(data, devicePtr,
sizeof(int), e3);
e4.wait();
sycl::free(devicePtr, gpuQueue);
</code></pre>
</div>
<div class="col" data-markdown>
* The USM data management model data model is prescriptive
* Dependencies are defined explicitly by passing around `event` objects
* Data movement is performed explicitly by enqueuing `memcpy` operations
* The user is responsible for ensuring data dependencies and consistency are maintained
</div>
</div>
</section>
<!--Slide 12-->
<section>
<div class="hbox" data-markdown>
#### Data flow with USM
</div>
<div class="container">
<div class="col">
<code class="code-100pc"><pre>
auto devicePtr =
sycl::malloc_device<int>(1024, gpuQueue);
<mark>auto e1</mark> = gpuQueue.memcpy(devicePtr, data, sizeof(int));
<mark>auto e2</mark> = gpuQueue.parallel_for<kernel_a>(
sycl::range{1024}, <mark>e1</mark>, [=](sycl::id<1> idx) {
devicePtr[idx] = /* some computation */
});
<mark>auto e3</mark> = gpuQueue.parallel_for<kernel_b>(
sycl::range{1024}, <mark>e2</mark>, [=](sycl::id<1> idx) {
devicePtr[idx] = /* some computation */
});
<mark>auto e4</mark> = gpuQueue.memcpy(data, devicePtr,
sizeof(int), <mark>e3</mark>);
<mark>e4.wait();</mark>
</code></pre>
</div>
<div class="col" data-markdown>
* Each command enqueued to the `queue` produces an `event` object which can be used to synchronize with the completion of that command
* Passing those `event` objects when enqueueing other commands creates dependencies
</div>
</div>
</section>
<!--Slide 13-->
<section>
<div class="hbox" data-markdown>
#### Data flow with USM
</div>
<div class="container">
<div class="col">
<code class="code-100pc"><pre>
auto devicePtr =
sycl::malloc_device<int>(1024, gpuQueue);
<mark>auto e1 = gpuQueue.memcpy(devicePtr, data, sizeof(int));</mark>
auto e2 = gpuQueue.parallel_for<kernel_a>(
sycl::range{1024}, e1, [=](sycl::id<1> idx) {
devicePtr[idx] = /* some computation */
});
auto e3 = gpuQueue.parallel_for<kernel_b>(
sycl::range{1024}, e2, [=](sycl::id<1> idx) {
devicePtr[idx] = /* some computation */
});
auto e4 = gpuQueue.memcpy(data, devicePtr,
sizeof(int), e3);
e4.wait();
sycl::free(devicePtr, gpuQueue);
</code></pre>
</div>
<div class="col" data-markdown>
* The `memcpy` member functions are used to enqueue data movement commands, moving the data to the GPU and then back again
</div>
</div>
</section>
<!--Slide 14-->
<section>
<div class="hbox" data-markdown>
#### Concurrent data flow
</div>
<div class="container">
<div class="col" data-markdown>
![SYCL](../common-revealjs/images/concurrent_data_flow.png "SYCL")
</div>
<div class="col" data-markdown>
* If two kernels are accessing different buffers then there is no dependency between them
* In this case the two kernels and their respective data movement are independent
* By default `queue`s are out-of-order which means that these commands can execute in any order
* They could also execute concurrently if the target device is able to do so
</div>
</div>
</section>
<!--Slide 15-->
<section>
<div class="hbox" data-markdown>
#### Concurrent data flow with buffers and accessors
</div>
<div class="container">
<div class="col">
<code class="code-100pc"><pre>
sycl::buffer bufA {dataA, sycl::range{1024}};
sycl::buffer bufB {dataB, sycl::range{1024}};
gpuQueue.submit([&](sycl::handler &cgh) {
<mark>sycl::accessor accA {bufA, cgh};</mark>
cgh.parallel_for<kernel_a>(sycl::range{1024},
[=](sycl::id<1> idx) {
accA[idx] = /* some computation */
});
});
gpuQueue.submit([&](sycl::handler &cgh) {
<mark>sycl::accessor accB {bufB, cgh};</mark>
cgh.parallel_for<kernel_b>(sycl::range{1024},
[=](sycl::id<1> idx) {
accB[idx] = /* some computation */
});
});
gpuQueue.wait();
</code></pre>
</div>
<div class="col" data-markdown>
* The buffer/accessor data management model automatically infers dependencies
* As each of the two kernel functions are accessing different `buffer` objects the SYCL runtime can infer there is no dependency between them
* Data movement is still performed for the two kernels as normal
* The two kernels and their respective copies collectively can be executed in any order
</div>
</div>
</section>
<!--Slide 16-->
<section>
<div class="hbox" data-markdown>
#### Concurrent data flow with USM
</div>
<div class="container">
<code class="code-100pc"><pre>
auto devicePtrA = sycl::malloc_device<int>(1024, gpuQueue);
auto devicePtrB = sycl::malloc_device<int>(1024, gpuQueue);
<mark>auto e1</mark> = gpuQueue.memcpy(devicePtrA, dataA, sizeof(int));
auto e2 = gpuQueue.memcpy(devicePtrB, dataB, sizeof(int));
<mark>auto e3</mark> = gpuQueue.parallel_for<kernel_a>(sycl::range{1024}, <mark>e1</mark>, [=](sycl::id<1> idx) {
devicePtrA[idx] = /* some computation */ });
auto e4 = gpuQueue.parallel_for<kernel_b>(sycl::range{1024}, e2, [=](sycl::id<1> idx) {
devicePtrB[idx] = /* some computation */ });
<mark>auto e5</mark> = gpuQueue.memcpy(dataA), devicePtrA, sizeof(int), <mark>e3</mark>);
auto e6 = gpuQueue.memcpy(dataB, devicePtrB, sizeof(int), e4);
<mark>e5.wait();</mark> e6.wait();
sycl::free(devicePtrA, gpuQueue);
sycl::free(devicePtrB, gpuQueue);
</code></pre>
</div>
<div class="container" data-markdown>
* Dependencies are defined explicitly
* We don't create dependencies between kernel functions but we do create dependencies on the data movement
</div>
</section>
<!--Slide 17-->
<section>
<div class="hbox" data-markdown>
#### Concurrent data flow with USM
</div>
<div class="container">
<code class="code-100pc"><pre>
auto devicePtrA = sycl::malloc_device<int>(1024, gpuQueue);
auto devicePtrB = sycl::malloc_device<int>(1024, gpuQueue);
auto e1 = gpuQueue.memcpy(devicePtrA, dataA, sizeof(int));
<mark>auto e2</mark> = gpuQueue.memcpy(devicePtrB, dataB, sizeof(int));
auto e3 = gpuQueue.parallel_for<kernel_a>(sycl::range{1024}, e1, [=](sycl::id<1> idx) {
devicePtrA[idx] = /* some computation */ });
<mark>auto e4</mark> = gpuQueue.parallel_for<kernel_b>(sycl::range{1024}, <mark>e2</mark>, [=](sycl::id<1> idx) {
devicePtrB[idx] = /* some computation */ });
auto e5 = gpuQueue.memcpy(dataA), devicePtrA, sizeof(int), e3);
<mark>auto e6</mark> = gpuQueue.memcpy(dataB, devicePtrB, sizeof(int), <mark>e4</mark>);
e5.wait(); <mark>e6.wait();</mark>
sycl::free(devicePtrA, gpuQueue);
sycl::free(devicePtrB, gpuQueue);
</code></pre>
</div>
<div class="container" data-markdown>
* The dependencies of each chain of commands is independant of the other
* The two kernels and their respective copies collectively can be executed in any order
</div>
</section>
<!--Slide 15-->
<section>
<div class="hbox" data-markdown>
#### Which should you choose?
</div>
<div class="container" data-markdown>
When should you use the buffer/accessor or USM data management models?
</div>
<div class="container">
<div class="col" data-markdown>
Buffer/accessor data movement model
<br/>
* If you want to guarantee consistency and avoid errors
* If you want to iterate over your data flow quicker
</div>
<div class="col" data-markdown>
USM data movement model
<br/>
* If you need to use USM
* If you want more fine grained control over data movement
</div>
</div>
</section>
<!--Slide 16-->
<section>
<div class="hbox" data-markdown>
## Questions
</div>
</section>
<!--Slide 17-->
<section>
<div class="hbox" data-markdown>
#### Exercise
</div>
<div class="container" data-markdown>
Code_Exercises/Data_and_Dependencies/source
</div>
<div class="container" data-markdown>
![SYCL](../common-revealjs/images/diamond_data_flow.png "SYCL")
</div>
<div class="container" data-markdown>
Put together what you've seen here to create the above diamond data flow graph in either buffer/accessor or USM data management models
</div>
</section>
</div>
</div>
<script src="../common-revealjs/js/reveal.js"></script>
<script src="../common-revealjs/plugin/markdown/marked.js"></script>
<script src="../common-revealjs/plugin/markdown/markdown.js"></script>
<script src="../common-revealjs/plugin/notes/notes.js"></script>
<script>
Reveal.initialize({mouseWheel: true, defaultNotes: true});
Reveal.configure({ slideNumber: true });
</script>
</body>
</html>