starpu_profiling.h 9.7 KB

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