12online_performance_tools.doxy 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. /*
  2. * This file is part of the StarPU Handbook.
  3. * Copyright (C) 2009--2011 Universit@'e de Bordeaux
  4. * Copyright (C) 2010, 2011, 2012, 2013, 2014 Centre National de la Recherche Scientifique
  5. * Copyright (C) 2011, 2012 Institut National de Recherche en Informatique et Automatique
  6. * See the file version.doxy for copying conditions.
  7. */
  8. /*! \page OnlinePerformanceTools Online Performance Tools
  9. \section On-linePerformanceFeedback On-line Performance Feedback
  10. \subsection EnablingOn-linePerformanceMonitoring Enabling On-line Performance Monitoring
  11. In order to enable online performance monitoring, the application can
  12. call starpu_profiling_status_set() with the parameter
  13. ::STARPU_PROFILING_ENABLE. It is possible to detect whether monitoring
  14. is already enabled or not by calling starpu_profiling_status_get().
  15. Enabling monitoring also reinitialize all previously collected
  16. feedback. The environment variable \ref STARPU_PROFILING can also be
  17. set to <c>1</c> to achieve the same effect. The function
  18. starpu_profiling_init() can also be called during the execution to
  19. reinitialize performance counters and to start the profiling if the
  20. environment variable \ref STARPU_PROFILING is set to <c>1</c>.
  21. Likewise, performance monitoring is stopped by calling
  22. starpu_profiling_status_set() with the parameter
  23. ::STARPU_PROFILING_DISABLE. Note that this does not reset the
  24. performance counters so that the application may consult them later
  25. on.
  26. More details about the performance monitoring API are available in \ref API_Profiling.
  27. \subsection Per-taskFeedback Per-task Feedback
  28. If profiling is enabled, a pointer to a structure
  29. starpu_profiling_task_info is put in the field
  30. starpu_task::profiling_info when a task terminates. This structure is
  31. automatically destroyed when the task structure is destroyed, either
  32. automatically or by calling starpu_task_destroy().
  33. The structure starpu_profiling_task_info indicates the date when the
  34. task was submitted (starpu_profiling_task_info::submit_time), started
  35. (starpu_profiling_task_info::start_time), and terminated
  36. (starpu_profiling_task_info::end_time), relative to the initialization
  37. of StarPU with starpu_init(). It also specifies the identifier of the worker
  38. that has executed the task (starpu_profiling_task_info::workerid).
  39. These date are stored as <c>timespec</c> structures which the user may convert
  40. into micro-seconds using the helper function
  41. starpu_timing_timespec_to_us().
  42. It it worth noting that the application may directly access this structure from
  43. the callback executed at the end of the task. The structure starpu_task
  44. associated to the callback currently being executed is indeed accessible with
  45. the function starpu_task_get_current().
  46. \subsection Per-codeletFeedback Per-codelet Feedback
  47. The field starpu_codelet::per_worker_stats is
  48. an array of counters. The i-th entry of the array is incremented every time a
  49. task implementing the codelet is executed on the i-th worker.
  50. This array is not reinitialized when profiling is enabled or disabled.
  51. \subsection Per-workerFeedback Per-worker Feedback
  52. The second argument returned by the function
  53. starpu_profiling_worker_get_info() is a structure
  54. starpu_profiling_worker_info that gives statistics about the specified
  55. worker. This structure specifies when StarPU started collecting
  56. profiling information for that worker
  57. (starpu_profiling_worker_info::start_time), the
  58. duration of the profiling measurement interval
  59. (starpu_profiling_worker_info::total_time), the time spent executing
  60. kernels (starpu_profiling_worker_info::executing_time), the time
  61. spent sleeping because there is no task to execute at all
  62. (starpu_profiling_worker_info::sleeping_time), and the number of tasks that were executed
  63. while profiling was enabled. These values give an estimation of the
  64. proportion of time spent do real work, and the time spent either
  65. sleeping because there are not enough executable tasks or simply
  66. wasted in pure StarPU overhead.
  67. Calling starpu_profiling_worker_get_info() resets the profiling
  68. information associated to a worker.
  69. When an FxT trace is generated (see \ref GeneratingTracesWithFxT), it is also
  70. possible to use the tool <c>starpu_workers_activity</c> (see \ref
  71. MonitoringActivity) to generate a graphic showing the evolution of
  72. these values during the time, for the different workers.
  73. \subsection Bus-relatedFeedback Bus-related Feedback
  74. TODO: ajouter \ref STARPU_BUS_STATS
  75. // how to enable/disable performance monitoring
  76. // what kind of information do we get ?
  77. The bus speed measured by StarPU can be displayed by using the tool
  78. <c>starpu_machine_display</c>, for instance:
  79. \verbatim
  80. StarPU has found:
  81. 3 CUDA devices
  82. CUDA 0 (Tesla C2050 02:00.0)
  83. CUDA 1 (Tesla C2050 03:00.0)
  84. CUDA 2 (Tesla C2050 84:00.0)
  85. from to RAM to CUDA 0 to CUDA 1 to CUDA 2
  86. RAM 0.000000 5176.530428 5176.492994 5191.710722
  87. CUDA 0 4523.732446 0.000000 2414.074751 2417.379201
  88. CUDA 1 4523.718152 2414.078822 0.000000 2417.375119
  89. CUDA 2 4534.229519 2417.069025 2417.060863 0.000000
  90. \endverbatim
  91. \subsection StarPU-TopInterface StarPU-Top Interface
  92. StarPU-Top is an interface which remotely displays the on-line state of a StarPU
  93. application and permits the user to change parameters on the fly.
  94. Variables to be monitored can be registered by calling the functions
  95. starpu_top_add_data_boolean(), starpu_top_add_data_integer(),
  96. starpu_top_add_data_float(), e.g.:
  97. \code{.c}
  98. starpu_top_data *data = starpu_top_add_data_integer("mynum", 0, 100, 1);
  99. \endcode
  100. The application should then call starpu_top_init_and_wait() to give its name
  101. and wait for StarPU-Top to get a start request from the user. The name is used
  102. by StarPU-Top to quickly reload a previously-saved layout of parameter display.
  103. \code{.c}
  104. starpu_top_init_and_wait("the application");
  105. \endcode
  106. The new values can then be provided thanks to
  107. starpu_top_update_data_boolean(), starpu_top_update_data_integer(),
  108. starpu_top_update_data_float(), e.g.:
  109. \code{.c}
  110. starpu_top_update_data_integer(data, mynum);
  111. \endcode
  112. Updateable parameters can be registered thanks to starpu_top_register_parameter_boolean(), starpu_top_register_parameter_integer(), starpu_top_register_parameter_float(), e.g.:
  113. \code{.c}
  114. float alpha;
  115. starpu_top_register_parameter_float("alpha", &alpha, 0, 10, modif_hook);
  116. \endcode
  117. <c>modif_hook</c> is a function which will be called when the parameter is being modified, it can for instance print the new value:
  118. \code{.c}
  119. void modif_hook(struct starpu_top_param *d) {
  120. fprintf(stderr,"%s has been modified: %f\n", d->name, alpha);
  121. }
  122. \endcode
  123. Task schedulers should notify StarPU-Top when it has decided when a task will be
  124. scheduled, so that it can show it in its Gantt chart, for instance:
  125. \code{.c}
  126. starpu_top_task_prevision(task, workerid, begin, end);
  127. \endcode
  128. Starting StarPU-Top (StarPU-Top is started via the binary
  129. <c>starpu_top</c>.) and the application can be done two ways:
  130. <ul>
  131. <li> The application is started by hand on some machine (and thus already
  132. waiting for the start event). In the Preference dialog of StarPU-Top, the SSH
  133. checkbox should be unchecked, and the hostname and port (default is 2011) on
  134. which the application is already running should be specified. Clicking on the
  135. connection button will thus connect to the already-running application.
  136. </li>
  137. <li> StarPU-Top is started first, and clicking on the connection button will
  138. start the application itself (possibly on a remote machine). The SSH checkbox
  139. should be checked, and a command line provided, e.g.:
  140. \verbatim
  141. $ ssh myserver STARPU_SCHED=dmda ./application
  142. \endverbatim
  143. If port 2011 of the remote machine can not be accessed directly, an ssh port bridge should be added:
  144. \verbatim
  145. $ ssh -L 2011:localhost:2011 myserver STARPU_SCHED=dmda ./application
  146. \endverbatim
  147. and "localhost" should be used as IP Address to connect to.
  148. </li>
  149. </ul>
  150. \section TaskAndWorkerProfiling Task And Worker Profiling
  151. A full example showing how to use the profiling API is available in
  152. the StarPU sources in the directory <c>examples/profiling/</c>.
  153. \code{.c}
  154. struct starpu_task *task = starpu_task_create();
  155. task->cl = &cl;
  156. task->synchronous = 1;
  157. /* We will destroy the task structure by hand so that we can
  158. * query the profiling info before the task is destroyed. */
  159. task->destroy = 0;
  160. /* Submit and wait for completion (since synchronous was set to 1) */
  161. starpu_task_submit(task);
  162. /* The task is finished, get profiling information */
  163. struct starpu_profiling_task_info *info = task->profiling_info;
  164. /* How much time did it take before the task started ? */
  165. double delay += starpu_timing_timespec_delay_us(&info->submit_time, &info->start_time);
  166. /* How long was the task execution ? */
  167. double length += starpu_timing_timespec_delay_us(&info->start_time, &info->end_time);
  168. /* We don't need the task structure anymore */
  169. starpu_task_destroy(task);
  170. \endcode
  171. \code{.c}
  172. /* Display the occupancy of all workers during the test */
  173. int worker;
  174. for (worker = 0; worker < starpu_worker_get_count(); worker++)
  175. {
  176. struct starpu_profiling_worker_info worker_info;
  177. int ret = starpu_profiling_worker_get_info(worker, &worker_info);
  178. STARPU_ASSERT(!ret);
  179. double total_time = starpu_timing_timespec_to_us(&worker_info.total_time);
  180. double executing_time = starpu_timing_timespec_to_us(&worker_info.executing_time);
  181. double sleeping_time = starpu_timing_timespec_to_us(&worker_info.sleeping_time);
  182. double overhead_time = total_time - executing_time - sleeping_time;
  183. float executing_ratio = 100.0*executing_time/total_time;
  184. float sleeping_ratio = 100.0*sleeping_time/total_time;
  185. float overhead_ratio = 100.0 - executing_ratio - sleeping_ratio;
  186. char workername[128];
  187. starpu_worker_get_name(worker, workername, 128);
  188. fprintf(stderr, "Worker %s:\n", workername);
  189. fprintf(stderr, "\ttotal time: %.2lf ms\n", total_time*1e-3);
  190. fprintf(stderr, "\texec time: %.2lf ms (%.2f %%)\n",
  191. executing_time*1e-3, executing_ratio);
  192. fprintf(stderr, "\tblocked time: %.2lf ms (%.2f %%)\n",
  193. sleeping_time*1e-3, sleeping_ratio);
  194. fprintf(stderr, "\toverhead time: %.2lf ms (%.2f %%)\n",
  195. overhead_time*1e-3, overhead_ratio);
  196. }
  197. \endcode
  198. \section PerformanceModelExample Performance Model Example
  199. To achieve good scheduling, StarPU scheduling policies need to be able to
  200. estimate in advance the duration of a task. This is done by giving to codelets
  201. a performance model, by defining a structure starpu_perfmodel and
  202. providing its address in the field starpu_codelet::model. The fields
  203. starpu_perfmodel::symbol and starpu_perfmodel::type are mandatory, to
  204. give a name to the model, and the type of the model, since there are
  205. several kinds of performance models. For compatibility, make sure to
  206. initialize the whole structure to zero, either by using explicit
  207. memset(), or by letting the compiler implicitly do it as examplified
  208. below.
  209. <ul>
  210. <li>
  211. Measured at runtime (model type ::STARPU_HISTORY_BASED). This assumes that for a
  212. given set of data input/output sizes, the performance will always be about the
  213. same. This is very true for regular kernels on GPUs for instance (<0.1% error),
  214. and just a bit less true on CPUs (~=1% error). This also assumes that there are
  215. few different sets of data input/output sizes. StarPU will then keep record of
  216. the average time of previous executions on the various processing units, and use
  217. it as an estimation. History is done per task size, by using a hash of the input
  218. and ouput sizes as an index.
  219. It will also save it in <c>$STARPU_HOME/.starpu/sampling/codelets</c>
  220. for further executions, and can be observed by using the tool
  221. <c>starpu_perfmodel_display</c>, or drawn by using
  222. the tool <c>starpu_perfmodel_plot</c> (\ref PerformanceModelCalibration). The
  223. models are indexed by machine name. To
  224. share the models between machines (e.g. for a homogeneous cluster), use
  225. <c>export STARPU_HOSTNAME=some_global_name</c>. Measurements are only done
  226. when using a task scheduler which makes use of it, such as
  227. <c>dmda</c>. Measurements can also be provided explicitly by the application, by
  228. using the function starpu_perfmodel_update_history().
  229. The following is a small code example.
  230. If e.g. the code is recompiled with other compilation options, or several
  231. variants of the code are used, the symbol string should be changed to reflect
  232. that, in order to recalibrate a new model from zero. The symbol string can even
  233. be constructed dynamically at execution time, as long as this is done before
  234. submitting any task using it.
  235. \code{.c}
  236. static struct starpu_perfmodel mult_perf_model = {
  237. .type = STARPU_HISTORY_BASED,
  238. .symbol = "mult_perf_model"
  239. };
  240. struct starpu_codelet cl = {
  241. .cpu_funcs = { cpu_mult, NULL },
  242. .cpu_funcs_name = { "cpu_mult", NULL },
  243. .nbuffers = 3,
  244. .modes = { STARPU_R, STARPU_R, STARPU_W },
  245. /* for the scheduling policy to be able to use performance models */
  246. .model = &mult_perf_model
  247. };
  248. \endcode
  249. </li>
  250. <li>
  251. Measured at runtime and refined by regression (model types
  252. ::STARPU_REGRESSION_BASED and ::STARPU_NL_REGRESSION_BASED). This
  253. still assumes performance regularity, but works
  254. with various data input sizes, by applying regression over observed
  255. execution times. ::STARPU_REGRESSION_BASED uses an a*n^b regression
  256. form, ::STARPU_NL_REGRESSION_BASED uses an a*n^b+c (more precise than
  257. ::STARPU_REGRESSION_BASED, but costs a lot more to compute).
  258. For instance,
  259. <c>tests/perfmodels/regression_based.c</c> uses a regression-based performance
  260. model for the function memset().
  261. Of course, the application has to issue
  262. tasks with varying size so that the regression can be computed. StarPU will not
  263. trust the regression unless there is at least 10% difference between the minimum
  264. and maximum observed input size. It can be useful to set the
  265. environment variable \ref STARPU_CALIBRATE to <c>1</c> and run the application
  266. on varying input sizes with \ref STARPU_SCHED set to <c>dmda</c> scheduler,
  267. so as to feed the performance model for a variety of
  268. inputs. The application can also provide the measurements explictly by
  269. using the function starpu_perfmodel_update_history(). The tools
  270. <c>starpu_perfmodel_display</c> and <c>starpu_perfmodel_plot</c> can
  271. be used to observe how much the performance model is calibrated (\ref
  272. PerformanceModelCalibration); when their output look good,
  273. \ref STARPU_CALIBRATE can be reset to <c>0</c> to let
  274. StarPU use the resulting performance model without recording new measures, and
  275. \ref STARPU_SCHED can be set to <c>dmda</c> to benefit from the performance models. If
  276. the data input sizes vary a lot, it is really important to set
  277. \ref STARPU_CALIBRATE to <c>0</c>, otherwise StarPU will continue adding the
  278. measures, and result with a very big performance model, which will take time a
  279. lot of time to load and save.
  280. For non-linear regression, since computing it
  281. is quite expensive, it is only done at termination of the application. This
  282. means that the first execution of the application will use only history-based
  283. performance model to perform scheduling, without using regression.
  284. </li>
  285. <li>
  286. Provided as an estimation from the application itself (model type
  287. ::STARPU_COMMON and field starpu_perfmodel::cost_function),
  288. see for instance
  289. <c>examples/common/blas_model.h</c> and <c>examples/common/blas_model.c</c>.
  290. </li>
  291. <li>
  292. Provided explicitly by the application (model type ::STARPU_PER_ARCH):
  293. the fields <c>.per_arch[arch][nimpl].cost_function</c> have to be
  294. filled with pointers to functions which return the expected duration
  295. of the task in micro-seconds, one per architecture.
  296. </li>
  297. </ul>
  298. For ::STARPU_HISTORY_BASED, ::STARPU_REGRESSION_BASED, and
  299. ::STARPU_NL_REGRESSION_BASED, the dimensions of task data (both input
  300. and output) are used as an index by default. ::STARPU_HISTORY_BASED uses a CRC
  301. hash of the dimensions as an index to distinguish histories, and
  302. ::REGRESSION_REGRESSION_BASED and ::STARPU_NL_REGRESSION_BASED use the total
  303. size as an index for the regression.
  304. The starpu_perfmodel::size_base and starpu_perfmodel::footprint fields however
  305. permit the application to override that, when for instance some of the data
  306. do not matter for task cost (e.g. mere reference table), or when using sparse
  307. structures (in which case it is the number of non-zeros which matter), or when
  308. there is some hidden parameter such as the number of iterations, or when the
  309. application actually has a very good idea of the complexity of the algorithm,
  310. and just not the speed of the processor, etc. The example in the directory
  311. <c>examples/pi</c> uses this to include the number of iterations in the base
  312. size. starpu_perfmodel::size_base should be used when the variance of the actual
  313. performance is known (i.e. bigger returned value is longer execution
  314. time), and thus particularly useful for ::STARPU_REGRESSION_BASED or
  315. ::STARPU_NL_REGRESSION_BASED. starpu_perfmodel::footprint can be used when the
  316. variance of the actual performance is unknown (irregular performance behavior,
  317. etc.), and thus only useful for ::STARPU_HISTORY_BASED.
  318. starpu_task_data_footprint() can be used as a base and combined with other
  319. parameters through starpu_hash_crc32c_be for instance.
  320. StarPU will automatically determine when the performance model is calibrated,
  321. or rather, it will assume the performance model is calibrated until the
  322. application submits a task for which the performance can not be predicted. For
  323. ::STARPU_HISTORY_BASED, StarPU will require 10 (STARPU_CALIBRATE_MINIMUM)
  324. measurements for a given size before estimating that an average can be taken as
  325. estimation for further executions with the same size. For
  326. ::STARPU_REGRESSION_BASED and ::STARPU_NL_REGRESSION_BASED, StarPU will require
  327. 10 (STARPU_CALIBRATE_MINIMUM) measurements, and that the minimum measured
  328. data size is smaller than 90% of the maximum measured data size (i.e. the
  329. measurement interval is large enough for a regression to have a meaning).
  330. Calibration can also be forced by setting the \ref STARPU_CALIBRATE environment
  331. variable to <c>1</c>, or even reset by setting it to <c>2</c>.
  332. How to use schedulers which can benefit from such performance model is explained
  333. in \ref TaskSchedulingPolicy.
  334. The same can be done for task power consumption estimation, by setting
  335. the field starpu_codelet::power_model the same way as the field
  336. starpu_codelet::model. Note: for now, the application has to give to
  337. the power consumption performance model a name which is different from
  338. the execution time performance model.
  339. The application can request time estimations from the StarPU performance
  340. models by filling a task structure as usual without actually submitting
  341. it. The data handles can be created by calling any of the functions
  342. <c>starpu_*_data_register</c> with a <c>NULL</c> pointer and <c>-1</c>
  343. node and the desired data sizes, and need to be unregistered as usual.
  344. The functions starpu_task_expected_length() and
  345. starpu_task_expected_power() can then be called to get an estimation
  346. of the task cost on a given arch. starpu_task_footprint() can also be
  347. used to get the footprint used for indexing history-based performance
  348. models. starpu_task_destroy() needs to be called to destroy the dummy
  349. task afterwards. See <c>tests/perfmodels/regression_based.c</c> for an example.
  350. \section DataTrace Data trace and tasks length
  351. It is possible to get statistics about tasks length and data size by using :
  352. \verbatim
  353. $ starpu_fxt_data_trace filename [codelet1 codelet2 ... codeletn]
  354. \endverbatim
  355. Where filename is the FxT trace file and codeletX the names of the codelets you
  356. want to profile (if no names are specified, <c>starpu_fxt_data_trace</c> will profile them all).
  357. This will create a file, <c>data_trace.gp</c> which
  358. can be executed to get a <c>.eps</c> image of these results. On the image, each point represents a
  359. task, and each color corresponds to a codelet.
  360. \image html data_trace.png
  361. \image latex data_trace.eps "" width=\textwidth
  362. */