starpu_profiling.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2014,2016,2017 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. /** @defgroup
  21. *
  22. * @{
  23. */
  24. #include <starpu.h>
  25. #include <errno.h>
  26. #include <time.h>
  27. #ifdef __cplusplus
  28. extern "C"
  29. {
  30. #endif
  31. #define STARPU_PROFILING_DISABLE 0
  32. #define STARPU_PROFILING_ENABLE 1
  33. struct starpu_profiling_task_info
  34. {
  35. struct timespec submit_time;
  36. struct timespec push_start_time;
  37. struct timespec push_end_time;
  38. struct timespec pop_start_time;
  39. struct timespec pop_end_time;
  40. struct timespec acquire_data_start_time;
  41. struct timespec acquire_data_end_time;
  42. struct timespec start_time;
  43. struct timespec end_time;
  44. struct timespec release_data_start_time;
  45. struct timespec release_data_end_time;
  46. struct timespec callback_start_time;
  47. struct timespec callback_end_time;
  48. /* TODO add expected length, expected start/end ? */
  49. int workerid;
  50. uint64_t used_cycles;
  51. uint64_t stall_cycles;
  52. double energy_consumed;
  53. };
  54. struct starpu_profiling_worker_info
  55. {
  56. struct timespec start_time;
  57. struct timespec total_time;
  58. struct timespec executing_time;
  59. struct timespec sleeping_time;
  60. int executed_tasks;
  61. uint64_t used_cycles;
  62. uint64_t stall_cycles;
  63. double energy_consumed;
  64. double flops;
  65. };
  66. struct starpu_profiling_bus_info
  67. {
  68. struct timespec start_time;
  69. struct timespec total_time;
  70. int long long transferred_bytes;
  71. int transfer_count;
  72. };
  73. void starpu_profiling_init(void);
  74. void starpu_profiling_set_id(int new_id);
  75. int starpu_profiling_status_set(int status);
  76. int starpu_profiling_status_get(void);
  77. #ifdef BUILDING_STARPU
  78. #include <common/utils.h>
  79. #ifdef __GNUC__
  80. extern int _starpu_profiling;
  81. #define starpu_profiling_status_get() ({ \
  82. int __ret; \
  83. ANNOTATE_HAPPENS_AFTER(&_starpu_profiling); \
  84. __ret = _starpu_profiling; \
  85. ANNOTATE_HAPPENS_BEFORE(&_starpu_profiling); \
  86. __ret; \
  87. })
  88. #endif
  89. #endif
  90. int starpu_profiling_worker_get_info(int workerid, struct starpu_profiling_worker_info *worker_info);
  91. int starpu_bus_get_count(void);
  92. int starpu_bus_get_id(int src, int dst);
  93. int starpu_bus_get_src(int busid);
  94. int starpu_bus_get_dst(int busid);
  95. void starpu_bus_set_direct(int busid, int direct);
  96. int starpu_bus_get_direct(int busid);
  97. void starpu_bus_set_ngpus(int busid, int ngpus);
  98. int starpu_bus_get_ngpus(int busid);
  99. int starpu_bus_get_profiling_info(int busid, struct starpu_profiling_bus_info *bus_info);
  100. /* Some helper functions to manipulate profiling API output */
  101. /* Reset timespec */
  102. static __starpu_inline void starpu_timespec_clear(struct timespec *tsp)
  103. {
  104. tsp->tv_sec = 0;
  105. tsp->tv_nsec = 0;
  106. }
  107. #define STARPU_NS_PER_S 1000000000
  108. /* Computes result = a + b */
  109. static __starpu_inline void starpu_timespec_add(struct timespec *a,
  110. struct timespec *b,
  111. struct timespec *result)
  112. {
  113. result->tv_sec = a->tv_sec + b->tv_sec;
  114. result->tv_nsec = a->tv_nsec + b->tv_nsec;
  115. if (result->tv_nsec >= STARPU_NS_PER_S)
  116. {
  117. ++(result)->tv_sec;
  118. result->tv_nsec -= STARPU_NS_PER_S;
  119. }
  120. }
  121. /* Computes res += b */
  122. static __starpu_inline void starpu_timespec_accumulate(struct timespec *result,
  123. struct timespec *a)
  124. {
  125. result->tv_sec += a->tv_sec;
  126. result->tv_nsec += a->tv_nsec;
  127. if (result->tv_nsec >= STARPU_NS_PER_S)
  128. {
  129. ++(result)->tv_sec;
  130. result->tv_nsec -= STARPU_NS_PER_S;
  131. }
  132. }
  133. /* Computes result = a - b */
  134. static __starpu_inline void starpu_timespec_sub(const struct timespec *a,
  135. const struct timespec *b,
  136. struct timespec *result)
  137. {
  138. result->tv_sec = a->tv_sec - b->tv_sec;
  139. result->tv_nsec = a->tv_nsec - b->tv_nsec;
  140. if ((result)->tv_nsec < 0)
  141. {
  142. --(result)->tv_sec;
  143. result->tv_nsec += STARPU_NS_PER_S;
  144. }
  145. }
  146. #define starpu_timespec_cmp(a, b, CMP) \
  147. (((a)->tv_sec == (b)->tv_sec) ? ((a)->tv_nsec CMP (b)->tv_nsec) : ((a)->tv_sec CMP (b)->tv_sec))
  148. double starpu_timing_timespec_delay_us(struct timespec *start, struct timespec *end);
  149. double starpu_timing_timespec_to_us(struct timespec *ts);
  150. void starpu_profiling_bus_helper_display_summary(void);
  151. void starpu_profiling_worker_helper_display_summary(void);
  152. #ifdef __cplusplus
  153. }
  154. #endif
  155. /** @} */
  156. #endif /* __STARPU_PROFILING_H__ */