index.html 27.8 KB
Newer Older
Nathalie Furmento's avatar
Nathalie Furmento committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
            "http://www.w3.org/TR/REC-html40/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<HEAD>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<TITLE>StarPU hands-on session</TITLE>
<link rel="stylesheet" type="text/css" href="../../style.css" />
<link rel="Shortcut icon" href="http://www.inria.fr/extension/site_inria/design/site_inria/images/favicon.ico" type="image/x-icon" />
</HEAD>

<body>

<div class="title">
<h1><a href="../../">StarPU</a></h1>
<h2>Inria automn school "High Performance Numerical Simulation"</h2>
16
<h3>StarPU Tutorial - Bordeaux,  November, 7th 2019</h3>
Nathalie Furmento's avatar
Nathalie Furmento committed
17
18
19
20
21
22
</div>

<div class="menu">
      <a href="../">Back to the main page</a>
</div>

23
24
25
<div class="section">
  <p>
    This tutorial is part of
Nathalie Furmento's avatar
Nathalie Furmento committed
26
27
  the <a href="https://project.inria.fr/hpcschool2019/">Inria automn
  school "High Performance Numerical Simulation"</a> taking place in Bordeaux on
28
29
    November, 4th-8th 2019
  </p>
THIBAULT Samuel's avatar
THIBAULT Samuel committed
30
31
32
  <p>
  The <a href="19-11-07-hpcschool.pdf">slides are available as PDF</a>.
  </p>
Nathalie Furmento's avatar
Nathalie Furmento committed
33
34

<div class="section">
35
36
37
<h2>Connection to the platform</h2>

<p>
38
The work will be done
39
40
41
42
on <a href="[https://www.plafrim.fr">PlaFRIM</a>.
We'll rely on ssh to connect to the platform. You have received on
Thursday October 31 an email from PlaFRIM support with instructions
to connect to the machine, together with a password. They must look
43
44
like the following lines where <tt>&lt;myname&gt;</tt> is to be
changed according to your login instructions.
45
</p>
Nathalie Furmento's avatar
Nathalie Furmento committed
46

47
<tt><pre>
48
49
$ ssh hpcs-&lt;myname&gt;@formation.plafrim.fr
$ ssh plafrim
50
51
52
</pre></tt>

<p>
53
These two steps can be gathered into a single step. To do so, you can
54
55
add the following lines in your <tt>.ssh/config</tt> file,
where <tt>&lt;myname&gt;</tt> is to be changed according to your login
56
instructions.
57
</p>
Nathalie Furmento's avatar
Nathalie Furmento committed
58

59
60
61
62
<tt><pre>
Host plafrim-hpcs
  ForwardAgent yes
  ForwardX11 yes
63
64
  User hpcs-&lt;myname&gt;
  ProxyCommand ssh -T -q -o "ForwardAgent yes" -l hpcs-&lt;myname&gt; formation.plafrim.fr 'ssh-add -t 1 && nc plafrim 22'
65
66
67
</pre></tt>

<p>
68
Then to log on to the platform, you can use <tt>ssh -X plafrim-hpcs</tt> or <tt>ssh -Y
69
70
71
72
73
plafrim-hpcs</tt>. In some cases, <tt>ssh -Y</tt> may create problems
asking for a key. Then change to <tt>ssh -X</tt>.
</p>

<tt><pre>
74
$ ssh -X plafrim-hpcs
75
76
77
</pre></tt>

<tt><pre>
78
$ ssh -Y plafrim-hpcs % can create problems with some environments
79
80
</pre></tt>

81
82
83
84
85
86
87
<p>
All the files needed in the following sections are available in this
<a href="material.tgz">archive</a>. You can get the file directly from
the platform using the following command.
</p>

<tt><pre>
88
$ wget http://starpu.gforge.inria.fr/tutorials/2019-11-HPNS-Inria/material.tgz
89
90
</pre></tt>

91
92
93
</div>

<div class="section">
94
<h2>Setup of the environment with Guix</h2>
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114

<p>
One of the objective of this school is to allow you mastering your
environment. We will use <a href="https://guix.gnu.org/">Guix</a> to
handle that. Guix is an advanced distribution of the GNU operating
system developed by the GNU Project, which respects the freedom of
computer users. It is a transactional package manager, with support
for per-user package installations. Users can install their own
packages without interfering with each other, yet without
unnecessarily increasing disk usage or rebuilding every package.
</p>

