380_offline_performance_tools.doxy 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2021 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. * Copyright (C) 2020,2021 Federal University of Rio Grande do Sul (UFRGS)
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. /*! \page OfflinePerformanceTools Offline Performance Tools
  18. To get an idea of what is happening, a lot of performance feedback is available,
  19. detailed in this chapter. The various informations should be checked for.
  20. <ul>
  21. <li>
  22. What does the Gantt diagram look like? (see \ref CreatingAGanttDiagram)
  23. <ul>
  24. <li> If it's mostly green (tasks running in the initial context) or context specific
  25. color prevailing, then the machine is properly
  26. utilized, and perhaps the codelets are just slow. Check their performance, see
  27. \ref PerformanceOfCodelets.
  28. </li>
  29. <li> If it's mostly purple (FetchingInput), tasks keep waiting for data
  30. transfers, do you perhaps have far more communication than computation? Did
  31. you properly use CUDA streams to make sure communication can be
  32. overlapped? Did you use data-locality aware schedulers to avoid transfers as
  33. much as possible?
  34. </li>
  35. <li> If it's mostly red (Blocked), tasks keep waiting for dependencies,
  36. do you have enough parallelism? It might be a good idea to check what the DAG
  37. looks like (see \ref CreatingADAGWithGraphviz).
  38. </li>
  39. <li> If only some workers are completely red (Blocked), for some reason the
  40. scheduler didn't assign tasks to them. Perhaps the performance model is bogus,
  41. check it (see \ref PerformanceOfCodelets). Do all your codelets have a
  42. performance model? When some of them don't, the schedulers switches to a
  43. greedy algorithm which thus performs badly.
  44. </li>
  45. </ul>
  46. </li>
  47. </ul>
  48. You can also use the Temanejo task debugger (see \ref UsingTheTemanejoTaskDebugger) to
  49. visualize the task graph more easily.
  50. \section Off-linePerformanceFeedback Off-line Performance Feedback
  51. \subsection GeneratingTracesWithFxT Generating Traces With FxT
  52. StarPU can use the FxT library (see
  53. https://savannah.nongnu.org/projects/fkt/) to generate traces
  54. with a limited runtime overhead.
  55. You can get a tarball from http://download.savannah.gnu.org/releases/fkt/?C=M
  56. Compiling and installing the FxT library in the <c>$FXTDIR</c> path is
  57. done following the standard procedure:
  58. \verbatim
  59. $ ./configure --prefix=$FXTDIR
  60. $ make
  61. $ make install
  62. \endverbatim
  63. In order to have StarPU to generate traces, StarPU needs be configured again
  64. after installing FxT, and configuration show:
  65. \verbatim
  66. FxT trace enabled: yes
  67. \endverbatim
  68. If <c>configure</c> does not find FxT automatically, it can be specified by hand with
  69. the option \ref with-fxt "--with-fxt" :
  70. \verbatim
  71. $ ./configure --with-fxt=$FXTDIR
  72. \endverbatim
  73. Or you can simply point the <c>PKG_CONFIG_PATH</c> to
  74. <c>$FXTDIR/lib/pkgconfig</c>
  75. When \ref STARPU_FXT_TRACE is set to 1, a trace is generated when StarPU is terminated by calling
  76. starpu_shutdown(). The trace is a binary file whose name has the form
  77. <c>prof_file_XXX_YYY</c> where <c>XXX</c> is the user name, and
  78. <c>YYY</c> is the MPI id of the process that used StarPU (or 0 when running a sequential program).
  79. One can change
  80. the name of the file by setting the environnement variable \ref
  81. STARPU_FXT_SUFFIX, its contents will be used instead of <c>prof_file_XXX</c>.
  82. This file is saved in the
  83. <c>/tmp/</c> directory by default, or by the directory specified by
  84. the environment variable \ref STARPU_FXT_PREFIX.
  85. The additional \c configure option \ref enable-fxt-lock "--enable-fxt-lock" can
  86. be used to generate trace events which describes the locks behaviour during
  87. the execution. It is however very heavy and should not be used unless debugging
  88. StarPU's internal locking.
  89. When the FxT trace file <c>prof_file_something</c> has been generated,
  90. it is possible to generate different trace formats by calling:
  91. \verbatim
  92. $ starpu_fxt_tool -i /tmp/prof_file_something
  93. \endverbatim
  94. Or alternatively, setting the environment variable \ref STARPU_GENERATE_TRACE
  95. to <c>1</c> before application execution will make StarPU
  96. automatically generate all traces at application shutdown. Note that
  97. if the environment variable \ref STARPU_FXT_PREFIX is set, files will
  98. be generated in the given directory.
  99. One can also set the environment variable \ref
  100. STARPU_GENERATE_TRACE_OPTIONS to specify options, see
  101. <c>starpu_fxt_tool --help</c>, for example:
  102. \verbatim
  103. $ export STARPU_GENERATE_TRACE=1
  104. $ export STARPU_GENERATE_TRACE_OPTIONS="-no-acquire"
  105. \endverbatim
  106. When running a MPI application, \ref STARPU_GENERATE_TRACE will not
  107. work as expected (each node will try to generate trace files, thus
  108. mixing outputs...), you have to collect the trace files from the MPI
  109. nodes, and specify them all on the command <c>starpu_fxt_tool</c>, for
  110. instance:
  111. \verbatim
  112. $ starpu_fxt_tool -i /tmp/prof_file_something*
  113. \endverbatim
  114. By default, the generated trace contains all informations. To reduce
  115. the trace size, various <c>-no-foo</c> options can be passed to
  116. <c>starpu_fxt_tool</c>, see <c>starpu_fxt_tool --help</c> .
  117. \subsubsection CreatingAGanttDiagram Creating a Gantt Diagram
  118. One of the generated files is a trace in the Paje format. The file,
  119. located in the current directory, is named <c>paje.trace</c>. It can
  120. be viewed with ViTE (http://vite.gforge.inria.fr/) a trace
  121. visualizing open-source tool. To open the file <c>paje.trace</c> with
  122. ViTE, use the following command:
  123. \verbatim
  124. $ vite paje.trace
  125. \endverbatim
  126. Tasks can be assigned a name (instead of the default \c unknown) by
  127. filling the optional starpu_codelet::name, or assigning them a
  128. performance model. The name can also be set with the field
  129. starpu_task::name or by using \ref STARPU_NAME when calling
  130. starpu_task_insert().
  131. Tasks are assigned default colors based on the worker which executed
  132. them (green for CPUs, yellow/orange/red for CUDAs, blue for OpenCLs, ...).
  133. To use a different color for every type of task,
  134. one can specify the option <c>-c</c> to <c>starpu_fxt_tool</c> or in
  135. \ref STARPU_GENERATE_TRACE_OPTIONS. Tasks can also be given a specific
  136. color by setting the field starpu_codelet::color or the
  137. starpu_task::color. Colors are expressed with the following format
  138. \c 0xRRGGBB (e.g \c 0xFF0000 for red). See
  139. <c>basic_examples/task_insert_color</c> for examples on how to assign
  140. colors.
  141. To get statistics on the time spend in runtime overhead, one can use the
  142. statistics plugin of ViTE. In Preferences, select Plugins. In "States Type",
  143. select "Worker State". Then click on "Reload" to update the histogram. The red
  144. "Idle" percentages are due to lack of parallelism, while the brown "Overhead"
  145. and "Scheduling" percentages are due to the overhead of the runtime and of the
  146. scheduler.
  147. To identify tasks precisely, the application can also set the field
  148. starpu_task::tag_id or setting \ref STARPU_TAG_ONLY when calling
  149. starpu_task_insert(). The value of the tag will then show up in the
  150. trace.
  151. One can also introduce user-defined events in the diagram thanks to the
  152. starpu_fxt_trace_user_event_string() function.
  153. One can also set the iteration number, by just calling starpu_iteration_push()
  154. at the beginning of submission loops and starpu_iteration_pop() at the end of
  155. submission loops. These iteration numbers will show up in traces for all tasks
  156. submitted from there.
  157. Coordinates can also be given to data with the starpu_data_set_coordinates() or
  158. starpu_data_set_coordinates_array() function. In the trace, tasks will then be
  159. assigned the coordinates of the first data they write to.
  160. Traces can also be inspected by hand by using the tool <c>fxt_print</c>, for instance:
  161. \verbatim
  162. $ fxt_print -o -f /tmp/prof_file_something
  163. \endverbatim
  164. Timings are in nanoseconds (while timings as seen in ViTE are in milliseconds).
  165. \subsubsection CreatingADAGWithGraphviz Creating a DAG With Graphviz
  166. Another generated trace file is a task graph described using the DOT
  167. language. The file, created in the current directory, is named
  168. <c>dag.dot</c> file in the current directory.
  169. It is possible to get a graphical output of the graph by using the
  170. <c>graphviz</c> library:
  171. \verbatim
  172. $ dot -Tpdf dag.dot -o output.pdf
  173. \endverbatim
  174. \subsubsection TraceTaskDetails Getting Task Details
  175. Another generated trace file gives details on the executed tasks. The
  176. file, created in the current directory, is named <c>tasks.rec</c>. This file
  177. is in the recutils format, i.e. <c>Field: value</c> lines, and empty lines are used to
  178. separate each task. This can be used as a convenient input for various ad-hoc
  179. analysis tools. By default it only contains information about the actual
  180. execution. Performance models can be obtained by running
  181. <c>starpu_tasks_rec_complete</c> on it:
  182. \verbatim
  183. $ starpu_tasks_rec_complete tasks.rec tasks2.rec
  184. \endverbatim
  185. which will add <c>EstimatedTime</c> lines which contain the performance
  186. model-estimated time (in µs) for each worker starting from 0. Since it needs
  187. the performance models, it needs to be run the same way as the application
  188. execution, or at least with <c>STARPU_HOSTNAME</c> set to the hostname of the
  189. machine used for execution, to get the performance models of that machine.
  190. Another possibility is to obtain the performance models as an auxiliary <c>perfmodel.rec</c> file, by using the <c>starpu_perfmodel_recdump</c> utility:
  191. \verbatim
  192. $ starpu_perfmodel_recdump tasks.rec -o perfmodel.rec
  193. \endverbatim
  194. \subsubsection TraceSchedTaskDetails Getting Scheduling Task Details
  195. The file, <c>sched_tasks.rec</c>, created in the current directory,
  196. and in the recutils format, gives information about the tasks
  197. scheduling, and lists the push and pop actions of the scheduler. For
  198. each action, it gives the timestamp, the job priority and the job id.
  199. Each action is separated from the next one by empty lines.
  200. \subsubsection MonitoringActivity Monitoring Activity
  201. Another generated trace file is an activity trace. The file, created
  202. in the current directory, is named <c>activity.data</c>. A profile of
  203. the application showing the activity of StarPU during the execution of
  204. the program can be generated:
  205. \verbatim
  206. $ starpu_workers_activity activity.data
  207. \endverbatim
  208. This will create a file named <c>activity.eps</c> in the current directory.
  209. This picture is composed of two parts.
  210. The first part shows the activity of the different workers. The green sections
  211. indicate which proportion of the time was spent executed kernels on the
  212. processing unit. The red sections indicate the proportion of time spent in
  213. StartPU: an important overhead may indicate that the granularity may be too
  214. low, and that bigger tasks may be appropriate to use the processing unit more
  215. efficiently. The black sections indicate that the processing unit was blocked
  216. because there was no task to process: this may indicate a lack of parallelism
  217. which may be alleviated by creating more tasks when it is possible.
  218. The second part of the picture <c>activity.eps</c> is a graph showing the
  219. evolution of the number of tasks available in the system during the execution.
  220. Ready tasks are shown in black, and tasks that are submitted but not
  221. schedulable yet are shown in grey.
  222. \subsubsection Animation Getting Modular Schedular Animation
  223. When using modular schedulers (i.e. schedulers which use a modular architecture,
  224. and whose name start with "modular-"), the call to
  225. <c>starpu_fxt_tool</c> will also produce a <c>trace.html</c> file
  226. which can be viewed in a javascript-enabled web browser. It shows the
  227. flow of tasks between the components of the modular scheduler.
  228. \subsubsection TimeBetweenSendRecvDataUse Analyzing Time Between MPI Data Transfer and Use by Tasks
  229. <c>starpu_fxt_tool</c> produces a file called <c>comms.rec</c> which describes all
  230. MPI communications. The script <c>starpu_send_recv_data_use.py</c> uses this file
  231. and <c>tasks.rec</c> in order to produce two graphs: the first one shows durations
  232. between the reception of data and their usage by a task and the second one plots the
  233. same graph but with elapsed time between send and usage of a data by the sender.
  234. \image html trace_recv_use.png
  235. \image latex trace_recv_use.eps "" width=\textwidth
  236. \image html trace_send_use.png
  237. \image latex trace_send_use.eps "" width=\textwidth
  238. \subsubsection NumberEvents Number of events in trace files
  239. When launched with the option <c>-number-events</c>, <c>starpu_fxt_tool</c> will
  240. produce a file named <c>number_events.data</c>. This file contains the number of
  241. events for each event type. Events are represented with their key. To convert
  242. event keys to event names, you can use the <c>starpu_fxt_number_events_to_names.py</c>
  243. script:
  244. \verbatim
  245. $ starpu_fxt_number_events_to_names.py number_events.data
  246. \endverbatim
  247. \subsection LimitingScopeTrace Limiting The Scope Of The Trace
  248. For computing statistics, it is useful to limit the trace to a given portion of
  249. the time of the whole execution. This can be achieved by calling
  250. \code{.c}
  251. starpu_fxt_autostart_profiling(0)
  252. \endcode
  253. before calling starpu_init(), to
  254. prevent tracing from starting immediately. Then
  255. \code{.c}
  256. starpu_fxt_start_profiling();
  257. \endcode
  258. and
  259. \code{.c}
  260. starpu_fxt_stop_profiling();
  261. \endcode
  262. can be used around the portion of code to be traced. This will show up as marks
  263. in the trace, and states of workers will only show up for that portion.
  264. \section PerformanceOfCodelets Performance Of Codelets
  265. The performance model of codelets (see \ref PerformanceModelExample)
  266. can be examined by using the tool <c>starpu_perfmodel_display</c>:
  267. \verbatim
  268. $ starpu_perfmodel_display -l
  269. file: <malloc_pinned.hannibal>
  270. file: <starpu_slu_lu_model_21.hannibal>
  271. file: <starpu_slu_lu_model_11.hannibal>
  272. file: <starpu_slu_lu_model_22.hannibal>
  273. file: <starpu_slu_lu_model_12.hannibal>
  274. \endverbatim
  275. Here, the codelets of the example <c>lu</c> are available. We can examine the
  276. performance of the kernel <c>22</c> (in micro-seconds), which is history-based:
  277. \verbatim
  278. $ starpu_perfmodel_display -s starpu_slu_lu_model_22
  279. performance model for cpu
  280. # hash size mean dev n
  281. 57618ab0 19660800 2.851069e+05 1.829369e+04 109
  282. performance model for cuda_0
  283. # hash size mean dev n
  284. 57618ab0 19660800 1.164144e+04 1.556094e+01 315
  285. performance model for cuda_1
  286. # hash size mean dev n
  287. 57618ab0 19660800 1.164271e+04 1.330628e+01 360
  288. performance model for cuda_2
  289. # hash size mean dev n
  290. 57618ab0 19660800 1.166730e+04 3.390395e+02 456
  291. \endverbatim
  292. We can see that for the given size, over a sample of a few hundreds of
  293. execution, the GPUs are about 20 times faster than the CPUs (numbers are in
  294. us). The standard deviation is extremely low for the GPUs, and less than 10% for
  295. CPUs.
  296. This tool can also be used for regression-based performance models. It will then
  297. display the regression formula, and in the case of non-linear regression, the
  298. same performance log as for history-based performance models:
  299. \verbatim
  300. $ starpu_perfmodel_display -s non_linear_memset_regression_based
  301. performance model for cpu_impl_0
  302. Regression : #sample = 1400
  303. Linear: y = alpha size ^ beta
  304. alpha = 1.335973e-03
  305. beta = 8.024020e-01
  306. Non-Linear: y = a size ^b + c
  307. a = 5.429195e-04
  308. b = 8.654899e-01
  309. c = 9.009313e-01
  310. # hash size mean stddev n
  311. a3d3725e 4096 4.763200e+00 7.650928e-01 100
  312. 870a30aa 8192 1.827970e+00 2.037181e-01 100
  313. 48e988e9 16384 2.652800e+00 1.876459e-01 100
  314. 961e65d2 32768 4.255530e+00 3.518025e-01 100
  315. ...
  316. \endverbatim
  317. The same can also be achieved by using StarPU's library API, see
  318. \ref API_Performance_Model and notably the function
  319. starpu_perfmodel_load_symbol(). The source code of the tool
  320. <c>starpu_perfmodel_display</c> can be a useful example.
  321. An XML output can also be printed by using the <c>-x</c> option:
  322. \verbatim
  323. $ tools/starpu_perfmodel_display -x -s non_linear_memset_regression_based
  324. <?xml version="1.0" encoding="UTF-8"?>
  325. <!DOCTYPE StarPUPerfmodel SYSTEM "starpu-perfmodel.dtd">
  326. <!-- symbol non_linear_memset_regression_based -->
  327. <!-- All times in us -->
  328. <perfmodel version="45">
  329. <combination>
  330. <device type="CPU" id="0" ncores="1"/>
  331. <implementation id="0">
  332. <!-- cpu0_impl0 (Comb0) -->
  333. <!-- time = a size ^b + c -->
  334. <nl_regression a="5.429195e-04" b="8.654899e-01" c="9.009313e-01"/>
  335. <entry footprint="a3d3725e" size="4096" flops="0.000000e+00" mean="4.763200e+00" deviation="7.650928e-01" nsample="100"/>
  336. <entry footprint="870a30aa" size="8192" flops="0.000000e+00" mean="1.827970e+00" deviation="2.037181e-01" nsample="100"/>
  337. <entry footprint="48e988e9" size="16384" flops="0.000000e+00" mean="2.652800e+00" deviation="1.876459e-01" nsample="100"/>
  338. <entry footprint="961e65d2" size="32768" flops="0.000000e+00" mean="4.255530e+00" deviation="3.518025e-01" nsample="100"/>
  339. </implementation>
  340. </combination>
  341. </perfmodel>
  342. \endverbatim
  343. The tool <c>starpu_perfmodel_plot</c> can be used to draw performance
  344. models. It writes a <c>.gp</c> file in the current directory, to be
  345. run with the tool <c>gnuplot</c>, which shows the corresponding curve.
  346. \verbatim
  347. $ tools/starpu_perfmodel_plot -s non_linear_memset_regression_based
  348. $ gnuplot starpu_non_linear_memset_regression_based.gp
  349. $ gv starpu_non_linear_memset_regression_based.eps
  350. \endverbatim
  351. \image html starpu_non_linear_memset_regression_based.png
  352. \image latex starpu_non_linear_memset_regression_based.eps "" width=\textwidth
  353. When the field starpu_task::flops is set (or \ref STARPU_FLOPS is passed to
  354. starpu_task_insert()), <c>starpu_perfmodel_plot</c> can directly draw a GFlops
  355. curve, by simply adding the <c>-f</c> option:
  356. \verbatim
  357. $ starpu_perfmodel_plot -f -s chol_model_11
  358. \endverbatim
  359. This will however disable displaying the regression model, for which we can not
  360. compute GFlops.
  361. \image html starpu_chol_model_11_type.png
  362. \image latex starpu_chol_model_11_type.eps "" width=\textwidth
  363. When the FxT trace file <c>prof_file_something</c> has been generated, it is possible to
  364. get a profiling of each codelet by calling:
  365. \verbatim
  366. $ starpu_fxt_tool -i /tmp/prof_file_something
  367. $ starpu_codelet_profile distrib.data codelet_name
  368. \endverbatim
  369. This will create profiling data files, and a <c>distrib.data.gp</c> file in the current
  370. directory, which draws the distribution of codelet time over the application
  371. execution, according to data input size.
  372. \image html distrib_data.png
  373. \image latex distrib_data.eps "" width=\textwidth
  374. This is also available in the tool <c>starpu_perfmodel_plot</c>, by passing it
  375. the fxt trace:
  376. \verbatim
  377. $ starpu_perfmodel_plot -s non_linear_memset_regression_based -i /tmp/prof_file_foo_0
  378. \endverbatim
  379. It will produce a <c>.gp</c> file which contains both the performance model
  380. curves, and the profiling measurements.
  381. \image html starpu_non_linear_memset_regression_based_2.png
  382. \image latex starpu_non_linear_memset_regression_based_2.eps "" width=\textwidth
  383. If you have the statistical tool <c>R</c> installed, you can additionally use
  384. \verbatim
  385. $ starpu_codelet_histo_profile distrib.data
  386. \endverbatim
  387. Which will create one <c>.pdf</c> file per codelet and per input size, showing a
  388. histogram of the codelet execution time distribution.
  389. \image html distrib_data_histo.png
  390. \image latex distrib_data_histo.eps "" width=\textwidth
  391. \section EnergyOfCodelets Energy Of Codelets
  392. A performance model of the energy of codelets can also be recorded thanks to
  393. the starpu_codelet::energy_model field of the starpu_codelet structure. StarPU usually cannot
  394. record this automatically since the energy measurement probes are usually not
  395. fine-grain enough. It is however possible to measure it by writing a program
  396. that submits batches of tasks, let StarPU measure the energy requirement of
  397. the batch, and compute an average, see \ref MeasuringEnergyandPower .
  398. The energy performance model can then be displayed in Joules with
  399. <c>starpu_perfmodel_display</c> just like the time performance model. The
  400. <c>starpu_perfmodel_plot</c> needs an extra <c>-e</c> option to display the
  401. proper unit in the graph:
  402. \verbatim
  403. $ tools/starpu_perfmodel_plot -e -s non_linear_memset_regression_based_energy
  404. $ gnuplot starpu_non_linear_memset_regression_based_energy.gp
  405. $ gv starpu_non_linear_memset_regression_based_energy.eps
  406. \endverbatim
  407. \image html starpu_non_linear_memset_regression_based_energy.png
  408. \image latex starpu_non_linear_memset_regression_based_energy.eps "" width=\textwidth
  409. The <c>-f</c> option can also be used to display the performance in terms of GFlop/s/W, i.e. the efficiency:
  410. \verbatim
  411. $ tools/starpu_perfmodel_plot -f -e -s non_linear_memset_regression_based_energy
  412. $ gnuplot starpu_gflops_non_linear_memset_regression_based_energy.gp
  413. $ gv starpu_gflops_non_linear_memset_regression_based_energy.eps
  414. \endverbatim
  415. \image html starpu_gflops_non_linear_memset_regression_based_energy.png
  416. \image latex starpu_gflops_non_linear_memset_regression_based_energy.eps "" width=\textwidth
  417. We clearly see here that it is much more energy-efficient to stay in the L3 cache.
  418. One can combine the two time and energy performance models to draw Watts:
  419. \verbatim
  420. $ tools/starpu_perfmodel_plot -se non_linear_memset_regression_based non_linear_memset_regression_based_energy
  421. $ gnuplot starpu_power_non_linear_memset_regression_based.gp
  422. $ gv starpu_power_non_linear_memset_regression_based.eps
  423. \endverbatim
  424. \image html starpu_power_non_linear_memset_regression_based.png
  425. \image latex starpu_power_non_linear_memset_regression_based.eps "" width=\textwidth
  426. \section DataTrace Data trace and tasks length
  427. It is possible to get statistics about tasks length and data size by using :
  428. \verbatim
  429. $ starpu_fxt_data_trace filename [codelet1 codelet2 ... codeletn]
  430. \endverbatim
  431. Where filename is the FxT trace file and codeletX the names of the codelets you
  432. want to profile (if no names are specified, <c>starpu_fxt_data_trace</c> will profile them all).
  433. This will create a file, <c>data_trace.gp</c> which
  434. can be executed to get a <c>.eps</c> image of these results. On the image, each point represents a
  435. task, and each color corresponds to a codelet.
  436. \image html data_trace.png
  437. \image latex data_trace.eps "" width=\textwidth
  438. \section TraceStatistics Trace Statistics
  439. More than just codelet performance, it is interesting to get statistics over all
  440. kinds of StarPU states (allocations, data transfers, etc.). This is particularly
  441. useful to check what may have gone wrong in the accurracy of the SimGrid
  442. simulation.
  443. This requires the <c>R</c> statistical tool, with the <c>plyr</c>,
  444. <c>ggplot2</c> and <c>data.table</c> packages. If your system
  445. distribution does not have packages for these, one can fetch them from
  446. <c>CRAN</c>:
  447. \verbatim
  448. $ R
  449. > install.packages("plyr")
  450. > install.packages("ggplot2")
  451. > install.packages("data.table")
  452. > install.packages("knitr")
  453. \endverbatim
  454. The <c>pj_dump</c> tool from <c>pajeng</c> is also needed (see
  455. https://github.com/schnorr/pajeng)
  456. One can then get textual or <c>.csv</c> statistics over the trace states:
  457. \verbatim
  458. $ starpu_paje_state_stats -v native.trace simgrid.trace
  459. "Value" "Events_native.csv" "Duration_native.csv" "Events_simgrid.csv" "Duration_simgrid.csv"
  460. "Callback" 220 0.075978 220 0
  461. "chol_model_11" 10 565.176 10 572.8695
  462. "chol_model_21" 45 9184.828 45 9170.719
  463. "chol_model_22" 165 64712.07 165 64299.203
  464. $ starpu_paje_state_stats native.trace simgrid.trace
  465. \endverbatim
  466. An other way to get statistics of StarPU states (without installing <c>R</c> and
  467. <c>pj_dump</c>) is to use the <c>starpu_trace_state_stats.py</c> script which parses the
  468. generated <c>trace.rec</c> file instead of the <c>paje.trace</c> file. The output is similar
  469. to the previous script but it doesn't need any dependencies.
  470. The different prefixes used in <c>trace.rec</c> are:
  471. \verbatim
  472. E: Event type
  473. N: Event name
  474. C: Event category
  475. W: Worker ID
  476. T: Thread ID
  477. S: Start time
  478. \endverbatim
  479. Here's an example on how to use it:
  480. \verbatim
  481. $ starpu_trace_state_stats.py trace.rec | column -t -s ","
  482. "Name" "Count" "Type" "Duration"
  483. "Callback" 220 Runtime 0.075978
  484. "chol_model_11" 10 Task 565.176
  485. "chol_model_21" 45 Task 9184.828
  486. "chol_model_22" 165 Task 64712.07
  487. \endverbatim
  488. <c>starpu_trace_state_stats.py</c> can also be used to compute the different
  489. efficiencies. Refer to the usage description to show some examples.
  490. And one can plot histograms of execution times, of several states for instance:
  491. \verbatim
  492. $ starpu_paje_draw_histogram -n chol_model_11,chol_model_21,chol_model_22 native.trace simgrid.trace
  493. \endverbatim
  494. and see the resulting pdf file:
  495. \image html paje_draw_histogram.png
  496. \image latex paje_draw_histogram.eps "" width=\textwidth
  497. A quick statistical report can be generated by using:
  498. \verbatim
  499. $ starpu_paje_summary native.trace simgrid.trace
  500. \endverbatim
  501. it includes gantt charts, execution summaries, as well as state duration charts
  502. and time distribution histograms.
  503. Other external Paje analysis tools can be used on these traces, one just needs
  504. to sort the traces by timestamp order (which not guaranteed to make recording
  505. more efficient):
  506. \verbatim
  507. $ starpu_paje_sort paje.trace
  508. \endverbatim
  509. \section PapiCounters PAPI counters
  510. Performance counter values could be obtained from the PAPI framework if
  511. <c>./configure</c> detected the libpapi.
  512. In Debian, the <c>libpapi-dev</c> package provides the required
  513. files. Additionally, the <c>papi-tools</c> package contains a set of useful tools, for example
  514. <c>papi_avail</c> to see which counters are available.
  515. To be able to use Papi counters, one may need to reduce the level of the kernel
  516. parameter <c>kernel.perf_event_paranoid</c> to 2 or below. See
  517. https://www.kernel.org/doc/html/latest/admin-guide/perf-security.html for the
  518. security impact of this parameter.
  519. Then one has to set the \ref STARPU_PROFILING environment variable to 1 and
  520. specify which events to record with the \ref STARPU_PROF_PAPI_EVENTS
  521. environment variable. For instance:
  522. \verbatim
  523. export STARPU_PROFILING=1 STARPU_PROF_PAPI_EVENTS="PAPI_TOT_INS PAPI_TOT_CYC"
  524. \endverbatim
  525. The comma can also be used to separate events to monitor.
  526. In the current simple implementation, only CPU tasks have their events measured
  527. and require CPUs that support the PAPI events. It is important to note that not
  528. all events are available on all systems, and general PAPI recommendations
  529. should be followed.
  530. The counter values can be accessed using the profiling interface:
  531. \code{.c}
  532. task->profiling_info->papi_values
  533. \endcode
  534. Also, it can be accessed and/or saved with tracing when using \ref STARPU_FXT_TRACE. With the use of <c>starpu_fxt_tool</c>
  535. the file <c>papi.rec</c> is generated containing the following triple:
  536. \verbatim
  537. Task Id
  538. Event Id
  539. Value
  540. \endverbatim
  541. External tools like <c>rec2csv</c> can be used to convert this rec file to a <c>csv</c>, where each
  542. line represents a value for an event for a task.
  543. \section TheoreticalLowerBoundOnExecutionTime Theoretical Lower Bound On Execution Time
  544. StarPU can record a trace of what tasks are needed to complete the
  545. application, and then, by using a linear system, provide a theoretical lower
  546. bound of the execution time (i.e. with an ideal scheduling).
  547. The computed bound is not really correct when not taking into account
  548. dependencies, but for an application which have enough parallelism, it is very
  549. near to the bound computed with dependencies enabled (which takes a huge lot
  550. more time to compute), and thus provides a good-enough estimation of the ideal
  551. execution time.
  552. \ref TheoreticalLowerBoundOnExecutionTimeExample provides an example on how to
  553. use this.
  554. \section TheoreticalLowerBoundOnExecutionTimeExample Theoretical Lower Bound On Execution Time Example
  555. For kernels with history-based performance models (and provided that
  556. they are completely calibrated), StarPU can very easily provide a
  557. theoretical lower bound for the execution time of a whole set of
  558. tasks. See for instance <c>examples/lu/lu_example.c</c>: before
  559. submitting tasks, call the function starpu_bound_start(), and after
  560. complete execution, call starpu_bound_stop().
  561. starpu_bound_print_lp() or starpu_bound_print_mps() can then be used
  562. to output a Linear Programming problem corresponding to the schedule
  563. of your tasks. Run it through <c>lp_solve</c> or any other linear
  564. programming solver, and that will give you a lower bound for the total
  565. execution time of your tasks. If StarPU was compiled with the library
  566. <c>glpk</c> installed, starpu_bound_compute() can be used to solve it
  567. immediately and get the optimized minimum, in ms. Its parameter
  568. <c>integer</c> allows to decide whether integer resolution should be
  569. computed and returned
  570. The <c>deps</c> parameter tells StarPU whether to take tasks, implicit
  571. data, and tag dependencies into account. Tags released in a callback
  572. or similar are not taken into account, only tags associated with a task are.
  573. It must be understood that the linear programming
  574. problem size is quadratic with the number of tasks and thus the time to solve it
  575. will be very long, it could be minutes for just a few dozen tasks. You should
  576. probably use <c>lp_solve -timeout 1 test.pl -wmps test.mps</c> to convert the
  577. problem to MPS format and then use a better solver, <c>glpsol</c> might be
  578. better than <c>lp_solve</c> for instance (the <c>--pcost</c> option may be
  579. useful), but sometimes doesn't manage to converge. <c>cbc</c> might look
  580. slower, but it is parallel. For <c>lp_solve</c>, be sure to try at least all the
  581. <c>-B</c> options. For instance, we often just use <c>lp_solve -cc -B1 -Bb
  582. -Bg -Bp -Bf -Br -BG -Bd -Bs -BB -Bo -Bc -Bi</c> , and the <c>-gr</c> option can
  583. also be quite useful. The resulting schedule can be observed by using
  584. the tool <c>starpu_lp2paje</c>, which converts it into the Paje
  585. format.
  586. Data transfer time can only be taken into account when <c>deps</c> is set. Only
  587. data transfers inferred from implicit data dependencies between tasks are taken
  588. into account. Other data transfers are assumed to be completely overlapped.
  589. Setting <c>deps</c> to 0 will only take into account the actual computations
  590. on processing units. It however still properly takes into account the varying
  591. performances of kernels and processing units, which is quite more accurate than
  592. just comparing StarPU performances with the fastest of the kernels being used.
  593. The <c>prio</c> parameter tells StarPU whether to simulate taking into account
  594. the priorities as the StarPU scheduler would, i.e. schedule prioritized
  595. tasks before less prioritized tasks, to check to which extend this results
  596. to a less optimal solution. This increases even more computation time.
  597. \section starvz Trace visualization with StarVZ
  598. Creating views with StarVZ (see: https://github.com/schnorr/starvz) is
  599. made up of two steps. The initial stage consists of a pre-processing
  600. of the traces generated by the application, while the second one
  601. consists of the analysis itself and is carried out with R packages'
  602. aid. StarVZ is available at CRAN
  603. (https://cran.r-project.org/package=starvz) and depends on pj_dump
  604. (from pajeng) and rec2csv (from recutils).
  605. To download and install StarVZ, it is necessary to have R,
  606. pajeng, and recutils:
  607. \verbatim
  608. # For pj_dump and rec2csv
  609. apt install -y pajeng recutils
  610. # For R
  611. apt install -y r-base libxml2-dev libssl-dev libcurl4-openssl-dev libgit2-dev libboost-dev
  612. \endverbatim
  613. To install the StarVZ, the following command can be used:
  614. \verbatim
  615. echo "install.packages('starvz', repos = 'https://cloud.r-project.org')" | R --vanilla
  616. \endverbatim
  617. To generate traces from an application, it is necessary to set \ref STARPU_GENERATE_TRACE
  618. and build StarPU with FxT. Then, StarVZ can be used on a folder with
  619. StarPU FxT traces to produce a default view:
  620. \verbatim
  621. export PATH=$(Rscript -e 'cat(system.file("tools/", package = "starvz"), sep="\n")'):$PATH
  622. starvz /foo/path-to-fxt-files
  623. \endverbatim
  624. An example of default view:
  625. \image html starvz_visu.png
  626. \image latex starvz_visu.pdf "" width=\textwidth
  627. One can also use existing trace files (paje.trace, tasks.rec,
  628. data.rec, papi.rec and dag.dot) skipping the StarVZ internal call to
  629. starpu_fxt_tool with:
  630. \verbatim
  631. starvz --use-paje-trace /foo/path-to-trace-files
  632. \endverbatim
  633. Alternatively, each StarVZ step can be executed separately. Step 1 can
  634. be used on a folder with:
  635. \verbatim
  636. starvz -1 /foo/path-to-fxt-files
  637. \endverbatim
  638. Then the second step can be
  639. executed directly in R. StarVZ enables a set of different plots that
  640. can be configured on a .yaml file. A default file is provided
  641. (<c>default.yaml</c>); also, the options can be changed directly in
  642. R.
  643. \verbatim
  644. library(starvz)
  645. library(dplyr)
  646. dtrace <- starvz_read("./", selective = FALSE)
  647. # show idleness ratio
  648. dtrace$config$st$idleness = TRUE
  649. # show ABE bound
  650. dtrace$config$st$abe$active = TRUE
  651. # find the last task with dplyr
  652. dtrace$config$st$tasks$list = dtrace$Application %>% filter(End == max(End)) %>% .$JobId
  653. # show last task dependencies
  654. dtrace$config$st$tasks$active = TRUE
  655. dtrace$config$st$tasks$levels = 50
  656. plot <- starvz_plot(dtrace)
  657. \endverbatim
  658. An example of visualization follows:
  659. \image html starvz_visu_r.png
  660. \image latex starvz_visu_r.pdf "" width=\textwidth
  661. \section EclipsePluginUsage StarPU Eclipse Plugin
  662. The StarPU Eclipse Plugin provides the ability to generate the
  663. different traces directly from the Eclipse IDE. Once StarPU has been
  664. configured and installed with its Eclipse plugin (see Section \ref
  665. EclipsePlugin), you first need to set up your environment for StarPU.
  666. \verbatim
  667. cd $HOME/usr/local/starpu
  668. source ./bin/starpu_env
  669. \endverbatim
  670. To generate traces from the application, it is necessary to set \ref
  671. STARPU_FXT_TRACE to 1.
  672. \verbatim
  673. export STARPU_FXT_TRACE=1
  674. \endverbatim
  675. The eclipse workspace together with an example is available in \c
  676. lib/starpu/eclipse-plugin.
  677. \verbatim
  678. cd ./lib/starpu/eclipse-plugin
  679. eclipse -data workspace
  680. \endverbatim
  681. You can then open the file \c hello/hello.c, and build the application
  682. by pressing \c Ctrl-B.
  683. \image html eclipse_hello_build.png
  684. \image latex eclipse_hello_build.png "" width=\textwidth
  685. The application can now be executed.
  686. \image html eclipse_hello_run.png
  687. \image latex eclipse_hello_run.png "" width=\textwidth
  688. After executing the C/C++ StarPU application, one can use the StarPU
  689. plugin to generate and visualise the task graph of the application.
  690. The StarPU plugin eclipse is either available through the icons in the
  691. upper toolbar, or from the dropdown menu \c StarPU.
  692. \image html eclipse_hello_plugin.png
  693. \image latex eclipse_hello_plugin.png "" width=\textwidth
  694. To start, one first need to run the StarPU FxT tool, either through
  695. the \c FxT icon of the toolbar, or from the menu \c StarPU / <c>StarPU
  696. FxT Tool</c>. This will call the tool \c starpu_fxt_tool to generate
  697. traces for your application execution.
  698. A message dialog box is displayed to confirm the generation of the
  699. different traces.
  700. \image html eclipse_hello_fxt.png
  701. \image latex eclipse_hello_fxt.png "" width=\textwidth
  702. One of the generated files is a Paje trace which can be viewed with
  703. ViTE, a trace explorer. To open and visualise the file \c paje.trace with
  704. ViTE, one can select the second command of the StarPU menu, which is
  705. named <c>Generate Paje Trace</c>, or click on the second icon named
  706. <c>Trace</c> in the toolbar.
  707. \image html eclipse_hello_paje_trace.png
  708. \image latex eclipse_hello_paje_trace.png "" width=\textwidth
  709. \image html eclipse_hello_vite.png
  710. \image latex eclipse_hello_vite.png "" width=\textwidth
  711. Another generated trace file is a task graph described using the DOT
  712. language. It is possible to get a graphical output of the graph by
  713. calling the <c>graphviz library</c>. To do this, one can click on the
  714. third command of StarPU menu. A task graph of the application in
  715. the \c png format is then generated.
  716. \image html eclipse_hello_graph.png
  717. \image latex eclipse_hello_graph.png "" width=\textwidth
  718. In StarPU eclipse plugin, one can display the graph task directly from
  719. eclipse, or through a web browser. To do this, there is another
  720. command named <c> Generate SVG graph</c> in the StarPU menu or HGraph
  721. in the toolbar of eclipse.
  722. From the HTML file, you can see the graph task, and by clicking on a
  723. task name, it will open the C file in which the task submission was
  724. called (if you have an editor which understands the syntax \c
  725. href="file.c#123").
  726. \image html eclipse_hello_svg_graph.png
  727. \image latex eclipse_hello_svg_graph.png "" width=\textwidth
  728. \image html eclipse_hello_hgraph.png
  729. \image latex eclipse_hello_hgraph.png "" width=\textwidth
  730. \section MemoryFeedback Memory Feedback
  731. It is possible to enable memory statistics. To do so, you need to pass
  732. the option \ref enable-memory-stats "--enable-memory-stats" when running <c>configure</c>. It is then
  733. possible to call the function starpu_data_display_memory_stats() to
  734. display statistics about the current data handles registered within StarPU.
  735. Moreover, statistics will be displayed at the end of the execution on
  736. data handles which have not been cleared out. This can be disabled by
  737. setting the environment variable \ref STARPU_MEMORY_STATS to <c>0</c>.
  738. For example, by adding a call to the function
  739. starpu_data_display_memory_stats() in the fblock example before
  740. unpartitioning the data, one will get something
  741. similar to:
  742. \verbatim
  743. $ STARPU_MEMORY_STATS=1 ./examples/filters/fblock
  744. ...
  745. #---------------------
  746. Memory stats :
  747. #-------
  748. Data on Node #2
  749. #-----
  750. Data : 0x5562074e8670
  751. Size : 144
  752. #--
  753. Data access stats
  754. /!\ Work Underway
  755. Node #0
  756. Direct access : 0
  757. Loaded (Owner) : 0
  758. Loaded (Shared) : 0
  759. Invalidated (was Owner) : 1
  760. Node #2
  761. Direct access : 0
  762. Loaded (Owner) : 1
  763. Loaded (Shared) : 0
  764. Invalidated (was Owner) : 0
  765. #-------
  766. Data on Node #3
  767. #-----
  768. Data : 0x5562074e9338
  769. Size : 96
  770. #--
  771. Data access stats
  772. /!\ Work Underway
  773. Node #0
  774. Direct access : 0
  775. Loaded (Owner) : 0
  776. Loaded (Shared) : 0
  777. Invalidated (was Owner) : 1
  778. Node #3
  779. Direct access : 0
  780. Loaded (Owner) : 1
  781. Loaded (Shared) : 0
  782. Invalidated (was Owner) : 0
  783. #---------------------
  784. ...
  785. \endverbatim
  786. \section DataStatistics Data Statistics
  787. Different data statistics can be displayed at the end of the execution
  788. of the application. To enable them, you need to define the environment
  789. variable \ref STARPU_ENABLE_STATS. When calling
  790. starpu_shutdown() various statistics will be displayed,
  791. execution, MSI cache statistics, allocation cache statistics, and data
  792. transfer statistics. The display can be disabled by setting the
  793. environment variable \ref STARPU_STATS to <c>0</c>.
  794. \verbatim
  795. $ ./examples/cholesky/cholesky_tag
  796. Computation took (in ms)
  797. 518.16
  798. Synthetic GFlops : 44.21
  799. #---------------------
  800. MSI cache stats :
  801. TOTAL MSI stats hit 1622 (66.23 %) miss 827 (33.77 %)
  802. ...
  803. \endverbatim
  804. \verbatim
  805. $ STARPU_STATS=0 ./examples/cholesky/cholesky_tag
  806. Computation took (in ms)
  807. 518.16
  808. Synthetic GFlops : 44.21
  809. \endverbatim
  810. // TODO: data transfer stats are similar to the ones displayed when
  811. // setting STARPU_BUS_STATS
  812. */