05check_list_performance.doxy 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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 CNRS
  5. * Copyright (C) 2011, 2012 INRIA
  6. * See the file version.doxy for copying conditions.
  7. */
  8. /*! \page CheckListWhenPerformanceAreNotThere Check List When Performance Are Not There
  9. TODO: improve!
  10. To achieve good
  11. performance, we give below a list of features which should be checked.
  12. \section ConfigurationImprovePerformance Configuration That May Improve Performance
  13. The \ref enable-fast "--enable-fast" configuration option disables all
  14. assertions. This makes starpu more performant for really small tasks by
  15. disabling all sanity checks. Only use this for measurements and production, not for development, since this will drop all basic checks.
  16. \section DataRelatedFeaturesToImprovePerformance Data Related Features That May Improve Performance
  17. link to \ref DataManagement
  18. link to \ref DataPrefetch
  19. \section TaskRelatedFeaturesToImprovePerformance Task Related Features That May Improve Performance
  20. link to \ref TaskGranularity
  21. link to \ref TaskSubmission
  22. link to \ref TaskPriorities
  23. \section SchedulingRelatedFeaturesToImprovePerformance Scheduling Related Features That May Improve Performance
  24. link to \ref TaskSchedulingPolicy
  25. link to \ref TaskDistributionVsDataTransfer
  26. link to \ref Power-basedScheduling
  27. link to \ref StaticScheduling
  28. \section CUDA-specificOptimizations CUDA-specific Optimizations
  29. Due to CUDA limitations, StarPU will have a hard time overlapping its own
  30. communications and the codelet computations if the application does not use a
  31. dedicated CUDA stream for its computations instead of the default stream,
  32. which synchronizes all operations of the GPU. StarPU provides one by the use
  33. of starpu_cuda_get_local_stream() which can be used by all CUDA codelet
  34. operations to avoid this issue. For instance:
  35. \code{.c}
  36. func <<<grid,block,0,starpu_cuda_get_local_stream()>>> (foo, bar);
  37. cudaStreamSynchronize(starpu_cuda_get_local_stream());
  38. \endcode
  39. Unfortunately, some CUDA libraries do not have stream variants of
  40. kernels. That will lower the potential for overlapping.
  41. Calling starpu_cublas_init() makes StarPU already do appropriate calls for the
  42. CUBLAS library. Some libraries like Magma may however change the current stream,
  43. one then has to call cublasSetKernelStream(starpu_cuda_get_local_stream()); at
  44. the beginning of the codelet to make sure that CUBLAS is really using the proper
  45. stream.
  46. If the kernel can be made to only use this local stream or other self-allocated
  47. streams, i.e. the whole kernel submission can be made asynchronous, then
  48. one should enable asynchronous execution of the kernel. That means setting
  49. the flag ::STARPU_CUDA_ASYNC in the corresponding field starpu_codelet::cuda_flags, and dropping the
  50. cudaStreamSynchronize() call at the end of the cuda_func function, so that it
  51. returns immediately after having queued the kernel to the local stream. That way, StarPU will be
  52. able to submit and complete data transfers while kernels are executing, instead of only at each
  53. kernel submission. The kernel just has to make sure that StarPU can use the
  54. local stream to synchronize with the kernel startup and completion.
  55. Using the flag ::STARPU_CUDA_ASYNC also permits to enable concurrent kernel
  56. execution, on cards which support it (Kepler and later, notably). This is
  57. enabled by setting the environment variable \ref STARPU_NWORKER_PER_CUDA to the
  58. number of kernels to execute concurrently. This is useful when kernels are
  59. small and do not feed the whole GPU with threads to run.
  60. \section OpenCL-specificOptimizations OpenCL-specific Optimizations
  61. If the kernel can be made to only use the StarPU-provided command queue or other self-allocated
  62. queues, i.e. the whole kernel submission can be made asynchronous, then
  63. one should enable asynchronous execution of the kernel. This means setting
  64. the flag ::STARPU_OPENCL_ASYNC in the corresponding field starpu_codelet::opencl_flags and dropping the
  65. clFinish() and starpu_opencl_collect_stats() calls at the end of the kernel, so
  66. that it returns immediately after having queued the kernel to the provided queue.
  67. That way, StarPU will be able to submit and complete data transfers while kernels are executing, instead of
  68. only at each kernel submission. The kernel just has to make sure
  69. that StarPU can use the command queue it has provided to synchronize with the
  70. kernel startup and completion.
  71. \section DetectionStuckConditions Detecting Stuck Conditions
  72. It may happen that for some reason, StarPU does not make progress for a long
  73. period of time. Reason are sometimes due to contention inside StarPU, but
  74. sometimes this is due to external reasons, such as stuck MPI driver, or CUDA
  75. driver, etc.
  76. <c>export STARPU_WATCHDOG_TIMEOUT=10000</c> (\ref STARPU_WATCHDOG_TIMEOUT)
  77. allows to make StarPU print an error message whenever StarPU does not terminate
  78. any task for 10ms, but lets the application continue normally. In addition to that,
  79. <c>export STARPU_WATCHDOG_CRASH=1</c> (\ref STARPU_WATCHDOG_CRASH)
  80. raises SIGABRT in that condition, thus allowing to catch the situation in gdb.
  81. It can also be useful to type "handle SIGABRT nopass" in gdb to be able to let
  82. the process continue, after inspecting the state of the process.
  83. \section HowToLimitMemoryPerNode How to limit memory used by StarPU and cache buffer allocations
  84. By default, StarPU makes sure to use at most 90% of the memory of GPU devices,
  85. moving data in and out of the device as appropriate and with prefetch and
  86. writeback optimizations. Concerning the main memory, by default it will not
  87. limit its consumption, since by default it has nowhere to push the data to when
  88. memory gets tight. This also means that by default StarPU will not cache buffer
  89. allocations in main memory, since it does not know how much of the system memory
  90. it can afford.
  91. In the case of GPUs, the \ref STARPU_LIMIT_CUDA_MEM, \ref
  92. STARPU_LIMIT_CUDA_devid_MEM, \ref STARPU_LIMIT_OPENCL_MEM, and \ref
  93. STARPU_LIMIT_OPENCL_devid_MEM environment variables can be used to control how
  94. much (in MiB) of the GPU device memory should be used at most by StarPU (their
  95. default values are 90% of the available memory).
  96. In the case of the main memory, the \ref STARPU_LIMIT_CPU_MEM environment
  97. variable can be used to specify how much (in MiB) of the main memory should be
  98. used at most by StarPU for buffer allocations. This way, StarPU will be able to
  99. cache buffer allocations (which can be a real benefit if a lot of bufferes are
  100. involved, or if allocation fragmentation can become a problem), and when using
  101. \ref OutOfCore, StarPU will know when it should evict data out to the disk.
  102. It should be noted that by default only buffer allocations automatically
  103. done by StarPU are accounted here, i.e. allocations performed through
  104. <c>starpu_malloc_on_node()</c> which are used by the data interfaces
  105. (matrix, vector, etc.). This does not include allocations performed by
  106. the application through e.g. malloc(). It does not include allocations
  107. performed through <c>starpu_malloc()</c> either, only allocations
  108. performed explicitly with the \ref STARPU_MALLOC_COUNT flag (i.e. through
  109. <c>starpu_malloc_flags(STARPU_MALLOC_COUNT)</c>) are taken into account. If the
  110. application wants to make StarPU aware of its own allocations, so that StarPU
  111. knows precisely how much data is allocated, and thus when to evict allocation
  112. caches or data out to the disk, \ref starpu_memory_allocate can be used to
  113. specify an amount of memory to be accounted for. \ref starpu_memory_deallocate
  114. can be used to account freed memory back. Those can for instance be used by data
  115. interfaces with dynamic data buffers: instead of using starpu_malloc_on_node,
  116. they would dynamically allocate data with malloc/realloc, and notify starpu of
  117. the delta thanks to starpu_memory_allocate and starpu_memory_deallocate calls.
  118. \ref starpu_memory_get_total and \ref starpu_memory_get_available
  119. can be used to get an estimation of how much memory is available.
  120. \ref starpu_memory_wait_available can also be used to block until an
  121. amount of memory becomes available (but it may be preferrable to use
  122. <c>starpu_memory_allocate(STARPU_MEMORY_WAIT)</c> to reserve that amount
  123. immediately).
  124. \section HowToReduceTheMemoryFootprintOfInternalDataStructures How To Reduce The Memory Footprint Of Internal Data Structures
  125. It is possible to reduce the memory footprint of the task and data internal
  126. structures of StarPU by describing the shape of your machine and/or your
  127. application at the configure step.
  128. To reduce the memory footprint of the data internal structures of StarPU, one
  129. can set the \ref enable-maxcpus "--enable-maxcpus", \ref enable-maxcudadev
  130. "--enable-maxcudadev", \ref enable-maxopencldev "--enable-maxopencldev" and
  131. \ref enable-maxnodes "--enable-maxnodes" configure parameters to give StarPU
  132. the architecture of the machine it will run on, thus tuning the size of the
  133. structures to the machine.
  134. To reduce the memory footprint of the task internal structures of StarPU, one
  135. can set the \ref enable-maxbuffers "--enable-maxbuffers" configure parameter to
  136. give StarPU the maximum number of buffers that a task can use during an
  137. execution. For example, in the Cholesky factorization (dense linear algebra
  138. application), the GEMM task uses up to 3 buffers, so it is possible to set the
  139. maximum number of task buffers to 3 to run a Cholesky factorization on StarPU.
  140. It is also often useless to submit *all* the tasks at the same time. One can
  141. make the starpu_task_submit function block when a reasonable given number of
  142. tasks have been submitted, by setting the STARPU_LIMIT_MIN_SUBMITTED_TASKS and
  143. STARPU_LIMIT_MAX_SUBMITTED_TASKS environment variables, for instance:
  144. <c>
  145. export STARPU_LIMIT_MAX_SUBMITTED_TASKS=10000
  146. export STARPU_LIMIT_MIN_SUBMITTED_TASKS=9000
  147. </c>
  148. To make StarPU block submission when 10000 tasks are submitted, and unblock
  149. submission when only 9000 tasks are submitted. Of course this may reduce
  150. parallelism if the threshold is set too low. The precise balance depends on the
  151. application task graph.
  152. \section HowtoReuseMemory How to reuse memory
  153. When your application needs to allocate more data than the available amount of
  154. memory usable by StarPU (given by \ref starpu_memory_get_available() ), the
  155. allocation cache system can reuse data buffers used by previously executed
  156. tasks. For that system to work with MPI tasks, you need to submit tasks progressively instead
  157. of as soon as possible, because in the case of MPI receives, the allocation cache check for reusing data
  158. buffers will be done at submission time, not at execution time.
  159. You have two options to control the task submission flow. The first one is by
  160. controlling the number of submitted tasks during the whole execution. This can
  161. be done whether by setting the environment variables \ref
  162. STARPU_LIMIT_MAX_NSUBMITTED_TASKS and \ref STARPU_LIMIT_MIN_NSUBMITTED_TASKS to
  163. tell StarPU when to stop submitting tasks and when to wake up and submit tasks
  164. again, or by explicitely calling \ref starpu_task_wait_for_n_submitted() in
  165. your application code for finest grain control (for example, between two
  166. iterations of a submission loop).
  167. The second option is to control the memory size of the allocation cache. This
  168. can be done in the application by using jointly \ref
  169. starpu_memory_get_available() and \ref starpu_memory_wait_available() to submit
  170. tasks only when there is enough memory space to allocate the data needed by the
  171. task, i.e when enough data are available for reuse in the allocation cache.
  172. \section PerformanceModelCalibration Performance Model Calibration
  173. Most schedulers are based on an estimation of codelet duration on each kind
  174. of processing unit. For this to be possible, the application programmer needs
  175. to configure a performance model for the codelets of the application (see
  176. \ref PerformanceModelExample for instance). History-based performance models
  177. use on-line calibration. StarPU will automatically calibrate codelets
  178. which have never been calibrated yet, and save the result in
  179. <c>$STARPU_HOME/.starpu/sampling/codelets</c>.
  180. The models are indexed by machine name. To share the models between
  181. machines (e.g. for a homogeneous cluster), use <c>export
  182. STARPU_HOSTNAME=some_global_name</c> (\ref STARPU_HOSTNAME). To force continuing calibration,
  183. use <c>export STARPU_CALIBRATE=1</c> (\ref STARPU_CALIBRATE). This may be necessary if your application
  184. has not-so-stable performance. StarPU will force calibration (and thus ignore
  185. the current result) until 10 (<c>_STARPU_CALIBRATION_MINIMUM</c>) measurements have been
  186. made on each architecture, to avoid badly scheduling tasks just because the
  187. first measurements were not so good. Details on the current performance model status
  188. can be obtained from the command <c>starpu_perfmodel_display</c>: the <c>-l</c>
  189. option lists the available performance models, and the <c>-s</c> option permits
  190. to choose the performance model to be displayed. The result looks like:
  191. \verbatim
  192. $ starpu_perfmodel_display -s starpu_slu_lu_model_11
  193. performance model for cpu_impl_0
  194. # hash size flops mean dev n
  195. 914f3bef 1048576 0.000000e+00 2.503577e+04 1.982465e+02 8
  196. 3e921964 65536 0.000000e+00 5.527003e+02 1.848114e+01 7
  197. e5a07e31 4096 0.000000e+00 1.717457e+01 5.190038e+00 14
  198. ...
  199. \endverbatim
  200. Which shows that for the LU 11 kernel with a 1MiB matrix, the average
  201. execution time on CPUs was about 25ms, with a 0.2ms standard deviation, over
  202. 8 samples. It is a good idea to check this before doing actual performance
  203. measurements.
  204. A graph can be drawn by using the tool <c>starpu_perfmodel_plot</c>:
  205. \verbatim
  206. $ starpu_perfmodel_plot -s starpu_slu_lu_model_11
  207. 4096 16384 65536 262144 1048576 4194304
  208. $ gnuplot starpu_starpu_slu_lu_model_11.gp
  209. $ gv starpu_starpu_slu_lu_model_11.eps
  210. \endverbatim
  211. \image html starpu_starpu_slu_lu_model_11.png
  212. \image latex starpu_starpu_slu_lu_model_11.eps "" width=\textwidth
  213. If a kernel source code was modified (e.g. performance improvement), the
  214. calibration information is stale and should be dropped, to re-calibrate from
  215. start. This can be done by using <c>export STARPU_CALIBRATE=2</c> (\ref STARPU_CALIBRATE).
  216. Note: history-based performance models get calibrated
  217. only if a performance-model-based scheduler is chosen.
  218. The history-based performance models can also be explicitly filled by the
  219. application without execution, if e.g. the application already has a series of
  220. measurements. This can be done by using starpu_perfmodel_update_history(),
  221. for instance:
  222. \code{.c}
  223. static struct starpu_perfmodel perf_model = {
  224. .type = STARPU_HISTORY_BASED,
  225. .symbol = "my_perfmodel",
  226. };
  227. struct starpu_codelet cl = {
  228. .cuda_funcs = { cuda_func1, cuda_func2 },
  229. .nbuffers = 1,
  230. .modes = {STARPU_W},
  231. .model = &perf_model
  232. };
  233. void feed(void) {
  234. struct my_measure *measure;
  235. struct starpu_task task;
  236. starpu_task_init(&task);
  237. task.cl = &cl;
  238. for (measure = &measures[0]; measure < measures[last]; measure++) {
  239. starpu_data_handle_t handle;
  240. starpu_vector_data_register(&handle, -1, 0, measure->size, sizeof(float));
  241. task.handles[0] = handle;
  242. starpu_perfmodel_update_history(&perf_model, &task,
  243. STARPU_CUDA_DEFAULT + measure->cudadev, 0,
  244. measure->implementation, measure->time);
  245. starpu_task_clean(&task);
  246. starpu_data_unregister(handle);
  247. }
  248. }
  249. \endcode
  250. Measurement has to be provided in milliseconds for the completion time models,
  251. and in Joules for the energy consumption models.
  252. \section Profiling Profiling
  253. A quick view of how many tasks each worker has executed can be obtained by setting
  254. <c>export STARPU_WORKER_STATS=1</c> (\ref STARPU_WORKER_STATS). This is a convenient way to check that
  255. execution did happen on accelerators, without penalizing performance with
  256. the profiling overhead.
  257. A quick view of how much data transfers have been issued can be obtained by setting
  258. <c>export STARPU_BUS_STATS=1</c> (\ref STARPU_BUS_STATS).
  259. More detailed profiling information can be enabled by using <c>export STARPU_PROFILING=1</c> (\ref STARPU_PROFILING)
  260. or by
  261. calling starpu_profiling_status_set() from the source code.
  262. Statistics on the execution can then be obtained by using <c>export
  263. STARPU_BUS_STATS=1</c> and <c>export STARPU_WORKER_STATS=1</c> .
  264. More details on performance feedback are provided in the next chapter.
  265. \section OverheadProfiling Overhead Profiling
  266. \ref OfflinePerformanceTools can already provide an idea of to what extent and
  267. which part of StarPU bring overhead on the execution time. To get a more precise
  268. analysis of the parts of StarPU which bring most overhead, gprof can be used.
  269. First, recompile and reinstall StarPU with gprof support:
  270. \code
  271. ./configure --enable-perf-debug --disable-shared --disable-build-tests --disable-build-examples
  272. \endcode
  273. Make sure not to leave a dynamic version of StarPU in the target path: remove
  274. any remaining libstarpu-*.so
  275. Then relink your application with the static StarPU library, make sure that
  276. running ldd on your application does not mention libstarpu (i.e. it's really statically-linked).
  277. \code
  278. gcc test.c -o test $(pkg-config --cflags starpu-1.3) $(pkg-config --libs starpu-1.3)
  279. \endcode
  280. Now you can run your application, and a gmon.out file should appear in the
  281. current directory, you can process by running gprof on your application:
  282. \code
  283. gprof ./test
  284. \endcode
  285. That will dump an analysis of the time spent in StarPU functions.
  286. */