<p>
Thanks to joint effort of the Guix development and PlaFRIM team, Guix
is readily available on PlaFRIM as
detailed <a href="[https://www.plafrim.fr/en/guix/">here</a>.
</p>

<p>
The <a href="[https://hpc.guix.info/">guix-hpc</a> initiative is
115
a <a href="https://hpc.guix.info/blog/2019/05/gnu-guix-1.0-foundation-for-hpc-reproducible-science">solid
116
    foundation for hpc reproducible science</a>. The software
117
118
environments created with Guix are fully reproducible: a package
built from a specific Guix commit on your laptop will be exactly the
119
120
121
122
123
124
125
126
127
same as the one built on the HPC cluster
-- <a href="https://www.plafrim.fr">PlaFRIM</a> in our case -- you
deploy it to, usually bit-for-bit.
</p>

<p>
Guix and its package collection are updated by running <tt>guix
pull</tt>
(see <a href="https://guix.gnu.org/manual/en/html_node/Invoking-guix-pull.html#Invoking-guix-pull">
128
129
Invoking guix pull</a>). By default, <tt>guix pull</tt> downloads
and deploys Guix itself from the official GNU Guix repository.
130
131
132
133
134
135
136
137
138
139
This can be customized by
defining <a href="https://guix.gnu.org/manual/en/html_node/Channels.html">channels</a>
in the <tt>~/.config/guix/channels.scm</tt> file. A channel specifies
a URL and branch of a Git repository to be deployed, and <tt>guix pull</tt>
can be instructed to pull from one or more channels. In other words,
channels can be used to customize and to extend Guix. We propose to
set up your channels as follows.
</p>

<p>
Nathalie Furmento's avatar
Nathalie Furmento committed
140
Once connected to the platform, create a
141
142
file <a href="files/channels.scm"><tt>$HOME/.config/guix/channels.scm</tt></a>
with the following contents
143
144
</p>

