starpu_profiling.h 9.7 KB

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