starpu_profiling.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2014,2016,2017,2019 Université de Bordeaux
  4. * Copyright (C) 2010,2011,2013,2015,2017,2019 CNRS
  5. * Copyright (C) 2016 Inria
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #ifndef __STARPU_PROFILING_H__
  19. #define __STARPU_PROFILING_H__
  20. #include <starpu.h>
  21. #include <errno.h>
  22. #include <time.h>
  23. #ifdef __cplusplus
  24. extern "C"
  25. {
  26. #endif
  27. /**
  28. @defgroup API_Profiling Profiling
  29. @{
  30. */
  31. /**
  32. Used when calling the function starpu_profiling_status_set() to disable profiling.
  33. */
  34. #define STARPU_PROFILING_DISABLE 0
  35. /**
  36. Used when calling the function starpu_profiling_status_set() to enable profiling.
  37. */
  38. #define STARPU_PROFILING_ENABLE 1
  39. /**
  40. Information about the execution of a task. It is accessible from
  41. the field starpu_task::profiling_info if profiling was enabled.
  42. */
  43. struct starpu_profiling_task_info
  44. {
  45. /** Date of task submission (relative to the initialization of StarPU). */
  46. struct timespec submit_time;
  47. /** Time when the task was submitted to the scheduler. */
  48. struct timespec push_start_time;
  49. /** Time when the scheduler finished with the task submission. */
  50. struct timespec push_end_time;
  51. /** Time when the scheduler started to be requested for a task, and eventually gave that task. */
  52. struct timespec pop_start_time;
  53. /** Time when the scheduler finished providing the task for execution. */
  54. struct timespec pop_end_time;
  55. /** Time when the worker started fetching input data. */
  56. struct timespec acquire_data_start_time;
  57. /** Time when the worker finished fetching input data. */
  58. struct timespec acquire_data_end_time;
  59. /** Date of task execution beginning (relative to the initialization of StarPU). */
  60. struct timespec start_time;
  61. /** Date of task execution termination (relative to the initialization of StarPU). */
  62. struct timespec end_time;
  63. /** Time when the worker started releasing data. */
  64. struct timespec release_data_start_time;
  65. /** Time when the worker finished releasing data. */
  66. struct timespec release_data_end_time;
  67. /** Time when the worker started the application callback for the task. */
  68. struct timespec callback_start_time;
  69. /** Time when the worker finished the application callback for the task. */
  70. struct timespec callback_end_time;
  71. /* TODO add expected length, expected start/end ? */
  72. /** Identifier of the worker which has executed the task. */
  73. int workerid;
  74. /** Number of cycles used by the task, only available in the MoviSim */
  75. uint64_t used_cycles;
  76. /** Number of cycles stalled within the task, only available in the MoviSim */
  77. uint64_t stall_cycles;
  78. /** Energy consumed by the task, in Joules */
  79. double energy_consumed;
  80. };
  81. /**
  82. Profiling information associated to a worker. The timing is
  83. provided since the previous call to
  84. starpu_profiling_worker_get_info()
  85. */
  86. struct starpu_profiling_worker_info
  87. {
  88. /** Starting date for the reported profiling measurements. */
  89. struct timespec start_time;
  90. /** Duration of the profiling measurement interval. */
  91. struct timespec total_time;
  92. /** Time spent by the worker to execute tasks during the profiling measurement interval. */
  93. struct timespec executing_time;
  94. /** Time spent idling by the worker during the profiling measurement interval. */
  95. struct timespec sleeping_time;
  96. /** Number of tasks executed by the worker during the profiling measurement interval. */
  97. int executed_tasks;
  98. /** Number of cycles used by the worker, only available in the MoviSim */
  99. uint64_t used_cycles;
  100. /** Number of cycles stalled within the worker, only available in the MoviSim */
  101. uint64_t stall_cycles;
  102. /** Energy consumed by the worker, in Joules */
  103. double energy_consumed;
  104. /* TODO: add wasted time due to failed tasks */
  105. double flops;
  106. };
  107. struct starpu_profiling_bus_info
  108. {
  109. /** Time of bus profiling startup. */
  110. struct timespec start_time;
  111. /** Total time of bus profiling. */
  112. struct timespec total_time;
  113. /** Number of bytes transferred during profiling. */
  114. int long long transferred_bytes;
  115. /** Number of transfers during profiling. */
  116. int transfer_count;
  117. };
  118. /**
  119. Reset performance counters and enable profiling if the
  120. environment variable \ref STARPU_PROFILING is set to a positive value.
  121. */
  122. void starpu_profiling_init(void);
  123. /**
  124. Set the ID used for profiling trace filename. Has to be called before starpu_init().
  125. */
  126. void starpu_profiling_set_id(int new_id);
  127. /**
  128. Set the profiling status. Profiling is activated
  129. by passing \ref STARPU_PROFILING_ENABLE in \p status. Passing
  130. \ref STARPU_PROFILING_DISABLE disables profiling. Calling this function
  131. resets all profiling measurements. When profiling is enabled, the
  132. field starpu_task::profiling_info points to a valid structure
  133. starpu_profiling_task_info containing information about the execution
  134. of the task. Negative return values indicate an error, otherwise the
  135. previous status is returned.
  136. */
  137. int starpu_profiling_status_set(int status);
  138. /**
  139. Return the current profiling status or a negative value in case
  140. there was an error.
  141. */
  142. int starpu_profiling_status_get(void);
  143. #ifdef BUILDING_STARPU
  144. #include <common/utils.h>
  145. #ifdef __GNUC__
  146. extern int _starpu_profiling;
  147. #define starpu_profiling_status_get() ({ \
  148. int __ret; \
  149. ANNOTATE_HAPPENS_AFTER(&_starpu_profiling); \
  150. __ret = _starpu_profiling; \
  151. ANNOTATE_HAPPENS_BEFORE(&_starpu_profiling); \
  152. __ret; \
  153. })
  154. #endif
  155. #endif
  156. /**
  157. Get the profiling info associated to the worker identified by
  158. \p workerid, and reset the profiling measurements. If the argument \p
  159. worker_info is <c>NULL</c>, only reset the counters associated to worker
  160. \p workerid. Upon successful completion, this function returns 0.
  161. Otherwise, a negative value is returned.
  162. */
  163. int starpu_profiling_worker_get_info(int workerid, struct starpu_profiling_worker_info *worker_info);
  164. /**
  165. Return the number of buses in the machine
  166. */
  167. int starpu_bus_get_count(void);
  168. /**
  169. Return the identifier of the bus between \p src and \p dst
  170. */
  171. int starpu_bus_get_id(int src, int dst);
  172. /**
  173. Return the source point of bus \p busid
  174. */
  175. int starpu_bus_get_src(int busid);
  176. /**
  177. Return the destination point of bus \p busid
  178. */
  179. int starpu_bus_get_dst(int busid);
  180. void starpu_bus_set_direct(int busid, int direct);
  181. int starpu_bus_get_direct(int busid);
  182. void starpu_bus_set_ngpus(int busid, int ngpus);
  183. int starpu_bus_get_ngpus(int busid);
  184. /**
  185. See _starpu_profiling_bus_helper_display_summary in src/profiling/profiling_helpers.c for a usage example.
  186. Note that calling starpu_bus_get_profiling_info() resets the counters to zero.
  187. */
  188. int starpu_bus_get_profiling_info(int busid, struct starpu_profiling_bus_info *bus_info);
  189. /* Some helper functions to manipulate profiling API output */
  190. /* Reset timespec */
  191. static __starpu_inline void starpu_timespec_clear(struct timespec *tsp)
  192. {
  193. tsp->tv_sec = 0;
  194. tsp->tv_nsec = 0;
  195. }
  196. #define STARPU_NS_PER_S 1000000000
  197. /* Computes result = a + b */
  198. static __starpu_inline void starpu_timespec_add(struct timespec *a,
  199. struct timespec *b,
  200. struct timespec *result)
  201. {
  202. result->tv_sec = a->tv_sec + b->tv_sec;
  203. result->tv_nsec = a->tv_nsec + b->tv_nsec;
  204. if (result->tv_nsec >= STARPU_NS_PER_S)
  205. {
  206. ++(result)->tv_sec;
  207. result->tv_nsec -= STARPU_NS_PER_S;
  208. }
  209. }
  210. /* Computes res += b */
  211. static __starpu_inline void starpu_timespec_accumulate(struct timespec *result,
  212. struct timespec *a)
  213. {
  214. result->tv_sec += a->tv_sec;
  215. result->tv_nsec += a->tv_nsec;
  216. if (result->tv_nsec >= STARPU_NS_PER_S)
  217. {
  218. ++(result)->tv_sec;
  219. result->tv_nsec -= STARPU_NS_PER_S;
  220. }
  221. }
  222. /* Computes result = a - b */
  223. static __starpu_inline void starpu_timespec_sub(const struct timespec *a,
  224. const struct timespec *b,
  225. struct timespec *result)
  226. {
  227. result->tv_sec = a->tv_sec - b->tv_sec;
  228. result->tv_nsec = a->tv_nsec - b->tv_nsec;
  229. if ((result)->tv_nsec < 0)
  230. {
  231. --(result)->tv_sec;
  232. result->tv_nsec += STARPU_NS_PER_S;
  233. }
  234. }
  235. #define starpu_timespec_cmp(a, b, CMP) \
  236. (((a)->tv_sec == (b)->tv_sec) ? ((a)->tv_nsec CMP (b)->tv_nsec) : ((a)->tv_sec CMP (b)->tv_sec))
  237. /**
  238. Return the time elapsed between \p start and \p end in microseconds.
  239. */
  240. double starpu_timing_timespec_delay_us(struct timespec *start, struct timespec *end);
  241. /**
  242. Convert the given timespec \p ts into microseconds
  243. */
  244. double starpu_timing_timespec_to_us(struct timespec *ts);
  245. /**
  246. Display statistics about the bus on \c stderr. if the environment
  247. variable \ref STARPU_BUS_STATS is defined. The function is called
  248. automatically by starpu_shutdown().
  249. */
  250. void starpu_profiling_bus_helper_display_summary(void);
  251. /**
  252. Display statistic about the workers on \c stderr if the
  253. environment variable \ref STARPU_WORKER_STATS is defined. The function is
  254. called automatically by starpu_shutdown().
  255. */
  256. void starpu_profiling_worker_helper_display_summary(void);
  257. /**
  258. Display statistics about the current data handles registered
  259. within StarPU. StarPU must have been configured with the configure
  260. option \ref enable-memory-stats "--enable-memory-stats" (see \ref
  261. MemoryFeedback).
  262. */
  263. void starpu_data_display_memory_stats();
  264. /** @} */
  265. #ifdef __cplusplus
  266. }
  267. #endif
  268. #endif /* __STARPU_PROFILING_H__ */