Nathalie Furmento's avatar
Nathalie Furmento committed
145
<tt><pre>
146
(list (channel
147
148
149
150
        (name 'guix-hpc)
        (url "https://gitlab.inria.fr/guix-hpc/guix-hpc.git")
        (commit
          "446507e4ee8ec9ca6335679c8bb96bfb7d929538"))
151
      (channel
152
153
154
155
        (name 'guix-hpc-non-free)
        (url "https://gitlab.inria.fr/guix-hpc/guix-hpc-non-free.git")
        (commit
          "e058192f39e427c9fac8c31f9fcb27b0f671e43f"))
156
      (channel
157
158
159
160
        (name 'guix)
        (url "https://git.savannah.gnu.org/git/guix.git")
        (commit
          "bbad38f4d8e6b6ecc15c476b973094cdf96cdeae")))
Nathalie Furmento's avatar
Nathalie Furmento committed
161
162
</pre></tt>

163
<p>
164
You then need to call
165
</p>
166
167

<tt><pre>
168
$ guix build hello
169
170
</pre></tt>

171
<p>
172
to make sure to initialize your Guix environment, then
173
</p>
174

Nathalie Furmento's avatar
Nathalie Furmento committed
175
<tt><pre>
176
$ guix pull
Nathalie Furmento's avatar
Nathalie Furmento committed
177
178
</pre></tt>

179
<p>
180
181
182
183
184
to get the proper package definitions.
</p>

<p>
You can then to go a compute node
185
</p>
186

Nathalie Furmento's avatar
Nathalie Furmento committed
187
<tt><pre>
188
$ srun -p hpc -N 1 --pty bash -i
Nathalie Furmento's avatar
Nathalie Furmento committed
189
190
191
192
193
194
195
196
197
198
199
200
201
</pre></tt>

</div>

<div class="section">
  <h3>Installing StarPU on your system</h3>

  <p>
    To be able to exercise accelerator support without having real
    GPUs cards, we will use a simulation version of StarPU, based on
    top of SimGrid.
  </p>
  <p>
202
    The following Guix command will put you in a dedicated StarPU SimGrid
Nathalie Furmento's avatar
Nathalie Furmento committed
203
    environment
204
  </p>
205
<tt><pre>
206
$ guix environment --pure starpu-simgrid --ad-hoc starpu-simgrid grep coreutils emacs vim less openssh inetutils  -- /bin/bash --norc
207
</pre></tt>
Nathalie Furmento's avatar
Nathalie Furmento committed
208

209
210
  <p>
    You also need to load the environment from the <tt>init.sh</tt> shell script
Nathalie Furmento's avatar
Nathalie Furmento committed
211
    from the <a href="./material.tgz"><tt>archive file</tt></a>.
212
  </p>
213

214
<tt><pre>
215
$ . ./init.sh
216
</pre></tt>
Nathalie Furmento's avatar
Nathalie Furmento committed
217

218
219
220
221
222
<!--
  <p>After building and installing StarPU, you can make sure that
    StarPU finds your hardware with:
  </p>
-->
Nathalie Furmento's avatar
Nathalie Furmento committed
223
  <p>
224
    Then you can see that StarPU detects the simulated platform with
225
226
  </p>

227
<tt><pre>
228
$ starpu_machine_display
229
</pre></tt>
Nathalie Furmento's avatar
Nathalie Furmento committed
230
231
232
233
234
235
236
237
238
239
240

</div>

<div class="section">
<h2>Session Part 1: Task-based Programming Model</h2>

<div class="section">
<h3>Application Example: Vector Scaling</h3>

<p>
  This example is at the root of
241
  the <a href="./material.tgz"><tt>archive file</tt></a></p>
Nathalie Furmento's avatar
Nathalie Furmento committed
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

<h4>Making it and Running it</h4>

<p>
A typical <a href="files/Makefile"><tt>Makefile</tt></a> for
applications using StarPU is the following:
</p>

<tt>
<pre>
CFLAGS += $(shell pkg-config --cflags starpu-1.3)
LDLIBS += $(shell pkg-config --libs starpu-1.3)
%.o: %.cu
	nvcc $(CFLAGS) $< -c -o $@

vector_scal_task_insert: vector_scal_task_insert.o vector_scal_cpu.o # vector_scal_cuda.o vector_scal_opencl.o
</pre>
</tt>

<p>If you have CUDA or OpenCL available on your system, you can uncomment adding
the corresponding files on the last line, and uncomment the corresponding link
flags.</p>

<p>
Here are the source files for the application, available in the material
tarball:
<ul>
<li><a href="files/vector_scal_task_insert.c">The main application</a></li>
<li><a href="files/vector_scal_cpu.c">The CPU implementation of the codelet</a></li>
<li><a href="files/vector_scal_cuda.cu">The CUDA implementation of the codelet</a></li>
<li><a href="files/vector_scal_opencl.c">The OpenCL host implementation of the codelet</a></li>
<li><a href="files/vector_scal_opencl_kernel.cl">The OpenCL device implementation of the codelet</a></li>
</ul>

Run <tt>make vector_scal_task_insert</tt>, and run the
resulting <tt>vector_scal_task_insert</tt> executable
using the <a href="files/vector_scal.sh">given script
  vector_scal.sh</a>. It should be working: it simply scales a given
vector by a given factor.
</p>

<tt>
<pre>
285
$ make vector_scal_task_insert
Nathalie Furmento's avatar
Nathalie Furmento committed
286

287
$ ./vector_scal_task_insert
Nathalie Furmento's avatar
Nathalie Furmento committed
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
</pre>
</tt>

<p>
Note that if you are using the simulation version of StarPU, the computation
will not be performed, and thus the final value will be equal to the initial
value, but the timing provided by <tt>starpu_timing_now()</tt> will correspond
to the correct execution time.
</p>

<h4>Computation Kernels</h4>
<p>
Examine the source code, starting from <tt>vector_scal_cpu.c</tt> : this is
the actual computation code, which is wrapped into a <tt>vector_scal_cpu</tt>
function which takes a series of DSM interfaces and a non-DSM parameter. The
code simply gets the factor value from the non-DSM parameter,
an actual pointer from the first DSM interface,
and performs the vector scaling.
</p>

<p>
The GPU implementation, in <tt>vector_scal_cuda.cu</tt>, is basically
the same, with the host part (<tt>vector_scal_cuda</tt>) which extracts the
actual CUDA pointer from the DSM interface, and passes it to the device part
(<tt>vector_mult_cuda</tt>) which performs the actual computation.
</p>

<p>
The OpenCL implementation in <tt>vector_scal_opencl.c</tt> and
317
<tt>vector_scal_opencl_kernel.cl</tt> is more hairy due to the low-level aspect
Nathalie Furmento's avatar
Nathalie Furmento committed
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
of the OpenCL standard, but the principle remains the same.
</p>

<!--
<p>
Modify the source code of the different implementations (CPU, CUDA and
OpenCL) to see which ones gets executed. You can force the execution
of one the implementations simply by disabling a type of device when
running your application, e.g.:
</p>

<tt>
<pre>
# to force the implementation on a GPU device, by default, it will enable CUDA
STARPU_NCPUS=0 ./vector_scal_task_insert

# to force the implementation on a OpenCL device
STARPU_NCPUS=0 STARPU_NCUDA=0 ./vector_scal_task_insert
</pre>
</tt>
-->

<p>
You can set the environment variable STARPU_WORKER_STATS to 1 when
running your application to see the number of tasks executed by each
device. You can see the whole list of environment
variables <a href="http://starpu.gforge.inria.fr/doc/html/ExecutionConfigurationThroughEnvironmentVariables.html">here</a>.
</p>

<tt>
<pre>
349
$ STARPU_WORKER_STATS=1 ./vector_scal_task_insert
Nathalie Furmento's avatar
Nathalie Furmento committed
350
351

# to force the implementation on a GPU device, by default, it will enable CUDA
352
$ STARPU_WORKER_STATS=1 STARPU_NCPUS=0 ./vector_scal_task_insert
Nathalie Furmento's avatar
Nathalie Furmento committed
353
354

# to force the implementation on a OpenCL device
355
$ STARPU_WORKER_STATS=1 STARPU_NCPUS=0 STARPU_NCUDA=0 ./vector_scal_task_insert
Nathalie Furmento's avatar
Nathalie Furmento committed
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
</pre>
</tt>

<h4>Main Code</h4>
<p>
Now examine <tt>vector_scal_task_insert.c</tt>: the <tt>cl</tt>
(codelet) structure simply gathers pointers on the functions
mentioned above.
</p>

<p>
The <tt>main</tt> function
<ul>
<li>Allocates an <tt>vector</tt> application buffer and fills it.</li>
<li>Registers it to StarPU, and gets back a DSM handle. From now on, the
application is not supposed to access <tt>vector</tt> directly, since its
content may be copied and modified by a task on a GPU, the main-memory copy then
being outdated.</li>
<li>Submits a (asynchronous) task to StarPU.</li>
<li>Waits for task completion.</li>
<li>Unregisters the vector from StarPU, which brings back the modified version
to main memory.</li>
</ul>
</p>

</div>

<div class="section">
<h3>Data Partitioning</h3>

<p>
In the previous section, we submitted only one task. We here discuss how to
<i>partition</i> data so as to submit multiple tasks which can be executed in
parallel by the various CPUs and GPUs.
</p>

<p>
Let's examine <a href="files/mult.c">mult.c</a>.

<ul>
<li>
The computation kernel, <tt>cpu_mult</tt> is a trivial matrix multiplication
kernel, which operates on 3 given DSM interfaces. These will actually not be
whole matrices, but only small parts of matrices.
</li>
<li>
<tt>init_problem_data</tt> initializes the whole A, B and C matrices.
</li>
<li>
<tt>partition_mult_data</tt> does the actual registration and partitioning.
Matrices are first registered completely, then two partitioning filters are
declared. The first one, <tt>vert</tt>, is used to split B and C vertically. The
second one, <tt>horiz</tt>, is used to split A and C horizontally. We thus end
up with a grid of pieces of C to be computed from stripes of A and B.
</li>
<li>
<tt>launch_tasks</tt> submits the actual tasks: for each piece of C, take
the appropriate piece of A and B to produce the piece of C.
</li>
<li>
The access mode is interesting: A and B just need to be read from, and C
will only be written to. This means that StarPU will make copies of the pieces
of A and B along the machines, where they are needed for tasks, and will give to
the tasks some
uninitialized buffers for the pieces of C, since they will not be read
from.
</li>
<li>
The <tt>main</tt> code initializes StarPU and data, launches tasks, unpartitions data,
and unregisters it. Unpartitioning is an interesting step: until then the pieces
of C are residing on the various GPUs where they have been computed.
Unpartitioning will collect all the pieces of C into the main memory to form the
whole C result matrix.
</li>
</ul>
</p>

<p>
Run the application with the script <a href="files/mult.sh">mult.sh</a>, enabling some statistics:
</p>

<tt>
<pre>
#!/bin/bash
make mult
STARPU_WORKER_STATS=1 ./mult
</pre>
</tt>

<p>
Figures show how the computation were distributed on the various processing
units.
</p>
</div>

<div class="section">
<h3>Other example</h3>

<p>
<a href="files/gemm/xgemm.c"><tt>gemm/xgemm.c</tt></a> is a very similar
matrix-matrix product example, but which makes use of BLAS kernels for
much better performance. The <tt>mult_kernel_common</tt> functions
shows how we call <tt>DGEMM</tt> (CPUs) or <tt>cublasDgemm</tt> (GPUs)
on the DSM interface.
</p>

<p>
Let's execute it.
</p>

<tt>
<pre>
#!/bin/bash
make gemm/sgemm
STARPU_WORKER_STATS=1 ./gemm/sgemm
</pre>
</tt>

<!--
<p>
We can notice that StarPU gave much more tasks to the GPU. You can also try
to set <tt>num_gpu=2</tt> to run on the machine which has two GPUs (there is
only one of them, so you may have to wait a long time, so submit this in
background in a separate terminal), the interesting thing here is that
with <b>no</b> application modification beyond making it use a task-based
programming model, we get multi-GPU support for free!
</p>
-->

</div>

<!--
<div class="section">
<h3>More Advanced Examples</h3>
<p>
<tt>examples/lu/xlu_implicit.c</tt> is a more involved example: this is a simple
LU decomposition algorithm. The <tt>dw_codelet_facto_v3</tt> is actually the
main algorithm loop, in a very readable, sequential-looking way. It simply
submits all the tasks asynchronously, and waits for them all.
</p>

<p>
<tt>examples/cholesky/cholesky_implicit.c</tt> is a similar example, but which makes use
of the <tt>starpu_insert_task</tt> helper. The <tt>_cholesky</tt> function looks
very much like <tt>dw_codelet_facto_v3</tt> of the previous paragraph, and all
task submission details are handled by <tt>starpu_insert_task</tt>.
</p>

<p>
Thanks to being already using a task-based programming model, MAGMA and PLASMA
have been easily ported to StarPU by simply using <tt>starpu_insert_task</tt>.
</p>
</div>
-->

<div class="section">
<h3>Exercise</h3>
<p>
Take the vector example again, and add partitioning support to it, using the
matrix-matrix multiplication as an example. Here we will use the
<a href="http://starpu.gforge.inria.fr/doc/html/group__API__Data__Partition.html#ga212189d3b83dfa4e225609b5f2bf8461"><tt>starpu_vector_filter_block()</tt></a> filter function. You can see the list of
predefined filters provided by
StarPU <a href="http://starpu.gforge.inria.fr/doc/html/starpu__data__filters_8h.html">here</a>.
Try to run it with various numbers of tasks.
</p>
</div>
</div>

<div class="section">
<h2>Session Part 2: Optimizations</h2>


<p>
This is based on StarPU's documentation
530
<a href="http://starpu.gforge.inria.fr/doc/html/CheckListWhenPerformanceAreNotThere.html">optimization
531
  chapter.</a>
Nathalie Furmento's avatar
Nathalie Furmento committed
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
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
</p>

<div class="section">
<h3>Data Management</h3>

<p>
We have explained how StarPU can overlap computation and data transfers
thanks to DMAs. This is however only possible when CUDA has control over the
application buffers. The application should thus use <a href="http://starpu.gforge.inria.fr/doc/html/group__API__Standard__Memory__Library.html#ga49603eaea3b05e8ced9ba1bd873070c3"><tt>starpu_malloc()</tt></a>
when allocating its buffer, to permit asynchronous DMAs from and to
it.
</p>

<p>
Take the vector example again, and fix the allocation, to make it use
<a href="http://starpu.gforge.inria.fr/doc/html/group__API__Standard__Memory__Library.html#ga49603eaea3b05e8ced9ba1bd873070c3"><tt>starpu_malloc()</tt></a>.
</p>

</div>

<div class="section">
<h3>Task Submission</h3>

<p>
To let StarPU reorder tasks, submit data transfers in advance, etc., task
submission should be asynchronous whenever possible. Ideally, the application
should behave like that: submit the
whole graph of tasks, and wait for termination.
</p>

</div>

<div class="section">
<h3>Performance Model Calibration</h3>

<p>
Performance prediction is essential for proper scheduling decisions, the
performance models thus have to be calibrated.  This is done automatically by
StarPU when a codelet is executed for the first time.  Once this is done, the
result is saved to a file in <tt>$STARPU_HOME</tt> for later re-use.  The
<tt>starpu_perfmodel_display</tt> tool can be used to check the resulting
performance model.
</p>

<tt>
<pre>
$ starpu_perfmodel_display -l
file: &lt;vector_scal.conan&gt;
file: &lt;mult_perf_model.conan&gt;
file: &lt;starpu_dgemm_gemm.conan&gt;
file: &lt;starpu_sgemm_gemm.conan&gt;
$ starpu_perfmodel_display -s vector_scal
# performance model for cuda0_impl0 (Comb0)
# performance model for cuda0_impl0 (Comb0)
	Regression : #sample = 132
	Linear: y = alpha size ^ beta
		alpha = 7.040874e-01
		beta = 3.326125e-01
	Non-Linear: y = a size ^b + c
		a = 6.207150e-05
		b = 9.503886e-01
		c = 1.887639e+01
# hash		size		flops		mean (us)	stddev (us)		n
a3d3725e	4096           	0.000000e+00   	1.902150e+01   	1.639952e+00   	10
870a30aa	8192           	0.000000e+00   	1.971540e+01   	1.115123e+00   	10
48e988e9	16384          	0.000000e+00   	1.934910e+01   	8.406537e-01   	10
...
09be3ca9	1048576        	0.000000e+00   	5.483990e+01   	7.629412e-01   	10
...
# performance model for cuda1_impl0 (Comb1)
...
09be3ca9	1048576        	0.000000e+00   	5.389290e+01   	8.083156e-01   	10
...
# performance model for cuda2_impl0 (Comb2)
...
09be3ca9	1048576        	0.000000e+00   	5.431150e+01   	4.599005e-01   	10
...
# performance model for cpu0_impl0 (Comb3)
...
a3d3725e	4096           	0.000000e+00   	5.149621e+00   	7.096558e-02   	66
...
09be3ca9	1048576        	0.000000e+00   	1.218595e+03   	4.823102e+00   	66
...
</pre>
</tt>

<p>
This shows that for the vector_scal kernel with a 4KB size, the average
execution time on CPUs was about 5.1µs, with a 0.07µs standard deviation, over
66 samples, while it took about 19µs on CUDA GPUs, with a 1.6µs standard
deviation.  With a 1MB size, execution time on CPUs is 1.2ms, while it is only
54µs on the CUDA GPU.
It is a good idea to check the variation before doing actual performance
measurements. If the kernel has varying performance, it may be a good idea to
force StarPU to continue calibrating the performance model, by using <tt>export
STARPU_CALIBRATE=1</tt>
</p>

<p>
The performance model can also be drawn by using <tt>starpu_perfmodel_plot</tt>,
which will emit a gnuplot file in the current directory:
</p>

<tt><pre>
$ starpu_perfmodel_plot -s vector_scal
...
[starpu][main] Gnuplot file &lt;starpu_vector_scal.gp&gt; generated
THIBAULT Samuel's avatar
THIBAULT Samuel committed
639
$ gnuplot starpu_vector_scal.gp
Nathalie Furmento's avatar
Nathalie Furmento committed
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
$ gv starpu_vector_scal.eps
</pre></tt>

<p>
If the code of a computation kernel is modified, the performance changes, the
performance model thus has to be recalibrated from start. To do so, use
<tt>export STARPU_CALIBRATE=2</tt>
</p>

</div>

<div class="section">
<h3>Task Scheduling Policy</h3>
<p>
By default, StarPU uses the <tt>lws</tt> simple greedy scheduler. This is
because it provides correct load balance even if the application codelets do not
have performance models: it uses a single central queue, from which workers draw
tasks to work on. This however does not permit to prefetch data, since the
scheduling decision is taken late.
</p>

<p>
If the application codelets have performance models, the scheduler should be
changed to take benefit from that. StarPU will then really take scheduling
decision in advance according to performance models, and issue data prefetch
requests, to overlap data transfers and computations.
</p>

<p>
For instance, compare the <tt>lws</tt> (default) and <tt>dmda</tt> scheduling
policies:
</p>

<tt>
<pre>
675
$ STARPU_BUS_STATS=1 STARPU_WORKER_STATS=1 gemm/sgemm -xy $((256*4)) -nblocks 4
Nathalie Furmento's avatar
Nathalie Furmento committed
676
677
678
679
680
681
682
683
684
</pre>
</tt>

<p>
with:
</p>

<tt>
<pre>
685
$ STARPU_BUS_STATS=1 STARPU_WORKER_STATS=1 STARPU_SCHED=dmda gemm/sgemm -xy $((256*4)) -nblocks 4
Nathalie Furmento's avatar
Nathalie Furmento committed
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
</pre>
</tt>

<p>
You can see most (all?) the computation have been done on GPUs,
leading to better performances.
</p>

<p>
Try other schedulers, use <tt>STARPU_SCHED=help</tt> to get the
list.
</p>

<p>
Also try with various sizes (keeping a 256 tile size, i.e. increase both
occurrences of 4 above) and draw curves.
</p>

<p>
You can also try the double version, <tt>dgemm</tt>, and notice that GPUs get
less great performance.
</p>

</div>


</div>

<div class="section">
<h2>Sessions Part 3: MPI Support</h2>

<p>
StarPU provides support for MPI communications. It does so in two ways. Either the
application specifies MPI transfers by hand, or it lets StarPU infer them from
data dependencies.
</p>

723
724
725
<p>
  We will use here the non-simulated version of StarPU, by calling the
  following Guix command
726
<tt><pre>
727
$ guix environment --pure starpu --ad-hoc starpu grep coreutils emacs vim less openssh inetutils  -- /bin/bash --norc
728
</pre></tt>
729
730
</p>

Nathalie Furmento's avatar
Nathalie Furmento committed
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
<div class="section">
<h3>Manual MPI transfers</h3>

<p>Basically, StarPU provides
equivalents of <tt>MPI_*</tt> functions, but which operate on DSM handles
instead of <tt>void*</tt> buffers. The difference is that the source data may be
residing on a GPU where it just got computed. StarPU will automatically handle
copying it back to main memory before submitting it to MPI.
</p>

<p>
In the mpi/ subdirectory,
<a href="files/mpi/ring_async_implicit.c"><tt>ring_async_implicit.c</tt></a>
shows an example of mixing MPI communications and task submission. It
is a classical ring MPI ping-pong, but the token which is being passed
on from neighbour to neighbour is incremented by a starpu task at each
step.
</p>

<p>
This is written very naturally by simply submitting all MPI
communication requests and task submission asynchronously in a
sequential-looking loop, and eventually waiting for all the tasks to
complete.
</p>

<tt>
<pre>
759
$ cd mpi
760
761
$ make ring_async_implicit
$ mpirun -np 2 $PWD/ring_async_implicit
Nathalie Furmento's avatar
Nathalie Furmento committed
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
</pre>
</tt>

</div>

<div class="section">
<h3>starpu_mpi_insert_task</h3>

<p>
<a href="files/mpi/stencil5.c">A stencil application</a> shows a basic MPI
task model application. The data distribution over MPI
nodes is decided by the <tt>my_distrib</tt> function, and can thus be changed
trivially.
It also shows how data can be migrated to a
new distribution.
</p>

<tt>
<pre>
781
782
$ make stencil5
$ mpirun -np 2 $PWD/stencil5 -display
Nathalie Furmento's avatar
Nathalie Furmento committed
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
</pre>
</tt>

</div>

<!--div class="section">
<h2>Session Part 4: OpenMP Support</h2>

<div class="section">
<h3>The Klang-Omp OpenMP Compiler</h3>

<p>
The <b>Klang-Omp</b> OpenMP compiler converts C/C++ source codes annotated with OpenMP 4 directives into StarPU enabled codes. Klang-Omp is source-to-source compiler based on the LLVM/CLang compiler framework.
</p>

<p>
The following shell sequence shows an example of an OpenMP version of the Cholesky decomposition compiled into StarPU code.
</p>

<tt>
<pre>
cd
source /gpfslocal/pub/training/runtime_june2016/openmp/environment
cp -r /gpfslocal/pub/training/runtime_june2016/openmp/Cholesky .
cd Cholesky
make
./cholesky_omp4.starpu
</pre>
</tt>

<p>
Homepage of the Klang-Omp OpenMP compiler: <a href="http://kstar.gforge.inria.fr/">Klang-Omp</a>
</p>

</div>
</div-->

</div>


<div class="section">
<h2>More Performance Optimizations</h2>
<p>
The StarPU
827
documentation chapter<a href="http://starpu.gforge.inria.fr/doc/html/OfflinePerformanceTools.html">performance
Nathalie Furmento's avatar
Nathalie Furmento committed
828
829
830
831
832
833
834
835
836
837
838
839
840
    feedback chapter</a> provides more optimization tips for further
reading after this tutorial.
</p>

<div class="section">
<h3>FxT Tracing Support</h3>

<p>
In addition to online profiling, StarPU provides offline profiling tools,
based on recording a trace of events during execution, and analyzing it
afterwards.
</p>

841
<p>
842
843
844
845
A Guix StarPU-FxT package is available. You need to call the following
Guix command to use it.
</p>

846
<tt><pre>
Nathalie Furmento's avatar
Nathalie Furmento committed
847
$ guix environment --pure starpu-fxt --ad-hoc starpu-fxt grep coreutils emacs vim less gv \
Nathalie Furmento's avatar
Nathalie Furmento committed
848
     --with-commit=starpu-fxt=3cc33c3cc85eae5dbc0f4b0ddc9291e3409287b2 -- /bin/bash --norc
849
</pre></tt>
850

851
852
853
854
855
856
857
858
<p>
  The Guix package <tt>starpu-fxt</tt> is currently based on the
  version 1.3.3 of StarPU which has a bug which leads to the creation
  of huge trace files. This has been fixed but not released yet, we
  hence use the Guix parameter <tt>--with-commit</tt> to indicate a
  specific commit for StarPU. This will no longer be needed after the
  next StarPU release and the upgrade of the Guix package.
</p>
859
<!--
Nathalie Furmento's avatar
Nathalie Furmento committed
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
<p>
To use the version of StarPU compiled with FxT support, you need to recompile
StarPU after installing FxT.
</p>

<p>
<a href="http://download.savannah.nongnu.org/releases/fkt/fxt-0.3.8.tar.gz">The
	latest version of FxT</a> can be built as usual:
</p>

<tt><pre>
$ cd fxt-0.3.8
$ ./configure
$ make
$ sudo make install
$ sudo ldconfig
</pre></tt>

<p>
StarPU can then reconfigured with an addition <tt>--with-fxt</tt>
</p>
881
-->
Nathalie Furmento's avatar
Nathalie Furmento committed
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926

<!--
<p>
To use the version of StarPU compiled with FxT support, you need to reload the
module StarPU after loading the module FxT.
</p>

<tt>
<pre>
module unload runtime/starpu/1.1.4
module load trace/fxt/0.2.13
module load runtime/starpu/1.1.4
</pre>
</tt>

<p>
The trace file is stored in <tt>/tmp</tt> by default. Since execution will
happen on a cluster node, the file will not be reachable after execution,
we need to tell StarPU to store output traces in the home directory, by
setting:
</p>

<tt>
<pre>
$ export STARPU_FXT_PREFIX=$HOME/
</pre>
</tt>

<p>
do not forget the add the line in your file <tt>.bash_profile</tt>.
</p>
-->

<p>
The trace file is stored in <tt>/tmp</tt> by default. To tell StarPU to store
output traces in the home directory, one can set:
</p>

<tt>
<pre>
$ export STARPU_FXT_PREFIX=$HOME/
</pre>
</tt>

<p>
927
928
929
930
931
932
933
934
935
936
937
938
939
The application should be run again, for instance:

<tt>
<pre>
$ make clean
$ make mult
$ ./mult
</pre>
</tt>

</p>

<p>This time a <tt>prof_file_XX_YY</tt>
Nathalie Furmento's avatar
Nathalie Furmento committed
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
trace file will be generated in your home directory. This can be converted to
several formats by using:
</p>

<tt>
<pre>
$ starpu_fxt_tool -i ~/prof_file_*
</pre>
</tt>

<p>
This will create
<ul>
<li>
a <tt>paje.trace</tt> file, which can be opened by using the <a
href="http://vite.gforge.inria.fr/">ViTE</a> tool. This shows a Gant diagram of
the tasks which executed, and thus the activity and idleness of tasks, as well
as dependencies, data transfers, etc. You may have to zoom in to actually focus
on the computation part, and not the lengthy CUDA initialization.
</li>
<li>
a <tt>dag.dot</tt> file, which contains the graph of all the tasks
submitted by the application. It can be opened by using Graphviz.
</li>
<li>
an <tt>activity.data</tt> file, which records the activity of all processing
units over time.
</li>
</ul>
</p>
</div>

</p>
</div>

<div class="section" id="contact">
<h2>Contact</h2>
<p>
978
979
For any questions regarding StarPU, please contact the StarPU
developers mailing list :
Nathalie Furmento's avatar
Nathalie Furmento committed
980
981
982
983
984
985
986
987
988
989
<a href="mailto:starpu-devel@lists.gforge.inria.fr?subject=StarPU">starpu-devel@lists.gforge.inria.fr</a>
</p>
</div>

<div class="section bot">
<p class="updated">
  Last updated on 2019/04/28.
</p>
</body>
</html>