05check_list_performance.doxy 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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 CheckListWhenPerformanceAreNotThere Check List When Performance Are Not There
  9. TODO: improve!
  10. Simply encapsulating application kernels into tasks already permits to
  11. seamlessly support CPU and GPUs at the same time. To achieve good
  12. performance, we give below a list of features which should be checked.
  13. \section DataRelatedFeaturesToImprovePerformance Data Related Features That May Improve Performance
  14. link to \ref DataManagement
  15. link to \ref DataPrefetch
  16. \section TaskRelatedFeaturesToImprovePerformance Task Related Features That May Improve Performance
  17. link to \ref TaskGranularity
  18. link to \ref TaskSubmission
  19. link to \ref TaskPriorities
  20. \section SchedulingRelatedFeaturesToImprovePerformance Scheduling Related Features That May Improve Performance
  21. link to \ref TaskSchedulingPolicy
  22. link to \ref TaskDistributionVsDataTransfer
  23. link to \ref Power-basedScheduling
  24. link to \ref StaticScheduling
  25. \section CUDA-specificOptimizations CUDA-specific Optimizations
  26. Due to CUDA limitations, StarPU will have a hard time overlapping its own
  27. communications and the codelet computations if the application does not use a
  28. dedicated CUDA stream for its computations instead of the default stream,
  29. which synchronizes all operations of the GPU. StarPU provides one by the use
  30. of starpu_cuda_get_local_stream() which can be used by all CUDA codelet
  31. operations to avoid this issue. For instance:
  32. \code{.c}
  33. func <<<grid,block,0,starpu_cuda_get_local_stream()>>> (foo, bar);
  34. cudaStreamSynchronize(starpu_cuda_get_local_stream());
  35. \endcode
  36. Unfortunately, some CUDA libraries do not have stream variants of
  37. kernels. That will lower the potential for overlapping.
  38. StarPU already does appropriate calls for the CUBLAS library.
  39. If the kernel can be made to only use this local stream or other self-allocated
  40. streams, i.e. the whole kernel submission can be made asynchronous, then
  41. one should enable asynchronous execution of the kernel. That means setting
  42. the flag ::STARPU_CUDA_ASYNC in the corresponding field starpu_codelet::cuda_flags, and dropping the
  43. cudaStreamSynchronize() call at the end of the cuda_func function, so that it
  44. returns immediately after having queued the kernel to the local stream. That way, StarPU will be
  45. able to submit and complete data transfers while kernels are executing, instead of only at each
  46. kernel submission. The kernel just has to make sure that StarPU can use the
  47. local stream to synchronize with the kernel startup and completion.
  48. Using the flag ::STARPU_CUDA_ASYNC also permits to enable concurrent kernel
  49. execution, on cards which support it (Kepler and later, notably). This is
  50. enabled by setting the environment variable \ref STARPU_NWORKER_PER_CUDA to the
  51. number of kernels to execute concurrently. This is useful when kernels are
  52. small and do not feed the whole GPU with threads to run.
  53. \section OpenCL-specificOptimizations OpenCL-specific Optimizations
  54. If the kernel can be made to only use the StarPU-provided command queue or other self-allocated
  55. queues, i.e. the whole kernel submission can be made asynchronous, then
  56. one should enable asynchronous execution of the kernel. This means setting
  57. the flag ::STARPU_OPENCL_ASYNC in the corresponding field starpu_codelet::opencl_flags and dropping the
  58. clFinish() and starpu_opencl_collect_stats() calls at the end of the kernel, so
  59. that it returns immediately after having queued the kernel to the provided queue.
  60. That way, StarPU will be able to submit and complete data transfers while kernels are executing, instead of
  61. only at each kernel submission. The kernel just has to make sure
  62. that StarPU can use the command queue it has provided to synchronize with the
  63. kernel startup and completion.
  64. \section DetectionStuckConditions Detection Stuck Conditions
  65. It may happen that for some reason, StarPU does not make progress for a long
  66. period of time. Reason are sometimes due to contention inside StarPU, but
  67. sometimes this is due to external reasons, such as stuck MPI driver, or CUDA
  68. driver, etc.
  69. <c>export STARPU_WATCHDOG_TIMEOUT=10000</c> (\ref STARPU_WATCHDOG_TIMEOUT)
  70. allows to make StarPU print an error message whenever StarPU does not terminate
  71. any task for 10ms. In addition to that,
  72. <c>export STARPU_WATCHDOG_CRASH=1</c> (\ref STARPU_WATCHDOG_CRASH)
  73. raises SIGABRT in that condition, thus allowing to catch the situation in gdb.
  74. It can also be useful to type "handle SIGABRT nopass" in gdb to be able to let
  75. the process continue, after inspecting the state of the process.
  76. \section HowToLimitMemoryPerNode How to limit memory per node
  77. TODO
  78. Talk about
  79. \ref STARPU_LIMIT_CUDA_devid_MEM, \ref STARPU_LIMIT_CUDA_MEM,
  80. \ref STARPU_LIMIT_OPENCL_devid_MEM, \ref STARPU_LIMIT_OPENCL_MEM
  81. and \ref STARPU_LIMIT_CPU_MEM
  82. starpu_memory_get_total()
  83. starpu_memory_get_available()
  84. \section PerformanceModelCalibration Performance Model Calibration
  85. Most schedulers are based on an estimation of codelet duration on each kind
  86. of processing unit. For this to be possible, the application programmer needs
  87. to configure a performance model for the codelets of the application (see
  88. \ref PerformanceModelExample for instance). History-based performance models
  89. use on-line calibration. StarPU will automatically calibrate codelets
  90. which have never been calibrated yet, and save the result in
  91. <c>$STARPU_HOME/.starpu/sampling/codelets</c>.
  92. The models are indexed by machine name. To share the models between
  93. machines (e.g. for a homogeneous cluster), use <c>export
  94. STARPU_HOSTNAME=some_global_name</c> (\ref STARPU_HOSTNAME). To force continuing calibration,
  95. use <c>export STARPU_CALIBRATE=1</c> (\ref STARPU_CALIBRATE). This may be necessary if your application
  96. has not-so-stable performance. StarPU will force calibration (and thus ignore
  97. the current result) until 10 (<c>_STARPU_CALIBRATION_MINIMUM</c>) measurements have been
  98. made on each architecture, to avoid badly scheduling tasks just because the
  99. first measurements were not so good. Details on the current performance model status
  100. can be obtained from the command <c>starpu_perfmodel_display</c>: the <c>-l</c>
  101. option lists the available performance models, and the <c>-s</c> option permits
  102. to choose the performance model to be displayed. The result looks like:
  103. \verbatim
  104. $ starpu_perfmodel_display -s starpu_slu_lu_model_11
  105. performance model for cpu_impl_0
  106. # hash size flops mean dev n
  107. 914f3bef 1048576 0.000000e+00 2.503577e+04 1.982465e+02 8
  108. 3e921964 65536 0.000000e+00 5.527003e+02 1.848114e+01 7
  109. e5a07e31 4096 0.000000e+00 1.717457e+01 5.190038e+00 14
  110. ...
  111. \endverbatim
  112. Which shows that for the LU 11 kernel with a 1MiB matrix, the average
  113. execution time on CPUs was about 25ms, with a 0.2ms standard deviation, over
  114. 8 samples. It is a good idea to check this before doing actual performance
  115. measurements.
  116. A graph can be drawn by using the tool <c>starpu_perfmodel_plot</c>:
  117. \verbatim
  118. $ starpu_perfmodel_plot -s starpu_slu_lu_model_11
  119. 4096 16384 65536 262144 1048576 4194304
  120. $ gnuplot starpu_starpu_slu_lu_model_11.gp
  121. $ gv starpu_starpu_slu_lu_model_11.eps
  122. \endverbatim
  123. \image html starpu_starpu_slu_lu_model_11.png
  124. \image latex starpu_starpu_slu_lu_model_11.eps "" width=\textwidth
  125. If a kernel source code was modified (e.g. performance improvement), the
  126. calibration information is stale and should be dropped, to re-calibrate from
  127. start. This can be done by using <c>export STARPU_CALIBRATE=2</c> (\ref STARPU_CALIBRATE).
  128. Note: history-based performance models get calibrated
  129. only if a performance-model-based scheduler is chosen.
  130. The history-based performance models can also be explicitly filled by the
  131. application without execution, if e.g. the application already has a series of
  132. measurements. This can be done by using starpu_perfmodel_update_history(),
  133. for instance:
  134. \code{.c}
  135. static struct starpu_perfmodel perf_model = {
  136. .type = STARPU_HISTORY_BASED,
  137. .symbol = "my_perfmodel",
  138. };
  139. struct starpu_codelet cl = {
  140. .cuda_funcs = { cuda_func1, cuda_func2 },
  141. .nbuffers = 1,
  142. .modes = {STARPU_W},
  143. .model = &perf_model
  144. };
  145. void feed(void) {
  146. struct my_measure *measure;
  147. struct starpu_task task;
  148. starpu_task_init(&task);
  149. task.cl = &cl;
  150. for (measure = &measures[0]; measure < measures[last]; measure++) {
  151. starpu_data_handle_t handle;
  152. starpu_vector_data_register(&handle, -1, 0, measure->size, sizeof(float));
  153. task.handles[0] = handle;
  154. starpu_perfmodel_update_history(&perf_model, &task,
  155. STARPU_CUDA_DEFAULT + measure->cudadev, 0,
  156. measure->implementation, measure->time);
  157. starpu_task_clean(&task);
  158. starpu_data_unregister(handle);
  159. }
  160. }
  161. \endcode
  162. Measurement has to be provided in milliseconds for the completion time models,
  163. and in Joules for the energy consumption models.
  164. \section Profiling Profiling
  165. A quick view of how many tasks each worker has executed can be obtained by setting
  166. <c>export STARPU_WORKER_STATS=1</c> (\ref STARPU_WORKER_STATS). This is a convenient way to check that
  167. execution did happen on accelerators, without penalizing performance with
  168. the profiling overhead.
  169. A quick view of how much data transfers have been issued can be obtained by setting
  170. <c>export STARPU_BUS_STATS=1</c> (\ref STARPU_BUS_STATS).
  171. More detailed profiling information can be enabled by using <c>export STARPU_PROFILING=1</c> (\ref STARPU_PROFILING)
  172. or by
  173. calling starpu_profiling_status_set() from the source code.
  174. Statistics on the execution can then be obtained by using <c>export
  175. STARPU_BUS_STATS=1</c> and <c>export STARPU_WORKER_STATS=1</c> .
  176. More details on performance feedback are provided in the next chapter.
  177. */